Java Code Examples for mil.nga.geopackage.GeoPackage#getExtensionsDao()

The following examples show how to use mil.nga.geopackage.GeoPackage#getExtensionsDao() . 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: GeoPackageExample.java    From geopackage-android with MIT License 6 votes vote down vote up
private void validateNGAExtensions(GeoPackage geoPackage, boolean has)
        throws SQLException {

    ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

    TestCase.assertEquals(
            has && GEOMETRY_INDEX,
            extensionsDao.isTableExists()
                    && !extensionsDao.queryByExtension(
                    FeatureTableIndex.EXTENSION_NAME).isEmpty());
    TestCase.assertEquals(has && FEATURE_TILE_LINK,
            new FeatureTileTableLinker(geoPackage).has());
    TestCase.assertEquals(
            has && TILE_SCALING,
            extensionsDao.isTableExists()
                    && !extensionsDao.queryByExtension(
                    TileTableScaling.EXTENSION_NAME).isEmpty());
    TestCase.assertEquals(has && PROPERTIES, new PropertiesExtension(
            geoPackage).has());
    TestCase.assertEquals(has && CONTENTS_ID, new ContentsIdExtension(
            geoPackage).has());
    TestCase.assertEquals(has && FEATURE_STYLE, new FeatureStyleExtension(
            geoPackage).has());

}
 
Example 2
Source File: GeoPackageExample.java    From geopackage-java with MIT License 6 votes vote down vote up
private void validateNGAExtensions(GeoPackage geoPackage, boolean has)
		throws SQLException {

	ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

	TestCase.assertEquals(has && GEOMETRY_INDEX,
			extensionsDao.isTableExists() && !extensionsDao
					.queryByExtension(FeatureTableIndex.EXTENSION_NAME)
					.isEmpty());
	TestCase.assertEquals(has && FEATURE_TILE_LINK,
			new FeatureTileTableLinker(geoPackage).has());
	TestCase.assertEquals(has && TILE_SCALING,
			extensionsDao.isTableExists() && !extensionsDao
					.queryByExtension(TileTableScaling.EXTENSION_NAME)
					.isEmpty());
	TestCase.assertEquals(has && PROPERTIES,
			new PropertiesExtension(geoPackage).has());
	TestCase.assertEquals(has && CONTENTS_ID,
			new ContentsIdExtension(geoPackage).has());
	TestCase.assertEquals(has && FEATURE_STYLE,
			new FeatureStyleExtension(geoPackage).has());

}
 
Example 3
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private void validateExtensions(GeoPackage geoPackage, boolean has)
        throws SQLException {

    ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

    TestCase.assertEquals(has && RTREE_SPATIAL_INDEX,
            new RTreeIndexExtension(geoPackage).has());
    TestCase.assertEquals(
            has
                    && (RELATED_TABLES_FEATURES || RELATED_TABLES_MEDIA || RELATED_TABLES_SIMPLE_ATTRIBUTES),
            new RelatedTablesExtension(geoPackage).has());
    TestCase.assertEquals(
            has && COVERAGE_DATA,
            extensionsDao.isTableExists()
                    && !extensionsDao.queryByExtension(
                    CoverageData.EXTENSION_NAME).isEmpty());

    TestCase.assertEquals(has && SCHEMA,
            new SchemaExtension(geoPackage).has());
    TestCase.assertEquals(has && METADATA,
            new MetadataExtension(geoPackage).has());
    TestCase.assertEquals(
            has && NON_LINEAR_GEOMETRY_TYPES,
            extensionsDao.isTableExists()
                    && !extensionsDao
                    .queryByExtension(
                            GeometryExtensions
                                    .getExtensionName(GeometryType.CIRCULARSTRING))
                    .isEmpty());
    TestCase.assertEquals(has && WEBP, extensionsDao.isTableExists()
            && !extensionsDao
            .queryByExtension(WebPExtension.EXTENSION_NAME)
            .isEmpty());
    TestCase.assertEquals(has && CRS_WKT,
            new CrsWktExtension(geoPackage).has());

}
 
