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

The following examples show how to use mil.nga.geopackage.GeoPackage#getAttributesTables() . 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: AttributesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage GeoPackage
 * @throws SQLException upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

    List<String> tables = geoPackage.getAttributesTables();

    if (!tables.isEmpty()) {

        for (String tableName : tables) {

            AttributesDao dao = geoPackage.getAttributesDao(tableName);
            TestCase.assertNotNull(dao);

            AttributesCursor cursor = dao.queryForAll();
            int count = cursor.getCount();
            if (count > 0) {

                // Choose random attribute
                int random = (int) (Math.random() * count);
                cursor.moveToPosition(random);

                AttributesRow attributesRow = cursor.getRow();
                cursor.close();

                // Delete row
                TestCase.assertEquals(1, dao.delete(attributesRow));

                // Verify deleted
                AttributesRow queryAttributesRow = dao
                        .queryForIdRow(attributesRow.getId());
                TestCase.assertNull(queryAttributesRow);
                cursor = dao.queryForAll();
                TestCase.assertEquals(count - 1, cursor.getCount());
                cursor.close();
            }
            cursor.close();
        }
    }
}
 
Example 2
Source File: AttributesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage
 *            GeoPackage
 * @throws SQLException
 *             upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	List<String> tables = geoPackage.getAttributesTables();

	if (!tables.isEmpty()) {

		for (String tableName : tables) {

			AttributesDao dao = geoPackage.getAttributesDao(tableName);
			TestCase.assertNotNull(dao);

			AttributesResultSet cursor = dao.queryForAll();
			int count = cursor.getCount();
			if (count > 0) {

				// Choose random attribute
				int random = (int) (Math.random() * count);
				cursor.moveToPosition(random);

				AttributesRow attributesRow = cursor.getRow();
				cursor.close();

				// Delete row
				TestCase.assertEquals(1, dao.delete(attributesRow));

				// Verify deleted
				AttributesRow queryAttributesRow = dao
						.queryForIdRow(attributesRow.getId());
				TestCase.assertNull(queryAttributesRow);
				cursor = dao.queryForAll();
				TestCase.assertEquals(count - 1, cursor.getCount());
				cursor.close();
			}
			cursor.close();
		}
	}
}
 
Example 3
Source File: AttributesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test update
 *
 * @param geoPackage GeoPackage
 * @throws SQLException upon error
 */
public static void testUpdate(GeoPackage geoPackage) throws SQLException {

    List<String> tables = geoPackage.getAttributesTables();

    if (!tables.isEmpty()) {

        for (String tableName : tables) {

            if (tableName.equals(PropertiesExtension.TABLE_NAME)) {
                continue;
            }

            AttributesDao dao = geoPackage.getAttributesDao(tableName);
            testUpdate(dao);

        }
    }

}
 
Example 4
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 5
Source File: AttributesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test update
 *
 * @param geoPackage
 *            GeoPackage
 * @throws SQLException
 *             upon error
 */
public static void testUpdate(GeoPackage geoPackage) throws SQLException {

	List<String> tables = geoPackage.getAttributesTables();

	if (!tables.isEmpty()) {

		for (String tableName : tables) {

			if (tableName.equals(PropertiesExtension.TABLE_NAME)) {
				continue;
			}

			AttributesDao dao = geoPackage.getAttributesDao(tableName);
			testUpdate(dao);

		}
	}

}
 
Example 6
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));

	}

}