@Override public MetadataStoreTransaction acquireTransaction() throws MetadataStoreException { return new EbrimEOMDStoreTransaction( getConnection( false ), useLegacyPredicates ); }
@Override public ResourceMetadata<MetadataStore<? extends MetadataRecord>> createFromLocation( Workspace workspace, ResourceLocation<MetadataStore<? extends MetadataRecord>> location ) { return new EbrimEOMDStoreMetadata( workspace, location, this ); }
@Override public String[] getCreateStatements( SQLDialect dbType ) throws UnsupportedEncodingException, IOException { List<String> creates = new ArrayList<String>(); if ( dbType instanceof PostGISDialect ) { URL script = EbrimEOMDStoreProvider.class.getResource( "postgis/create.sql" ); creates.addAll( readStatements( new BufferedReader( new InputStreamReader( script.openStream(), "UTF-8" ) ) ) ); } return creates.toArray( new String[creates.size()] ); }
ResultSet rs = null; ConnectionProvider prov = workspace.getResource( ConnectionProviderProvider.class, connId ); Connection conn = getConnection( true ); try { EOPropertyNameMapper propMapper = new EOPropertyNameMapper( query.getQueryTypeNames(), useLegacyPredicates ); if ( query.getFilter() instanceof IdFilter ) { throw new MetadataStoreException( "ID filters are currently not supported." ); AliasedRIMType returnType = propMapper.getReturnType( query.getReturnTypeNames() ); StringBuilder idSelect = new StringBuilder( "SELECT DISTINCT(" ); idSelect.append( propMapper.getTableAlias( returnType ) ); idSelect.append( ".internalId) FROM " ); idSelect.append( propMapper.getTable( returnType ) ); idSelect.append( ' ' ); idSelect.append( propMapper.getTableAlias( returnType ) ); boolean first = true; for ( AliasedRIMType queryType : propMapper.getQueryTypes() ) { if ( queryType != returnType ) { if ( first ) { idSelect.append( propMapper.getTable( queryType ).name() ); idSelect.append( ' ' ); idSelect.append( propMapper.getTableAlias( queryType ) ); idSelect.append( " ON TRUE" ); first = false; for ( Join additionalJoin : propMapper.getAdditionalJoins() ) { if ( first ) { idSelect.append( " LEFT OUTER JOIN " );
throws MetadataStoreException { InsertRow ir = new InsertRow( new TableName( Table.idxtb_registrypackage.name() ), null ); try { int id = getNewId( conn ); ir.addPreparedArgument( new SQLIdentifier( "internalId" ), id ); ir.addPreparedArgument( new SQLIdentifier( "id" ), registryPackage.getId() ); ir.addPreparedArgument( new SQLIdentifier( "name" ), registryPackage.getName() ); ir.addPreparedArgument( new SQLIdentifier( "description" ), registryPackage.getDesc() ); ir.addPreparedArgument( new SQLIdentifier( "data" ), getAsByteArray( registryPackage.getElement() ) ); for ( EOTYPE type : EOTYPE.values() ) { for ( ExtrinsicObject eo : registryPackage.getExtrinsicObjects( type.getType() ) ) { insertExtrinsicObject( eo, id, conn ); insertAssociation( association, id, conn ); insertClassification( classification, id, conn ); insertClassificationNode( classificationNode, id, conn );
private void insertExtrinsicObject( ExtrinsicObject eo, int regPackId, Connection conn ) throws SQLException { InsertRow ir = new InsertRow( new TableName( Table.idxtb_extrinsicobject.name() ), null ); addRegistryObject( ir, eo ); ir.addPreparedArgument( new SQLIdentifier( "data" ), getAsByteArray( eo.getElement() ) ); if ( PRODUCT.getType().equals( eo.getObjectType() ) ) { slots = PRODUCT.getSlots(); } else if ( ACQUPLATFORM.getType().equals( eo.getObjectType() ) ) { ir.addPreparedArgument( new SQLIdentifier( "ap_shortName" ), eo.getName() ); slots = ACQUPLATFORM.getSlots(); } else if ( MASKINFO.getType().equals( eo.getObjectType() ) ) { ir.addPreparedArgument( new SQLIdentifier( "mi_type" ), eo.getName() ); slots = MASKINFO.getSlots(); } else if ( ARCHIVINGINFO.getType().equals( eo.getObjectType() ) ) { ir.addPreparedArgument( new SQLIdentifier( "ai_archivingCenter" ), eo.getName() ); slots = ARCHIVINGINFO.getSlots(); } else if ( PRODUCTINFO.getType().equals( eo.getObjectType() ) ) { slots = PRODUCTINFO.getSlots(); } else if ( DATALAYER.getType().equals( eo.getObjectType() ) ) { ir.addPreparedArgument( new SQLIdentifier( "dl_specy" ), eo.getName() ); slots = DATALAYER.getSlots(); } else if ( BROWSEINFO.getType().equals( eo.getObjectType() ) ) { ir.addPreparedArgument( new SQLIdentifier( "bi_type" ), eo.getName() ); slots = BROWSEINFO.getSlots(); prepareSlot( slot, eo, ir );
List<AliasedRIMType> aliasedTypes = AliasedRIMType.valueOf( recordTypeNames[0] ); if ( aliasedTypes.get( 0 ).getType() == AdhocQuery ) { return getAdhocQueries( idList ); table = SlotMapper.getTable( aliasedTypes.get( 0 ).getType() ); } catch ( Throwable t ) { String msg = "Specified type name '" + recordTypeNames[0] ResultSet rs = null; ConnectionProvider prov = workspace.getResource( ConnectionProviderProvider.class, connId ); Connection conn = getConnection( true ); sql.append( "SELECT data" ); sql.append( " FROM " ); sql.append( table.name() ); sql.append( " WHERE id IN (" ); sql.append( "?" ); return new EbrimEOMDResultSet( rs, conn, stmt ); } catch ( Throwable t ) { JDBCUtils.close( rs, stmt, conn, LOG );
private void insertAssociation( Association association, int regPackId, Connection conn ) throws SQLException { InsertRow ir = new InsertRow( new TableName( Table.idxtb_association.name() ), null ); addRegistryObject( ir, association ); ir.addPreparedArgument( new SQLIdentifier( "sourceObject" ), association.getSourceObject() ); ir.addPreparedArgument( new SQLIdentifier( "targetObject" ), association.getTargetObject() ); ir.addPreparedArgument( new SQLIdentifier( "associationType" ), association.getAssociationType() ); ir.addPreparedArgument( new SQLIdentifier( "data" ), getAsByteArray( association.getElement() ) ); ir.addPreparedArgument( new SQLIdentifier( "fk_registrypackage" ), regPackId ); ir.performInsert( conn ); }
String dir = null; try { dir = storeConfig.getAdhocQueriesDirectory(); if ( dir != null ) { URL resolved = metadata.getLocation().resolveToUrl( dir ); profile = storeConfig.getExtensionPackage(); Date lastModified = null; try { throw new ResourceInitException( msg, e ); long queryTimeout = storeConfig.getQueryTimeout() == null ? 0 : storeConfig.getQueryTimeout().intValue(); EbrimEOMDStore store = new EbrimEOMDStore( storeConfig.getJDBCConnId(), queriesDir, rp, lastModified, queryTimeout, metadata, workspace ); return store;
private void prepareSlot( SlotMapping slot, ExtrinsicObject extrinsicObject, InsertRow ir ) { if ( SlotType._geom.equals( slot.getType() ) ) { Geometry geom = (Geometry) extrinsicObject.getGeometrySlotValue( SLOTURN + slot.getName() ); if ( geom != null ) { try { ir.addPreparedArgument( new SQLIdentifier( slot.getColumn() ), wkt, sb.toString() ); } catch ( ParseException e ) { String msg = "Could not write as WKB " + geom + ": " + e.getMessage(); if ( SlotType._multiple.equals( slot.getType() ) ) { String[] slotValue = extrinsicObject.getSlotValueList( SLOTURN + slot.getName() ); ir.addPreparedArgument( new SQLIdentifier( slot.getColumn() ), concatenate( slotValue ) ); String slotValue = extrinsicObject.getSlotValue( SLOTURN + slot.getName() ); if ( slotValue != null ) { switch ( slot.getType() ) { case _date: try { ir.addPreparedArgument( new SQLIdentifier( slot.getColumn() ), new Timestamp( ( parseDateTime( slotValue ).getTimeInMilliseconds() ) ) ); case _double: try { ir.addPreparedArgument( new SQLIdentifier( slot.getColumn() ), Double.parseDouble( slotValue ) ); } catch ( NumberFormatException e ) { String msg = "Could not parse as double:" + slotValue; case _int:
@Override public ResourceBuilder<MetadataStore<? extends MetadataRecord>> prepare() { EbrimEOMDStoreConfig storeConfig; try { storeConfig = (EbrimEOMDStoreConfig) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, provider.getSchema(), location.getAsStream(), workspace ); dependencies.add( new DefaultResourceIdentifier<ConnectionProvider>( ConnectionProviderProvider.class, storeConfig.getJDBCConnId() ) ); return new EbrimEOMDStoreBuilder( this, workspace, storeConfig ); } catch ( Exception e ) { String msg = Messages.getMessage( "ERROR_IN_CONFIG_FILE", location.getIdentifier(), e.getMessage() ); throw new ResourceInitException( msg, e ); } }
Connection conn = null; try { conn = getConnection( true ); useLegacyPredicates = JDBCUtils.useLegayPostGISPredicates( conn, LOG ); } catch ( MetadataStoreException e ) { ResultSet result = null; try { conn = getConnection( false ); String sql = "Select value FROM management WHERE key = 'LAST_INSERTED'"; stmt = conn.prepareStatement( sql ); String insertedId = updateProfile( regPackId, lastInserted, profile, lastModified ); if ( insertedId != null ) { sql = "DELETE FROM management where key = 'REGISTRYPACKAGE_ID' or key = 'LAST_INSERTED'";
@Override public List<String> performInsert( InsertOperation insert ) throws MetadataStoreException, MetadataInspectorException { List<String> identifierList = new ArrayList<String>(); for ( MetadataRecord record : insert.getRecords() ) { if ( record != null ) { // TODO: suppor of other registryObjects RegistryPackage ebrimRecord = new RegistryPackage( record.getAsOMElement() ); // TODO: inspect records insert( ebrimRecord ); identifierList.add( ebrimRecord.getIdentifier() ); } } return identifierList; }
MetadataStoreTransaction trans; try { trans = acquireTransaction(); } catch ( MetadataStoreException e ) { String msg = "Could not aquireTranacation to update the profile: " + e.getMessage();
ResultSet rs = null; ConnectionProvider prov = workspace.getResource( ConnectionProviderProvider.class, connId ); Connection conn = getConnection( true ); try { EOPropertyNameMapper propMapper = new EOPropertyNameMapper( query.getQueryTypeNames(), useLegacyPredicates ); if ( query.getFilter() instanceof IdFilter ) { throw new MetadataStoreException( "ID filters are currently not supported." ); AliasedRIMType returnType = propMapper.getReturnType( query.getReturnTypeNames() ); StringBuilder sql = new StringBuilder( "SELECT COUNT(DISTINCT(" ); sql.append( propMapper.getTableAlias( returnType ) ); sql.append( ".internalId)) FROM " ); sql.append( propMapper.getTable( returnType ) ); sql.append( ' ' ); sql.append( propMapper.getTableAlias( returnType ) ); boolean first = true; for ( AliasedRIMType queryType : propMapper.getQueryTypes() ) { if ( queryType != returnType ) { if ( first ) { sql.append( propMapper.getTable( queryType ).name() ); sql.append( ' ' ); sql.append( propMapper.getTableAlias( queryType ) ); sql.append( " ON TRUE" ); first = false; for ( Join additionalJoin : propMapper.getAdditionalJoins() ) { if ( first ) { sql.append( " LEFT OUTER JOIN " );
private void insertClassification( Classification classification, int regPackId, Connection conn ) throws SQLException { InsertRow ir = new InsertRow( new TableName( Table.idxtb_classification.name() ), null ); addRegistryObject( ir, classification ); ir.addPreparedArgument( new SQLIdentifier( "classificationNode" ), classification.getClassificationNode() ); ir.addPreparedArgument( new SQLIdentifier( "classifiedObject" ), classification.getClassifiedObject() ); ir.addPreparedArgument( new SQLIdentifier( "classificationScheme" ), classification.getClassificationScheme() ); ir.addPreparedArgument( new SQLIdentifier( "data" ), getAsByteArray( classification.getElement() ) ); ir.addPreparedArgument( new SQLIdentifier( "fk_registrypackage" ), regPackId ); ir.performInsert( conn ); }
@Override public String[] getDropStatements( SQLDialect dbType ) throws UnsupportedEncodingException, IOException { List<String> creates = new ArrayList<String>(); if ( dbType instanceof PostGISDialect ) { URL script = EbrimEOMDStoreProvider.class.getResource( "postgis/drop.sql" ); creates.addAll( readStatements( new BufferedReader( new InputStreamReader( script.openStream(), "UTF-8" ) ) ) ); } return creates.toArray( new String[creates.size()] ); }
private void insertClassificationNode( ClassificationNode classificationNode, int regPackId, Connection conn ) throws SQLException { InsertRow ir = new InsertRow( new TableName( Table.idxtb_classificationNode.name() ), null ); addRegistryObject( ir, classificationNode ); ir.addPreparedArgument( new SQLIdentifier( "parent" ), classificationNode.getParent() ); ir.addPreparedArgument( new SQLIdentifier( "code" ), classificationNode.getCode() ); ir.addPreparedArgument( new SQLIdentifier( "path" ), classificationNode.getPath() ); ir.addPreparedArgument( new SQLIdentifier( "data" ), getAsByteArray( classificationNode.getElement() ) ); ir.addPreparedArgument( new SQLIdentifier( "fk_registrypackage" ), regPackId ); ir.performInsert( conn ); }