private static void insert( FeatureStore fs, String datasetFile, GMLVersion gmlVersion, IDGenMode mode ) throws XMLStreamException, FactoryConfigurationError, IOException, XMLParsingException, UnknownCRSException, FeatureStoreException { File f = new File( datasetFile ); URL url = f.toURI().toURL(); System.out.print( "- Reading dataset: '" + datasetFile + "'..." ); GMLStreamReader gmlReader = GMLInputFactory.createGMLStreamReader( gmlVersion, url ); gmlReader.setApplicationSchema( fs.getSchema() ); FeatureCollection fc = gmlReader.readFeatureCollection(); System.out.println( "done." ); FeatureStoreTransaction ta = null; try { ta = fs.acquireTransaction(); System.out.print( "- Inserting features..." ); List<String> fids = ta.performInsert( fc, mode ); System.out.println( "done." ); for ( String fid : fids ) { System.out.println( "- Inserted: " + fid ); } System.out.println( "\n- Insert succeeded (" + fids.size() + " features). Committing transaction." ); ta.commit(); } catch ( Exception e ) { e.printStackTrace(); System.err.println( "Error performing insert: " + e.getMessage() ); if ( ta != null ) { ta.rollback(); } } }
int fids = ta.performInsert( fc, USE_EXISTING ).size(); LOG.info( "Inserted " + fids + " features." ); ta.commit(); } catch ( Exception e ) { String msg = Messages.getMessage( "STORE_MANAGER_STORE_SETUP_ERROR", e.getMessage() );