Package org.geotools.jdbc

Examples of org.geotools.jdbc.JDBCDataStore


    private void dropSchema(DataStore ds, String featureTypeName) throws Exception {
        // @todo this needs implementation in geotools
        SimpleFeatureType schema = ds.getSchema(featureTypeName);
        if (schema != null) {
            if (ds instanceof JDBCDataStore) {
                JDBCDataStore dataStore = (JDBCDataStore) ds;
                Connection conn = dataStore.getConnection(Transaction.AUTO_COMMIT);
                Statement st = null;
                try {
                    st = conn.createStatement();
                    st.execute("drop table " + featureTypeName);
                    LOGGER.fine("dropSchema " + featureTypeName + " successful");
                } finally {
                    dataStore.closeSafe(conn);
                    dataStore.closeSafe(st);
                }
            } else {
                LOGGER.warning("Unable to dropSchema " + featureTypeName + " from datastore " + ds.getClass());
            }
        } else {
View Full Code Here


        params.put( JDBCDataStoreFactory.DATABASE.key, databasePath());
        params.put( JDBCDataStoreFactory.DBTYPE.key, "h2");
       
        H2DataStoreFactory fac =  new H2DataStoreFactory();
       
        JDBCDataStore ds = fac.createDataStore(params);

        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setName( "widgets" );
        tb.setSRS( "EPSG:4326");
        tb.add( "g", Point.class );
        tb.add( "name", String.class );
       
        ds.createSchema( tb.buildFeatureType() );
       
        FeatureWriter fw = ds.getFeatureWriterAppend( "widgets", Transaction.AUTO_COMMIT );
        fw.hasNext();
        SimpleFeature sf = (SimpleFeature) fw.next();
        sf.setAttribute("g", new GeometryFactory().createPoint( new Coordinate(1,1)));
        sf.setAttribute( "name", "one");
        fw.write();
       
        fw.hasNext();
        sf = (SimpleFeature) fw.next();
        sf.setAttribute("g", new GeometryFactory().createPoint( new Coordinate(2,2)));
        sf.setAttribute( "name", "two");
        fw.write();
       
        fw.close();
        ds.dispose();
    }
View Full Code Here

     * @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

        }
    }
   
    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

     * @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);
            vt.setEscapeSql(escapeSql);
            ds.addVirtualTable(vt);
            return guessFeatureType(ds, vt.getName(), guessGeometrySrid);
        } finally {
            if(vtName != null) {
                ds.removeVirtualTable(name);
            }
           
        }
    }
View Full Code Here

    @Override
    public boolean initialize(FeatureTypeInfo info,
            DataAccess<? extends FeatureType, ? extends Feature> dataAccess, Name temporaryName)
            throws IOException {
        JDBCDataStore jstore = (JDBCDataStore) dataAccess;
        VirtualTable vt = info.getMetadata().get(FeatureTypeInfo.JDBC_VIRTUAL_TABLE,
                VirtualTable.class);

        FeatureType ft = null;
        // building the virtual table structure is expensive, see if the VT is already registered in
        // the db
        if (jstore.getVirtualTables().containsValue(vt)) {
            // if the virtual table is already registered in the store (and equality in the test
            // above guarantees the structure is the same), we can just get the schema from it
            // directly
            ft = jstore.getSchema(vt.getName());
            // paranoid check: make sure nobody changed the vt structure while we fetched
            // the data (rather unlikely, even more unlikely would be
            if (!jstore.getVirtualTables().containsValue(vt)) {
                ft = null;
            }
        }

        if (ft == null) {
            if (temporaryName != null) {
                jstore.createVirtualTable(new VirtualTable(temporaryName.getLocalPart(), vt));
                return true;
            } else {
                jstore.createVirtualTable(vt);
            }
        }
       
        return false;
    }
View Full Code Here

        params.put( JDBCDataStoreFactory.DBTYPE.key, "h2");
       
        H2DataStoreFactory fac =  new H2DataStoreFactory();
        fac.setBaseDirectory( getTestData().getDataDirectoryRoot() );
       
        JDBCDataStore ds = fac.createDataStore(params);
        try {
            if ( ds.getSchema("widgets") != null ) {
                return;
            }
        }
        catch( Exception e ) {
           
        }
       
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setName( "widgets" );
        tb.setSRS( "EPSG:4326");
        tb.add( "g", Point.class );
        tb.add( "name", String.class );
       
        ds.createSchema( tb.buildFeatureType() );
       
        FeatureWriter fw = ds.getFeatureWriterAppend( "widgets", Transaction.AUTO_COMMIT );
        fw.hasNext();
        SimpleFeature sf = (SimpleFeature) fw.next();
        sf.setAttribute("g", new GeometryFactory().createPoint( new Coordinate(1,1)));
        sf.setAttribute( "name", "one");
        fw.write();
       
        fw.hasNext();
        sf = (SimpleFeature) fw.next();
        sf.setAttribute("g", new GeometryFactory().createPoint( new Coordinate(2,2)));
        sf.setAttribute( "name", "two");
        fw.write();
       
        fw.close();
        ds.dispose();
    }
View Full Code Here

TOP

Related Classes of org.geotools.jdbc.JDBCDataStore

Copyright © 2018 www.massapicom. 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.