Java Code Examples for mil.nga.geopackage.GeoPackage#deleteTable()
The following examples show how to use
mil.nga.geopackage.GeoPackage#deleteTable() .
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: SQLExecAlterTable.java From geopackage-java with MIT License | 6 votes |
/** * Check for a drop table statement and execute * * @param database * database * @param sql * SQL statement * @return result if dropped table, null if not */ private static SQLExecResult dropTable(GeoPackage database, String sql) { SQLExecResult result = null; Matcher matcher = DROP_TABLE_PATTERN.matcher(sql); if (matcher.matches() && SQLExec.isGeoPackage(database)) { String tableName = CoreSQLUtils .quoteUnwrap(matcher.group(TABLE_NAME_GROUP)); if (tableName != null) { tableName = tableName.trim(); if (!database.isTable(tableName)) { throw new GeoPackageException( "Table does not exist: " + tableName); } database.deleteTable(tableName.trim()); result = new SQLExecResult(); } } return result; }
Example 2
Source File: GeoPackageRepository.java From geopackage-mapcache-android with MIT License | 5 votes |
/** * Delete a layer from a geopackage in both the manager and make sure it's removed from the * geos list */ public boolean removeLayerFromGeo(String geoPackageName, String layerName) { try { removeLayerFromGeos(geoPackageName, layerName); GeoPackage geo = manager.open(geoPackageName); if (geo != null) { geo.deleteTable(layerName); geo.close(); return true; } return false; } catch (Exception e) { return false; } }
Example 3
Source File: GeoPackageTestUtils.java From geopackage-android with MIT License | 4 votes |
/** * 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 4
Source File: GeoPackageTestUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test the GeoPackage vacuum * * @param activity activity * @param geoPackage GeoPackage */ public static void testVacuum(Activity activity, GeoPackage geoPackage) { GeoPackageManager manager = GeoPackageFactory.getManager(activity); long size = manager.size(geoPackage.getName()); for (String table : geoPackage.getTables()) { geoPackage.deleteTable(table); geoPackage.vacuum(); long newSize = manager.size(geoPackage.getName()); TestCase.assertTrue(size > newSize); size = newSize; } }
Example 5
Source File: GeoPackageTestUtils.java From geopackage-java with MIT License | 4 votes |
/** * 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 6
Source File: GeoPackageTestUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test the GeoPackage vacuum * * @param geoPackage * GeoPackage */ public static void testVacuum(GeoPackage geoPackage) { String path = geoPackage.getPath(); File file = new File(path); long size = file.length(); for (String table : geoPackage.getTables()) { geoPackage.deleteTable(table); TestCase.assertEquals(size, file.length()); geoPackage.vacuum(); long newSize = file.length(); TestCase.assertTrue(size > newSize); size = newSize; } }