mil.nga.geopackage.db.GeoPackageTableCreator Java Examples
The following examples show how to use
mil.nga.geopackage.db.GeoPackageTableCreator.
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: GeoPackageManagerImpl.java From geopackage-android with MIT License | 5 votes |
/** * Create the required GeoPackage application id and tables in the newly created and open database connection. Then close the connection. * * @param db */ private void createAndCloseGeoPackage(GeoPackageDatabase db) { GeoPackageConnection connection = new GeoPackageConnection(db); // Set the GeoPackage application id and user version connection.setApplicationId(); connection.setUserVersion(); // Create the minimum required tables GeoPackageTableCreator tableCreator = new GeoPackageTableCreator(connection); tableCreator.createRequired(); connection.close(); }
Example #2
Source File: ConstraintTest.java From geopackage-core-java with MIT License | 5 votes |
/** * Test the database script for constraint parsing * * @param script * database script * @param primaryKey * expected primary key count * @param unique * expected unique count * @param check * expected check count * @param foreignKey * expected foreign key count * @param names * expected constraint names */ private void testSQLScript(String script, int primaryKey, int unique, int check, int foreignKey, List<String> names) { int count = 0; int primaryKeyCount = 0; int uniqueCount = 0; int checkCount = 0; int foreignKeyCount = 0; List<String> statements = GeoPackageTableCreator.readSQLScript(script); for (String sql : statements) { ConstraintTestResult constraintResult = testConstraint(sql, names); count += constraintResult.getCount(); primaryKeyCount += constraintResult.getPrimaryKeyCount(); uniqueCount += constraintResult.getUniqueCount(); checkCount += constraintResult.getCheckCount(); foreignKeyCount += constraintResult.getForeignKeyCount(); } TestCase.assertEquals(primaryKey + unique + check + foreignKey, count); TestCase.assertEquals(primaryKey, primaryKeyCount); TestCase.assertEquals(unique, uniqueCount); TestCase.assertEquals(check, checkCount); TestCase.assertEquals(foreignKey, foreignKeyCount); }
Example #3
Source File: GeoPackageManager.java From geopackage-java with MIT License | 5 votes |
/** * Create a GeoPackage * * @param file * file * @return true if created */ public static boolean create(File file) { boolean created = false; // Validate or add the file extension if (GeoPackageIOUtils.hasFileExtension(file)) { GeoPackageValidate.validateGeoPackageExtension(file); } else { file = GeoPackageIOUtils.addFileExtension(file, GeoPackageConstants.EXTENSION); } if (file.exists()) { throw new GeoPackageException( "GeoPackage already exists: " + file.getAbsolutePath()); } else { // Create the GeoPackage Connection GeoPackageConnection connection = connect(file); // Set the GeoPackage application id and user version connection.setApplicationId(); connection.setUserVersion(); // Create the minimum required tables GeoPackageTableCreator tableCreator = new GeoPackageTableCreator( connection); tableCreator.createRequired(); connection.close(); created = true; } return created; }
Example #4
Source File: GeoPackageManager.java From geopackage-java with MIT License | 5 votes |
/** * Open a GeoPackage * * @param name * GeoPackage name * @param file * GeoPackage file * @param validate * validate the GeoPackage * @return GeoPackage * @since 3.3.0 */ public static GeoPackage open(String name, File file, boolean validate) { // Validate or add the file extension if (validate) { if (GeoPackageIOUtils.hasFileExtension(file)) { GeoPackageValidate.validateGeoPackageExtension(file); } else { file = GeoPackageIOUtils.addFileExtension(file, GeoPackageConstants.EXTENSION); } } // Create the GeoPackage Connection and table creator GeoPackageConnection connection = connect(file); GeoPackageTableCreator tableCreator = new GeoPackageTableCreator( connection); // Create a GeoPackage GeoPackage geoPackage = new GeoPackageImpl(name, file, connection, tableCreator); // Validate the GeoPackage has the minimum required tables if (validate) { try { GeoPackageValidate.validateMinimumTables(geoPackage); } catch (RuntimeException e) { geoPackage.close(); throw e; } } return geoPackage; }
Example #5
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); } }
Example #6
Source File: ConstraintTest.java From geopackage-core-java with MIT License | 4 votes |
/** * Test parsing constraints in the GeoPackage database tables */ @Test public void testTables() { testSQLScript(GeoPackageTableCreator.SPATIAL_REFERENCE_SYSTEM, 0, 0, 0, 0, createNames()); testSQLScript(GeoPackageTableCreator.CONTENTS, 0, 0, 0, 1, createNames("fk_gc_r_srs_id")); testSQLScript(GeoPackageTableCreator.GEOMETRY_COLUMNS, 1, 1, 0, 2, createNames("pk_geom_cols", "uk_gc_table_name", "fk_gc_tn", "fk_gc_srs")); testSQLScript(GeoPackageTableCreator.TILE_MATRIX_SET, 0, 0, 0, 2, createNames("fk_gtms_table_name", "fk_gtms_srs")); testSQLScript(GeoPackageTableCreator.TILE_MATRIX, 1, 0, 0, 1, createNames("pk_ttm", "fk_tmm_table_name")); testSQLScript(GeoPackageTableCreator.DATA_COLUMNS, 1, 1, 0, 0, createNames("pk_gdc", "gdc_tn")); testSQLScript(GeoPackageTableCreator.DATA_COLUMN_CONSTRAINTS, 0, 1, 0, 0, createNames("gdcc_ntv")); testSQLScript(GeoPackageTableCreator.METADATA, 0, 0, 0, 0, createNames("m_pk")); testSQLScript(GeoPackageTableCreator.METADATA_REFERENCE, 0, 0, 0, 2, createNames("crmr_mfi_fk", "crmr_mpi_fk")); testSQLScript(GeoPackageTableCreator.EXTENSIONS, 0, 1, 0, 0, createNames("ge_tce")); testSQLScript(GeoPackageTableCreator.GRIDDED_COVERAGE, 0, 0, 1, 1, createNames("fk_g2dgtct_name", null)); testSQLScript(GeoPackageTableCreator.GRIDDED_TILE, 0, 1, 0, 1, createNames("fk_g2dgtat_name", null)); testSQLScript(GeoPackageTableCreator.EXTENDED_RELATIONS, 0, 0, 0, 0, createNames()); testSQLScript(GeoPackageTableCreator.TABLE_INDEX, 0, 0, 0, 0, createNames()); testSQLScript(GeoPackageTableCreator.GEOMETRY_INDEX, 1, 0, 0, 1, createNames("pk_ngi", "fk_ngi_nti_tn")); testSQLScript(GeoPackageTableCreator.FEATURE_TILE_LINK, 1, 0, 0, 0, createNames("pk_nftl")); testSQLScript(GeoPackageTableCreator.TILE_SCALING, 0, 0, 1, 1, createNames("fk_nts_gtms_tn", null)); testSQLScript(GeoPackageTableCreator.CONTENTS_ID, 0, 1, 0, 1, createNames("uk_nci_table_name", "fk_nci_gc_tn")); }
Example #7
Source File: GeoPackageImpl.java From geopackage-android with MIT License | 3 votes |
/** * Constructor * * @param context context * @param name GeoPackage name * @param path database path * @param database database connection * @param cursorFactory cursor factory * @param tableCreator table creator * @param writable writable flag */ GeoPackageImpl(Context context, String name, String path, GeoPackageConnection database, GeoPackageCursorFactory cursorFactory, GeoPackageTableCreator tableCreator, boolean writable) { super(name, path, database, tableCreator, writable); this.context = context; this.database = database; this.cursorFactory = cursorFactory; }
Example #8
Source File: GeoPackageCoreImpl.java From geopackage-core-java with MIT License | 3 votes |
/** * Constructor * * @param name * name * @param path * path * @param database * database * @param tableCreator * table creator * @param writable * true if writable */ protected GeoPackageCoreImpl(String name, String path, GeoPackageCoreConnection database, GeoPackageTableCreator tableCreator, boolean writable) { this.name = name; this.path = path; this.database = database; this.tableCreator = tableCreator; this.writable = writable; }
Example #9
Source File: GeoPackageImpl.java From geopackage-java with MIT License | 2 votes |
/** * Constructor * * @param name * GeoPackage name * @param file * GeoPackage file * @param database * connection * @param tableCreator * table creator */ GeoPackageImpl(String name, File file, GeoPackageConnection database, GeoPackageTableCreator tableCreator) { super(name, file.getAbsolutePath(), database, tableCreator, true); this.database = database; }