/** * If the given metadata is a proxy generated by this {@code MetadataSource}, returns the * identifier of that proxy. Such metadata do not need to be inserted again in the database. * * @param metadata the metadata to test. * @return the identifier (primary key), or {@code null} if the given metadata is not a proxy. */ final String proxy(final Object metadata) { return (metadata instanceof MetadataProxy) ? ((MetadataProxy) metadata).identifier(this) : null; }
/** * Runs the installation script. */ public void run() throws IOException, SQLException { run(Installer.class, "Create.sql"); }
/** * Invoked in a background thread for closing all expired {@link CachedStatement} instances. */ @Override public void run() { closeExpired(); } }
/** * Runs all public tests declared in this class. * Also opportunistically run tests declared in {@link MetadataFallbackVerifier}. */ private static void testAll(final TestDatabase db) throws Exception { try (MetadataSource source = new MetadataSource(MetadataStandard.ISO_19115, db.source, "metadata", null)) { source.install(); verifyFormats(source); testSearch(source); ensureReadOnly(source); // Opportunistic verification using the database we have at hand. MetadataFallbackVerifier.compare(source); } }
/** * Compares {@link MetadataFallback} content with database content using the given source. * This method is invoked by {@link MetadataSourceTest} for opportunistically reusing the * available database. */ static void compare(final MetadataSource source) throws MetadataStoreException { for (final Citation c : Citations.values()) { final String name = ((CitationConstant) c).title; final boolean exclude = EXCLUDES.contains(name); final Citation fromFB = MetadataFallback.createCitation(name); assertEquals(name, exclude, fromFB == null); // Verify that missing fallbacks are known ones. if (!exclude) { compare(name, source.lookup(Citation.class, name), fromFB); } } compare("IOGP", source.lookup(Citation.class, "IOGP"), MetadataFallback.createCitation("IOGP")); }
/** * Tests {@link MetadataSource#lookup(Class, String)} be fetching some {@link Format} instances from * the given source. The first call to the {@code lookup(…)} method will trig the database installation. * * @param source the instance to test. * @throws MetadataStoreException if an error occurred while querying the database. */ @TestStep public static void verifyFormats(final MetadataSource source) throws MetadataStoreException { verify(source.lookup(Format.class, "PNG"), "PNG", "PNG (Portable Network Graphics) Specification"); verify(source.lookup(Format.class, "NetCDF"), "NetCDF", "NetCDF Classic and 64-bit Offset Format"); verify(source.lookup(Format.class, "GeoTIFF"), "GeoTIFF", "GeoTIFF Coverage Encoding Profile"); verify(source.lookup(Format.class, "CSV"), "CSV", "Common Format and MIME Type for Comma-Separated Values (CSV) Files"); verify(source.lookup(Format.class, "CSV-MF"), "CSV", "OGC Moving Features Encoding Extension: Simple Comma-Separated Values (CSV)"); }
/** * Returns the SQL statement for creating the given table with the given primary key. * This method returns a string of the following form: * * {@preformat sql * CREATE TABLE "schema"."table" (primaryKey VARCHAR(20) NOT NULL PRIMARY KEY) * } */ private String createTable(final String table, final String primaryKey) throws SQLException { return helper().clear().append("CREATE TABLE ").appendIdentifier(schema(), table) .append(" (").append(primaryKey).append(" VARCHAR(").append(maximumIdentifierLength) .append(") NOT NULL PRIMARY KEY)").toString(); }
/** * Creates a new temporary database and write elements in it. * * @throws MetadataStoreException if an error occurred while writing or reading the database. */ private void write() throws MetadataStoreException { assertEquals("ISO 19115", source.add(HardCodedCitations.ISO_19115)); assertEquals("EPSG", source.add(HardCodedCitations.EPSG)); assertEquals("SIS", source.add(HardCodedCitations.SIS)); }
/** * Gets the {@link LookupInfo} instance for call to the {@link #readColumn(LookupInfo, Method, Dispatcher)} method. * The call to those two methods must be in the same thread, and no other metadata object shall be queried between * the two calls (unless {@link LookupInfo#setMetadataType(Class)} is invoked again). * * @param type the interface class. This is mapped to the table name in the database. */ final LookupInfo getLookupInfo(final Class<?> type) { final LookupInfo info = lastUsed.get(); info.setMetadataType(type); return info; }
/** * Returns a string representation of this handler. * This is mostly for debugging purpose. */ @Override public String toString() { return toString(getClass()); } }
/** * Closes the statement and free all resources. * After this method has been invoked, this object can not be used anymore. * * <p>This method is not invoked by the method or thread that created this {@code CachedStatement} instance. * This method is invoked by {@link MetadataSource#close()} instead.</p> * * @throws SQLException if an error occurred while closing the statement. */ @Override public void close() throws SQLException { closeResultSet(); statement.close(); }
@Override protected LookupInfo initialValue() { return new LookupInfo(); } };
/** * Tests the creation of identifiers with sequence numbers. * * @param prefix The prefix of the records to add. * @param count The number of records to add (in addition of the "main" one). */ private void addRecords(final String prefix, final int count) throws SQLException { assertEquals("The very first record added should not have any suffix.", prefix, addRecord(prefix)); for (int i=1; i<=count; i++) { assertEquals("Any record added after the first one should have a sequential number in suffix.", prefix + IdentifierGenerator.SEPARATOR + i, addRecord(prefix)); } }
/** * Returns the SQL statement for creating the given table with the given primary key. * This method returns a string of the following form: * * {@preformat sql * CREATE TABLE "schema"."table" (primaryKey VARCHAR(20) NOT NULL PRIMARY KEY) * } */ private String createTable(final String table, final String primaryKey) throws SQLException { return helper().clear().append("CREATE TABLE ").appendIdentifier(schema(), table) .append(" (").appendIdentifier(primaryKey).append(" VARCHAR(").append(maximumIdentifierLength) .append(") NOT NULL PRIMARY KEY)").toString(); }
/** * If the given metadata is a proxy generated by this {@code MetadataSource}, returns the * identifier of that proxy. Such metadata do not need to be inserted again in the database. * * @param metadata the metadata to test. * @return the identifier (primary key), or {@code null} if the given metadata is not a proxy. */ final String proxy(final Object metadata) { return (metadata instanceof MetadataProxy) ? ((MetadataProxy) metadata).identifier(this) : null; }
/** * Invoked in a background thread for closing all expired {@link CachedStatement} instances. */ @Override public void run() { closeExpired(); } }
/** * Gets the {@link LookupInfo} instance for call to the {@link #readColumn(LookupInfo, Method, Dispatcher)} method. * The call to those two methods must be in the same thread, and no other metadata object shall be queried between * the two calls (unless {@link LookupInfo#setMetadataType(Class)} is invoked again). * * @param type the interface class. This is mapped to the table name in the database. */ final LookupInfo getLookupInfo(final Class<?> type) { final LookupInfo info = lastUsed.get(); info.setMetadataType(type); return info; }
/** * Returns a string representation of this handler. * This is mostly for debugging purpose. */ @Override public String toString() { return toString(getClass()); }
/** * Closes the statement and free all resources. * After this method has been invoked, this object can not be used anymore. * * <p>This method is not invoked by the method or thread that created this {@code CachedStatement} instance. * This method is invoked by {@link MetadataSource#close()} instead.</p> * * @throws SQLException if an error occurred while closing the statement. */ @Override public void close() throws SQLException { closeResultSet(); statement.close(); }