Example 4
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private void validateExtensions(GeoPackage geoPackage, boolean has)
		throws SQLException {

	ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

	TestCase.assertEquals(has && RTREE_SPATIAL_INDEX,
			new RTreeIndexExtension(geoPackage).has());
	TestCase.assertEquals(
			has && (RELATED_TABLES_FEATURES || RELATED_TABLES_MEDIA
					|| RELATED_TABLES_SIMPLE_ATTRIBUTES),
			new RelatedTablesExtension(geoPackage).has());
	TestCase.assertEquals(has && COVERAGE_DATA,
			extensionsDao.isTableExists() && !extensionsDao
					.queryByExtension(CoverageData.EXTENSION_NAME)
					.isEmpty());
	TestCase.assertEquals(has && SCHEMA,
			new SchemaExtension(geoPackage).has());
	TestCase.assertEquals(has && METADATA,
			new MetadataExtension(geoPackage).has());
	TestCase.assertEquals(has && NON_LINEAR_GEOMETRY_TYPES,
			extensionsDao.isTableExists() && !extensionsDao
					.queryByExtension(GeometryExtensions
							.getExtensionName(GeometryType.CIRCULARSTRING))
					.isEmpty());
	TestCase.assertEquals(has && WEBP,
			extensionsDao.isTableExists() && !extensionsDao
					.queryByExtension(WebPExtension.EXTENSION_NAME)
					.isEmpty());
	TestCase.assertEquals(has && CRS_WKT,
			new CrsWktExtension(geoPackage).has());

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

	ExtensionsDao dao = geoPackage.getExtensionsDao();

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

		// Create new extensions
		String tableName = "CREATE_TABLE_NAME";
		String columnName = "CREATE_COLUMN_NAME";
		String author = "nga";
		String extension = "create_extension";
		String definition = "definition";
		ExtensionScopeType scopeType = ExtensionScopeType.READ_WRITE;

		Extensions extensions = new Extensions();
		extensions.setTableName(tableName);
		extensions.setColumnName(columnName);
		extensions.setExtensionName(author, extension);
		extensions.setDefinition(definition);
		extensions.setScope(scopeType);
		dao.create(extensions);

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

		// Verify saved extensions
		Extensions queryExtensions = dao.queryByExtension(
				extensions.getExtensionName(), extensions.getTableName(),
				extensions.getColumnName());
		TestCase.assertNotNull(queryExtensions);
		TestCase.assertEquals(tableName, queryExtensions.getTableName());
		TestCase.assertEquals(columnName, queryExtensions.getColumnName());
		TestCase.assertEquals(author + Extensions.EXTENSION_NAME_DIVIDER
				+ extension, queryExtensions.getExtensionName());
		TestCase.assertEquals(author, queryExtensions.getAuthor());
		TestCase.assertEquals(extension,
				queryExtensions.getExtensionNameNoAuthor());
		TestCase.assertEquals(definition, queryExtensions.getDefinition());
		TestCase.assertEquals(scopeType, queryExtensions.getScope());
	}

}
 
Example 6
Source File: ExtensionsUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	ExtensionsDao dao = geoPackage.getExtensionsDao();

	if (dao.isTableExists()) {
		List<Extensions> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random metadata
			int random = (int) (Math.random() * results.size());
			Extensions extensions = results.get(random);

			// Delete the extensions
			dao.delete(extensions);

			// Verify deleted
			Extensions queryExtensions = dao.queryByExtension(
					extensions.getExtensionName(),
					extensions.getTableName(), extensions.getColumnName());
			TestCase.assertNull(queryExtensions);

			// Choose prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random metadata
				random = (int) (Math.random() * results.size());
				extensions = results.get(random);

				// Find which metadata to delete
				QueryBuilder<Extensions, Void> qb = dao.queryBuilder();
				qb.where().eq(Extensions.COLUMN_EXTENSION_NAME,
						extensions.getExtensionName());
				PreparedQuery<Extensions> query = qb.prepare();
				List<Extensions> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<Extensions, Void> db = dao.deleteBuilder();
				db.where().eq(Extensions.COLUMN_EXTENSION_NAME,
						extensions.getExtensionName());
				PreparedDelete<Extensions> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 7
Source File: FeatureTableIndexUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test table index delete all
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testDeleteAll(GeoPackage geoPackage) throws SQLException {

    // Test indexing each feature table
    List<String> featureTables = geoPackage.getFeatureTables();
    for (String featureTable : featureTables) {

        FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
        FeatureTableIndex featureTableIndex = new FeatureTableIndex(
                geoPackage, featureDao);

        if(featureTableIndex.isIndexed()){
            featureTableIndex.deleteIndex();
        }

        TestCase.assertFalse(featureTableIndex.isIndexed());

        TestUtils.validateGeoPackage(geoPackage);

        // Test indexing
        featureTableIndex.index();
        TestUtils.validateGeoPackage(geoPackage);

        TestCase.assertTrue(featureTableIndex.isIndexed());

    }

    ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
    GeometryIndexDao geometryIndexDao = geoPackage.getGeometryIndexDao();
    TableIndexDao tableIndexDao = geoPackage.getTableIndexDao();

    TestCase.assertTrue(geometryIndexDao.isTableExists());
    TestCase.assertTrue(tableIndexDao.isTableExists());
    TestCase.assertTrue(extensionsDao.queryByExtension(
            FeatureTableIndex.EXTENSION_NAME).size() > 0);

    TestCase.assertTrue(geometryIndexDao.countOf() > 0);
    long count = tableIndexDao.countOf();
    TestCase.assertTrue(count > 0);

    int deleteCount = tableIndexDao.deleteAllCascade();
    TestCase.assertEquals(count, deleteCount);

    TestCase.assertTrue(geometryIndexDao.countOf() == 0);
    TestCase.assertTrue(tableIndexDao.countOf() == 0);
}
 
Example 8
Source File: ExtensionsUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	ExtensionsDao dao = geoPackage.getExtensionsDao();

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

		// Create new extensions
		String tableName = "CREATE_TABLE_NAME";
		String columnName = "CREATE_COLUMN_NAME";
		String author = "nga";
		String extension = "create_extension";
		String definition = "definition";
		ExtensionScopeType scopeType = ExtensionScopeType.READ_WRITE;

		Extensions extensions = new Extensions();
		extensions.setTableName(tableName);
		extensions.setColumnName(columnName);
		extensions.setExtensionName(author, extension);
		extensions.setDefinition(definition);
		extensions.setScope(scopeType);
		dao.create(extensions);

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

		// Verify saved extensions
		Extensions queryExtensions = dao.queryByExtension(
				extensions.getExtensionName(), extensions.getTableName(),
				extensions.getColumnName());
		TestCase.assertNotNull(queryExtensions);
		TestCase.assertEquals(tableName, queryExtensions.getTableName());
		TestCase.assertEquals(columnName, queryExtensions.getColumnName());
		TestCase.assertEquals(author + Extensions.EXTENSION_NAME_DIVIDER
				+ extension, queryExtensions.getExtensionName());
		TestCase.assertEquals(author, queryExtensions.getAuthor());
		TestCase.assertEquals(extension,
				queryExtensions.getExtensionNameNoAuthor());
		TestCase.assertEquals(definition, queryExtensions.getDefinition());
		TestCase.assertEquals(scopeType, queryExtensions.getScope());
	}

}
 
