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

The following examples show how to use mil.nga.geopackage.GeoPackage#foreignKeys() . 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: TileMatrixSetUtils.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 {

	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();
	if (dao.isTableExists()) {
		List<TileMatrixSet> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random tile matrix set
			int random = (int) (Math.random() * results.size());
			TileMatrixSet tileMatrixSet = results.get(random);

			// Delete the tile matrix set
			geoPackage.foreignKeys(false);
			dao.delete(tileMatrixSet);

			// Verify deleted
			TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet
					.getId());
			TestCase.assertNull(queryTileMatrixSet);

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

				// Choose random tile matrix set
				random = (int) (Math.random() * results.size());
				tileMatrixSet = results.get(random);

				// Find which tile matrix set to delete
				QueryBuilder<TileMatrixSet, String> qb = dao.queryBuilder();
				qb.where().eq(TileMatrixSet.COLUMN_SRS_ID,
						tileMatrixSet.getSrsId());
				PreparedQuery<TileMatrixSet> query = qb.prepare();
				List<TileMatrixSet> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<TileMatrixSet, String> db = dao
						.deleteBuilder();
				db.where().eq(TileMatrixSet.COLUMN_SRS_ID,
						tileMatrixSet.getSrsId());
				PreparedDelete<TileMatrixSet> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 2
Source File: GeoPackageTestUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test deleting tables by name
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testDeleteTables(GeoPackage geoPackage)
        throws SQLException {

    GeometryColumnsDao geometryColumnsDao = geoPackage
            .getGeometryColumnsDao();
    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
    ContentsDao contentsDao = geoPackage.getContentsDao();

    TestCase.assertTrue(geometryColumnsDao.isTableExists()
            || tileMatrixSetDao.isTableExists());

    geoPackage.foreignKeys(false);

    if (geometryColumnsDao.isTableExists()) {

        TestCase.assertEquals(geoPackage.getFeatureTables().size(),
                geometryColumnsDao.countOf());
        for (String featureTable : geoPackage.getFeatureTables()) {
            TestCase.assertTrue(geoPackage.isTable(featureTable));
            TestCase.assertNotNull(contentsDao.queryForId(featureTable));
            geoPackage.deleteTable(featureTable);
            TestCase.assertFalse(geoPackage.isTable(featureTable));
            TestCase.assertNull(contentsDao.queryForId(featureTable));
        }
        TestCase.assertEquals(0, geometryColumnsDao.countOf());

        geoPackage.dropTable(GeometryColumns.TABLE_NAME);

        TestCase.assertFalse(geometryColumnsDao.isTableExists());
    }

    if (tileMatrixSetDao.isTableExists()) {
        TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

        TestCase.assertTrue(tileMatrixSetDao.isTableExists());
        TestCase.assertTrue(tileMatrixDao.isTableExists());

        TestCase.assertEquals(geoPackage.getTables(ContentsDataType.TILES).size() + geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE).size(),
                tileMatrixSetDao.countOf());
        for (String tileTable : geoPackage.getTileTables()) {
            TestCase.assertTrue(geoPackage.isTable(tileTable));
            TestCase.assertNotNull(contentsDao.queryForId(tileTable));
            geoPackage.deleteTable(tileTable);
            TestCase.assertFalse(geoPackage.isTable(tileTable));
            TestCase.assertNull(contentsDao.queryForId(tileTable));
        }
        TestCase.assertEquals(geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE).size(), tileMatrixSetDao.countOf());

        geoPackage.dropTable(TileMatrix.TABLE_NAME);
        geoPackage.dropTable(TileMatrixSet.TABLE_NAME);

        TestCase.assertFalse(tileMatrixSetDao.isTableExists());
        TestCase.assertFalse(tileMatrixDao.isTableExists());
    }

    for (String attributeTable : geoPackage.getAttributesTables()) {

        TestCase.assertTrue(geoPackage.isTable(attributeTable));
        TestCase.assertNotNull(contentsDao.queryForId(attributeTable));
        geoPackage.deleteTable(attributeTable);
        TestCase.assertFalse(geoPackage.isTable(attributeTable));
        TestCase.assertNull(contentsDao.queryForId(attributeTable));

    }

}
 
