@Override public boolean next() throws MetadataStoreException { try { return rs.next(); } catch ( SQLException e ) { throw new MetadataStoreException( e.getMessage(), e ); } }
@Override public void skip( int rows ) throws MetadataStoreException { try { for ( int i = 0; i < rows; i++ ) { rs.next(); } } catch ( SQLException e ) { throw new MetadataStoreException( e.getMessage(), e ); } }
private void deleteFile( TransactionStatus status, File file ) throws MetadataStoreException { boolean deleted = file.delete(); LOG.debug( "File {} was " + ( deleted ? "successful" : "not" ) + " deleted", file ); if ( !deleted ) throw new MetadataStoreException( "Commit failed: could not " + status + " record at " + file ); }
@Override public int getRemaining() throws MetadataStoreException { int i = 0; try { while ( rs.next() ) { i++; } } catch ( SQLException e ) { throw new MetadataStoreException( e.getMessage(), e ); } return i; }
@Override public MetadataResultSet<ISORecord> getRecords( MetadataQuery query ) throws MetadataStoreException { try { return storedIsoRecords.getRecords( query ); } catch ( FilterEvaluationException e ) { throw new MetadataStoreException( e ); } }
public static URI determineOutputSchema( OutputSchema outputSchema ) throws MetadataStoreException { URI schema = null; try { switch ( outputSchema ) { case DC: schema = new URI( CSWConstants.CSW_202_NS ); break; case ISO_19115: schema = new URI( CSWConstants.GMD_NS ); break; } } catch ( URISyntaxException e ) { throw new MetadataStoreException( e.getMessage() ); } return schema; }
@Override public T getRecord() throws MetadataStoreException { try { BufferedInputStream bais = new BufferedInputStream( rs.getBinaryStream( 1 ) ); XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader( bais ); return getRecord( xmlReader ); } catch ( Exception e ) { throw new MetadataStoreException( "Error re-creating MetadataRecord from result set: " + e.getMessage() ); } }
private ServiceManagerProvider() throws MetadataStoreException { Iterator<ServiceManager> iter = ServiceLoader.load( ServiceManager.class ).iterator(); while ( iter.hasNext() ) { if ( serviceManager != null ) { String msg = "It is not allowed to specify more than one service manager. Please check " + ServiceManager.class.getName(); throw new MetadataStoreException( msg ); } serviceManager = iter.next(); } if ( serviceManager == null ) { serviceManager = new DefaultServiceManager(); } }
@Override public void commit() throws MetadataStoreException { LOG.debug( "Performing commit of transaction." ); try { conn.commit(); } catch ( SQLException e ) { String msg = "Commit failed: " + e.getMessage(); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { JDBCUtils.close( conn ); } }
@Override public void rollback() throws MetadataStoreException { LOG.debug( "Performing rollback of transaction." ); try { conn.rollback(); } catch ( SQLException e ) { String msg = "Rollback failed: " + e.getMessage(); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { JDBCUtils.close( conn ); } }
private void deleteExistingRows( Connection connection, int operatesOnId, String databaseTable ) throws MetadataStoreException { PreparedStatement stmt = null; StringWriter sqlStatement = new StringWriter(); try { sqlStatement.append( "DELETE FROM " + databaseTable + " WHERE " + fk_main + " = ?" ); stmt = connection.prepareStatement( sqlStatement.toString() ); stmt.setInt( 1, operatesOnId ); LOG.debug( stmt.toString() ); stmt.executeUpdate(); } catch ( SQLException e ) { String msg = Messages.getMessage( "ERROR_SQL", sqlStatement.toString(), e.getMessage() ); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { close( null, stmt, null, LOG ); } }
@Override public int getRecordCount( MetadataQuery query ) throws MetadataStoreException { try { List<ISORecord> records = storedIsoRecords.getRecords( query.getFilter() ); return records.size(); } catch ( FilterEvaluationException e ) { throw new MetadataStoreException( e ); } }
@Override public void commit() throws MetadataStoreException { LOG.debug( Messages.getMessage( "INFO_TA_COMMIT" ) ); try { conn.commit(); } catch ( SQLException e ) { String msg = Messages.getMessage( "ERROR_TA_COMMIT", e.getMessage() ); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { JDBCUtils.close( conn ); } }
@Override public void rollback() throws MetadataStoreException { LOG.debug( Messages.getMessage( "INFO_TA_ROLLBACK" ) ); try { conn.rollback(); } catch ( SQLException e ) { String msg = Messages.getMessage( "ERROR_TA_ROLLBACK", e.getMessage() ); LOG.debug( msg ); throw new MetadataStoreException( msg ); } finally { JDBCUtils.close( conn ); } }
/** * NOTE: Although autoCommit=true disables cursor-based access (streaming), it is currently set for very good * reasons: It was found that it can ruin the performance of INNER SELECTs. Ask Andreas P. / Markus before changing * this! * * @param autoCommit * @return * @throws MetadataStoreException */ private Connection getConnection( boolean autoCommit ) throws MetadataStoreException { ConnectionProvider prov = workspace.getResource( ConnectionProviderProvider.class, connId ); try { Connection conn = prov.getConnection(); conn.setAutoCommit( autoCommit ); return conn; } catch ( SQLException e ) { throw new MetadataStoreException( "Could not get Connection with ID " + connId + " " + e.getMessage() ); } }
@Override public MetadataStoreTransaction acquireTransaction() throws MetadataStoreException { ISOMetadataStoreTransaction ta = null; try { Connection conn = getConnection(); ta = new ISOMetadataStoreTransaction( conn, dialect, inspectorChain, getQueryables(), config.getAnyText() ); } catch ( SQLException e ) { LOG.error( "error " + e.getMessage(), e ); throw new MetadataStoreException( e.getMessage(), e ); } return ta; }
@Override public int performDelete( DeleteOperation delete ) throws MetadataStoreException { List<ISORecord> recordsToDelete; try { recordsToDelete = storedRecords.getRecords( delete.getConstraint() ); for ( ISORecord record : recordsToDelete ) { transactionCandidates.add( new TransactionCandidate( TransactionStatus.DELETE, record.getIdentifier(), record ) ); } } catch ( FilterEvaluationException e ) { LOG.error( "Could not evaluate filter!", e ); throw new MetadataStoreException( e ); } return recordsToDelete.size(); }
@Override public List<String> performInsert( InsertOperation insert ) throws MetadataStoreException, MetadataInspectorException { List<? extends MetadataRecord> recordsToInsert = insert.getRecords(); List<String> insertedIds = new ArrayList<String>( recordsToInsert.size() ); for ( MetadataRecord record : recordsToInsert ) { ISORecord isoRecord = (ISORecord) record; if ( storedRecords.contains( isoRecord ) ) { throw new MetadataStoreException( "Insert failed: record with identifier " + record.getIdentifier() + " exists." ); } transactionCandidates.add( new TransactionCandidate( TransactionStatus.INSERT, isoRecord.getIdentifier(), isoRecord ) ); insertedIds.add( isoRecord.getIdentifier() ); } return insertedIds; }
@Override public int performDelete( DeleteOperation delete ) throws MetadataStoreException { try { // TODO: mapping! ISOPropertyNameMapper mapping = new ISOPropertyNameMapper( dialect, queryables ); AbstractWhereBuilder builder = dialect.getWhereBuilder( mapping, (OperatorFilter) delete.getConstraint(), null, false ); TransactionService transactionService = getTransactionalSqlService(); return transactionService.executeDelete( conn, builder ); } catch ( Exception e ) { throw new MetadataStoreException( e.getMessage() ); } }
@Override public void commit() throws MetadataStoreException { try { for ( TransactionCandidate transactionCandidate : transactionCandidates ) { switch ( transactionCandidate.status ) { case INSERT: committer.commitInsert( transactionCandidate ); break; case UPDATE: committer.commitUpdate( transactionCandidate ); break; case DELETE: committer.commitDelete( transactionCandidate ); break; } } metadataStore.releaseTransaction(); } catch ( Exception e ) { rollback(); LOG.error( "Commit failed: ", e ); throw new MetadataStoreException( e ); } }