Examples of JDBCDataStore


Examples of org.geotools.jdbc.JDBCDataStore

        params.put(PostgisNGDataStoreFactory.SIMPLIFY.key, false);
       
        params.put(DBTYPE.key, dbtype);

        assertTrue(factory.canProcess(params));
        JDBCDataStore store = factory.createDataStore(params);
        assertNotNull(store);
        try {
            // check dialect
            assertTrue(store.getSQLDialect() instanceof PostGISDialect);
            // force connection usage
            assertNotNull(store.getSchema(tname("ft1")));
        } finally {
            store.dispose();
        }
    }
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

        params.put(USER.key, db.getProperty(USER.key));
        params.put(PASSWD.key, db.getProperty(PASSWD.key));
       
        // force simplify off
        params.put(PostgisNGDataStoreFactory.SIMPLIFY.key, false);
        JDBCDataStore store = factory.createDataStore(params);
        assertNotNull(store);
        try {
            // check dialect
            PostGISDialect dialect = (PostGISDialect) store.getSQLDialect();
            assertFalse(dialect.isSimplifyEnabled());
            Set<Hints.Key> baseHints = new HashSet<Key>();
            dialect.addSupportedHints(baseHints);
            assertTrue(baseHints.isEmpty());
        } finally {
            store.dispose();
        }
    }
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

        params.put(PORT.key, db.getProperty(PORT.key));
        params.put(USER.key, db.getProperty(USER.key));
        params.put(PASSWD.key, db.getProperty(PASSWD.key));
       
        // do not specify simplify, on by default
        JDBCDataStore store = factory.createDataStore(params);
        assertNotNull(store);
        try {
            // check dialect
            PostGISDialect dialect = (PostGISDialect) store.getSQLDialect();
            assertTrue(dialect.isSimplifyEnabled());
            Set<Hints.Key> baseHints = new HashSet<Key>();
            dialect.addSupportedHints(baseHints);
            assertFalse(baseHints.isEmpty());
            assertTrue(baseHints.contains(Hints.GEOMETRY_SIMPLIFICATION));
        } finally {
            store.dispose();
        }
    }
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

        e.setLastChange(new Date());

        //pass in teh feature entry to the datsatore as user data
        schema.getUserData().put(FeatureEntry.class, e);

        JDBCDataStore dataStore = dataStore();

        //create the feature table
        dataStore.createSchema(schema);

        //update the metadata tables
        //addGeoPackageContentsEntry(e);

        //update the entry
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

        return "jdbc:postgresql" + "://" + host + ":" + port + "/" + db;
    }
   
    protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOException {
        DataSource ds = super.createDataSource(params, dialect);
        JDBCDataStore closer = new JDBCDataStore();

        if (Boolean.TRUE.equals(CREATE_DB_IF_MISSING.lookUp(params))) {
            // verify we can connect
            Connection cx = null;
            boolean canConnect = true;
            try {
                cx = ds.getConnection();
            } catch (SQLException e) {
                canConnect = false;
            } finally {
                closer.closeSafe(cx);
            }

            if (!canConnect) {
                // get the connection params
                String host = (String) HOST.lookUp(params);
                int port = (Integer) PORT.lookUp(params);
                String db = (String) DATABASE.lookUp(params);
                String user = (String) USER.lookUp(params);
                String password = (String) PASSWD.lookUp(params);

                Statement st = null;
                try {
                    // connect to template1 instead
                    String url = "jdbc:postgresql" + "://" + host + ":" + port + "/template1";
                    cx = getConnection(user, password, url);

                    // create the database

                    String createParams = (String) CREATE_PARAMS.lookUp(params);
                    String sql = "CREATE DATABASE \"" + db + "\" " + (createParams == null ? "" : createParams);
                    st = cx.createStatement();
                    st.execute(sql);
                } catch (SQLException e) {
                    throw new IOException("Failed to create the target database", e);
                } finally {
                    closer.closeSafe(st);
                    closer.closeSafe(cx);
                }

                // if we got here the database has been created, now verify it has the postgis
                // extensions
                // and eventually try to create them
                ResultSet rs = null;
                try {
                    String url = "jdbc:postgresql" + "://" + host + ":" + port + "/" + db;
                    cx = DriverManager.getConnection(url, user, password);

                    // check we have postgis
                    st = cx.createStatement();
                    try {
                        rs = st.executeQuery("select PostGIS_version()");
                        rs.close();
                    } catch (SQLException e) {
                        // not available eh? create it
                        st.execute("create extension postgis");
                    }
                } catch (SQLException e) {
                    throw new IOException("Failed to create the target database", e);
                } finally {
                    closer.closeSafe(st);
                    closer.closeSafe(cx);
                }

                // and finally re-create the connection pool
                ds = super.createDataSource(params, dialect);
            }
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

     * the user must have the necessary privileges
     * @param params
     * @throws IOException
     */
    public void dropDatabase(Map<String, Object> params) throws IOException {
        JDBCDataStore closer = new JDBCDataStore();
        // get the connection params
        String host = (String) HOST.lookUp(params);
        int port = (Integer) PORT.lookUp(params);
        String db = (String) DATABASE.lookUp(params);
        String user = (String) USER.lookUp(params);
        String password = (String) PASSWD.lookUp(params);

        Connection cx = null;
        Statement st = null;
        try {
            // connect to template1 instead
            String url = "jdbc:postgresql" + "://" + host + ":" + port + "/template1";
            cx = getConnection(user, password, url);

            // drop the database
            String sql = "DROP DATABASE \"" + db + "\"";
            st = cx.createStatement();
            st.execute(sql);
        } catch (SQLException e) {
            throw new IOException("Failed to drop the target database", e);
        } finally {
            closer.closeSafe(st);
            closer.closeSafe(cx);
        }

    }
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

     * @return
     * @throws IOException
     */
    protected SimpleFeatureType testViewDefinition(boolean guessGeometrySrid) throws IOException {
        // check out if the view can be used
        JDBCDataStore ds = (JDBCDataStore) getCatalog().getDataStore(storeId).getDataStore(null);
        String vtName = null;
        try {
            // use a highly random name
            do {
                vtName = UUID.randomUUID().toString();
            } while (Arrays.asList(ds.getTypeNames()).contains(vtName));

            // try adding the vt and see if that works
            VirtualTable vt = new VirtualTable(vtName, sql);
            paramProvider.updateVirtualTable(vt);
            ds.addVirtualTable(vt);
            return guessFeatureType(ds, vt.getName(), guessGeometrySrid);
        } finally {
            if(vtName != null) {
                ds.removeVirtualTable(vtName);
            }
           
        }
    }
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

        }
    }
   
    protected SimpleFeatureType getFeatureType(VirtualTable vt) throws IOException {
     // check out if the view can be used
        JDBCDataStore ds = (JDBCDataStore) getCatalog().getDataStore(storeId).getDataStore(null);
        String vtName = null;
        try {
            // use a highly random name
            do {
                vtName = UUID.randomUUID().toString();
            } while (Arrays.asList(ds.getTypeNames()).contains(vtName));

            // try adding the vt and see if that works
            ds.addVirtualTable(new VirtualTable(vtName, vt));
            return ds.getSchema(vtName);
        } finally {
            if(vtName != null) {
                ds.removeVirtualTable(vtName);
            }
           
        }
    }
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

     * @return
     * @throws IOException
     */
    protected SimpleFeatureType testViewDefinition(VirtualTable virtualTable, boolean guessGeometrySrid) throws IOException {
        // check out if the view can be used
        JDBCDataStore ds = (JDBCDataStore) getCatalog().getDataStore(storeId).getDataStore(null);
        String vtName = null;
        try {
            // use a highly random name
            do {
                vtName = UUID.randomUUID().toString();
            } while (Arrays.asList(ds.getTypeNames()).contains(vtName));

            // try adding the vt and see if that works
            VirtualTable vt = new VirtualTable(vtName, virtualTable);
            // hide the primary key definitions or we'll loose some columns
            vt.setPrimaryKeyColumns(Collections.EMPTY_LIST);
            ds.addVirtualTable(vt);
            return guessFeatureType(ds, vt.getName(), guessGeometrySrid);
        } finally {
            if(vtName != null) {
                ds.removeVirtualTable(name);
            }
           
        }
    }
