Skip to content

Commit

Permalink
abstract user dao by table, set user custom dao contents
Browse files Browse the repository at this point in the history
  • Loading branch information
bosborn committed Feb 13, 2024
1 parent 465d1eb commit c5cdeee
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> 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);
}
}
}

}

}
11 changes: 11 additions & 0 deletions geopackage-sdk/src/main/java/mil/nga/geopackage/GeoPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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}
*/
Expand Down

0 comments on commit c5cdeee

Please sign in to comment.