Example 9
Source File: ExtensionsUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	ExtensionsDao dao = geoPackage.getExtensionsDao();

	if (dao.isTableExists()) {
		List<Extensions> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random metadata
			int random = (int) (Math.random() * results.size());
			Extensions extensions = results.get(random);

			// Delete the extensions
			dao.delete(extensions);

			// Verify deleted
			Extensions queryExtensions = dao.queryByExtension(
					extensions.getExtensionName(),
					extensions.getTableName(), extensions.getColumnName());
			TestCase.assertNull(queryExtensions);

			// Choose prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random metadata
				random = (int) (Math.random() * results.size());
				extensions = results.get(random);

				// Find which metadata to delete
				QueryBuilder<Extensions, Void> qb = dao.queryBuilder();
				qb.where().eq(Extensions.COLUMN_EXTENSION_NAME,
						extensions.getExtensionName());
				PreparedQuery<Extensions> query = qb.prepare();
				List<Extensions> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<Extensions, Void> db = dao.deleteBuilder();
				db.where().eq(Extensions.COLUMN_EXTENSION_NAME,
						extensions.getExtensionName());
				PreparedDelete<Extensions> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 10
Source File: FeatureTableIndexUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test table index delete all
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDeleteAll(GeoPackage geoPackage) throws SQLException {

	// Test indexing each feature table
	List<String> featureTables = geoPackage.getFeatureTables();
	for (String featureTable : featureTables) {

		FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
		FeatureTableIndex featureTableIndex = new FeatureTableIndex(
				geoPackage, featureDao);

		if (featureTableIndex.isIndexed()) {
			featureTableIndex.deleteIndex();
		}

		TestCase.assertFalse(featureTableIndex.isIndexed());

		TestUtils.validateGeoPackage(geoPackage);

		// Test indexing
		featureTableIndex.index();
		TestUtils.validateGeoPackage(geoPackage);

		TestCase.assertTrue(featureTableIndex.isIndexed());

	}

	ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
	GeometryIndexDao geometryIndexDao = geoPackage.getGeometryIndexDao();
	TableIndexDao tableIndexDao = geoPackage.getTableIndexDao();

	TestCase.assertTrue(geometryIndexDao.isTableExists());
	TestCase.assertTrue(tableIndexDao.isTableExists());
	TestCase.assertTrue(extensionsDao.queryByExtension(
			FeatureTableIndex.EXTENSION_NAME).size() > 0);

	TestCase.assertTrue(geometryIndexDao.countOf() > 0);
	long count = tableIndexDao.countOf();
	TestCase.assertTrue(count > 0);

	int deleteCount = tableIndexDao.deleteAllCascade();
	TestCase.assertEquals(count, deleteCount);

	TestCase.assertTrue(geometryIndexDao.countOf() == 0);
	TestCase.assertTrue(tableIndexDao.countOf() == 0);
}