View Full Code Here

Examples of org.geotools.jdbc.JDBCDataStore

                    // sql view handling
                    VirtualTable vt = null;
                    String vtName = null;
                    if(dataAccess instanceof JDBCDataStore && info.getMetadata() != null &&
                            (info.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE) instanceof VirtualTable)) {
                        JDBCDataStore jstore = (JDBCDataStore) dataAccess;
                        vt = info.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, VirtualTable.class);
                       
                        if(!cacheable) {
                            // use a highly random name, we don't want to actually add the
                            // virtual table to the store as this feature type is not cacheable,
                            // it is "dirty" or un-saved. The renaming below will take care
                            // of making the user see the actual name
                            final String[] typeNames = jstore.getTypeNames();
                            do {
                                vtName = UUID.randomUUID().toString();
                            } while (Arrays.asList(typeNames).contains(vtName));
   
                            // try adding the vt and see if that works
                            jstore.addVirtualTable(new VirtualTable(vtName, vt));
                            ft = jstore.getSchema(vtName);
                        } else {
                            vtName = vt.getName();
                            jstore.addVirtualTable(vt);
                            ft = jstore.getSchema(vt.getName());
                        }
                    } else {
                        ft = dataAccess.getSchema(info.getQualifiedNativeName());
                    }
                   
                    // TODO: support reprojection for non-simple FeatureType
                    if (ft instanceof SimpleFeatureType) {
                        SimpleFeatureType sft = (SimpleFeatureType) ft;
                        //create the feature type so it lines up with the "declared" schema
                        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
                        tb.setName( info.getName() );
                        tb.setNamespaceURI( info.getNamespace().getURI() );

                        if ( info.getAttributes() == null || info.getAttributes().isEmpty() ) {
                            //take this to mean just load all native
                            for ( PropertyDescriptor pd : ft.getDescriptors() ) {
                                if ( !( pd instanceof AttributeDescriptor ) ) {
                                    continue;
                                }
                               
                                AttributeDescriptor ad = (AttributeDescriptor) pd;
                                if(handleProjectionPolicy) {
                                    ad = handleDescriptor(ad, info);
                                }
                                tb.add( ad );
                            }
                        }
                        else {
                            //only load native attributes configured
                            for ( AttributeTypeInfo att : info.getAttributes() ) {
                                String attName = att.getName();
                               
                                //load the actual underlying attribute type
                                PropertyDescriptor pd = ft.getDescriptor( attName );
                                if ( pd == null || !( pd instanceof AttributeDescriptor) ) {
                                    throw new IOException("the SimpleFeatureType " + info.getPrefixedName()
                                            + " does not contains the configured attribute " + attName
                                            + ". Check your schema configuration");
                                }
                           
                                AttributeDescriptor ad = (AttributeDescriptor) pd;
                                ad = handleDescriptor(ad, info);
                                tb.add( (AttributeDescriptor) ad );
                            }
                        }
                        ft = tb.buildFeatureType();
                    } // end special case for SimpleFeatureType
                   
                    if(cacheable) {
                        featureTypeCache.put( info.getId(), ft );
                    } else if(vtName != null) {
                        JDBCDataStore jstore = (JDBCDataStore) dataAccess;
                        jstore.removeVirtualTable(vtName);
                    }
                }
            }
        }
       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.