private FeatureStoreTransaction acquireTransaction( FeatureStore fs ) throws OWSException { FeatureStoreTransaction ta = acquiredTransactions.get( fs ); if ( ta == null ) { try { LOG.debug( "Acquiring transaction for feature store " + fs ); ta = fs.acquireTransaction(); acquiredTransactions.put( fs, ta ); } catch ( FeatureStoreException e ) { throw new OWSException( Messages.get( "WFS_CANNOT_ACQUIRE_TA", e.getMessage() ), NO_APPLICABLE_CODE ); } } return ta; }
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(); } } }