Java Code Examples for mil.nga.geopackage.db.CoreSQLUtils#transferTableContent()
The following examples show how to use
mil.nga.geopackage.db.CoreSQLUtils#transferTableContent() .
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: GeoPackageExtensions.java From geopackage-core-java with MIT License | 6 votes |
/** * Copy the Metadata extensions for the table * * @param geoPackage * GeoPackage * @param table * table name * @param newTable * new table name * @since 3.3.0 */ public static void copyMetadata(GeoPackageCore geoPackage, String table, String newTable) { try { if (geoPackage.isTable(MetadataReference.TABLE_NAME)) { CoreSQLUtils.transferTableContent(geoPackage.getDatabase(), MetadataReference.TABLE_NAME, MetadataReference.COLUMN_TABLE_NAME, newTable, table); } } catch (Exception e) { logger.log(Level.WARNING, "Failed to create Metadata for table: " + newTable + ", copied from table: " + table, e); } }
Example 2
Source File: NGAExtensions.java From geopackage-core-java with MIT License | 5 votes |
/** * Copy the Tile Scaling extensions for the table * * @param geoPackage * GeoPackage * @param table * table name * @param newTable * new table name * @since 3.3.0 */ public static void copyTileScaling(GeoPackageCore geoPackage, String table, String newTable) { try { TileTableScaling tileTableScaling = new TileTableScaling(geoPackage, table); if (tileTableScaling.has()) { Extensions extension = tileTableScaling.getExtension(); if (extension != null) { extension.setTableName(newTable); tileTableScaling.getExtensionsDao().create(extension); if (geoPackage.isTable(TileScaling.TABLE_NAME)) { CoreSQLUtils.transferTableContent( geoPackage.getDatabase(), TileScaling.TABLE_NAME, TileScaling.COLUMN_TABLE_NAME, newTable, table); } } } } catch (Exception e) { logger.log(Level.WARNING, "Failed to create Tile Scaling for table: " + newTable + ", copied from table: " + table, e); } }
Example 3
Source File: NGAExtensions.java From geopackage-core-java with MIT License | 4 votes |
/** * Copy the Geometry Index extension for the table * * @param geoPackage * GeoPackage * @param table * table name * @param newTable * new table name * @since 3.3.0 */ public static void copyGeometryIndex(GeoPackageCore geoPackage, String table, String newTable) { try { ExtensionsDao extensionsDao = geoPackage.getExtensionsDao(); if (extensionsDao.isTableExists()) { List<Extensions> extensions = extensionsDao.queryByExtension( FeatureTableCoreIndex.EXTENSION_NAME, table); if (!extensions.isEmpty()) { Extensions extension = extensions.get(0); extension.setTableName(newTable); extensionsDao.create(extension); TableIndexDao tableIndexDao = geoPackage.getTableIndexDao(); if (tableIndexDao.isTableExists()) { TableIndex tableIndex = tableIndexDao.queryForId(table); if (tableIndex != null) { tableIndex.setTableName(newTable); tableIndexDao.create(tableIndex); if (geoPackage.isTable(GeometryIndex.TABLE_NAME)) { CoreSQLUtils.transferTableContent( geoPackage.getDatabase(), GeometryIndex.TABLE_NAME, GeometryIndex.COLUMN_TABLE_NAME, newTable, table); } } } } } } catch (Exception e) { logger.log(Level.WARNING, "Failed to create Geometry Index for table: " + newTable + ", copied from table: " + table, e); } }
Example 4
Source File: NGAExtensions.java From geopackage-core-java with MIT License | 4 votes |
/** * Copy the feature table style * * @param featureStyleExtension * feature style extension * @param mappingTablePrefix * mapping table prefix * @param table * table name * @param newTable * new table name * @param contentsId * contents id * @param newContentsId * new contents id */ private static void copyFeatureTableStyle( FeatureCoreStyleExtension featureStyleExtension, String mappingTablePrefix, String table, String newTable, long contentsId, long newContentsId) throws SQLException { GeoPackageCore geoPackage = featureStyleExtension.getGeoPackage(); String mappingTableName = featureStyleExtension .getMappingTableName(mappingTablePrefix, table); ExtensionsDao extensionsDao = featureStyleExtension.getExtensionsDao(); List<Extensions> extensions = extensionsDao.queryByExtension( RelatedTablesCoreExtension.EXTENSION_NAME, mappingTableName); if (!extensions.isEmpty()) { String newMappingTableName = featureStyleExtension .getMappingTableName(mappingTablePrefix, newTable); UserCustomTable userTable = UserCustomTableReader .readTable(geoPackage.getDatabase(), mappingTableName); AlterTable.copyTable(geoPackage.getDatabase(), userTable, newMappingTableName, false); TableMapping mappingTableTableMapping = new TableMapping(userTable, newMappingTableName); MappedColumn baseIdColumn = mappingTableTableMapping .getColumn(UserMappingTable.COLUMN_BASE_ID); baseIdColumn.setConstantValue(newContentsId); baseIdColumn.setWhereValue(contentsId); CoreSQLUtils.transferTableContent(geoPackage.getDatabase(), mappingTableTableMapping); Extensions extension = extensions.get(0); extension.setTableName(newMappingTableName); extensionsDao.create(extension); TableMapping extendedRelationTableMapping = new TableMapping( geoPackage.getDatabase(), ExtendedRelation.TABLE_NAME); extendedRelationTableMapping .removeColumn(ExtendedRelation.COLUMN_ID); MappedColumn baseTableNameColumn = extendedRelationTableMapping .getColumn(ExtendedRelation.COLUMN_BASE_TABLE_NAME); baseTableNameColumn.setWhereValue(ContentsId.TABLE_NAME); MappedColumn mappingTableNameColumn = extendedRelationTableMapping .getColumn(ExtendedRelation.COLUMN_MAPPING_TABLE_NAME); mappingTableNameColumn.setConstantValue(newMappingTableName); mappingTableNameColumn.setWhereValue(mappingTableName); CoreSQLUtils.transferTableContent(geoPackage.getDatabase(), extendedRelationTableMapping); } }
Example 5
Source File: GeoPackageExtensions.java From geopackage-core-java with MIT License | 4 votes |
/** * Copy the Related Tables extensions for the table * * @param geoPackage * GeoPackage * @param table * table name * @param newTable * new table name * @since 3.3.0 */ public static void copyRelatedTables(GeoPackageCore geoPackage, String table, String newTable) { try { RelatedTablesCoreExtension relatedTablesExtension = getRelatedTableExtension( geoPackage); if (relatedTablesExtension.has()) { ExtendedRelationsDao extendedRelationsDao = relatedTablesExtension .getExtendedRelationsDao(); ExtensionsDao extensionsDao = geoPackage.getExtensionsDao(); List<ExtendedRelation> extendedRelations = extendedRelationsDao .getBaseTableRelations(table); for (ExtendedRelation extendedRelation : extendedRelations) { String mappingTableName = extendedRelation .getMappingTableName(); List<Extensions> extensions = extensionsDao .queryByExtension( RelatedTablesCoreExtension.EXTENSION_NAME, mappingTableName); if (!extensions.isEmpty()) { String newMappingTableName = CoreSQLUtils.createName( geoPackage.getDatabase(), mappingTableName, table, newTable); UserCustomTable userTable = UserCustomTableReader .readTable(geoPackage.getDatabase(), mappingTableName); AlterTable.copyTable(geoPackage.getDatabase(), userTable, newMappingTableName); Extensions extension = extensions.get(0); extension.setTableName(newMappingTableName); extensionsDao.create(extension); TableMapping extendedRelationTableMapping = new TableMapping( geoPackage.getDatabase(), ExtendedRelation.TABLE_NAME); extendedRelationTableMapping .removeColumn(ExtendedRelation.COLUMN_ID); MappedColumn baseTableNameColumn = extendedRelationTableMapping .getColumn( ExtendedRelation.COLUMN_BASE_TABLE_NAME); baseTableNameColumn.setConstantValue(newTable); baseTableNameColumn.setWhereValue(table); MappedColumn mappingTableNameColumn = extendedRelationTableMapping .getColumn( ExtendedRelation.COLUMN_MAPPING_TABLE_NAME); mappingTableNameColumn .setConstantValue(newMappingTableName); mappingTableNameColumn.setWhereValue(mappingTableName); CoreSQLUtils.transferTableContent( geoPackage.getDatabase(), extendedRelationTableMapping); } } } } catch (Exception e) { logger.log(Level.WARNING, "Failed to create Related Tables for table: " + newTable + ", copied from table: " + table, e); } }
Example 6
Source File: GeoPackageExtensions.java From geopackage-core-java with MIT License | 4 votes |
/** * Copy the Gridded Coverage extensions for the table * * @param geoPackage * GeoPackage * @param table * table name * @param newTable * new table name * @since 3.3.0 */ public static void copyGriddedCoverage(GeoPackageCore geoPackage, String table, String newTable) { try { if (geoPackage.isTableType(ContentsDataType.GRIDDED_COVERAGE, table)) { ExtensionsDao extensionsDao = geoPackage.getExtensionsDao(); if (extensionsDao.isTableExists()) { List<Extensions> extensions = extensionsDao .queryByExtension(CoverageDataCore.EXTENSION_NAME, table); if (!extensions.isEmpty()) { Extensions extension = extensions.get(0); extension.setTableName(newTable); extensionsDao.create(extension); GriddedCoverageDao griddedCoverageDao = geoPackage .getGriddedCoverageDao(); if (griddedCoverageDao.isTableExists()) { CoreSQLUtils.transferTableContent( geoPackage.getDatabase(), GriddedCoverage.TABLE_NAME, GriddedCoverage.COLUMN_TILE_MATRIX_SET_NAME, newTable, table, GriddedCoverage.COLUMN_ID); } GriddedTileDao griddedTileDao = geoPackage .getGriddedTileDao(); if (griddedTileDao.isTableExists()) { CoreSQLUtils.transferTableContent( geoPackage.getDatabase(), GriddedTile.TABLE_NAME, GriddedTile.COLUMN_TABLE_NAME, newTable, table, GriddedTile.COLUMN_ID); } } } } } catch (Exception e) { logger.log(Level.WARNING, "Failed to create Gridded Coverage for table: " + newTable + ", copied from table: " + table, e); } }
Example 7
Source File: GeoPackageExtensions.java From geopackage-core-java with MIT License | 4 votes |
/** * Copy the Schema extensions for the table * * @param geoPackage * GeoPackage * @param table * table name * @param newTable * new table name * @since 3.3.0 */ public static void copySchema(GeoPackageCore geoPackage, String table, String newTable) { try { if (geoPackage.isTable(DataColumns.TABLE_NAME)) { UserCustomTable dataColumnsTable = UserCustomTableReader .readTable(geoPackage.getDatabase(), DataColumns.TABLE_NAME); UserCustomColumn nameColumn = dataColumnsTable .getColumn(DataColumns.COLUMN_NAME); if (nameColumn.hasConstraints()) { nameColumn.clearConstraints(); if (dataColumnsTable.hasConstraints()) { dataColumnsTable.clearConstraints(); String constraintSql = GeoPackageTableCreator .readSQLScript( GeoPackageTableCreator.DATA_COLUMNS) .get(0); TableConstraints constraints = ConstraintParser .getConstraints(constraintSql); dataColumnsTable.addConstraints( constraints.getTableConstraints()); } AlterTable.alterColumn(geoPackage.getDatabase(), dataColumnsTable, nameColumn); } CoreSQLUtils.transferTableContent(geoPackage.getDatabase(), DataColumns.TABLE_NAME, DataColumns.COLUMN_TABLE_NAME, newTable, table); } } catch (Exception e) { logger.log(Level.WARNING, "Failed to create Schema for table: " + newTable + ", copied from table: " + table, e); } }