Java Code Examples for mil.nga.geopackage.metadata.MetadataDao#isTableExists()

The following examples show how to use mil.nga.geopackage.metadata.MetadataDao#isTableExists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createMetadataTable() {
	verifyWritable();

	boolean created = false;
	MetadataDao dao = getMetadataDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createMetadata() > 0;
			if (created) {
				// Create the metadata extension record
				MetadataExtension metadataExtension = new MetadataExtension(
						this);
				metadataExtension.getOrCreate();
			}
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + Metadata.class.getSimpleName()
						+ " table exists and create it",
				e);
	}
	return created;
}
 
Example 2
Source File: MetadataUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	MetadataDao dao = geoPackage.getMetadataDao();

	if (dao.isTableExists()) {
		// Get current count
		long count = dao.countOf();

		long id = 12345;
		MetadataScopeType scopeType = MetadataScopeType.SOFTWARE;
		String standardUri = "https://www.nga.mil";
		String mimeType = "text/xml";
		String metadataText = "Create metadata text";

		// Create new metadata
		Metadata metadata = new Metadata();
		metadata.setId(id);
		metadata.setMetadataScope(scopeType);
		metadata.setStandardUri(standardUri);
		metadata.setMimeType(mimeType);
		metadata.setMetadata(metadataText);
		dao.create(metadata);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved metadata
		Metadata queryMetadata = dao.queryForId(id);
		TestCase.assertEquals(id, queryMetadata.getId());
		TestCase.assertEquals(scopeType, queryMetadata.getMetadataScope());
		TestCase.assertEquals(standardUri, queryMetadata.getStandardUri());
		TestCase.assertEquals(mimeType, queryMetadata.getMimeType());
		TestCase.assertEquals(metadataText, queryMetadata.getMetadata());
	}

}
 
Example 3
Source File: MetadataUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	MetadataDao dao = geoPackage.getMetadataDao();

	if (dao.isTableExists()) {
		// Get current count
		long count = dao.countOf();

		long id = 12345;
		MetadataScopeType scopeType = MetadataScopeType.SOFTWARE;
		String standardUri = "https://www.nga.mil";
		String mimeType = "text/xml";
		String metadataText = "Create metadata text";

		// Create new metadata
		Metadata metadata = new Metadata();
		metadata.setId(id);
		metadata.setMetadataScope(scopeType);
		metadata.setStandardUri(standardUri);
		metadata.setMimeType(mimeType);
		metadata.setMetadata(metadataText);
		dao.create(metadata);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved metadata
		Metadata queryMetadata = dao.queryForId(id);
		TestCase.assertEquals(id, queryMetadata.getId());
		TestCase.assertEquals(scopeType, queryMetadata.getMetadataScope());
		TestCase.assertEquals(standardUri, queryMetadata.getStandardUri());
		TestCase.assertEquals(mimeType, queryMetadata.getMimeType());
		TestCase.assertEquals(metadataText, queryMetadata.getMetadata());
	}

}