diff --git a/CHANGELOG.md b/CHANGELOG.md index d438a3d3..e807d417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Adheres to [Semantic Versioning](http://semver.org/). * geopackage-core version 6.6.7 * Ignored internal databases support for non GeoPackages (preconfigured to ignore ue3.db for Google Maps) +* Get abstract User DAO by table name +* Set User Custom DAO contents ## [6.7.3](https://github.com/ngageoint/geopackage-android/releases/tag/6.7.3) (11-30-2023) diff --git a/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageCreateTest.java b/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageCreateTest.java index 31f0b306..d554f926 100644 --- a/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageCreateTest.java +++ b/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageCreateTest.java @@ -121,4 +121,17 @@ public void testTableTypes() throws SQLException { } + /** + * Test user daos + * + * @throws SQLException + * upon error + */ + @Test + public void testUserDao() throws SQLException { + + GeoPackageTestUtils.testUserDao(geoPackage); + + } + } diff --git a/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageExternalTest.java b/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageExternalTest.java index 399ff050..02dcb777 100644 --- a/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageExternalTest.java +++ b/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageExternalTest.java @@ -134,4 +134,17 @@ public void testTableTypes() throws SQLException { } + /** + * Test user daos + * + * @throws SQLException + * upon error + */ + @Test + public void testUserDao() throws SQLException { + + GeoPackageTestUtils.testUserDao(geoPackage); + + } + } diff --git a/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageImportTest.java b/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageImportTest.java index a19756d9..afb2a014 100644 --- a/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageImportTest.java +++ b/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageImportTest.java @@ -121,4 +121,17 @@ public void testTableTypes() throws SQLException { } + /** + * Test user daos + * + * @throws SQLException + * upon error + */ + @Test + public void testUserDao() throws SQLException { + + GeoPackageTestUtils.testUserDao(geoPackage); + + } + } diff --git a/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageTestUtils.java b/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageTestUtils.java index 76e52113..614a466d 100644 --- a/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageTestUtils.java +++ b/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/GeoPackageTestUtils.java @@ -12,15 +12,13 @@ import java.util.Map; import java.util.Set; -import mil.nga.geopackage.BoundingBox; -import mil.nga.geopackage.GeoPackage; -import mil.nga.geopackage.GeoPackageFactory; -import mil.nga.geopackage.GeoPackageManager; +import mil.nga.geopackage.attributes.AttributesDao; import mil.nga.geopackage.contents.Contents; import mil.nga.geopackage.contents.ContentsDao; import mil.nga.geopackage.contents.ContentsDataType; import mil.nga.geopackage.db.GeoPackageDataType; import mil.nga.geopackage.db.TableColumnKey; +import mil.nga.geopackage.db.table.TableInfo; import mil.nga.geopackage.extension.coverage.CoverageData; import mil.nga.geopackage.features.columns.GeometryColumns; import mil.nga.geopackage.features.columns.GeometryColumnsDao; @@ -35,6 +33,8 @@ import mil.nga.geopackage.tiles.matrixset.TileMatrixSet; import mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao; import mil.nga.geopackage.tiles.user.TileDao; +import mil.nga.geopackage.user.UserDao; +import mil.nga.geopackage.user.custom.UserCustomDao; import mil.nga.proj.Projection; import mil.nga.proj.ProjectionConstants; import mil.nga.proj.ProjectionFactory; @@ -709,4 +709,52 @@ public static void testTableTypes(GeoPackage geoPackage) } + /** + * Test user daos + * + * @param geoPackage + * GeoPackage + * @throws SQLException + * upon error + */ + public static void testUserDao(GeoPackage geoPackage) throws SQLException { + + List tables = geoPackage.getTables(); + for (String table : tables) { + UserDao dao = geoPackage.getUserDao(table); + TestCase.assertNotNull(dao); + ContentsDataType dataType = geoPackage.getTableCoreDataType(table); + TableInfo tableInfo = TableInfo.info(geoPackage.getConnection(), + table); + TestCase.assertEquals(tableInfo.numColumns(), dao.columnCount()); + Contents contents = dao.getContents(); + TestCase.assertNotNull(contents); + if (dataType == null) { + TestCase.assertTrue(dao instanceof UserCustomDao); + TestCase.assertNotNull(contents.getDataTypeName()); + } else { + switch (dataType) { + case ATTRIBUTES: + TestCase.assertTrue(dao instanceof AttributesDao); + TestCase.assertEquals(ContentsDataType.ATTRIBUTES, + contents.getDataType()); + break; + case FEATURES: + TestCase.assertTrue(dao instanceof FeatureDao); + TestCase.assertEquals(ContentsDataType.FEATURES, + contents.getDataType()); + break; + case TILES: + TestCase.assertTrue(dao instanceof TileDao); + TestCase.assertEquals(ContentsDataType.TILES, + contents.getDataType()); + break; + default: + TestCase.fail("Unsupported data type: " + dataType); + } + } + } + + } + } diff --git a/geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackage.java b/geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackage.java index 8e060409..6a42f815 100644 --- a/geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackage.java +++ b/geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackage.java @@ -15,6 +15,7 @@ import mil.nga.geopackage.tiles.matrixset.TileMatrixSet; import mil.nga.geopackage.tiles.user.TileDao; import mil.nga.geopackage.tiles.user.TileTable; +import mil.nga.geopackage.user.UserDao; import mil.nga.geopackage.user.custom.UserCustomDao; import mil.nga.geopackage.user.custom.UserCustomTable; @@ -153,6 +154,16 @@ public interface GeoPackage extends GeoPackageCore { */ public UserCustomDao getUserCustomDao(UserCustomTable table); + /** + * Get a User DAO from a table + * + * @param tableName + * table name + * @return user dao + * @since 6.7.4 + */ + public UserDao getUserDao(String tableName); + /** * Perform a raw query on the database * diff --git a/geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackageImpl.java b/geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackageImpl.java index 028aa4a1..667ad101 100644 --- a/geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackageImpl.java +++ b/geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackageImpl.java @@ -32,6 +32,7 @@ import mil.nga.geopackage.tiles.user.TileDao; import mil.nga.geopackage.tiles.user.TileTable; import mil.nga.geopackage.tiles.user.TileTableReader; +import mil.nga.geopackage.user.UserDao; import mil.nga.geopackage.user.custom.UserCustomCursor; import mil.nga.geopackage.user.custom.UserCustomDao; import mil.nga.geopackage.user.custom.UserCustomTable; @@ -407,6 +408,21 @@ public UserCustomDao getUserCustomDao(String tableName) { */ @Override public UserCustomDao getUserCustomDao(UserCustomTable table) { + + if (table.getContents() == null) { + ContentsDao contentsDao = getContentsDao(); + Contents contents = null; + try { + contents = contentsDao.queryForId(table.getTableName()); + } catch (SQLException e) { + throw new GeoPackageException( + "Failed to retrieve " + Contents.class.getSimpleName() + + " for table name: " + table.getTableName(), + e); + } + table.setContents(contents); + } + UserCustomDao dao = new UserCustomDao(getName(), database, table); // Register the table name (with and without quotes) to wrap cursors with the user custom cursor @@ -423,6 +439,41 @@ public Cursor wrapCursor(Cursor cursor) { return dao; } + /** + * {@inheritDoc} + */ + @Override + public UserDao getUserDao(String tableName) { + + UserDao dao = null; + + if (!isContentsTable(tableName)) { + throw new GeoPackageException( + "No contents for user table: " + tableName); + } + ContentsDataType dataType = getTableCoreDataType(tableName); + if (dataType != null) { + switch (dataType) { + case ATTRIBUTES: + dao = getAttributesDao(tableName); + break; + case FEATURES: + dao = getFeatureDao(tableName); + break; + case TILES: + dao = getTileDao(tableName); + break; + default: + throw new GeoPackageException("Unsupported data type: " + + dataType + ", table: " + tableName); + } + } else { + dao = getUserCustomDao(tableName); + } + + return dao; + } + /** * {@inheritDoc} */