EbrimEOMDStore implements MetadataStore<RegistryObject> { @Override public MetadataResultSet<RegistryObject> getRecordById( List<String> idList, QName[] recordTypeNames ) throws MetadataStoreException { Table table = Table.idxtb_registrypackage; if ( recordTypeNames != null && recordTypeNames.length > 0 ) { if ( recordTypeNames.length > 1 ) { String msg = "Record by id queries with multiple specified type names are not supported."; throw new MetadataStoreException( msg ); } try { 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] + "' is not a known ebRIM 3.0 registry object type."; throw new MetadataStoreException( msg ); } if ( table == null ) { String msg = "Queries on registry object type '" + recordTypeNames[0] + "' are not supported."; throw new MetadataStoreException( msg ); } } PreparedStatement stmt = null; ResultSet rs = null; ConnectionProvider prov = workspace.getResource( ConnectionProviderProvider.class, connId ); Connection conn = getConnection( true ); try { StringBuilder sql = new StringBuilder(); sql.append( "SELECT data" ); sql.append( " FROM " ); sql.append( table.name() ); sql.append( " WHERE id IN (" ); sql.append( "?" ); for ( int i = 1; i < idList.size(); i++ ) { sql.append( ",?" ); } sql.append( ")" ); stmt = conn.prepareStatement( sql.toString() ); stmt.setFetchSize( DEFAULT_FETCH_SIZE ); int i = 1; for ( String identifier : idList ) { stmt.setString( i, identifier ); i++; } LOG.debug( "Execute: " + stmt.toString() ); rs = executeQuery( stmt, prov, queryTimeout ); return new EbrimEOMDResultSet( rs, conn, stmt ); } catch ( Throwable t ) { JDBCUtils.close( rs, stmt, conn, LOG ); LOG.debug( t.getMessage(), t ); throw new MetadataStoreException( t.getMessage(), t ); } } EbrimEOMDStore( String connId, File queriesDir, RegistryPackage profile, Date lastModified,
                           long queryTimeout, ResourceMetadata<MetadataStore<? extends MetadataRecord>> metadata,
                           Workspace workspace ); @Override void init(); @Override void destroy(); @Override MetadataResultSet<RegistryObject> getRecords( MetadataQuery query ); @Override int getRecordCount( MetadataQuery query ); @Override MetadataResultSet<RegistryObject> getRecordById( List<String> idList, QName[] recordTypeNames ); @Override MetadataStoreTransaction acquireTransaction(); @Override String getConnId(); @Override String getType(); @Override ResourceMetadata<? extends Resource> getMetadata(); static final int DEFAULT_FETCH_SIZE; }
@Test public void testGetRecordById() throws SQLException, MetadataStoreException, UnsupportedEncodingException, IOException, MetadataInspectorException { if ( insertSuccess ) { LOG.info( "Could not insert test datasets, skip testGetRecordById" ); return; } Connection conn = getConnection(); if ( conn == null ) { LOG.info( "Could not get database connection, skip testGetRecordById" ); return; } MetadataResultSet<RegistryObject> recordById = store.getRecordById( Collections.singletonList( id_rec1 ), null ); assertNotNull( recordById ); recordById.next(); RegistryObject record = recordById.getRecord(); Assert.assertNotNull( record ); assertEquals( id_rec1, record.getIdentifier() ); }