/** * {@inheritDoc} */ @Override public Contents getTableContents(String table) { ContentsDao contentDao = getContentsDao(); Contents contents = null; try { contents = contentDao.queryForId(table); } catch (SQLException e) { throw new GeoPackageException("Failed to retrieve table contents: " + table, e); } return contents; }
/** * Delete a Contents by id, cascading optionally including the user table * * @param id * id * @param userTable * true if a user table * @return deleted count * @throws SQLException * upon deletion error */ public int deleteByIdCascade(String id, boolean userTable) throws SQLException { int count = 0; if (id != null) { Contents contents = queryForId(id); if (contents != null) { count = deleteCascade(contents, userTable); } else if (userTable) { dropTable(id); } } return count; }
/** * Get the bounding box for all tables in the provided projection * * @param projection * desired bounding box projection * * @return bounding box * @since 3.1.0 */ public BoundingBox getBoundingBox(Projection projection) { BoundingBox boundingBox = null; List<String> tables = null; try { tables = getTables(); } catch (SQLException e) { throw new GeoPackageException( "Failed to query for contents tables", e); } for (String table : tables) { BoundingBox tableBoundingBox = getBoundingBox(projection, table); if (tableBoundingBox != null) { if (boundingBox != null) { boundingBox = boundingBox.union(tableBoundingBox); } else { boundingBox = tableBoundingBox; } } } return boundingBox; }
/** * Delete the Contents matching the prepared query, cascading optionally * including the user table * * @param preparedDelete * prepared delete query * @param userTable * true if a user table * @return deleted count * @throws SQLException * upon deletion error */ public int deleteCascade(PreparedQuery<Contents> preparedDelete, boolean userTable) throws SQLException { int count = 0; if (preparedDelete != null) { List<Contents> contentsList = query(preparedDelete); count = deleteCascade(contentsList, userTable); } return count; }
/** * Delete the Contents, cascading optionally including the user table * * @param contents * contents * @param userTable * true if a user table * @return deleted count * @throws SQLException * upon deletion error */ public int deleteCascade(Contents contents, boolean userTable) throws SQLException { int count = deleteCascade(contents); if (userTable) { dropTable(contents.getTableName()); } return count; }
List<Contents> results = dao.queryForAll(); dao.deleteCascade(contents); } else { dao.delete(contents); Contents queryContents = dao.queryForId(contents.getId()); TestCase.assertNull(queryContents); results = dao.queryForAll(); if (!results.isEmpty()) { QueryBuilder<Contents, String> qb = dao.queryBuilder(); qb.where().eq(Contents.COLUMN_DATA_TYPE, contents.getDataType().getName()); PreparedQuery<Contents> query = qb.prepare(); List<Contents> queryResults = dao.query(query); int count = queryResults.size(); geometryColumnsIds = new ArrayList<TableColumnKey>(); deleted = dao.deleteCascade(query); } else { DeleteBuilder<Contents, String> db = dao.deleteBuilder(); db.where().eq(Contents.COLUMN_DATA_TYPE, contents.getDataType().getName()); PreparedDelete<Contents> deleteQuery = db.prepare(); deleted = dao.delete(deleteQuery);
List<Contents> results = dao.queryForAll(); dao.update(contents); Contents updatedContents = dao.queryForId(contents.getId()); TestCase.assertEquals(updatedLastChange, updatedContents.getLastChange()); QueryBuilder<Contents, String> qb = dao.queryBuilder(); qb.where().ge(Contents.COLUMN_MIN_X, 0).or() .ge(Contents.COLUMN_MIN_Y, 0); PreparedQuery<Contents> preparedQuery = qb.prepare(); List<Contents> queryContents = dao.query(preparedQuery); UpdateBuilder<Contents, String> ub = dao.updateBuilder(); ub.updateColumnValue(Contents.COLUMN_MIN_X, updatedMinimum); ub.updateColumnValue(Contents.COLUMN_MIN_Y, updatedMinimum); .ge(Contents.COLUMN_MIN_Y, 0); PreparedUpdate<Contents> update = ub.prepare(); int updated = dao.update(update); TestCase.assertEquals(queryContents.size(), updated); Contents reloadedContents = dao.queryForId(updatedContent .getId()); TestCase.assertEquals(updatedMinimum,
List<Contents> results = dao.queryForAll(); if (expectedResults != null) { TestCase.assertEquals("Unexpected number of contents rows", Contents queryContents = dao.queryForId(contents.getTableName()); TestCase.assertNotNull(queryContents); TestCase.assertEquals(contents.getTableName(), List<Contents> queryContentsList = dao.queryForEq( Contents.COLUMN_IDENTIFIER, contents.getIdentifier()); TestCase.assertNotNull(queryContentsList); queryContentsList = dao.queryForFieldValues(fieldValues); TestCase.assertNotNull(queryContentsList); TestCase.assertTrue(queryContentsList.size() >= 1); QueryBuilder<Contents, String> qb = dao.queryBuilder(); qb.where() .le(Contents.COLUMN_LAST_CHANGE, contents.getLastChange()); PreparedQuery<Contents> query = qb.prepare(); queryContentsList = dao.query(query); qb = dao.queryBuilder(); qb.where() .gt(Contents.COLUMN_LAST_CHANGE, contents.getLastChange()); query = qb.prepare(); queryContentsList = dao.query(query);
geoPackage.createFeatureTable(table); contentsDao.create(contents);
TestCase.assertFalse(contentsDao.getTables().contains( simpleTable.getTableName())); ExtendedRelation extendedRelation = rte TestCase.assertTrue(geoPackage.getDatabase().tableExists( simpleTable.getTableName())); TestCase.assertTrue(contentsDao.getTables().contains( simpleTable.getTableName())); validateContents(simpleTable, contentsDao.queryForId(simpleTable.getTableName())); TestCase.assertEquals(SimpleAttributesTable.RELATION_TYPE.getDataType(), geoPackage.getTableType(simpleTable.getTableName())); TestCase.assertNotNull(contentsDao.queryForId(simpleTable .getTableName())); geoPackage.deleteTable(simpleTable.getTableName()); TestCase.assertFalse(geoPackage.isTable(simpleTable.getTableName())); TestCase.assertNull(contentsDao.queryForId(simpleTable.getTableName()));
long count = dao.countOf(); dao.create(contents); long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); Contents queryContents = dao.queryForId(tableName); String queryContentsId = queryContents.getId(); TestCase.assertEquals(tableName, queryContents.getTableName()); copyContents.getTableName(), "geom", GeometryType.GEOMETRY)); dao.create(copyContents); long newCount2 = dao.countOf(); TestCase.assertEquals(count + 2, newCount2); Contents queryCopiedContents = dao.queryForId(copyTableName); TestCase.assertEquals(copyTableName, queryCopiedContents.getTableName()); TestCase.assertEquals(queryContents.getDataType(), queryContents = dao.queryForId(tableName); TestCase.assertEquals(queryContentsId, queryContents.getId()); TestCase.assertEquals(tableName, queryContents.getTableName());
public static void updateLastChange(GeoPackage geoPackage, FeatureDao featureDao) throws SQLException { Contents contents = featureDao.getGeometryColumns().getContents(); contents.setLastChange(new Date()); ContentsDao contentsDao = geoPackage.getContentsDao(); contentsDao.update(contents); }
GeometryColumnsDao geometryColumnsDao = getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { GeometryColumns geometryColumns = contents TileMatrixDao tileMatrixDao = getTileMatrixDao(); if (tileMatrixDao.isTableExists()) { ForeignCollection<TileMatrix> tileMatrixCollection = contents TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao(); if (tileMatrixSetDao.isTableExists()) { TileMatrixSet tileMatrixSet = contents dropTable(contents.getTableName()); dropTable(contents.getTableName()); count = delete(contents);
/** * Delete the collection of Contents, cascading * * @param contentsCollection * contents collection * @return deleted count * @throws SQLException * upon deletion error */ public int deleteCascade(Collection<Contents> contentsCollection) throws SQLException { return deleteCascade(contentsCollection, false); }
/** * Get table names by data type * * @param dataType * data type * @return table names * @throws SQLException * upon query error * @since 1.2.1 */ public List<String> getTables(ContentsDataType dataType) throws SQLException { return getTables(dataType.getName()); }
/** * Get table names * * @return table names * @throws SQLException * upon query error * @since 1.2.1 */ public List<String> getTables() throws SQLException { List<Contents> contents = queryForAll(); List<String> tableNames = new ArrayList<String>(); for (Contents content : contents) { tableNames.add(content.getTableName()); } return tableNames; }
/** * Check the GeoPackage for the minimum required tables * * @param geoPackage * GeoPackage * @return true if has minimum tables */ public static boolean hasMinimumTables(GeoPackageCore geoPackage) { boolean hasMinimum; try { hasMinimum = geoPackage.getSpatialReferenceSystemDao() .isTableExists() && geoPackage.getContentsDao().isTableExists(); } catch (SQLException e) { throw new GeoPackageException( "Failed to check for required minimum GeoPackage tables. GeoPackage Name: " + geoPackage.getName()); } return hasMinimum; }
/** * Get contents by data type * * @param dataType * data type * @return list of contents * @throws SQLException * upon query error * @since 3.0.1 */ public List<Contents> getContents(String dataType) throws SQLException { List<Contents> contents = queryForEq(Contents.COLUMN_DATA_TYPE, dataType); return contents; }
contents.setIdentifier(tableName); getContentsDao().create(contents);