Example 3
Source File: TileMatrixSetUtils.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 {

	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();
	if (dao.isTableExists()) {
		List<TileMatrixSet> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random tile matrix set
			int random = (int) (Math.random() * results.size());
			TileMatrixSet tileMatrixSet = results.get(random);

			// Delete the tile matrix set
			geoPackage.foreignKeys(false);
			dao.delete(tileMatrixSet);

			// Verify deleted
			TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet
					.getId());
			TestCase.assertNull(queryTileMatrixSet);

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

				// Choose random tile matrix set
				random = (int) (Math.random() * results.size());
				tileMatrixSet = results.get(random);

				// Find which tile matrix set to delete
				QueryBuilder<TileMatrixSet, String> qb = dao.queryBuilder();
				qb.where().eq(TileMatrixSet.COLUMN_SRS_ID,
						tileMatrixSet.getSrsId());
				PreparedQuery<TileMatrixSet> query = qb.prepare();
				List<TileMatrixSet> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<TileMatrixSet, String> db = dao
						.deleteBuilder();
				db.where().eq(TileMatrixSet.COLUMN_SRS_ID,
						tileMatrixSet.getSrsId());
				PreparedDelete<TileMatrixSet> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 4
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test deleting tables by name
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDeleteTables(GeoPackage geoPackage)
		throws SQLException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();
	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
	ContentsDao contentsDao = geoPackage.getContentsDao();

	TestCase.assertTrue(geometryColumnsDao.isTableExists()
			|| tileMatrixSetDao.isTableExists());

	geoPackage.foreignKeys(false);

	if (geometryColumnsDao.isTableExists()) {

		TestCase.assertEquals(geoPackage.getFeatureTables().size(),
				geometryColumnsDao.countOf());
		for (String featureTable : geoPackage.getFeatureTables()) {
			TestCase.assertTrue(geoPackage.isTable(featureTable));
			TestCase.assertNotNull(contentsDao.queryForId(featureTable));
			geoPackage.deleteTable(featureTable);
			TestCase.assertFalse(geoPackage.isTable(featureTable));
			TestCase.assertNull(contentsDao.queryForId(featureTable));
		}
		TestCase.assertEquals(0, geometryColumnsDao.countOf());

		geoPackage.dropTable(GeometryColumns.TABLE_NAME);

		TestCase.assertFalse(geometryColumnsDao.isTableExists());
	}

	if (tileMatrixSetDao.isTableExists()) {
		TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

		TestCase.assertTrue(tileMatrixSetDao.isTableExists());
		TestCase.assertTrue(tileMatrixDao.isTableExists());

		TestCase.assertEquals(geoPackage.getTables(ContentsDataType.TILES)
				.size()
				+ geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE)
						.size(),
				tileMatrixSetDao.countOf());
		for (String tileTable : geoPackage.getTileTables()) {
			TestCase.assertTrue(geoPackage.isTable(tileTable));
			TestCase.assertNotNull(contentsDao.queryForId(tileTable));
			geoPackage.deleteTable(tileTable);
			TestCase.assertFalse(geoPackage.isTable(tileTable));
			TestCase.assertNull(contentsDao.queryForId(tileTable));
		}
		TestCase.assertEquals(geoPackage
				.getTables(ContentsDataType.GRIDDED_COVERAGE).size(),
				tileMatrixSetDao.countOf());

		geoPackage.dropTable(TileMatrix.TABLE_NAME);
		geoPackage.dropTable(TileMatrixSet.TABLE_NAME);

		TestCase.assertFalse(tileMatrixSetDao.isTableExists());
		TestCase.assertFalse(tileMatrixDao.isTableExists());
	}

	for (String attributeTable : geoPackage.getAttributesTables()) {

		TestCase.assertTrue(geoPackage.isTable(attributeTable));
		TestCase.assertNotNull(contentsDao.queryForId(attributeTable));
		geoPackage.deleteTable(attributeTable);
		TestCase.assertFalse(geoPackage.isTable(attributeTable));
		TestCase.assertNull(contentsDao.queryForId(attributeTable));

	}

}