mil.nga.geopackage.schema.columns.DataColumns Java Examples

The following examples show how to use mil.nga.geopackage.schema.columns.DataColumns. 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: FeatureInfoBuilder.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Get the column name by checking for a DataColumns name, otherwise returns the provided column name
 *
 * @param dataColumnsDao data columns dao
 * @param featureRow     feature row
 * @param columnName     column name
 * @return column name
 */
private String getColumnName(DataColumnsDao dataColumnsDao, FeatureRow featureRow, String columnName) {

    String newColumnName = columnName;

    if (dataColumnsDao != null) {
        try {
            DataColumns dataColumn = dataColumnsDao.getDataColumn(featureRow.getTable().getTableName(), columnName);
            if (dataColumn != null) {
                newColumnName = dataColumn.getName();
            }
        } catch (SQLException e) {
            Log.e(FeatureOverlayQuery.class.getSimpleName(),
                    "Failed to search for Data Column name for column: " + columnName
                            + ", Feature Table: " + featureRow.getTable().getTableName(), e);
        }
    }

    return newColumnName;
}
 
Example #2
Source File: SchemaExtension.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Remove all trace of the extension
 * 
 * @since 3.2.0
 */
public void removeExtension() {

	if (geoPackage.isTable(DataColumns.TABLE_NAME)) {
		geoPackage.dropTable(DataColumns.TABLE_NAME);
	}

	if (geoPackage.isTable(DataColumnConstraints.TABLE_NAME)) {
		geoPackage.dropTable(DataColumnConstraints.TABLE_NAME);
	}

	try {
		if (extensionsDao.isTableExists()) {
			extensionsDao.deleteByExtension(EXTENSION_NAME);
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to delete Schema extension. GeoPackage: "
						+ geoPackage.getName(),
				e);
	}

}
 
Example #3
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createDataColumnsTable() {
	verifyWritable();

	boolean created = false;
	DataColumnsDao dao = getDataColumnsDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createDataColumns() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + DataColumns.class.getSimpleName()
						+ " table exists and create it",
				e);
	}
	return created;
}
 
Example #4
Source File: GeoPackageDaoManager.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Unregister all GeoPackage DAO with the connection source
 * 
 * @param connectionSource
 *            connection source
 */
public static void unregisterDaos(ConnectionSource connectionSource) {
	// TODO when ormlite-core version > 5.1 is released, replace with:
	// "DaoManager.unregisterDaos(connectionSource);"
	// See https://github.com/j256/ormlite-core/pull/149
	unregisterDao(connectionSource, Contents.class,
			SpatialReferenceSystem.class,
			SpatialReferenceSystemSfSql.class,
			SpatialReferenceSystemSqlMm.class, Extensions.class,
			GriddedCoverage.class, GriddedTile.class, GeometryIndex.class,
			TableIndex.class, FeatureTileLink.class,
			ExtendedRelation.class, TileScaling.class,
			GeometryColumns.class, GeometryColumnsSfSql.class,
			GeometryColumnsSqlMm.class, Metadata.class,
			MetadataReference.class, DataColumns.class,
			DataColumnConstraints.class, TileMatrix.class,
			TileMatrixSet.class, ContentsId.class);
}
 
Example #5
Source File: FeatureInfoBuilder.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Get a Data Columns DAO
 *
 * @return data columns dao
 */
private DataColumnsDao getDataColumnsDao() {
    DataColumnsDao dataColumnsDao = null;
    try {
        dataColumnsDao = DaoManager.createDao(featureDao.getDb().getConnectionSource(), DataColumns.class);
        if (!dataColumnsDao.isTableExists()) {
            dataColumnsDao = null;
        }
    } catch (SQLException e) {
        dataColumnsDao = null;
        Log.e(FeatureOverlayQuery.class.getSimpleName(), "Failed to get a Data Columns DAO", e);
    }
    return dataColumnsDao;
}
 
Example #6
Source File: TestUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Create the feature table with data columns entry
 *
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage,
                                              Contents contents, String geometryColumn, GeometryType geometryType)
        throws SQLException {

    FeatureTable table = buildFeatureTable(contents.getTableName(),
            geometryColumn, geometryType);
    geoPackage.createFeatureTable(table);

    double random = Math.random();

    DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
    DataColumns dataColumns = new DataColumns();
    dataColumns.setContents(contents);
    dataColumns.setColumnName(TEST_INTEGER_COLUMN);
    dataColumns.setName(contents.getTableName());
    dataColumns.setTitle("TEST_TITLE");
    dataColumns.setDescription("TEST_DESCRIPTION");
    dataColumns.setMimeType("TEST_MIME_TYPE");

    if (random < (1.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
    } else if (random < (2.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
    } else {
        dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
    }

    dataColumnsDao.create(dataColumns);

    return table;
}
 
Example #7
Source File: TestUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Create the feature table with data columns entry
 *
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage,
                                              Contents contents, String geometryColumn, GeometryType geometryType)
        throws SQLException {

    FeatureTable table = buildFeatureTable(contents.getTableName(),
            geometryColumn, geometryType);
    geoPackage.createFeatureTable(table);

    double random = Math.random();

    DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
    DataColumns dataColumns = new DataColumns();
    dataColumns.setContents(contents);
    dataColumns.setColumnName(TEST_INTEGER_COLUMN);
    dataColumns.setName(contents.getTableName());
    dataColumns.setTitle("TEST_TITLE");
    dataColumns.setDescription("TEST_DESCRIPTION");
    dataColumns.setMimeType("TEST_MIME_TYPE");

    if (random < (1.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
    } else if (random < (2.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
    } else {
        dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
    }

    dataColumnsDao.create(dataColumns);

    return table;
}
 
Example #8
Source File: SchemaExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get or create the extension
 * 
 * @return extensions
 */
public List<Extensions> getOrCreate() {

	List<Extensions> extensions = new ArrayList<>();

	extensions.add(getOrCreate(EXTENSION_NAME, DataColumns.TABLE_NAME, null,
			DEFINITION, ExtensionScopeType.READ_WRITE));
	extensions.add(
			getOrCreate(EXTENSION_NAME, DataColumnConstraints.TABLE_NAME,
					null, DEFINITION, ExtensionScopeType.READ_WRITE));

	return extensions;
}
 
Example #9
Source File: DataColumnConstraintsDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get or create a Data Columns DAO
 * 
 * @return data columns dao
 * @throws SQLException
 */
private DataColumnsDao getDataColumnsDao() throws SQLException {
	if (dataColumnsDao == null) {
		dataColumnsDao = DaoManager.createDao(connectionSource,
				DataColumns.class);
	}
	return dataColumnsDao;
}
 
Example #10
Source File: DataColumnConstraints.java    From geopackage-core-java with MIT License 5 votes vote down vote up
public List<DataColumns> getColumns(DataColumnsDao dao) throws SQLException {
	List<DataColumns> columns = null;
	if (constraintName != null) {
		columns = dao.queryByConstraintName(constraintName);
	}
	return columns;
}
 
Example #11
Source File: TestUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Create the feature table with data columns entry
 * 
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return feature table
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage,
		Contents contents, String geometryColumn, GeometryType geometryType)
		throws SQLException {

	FeatureTable table = buildFeatureTable(contents.getTableName(),
			geometryColumn, geometryType);
	geoPackage.createFeatureTable(table);

	double random = Math.random();

	DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
	DataColumns dataColumns = new DataColumns();
	dataColumns.setContents(contents);
	dataColumns.setColumnName(TEST_INTEGER_COLUMN);
	dataColumns.setName(contents.getTableName());
	dataColumns.setTitle("TEST_TITLE");
	dataColumns.setDescription("TEST_DESCRIPTION");
	dataColumns.setMimeType("TEST_MIME_TYPE");

	if (random < (1.0 / 3.0)) {
		dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
	} else if (random < (2.0 / 3.0)) {
		dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
	} else {
		dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
	}

	dataColumnsDao.create(dataColumns);

	return table;
}
 
Example #12
Source File: DataColumnsUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	DataColumnsDao dao = geoPackage.getDataColumnsDao();
	if (dao.isTableExists()) {
		List<DataColumns> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random data columns
			int random = (int) (Math.random() * results.size());
			DataColumns dataColumns = results.get(random);

			// Delete the data columns
			dao.delete(dataColumns);

			// Verify deleted
			DataColumns queryDataColumns = dao.queryForId(dataColumns
					.getId());
			TestCase.assertNull(queryDataColumns);

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random data columns
				random = (int) (Math.random() * results.size());
				dataColumns = results.get(random);

				// Find which data columns to delete
				QueryBuilder<DataColumns, TableColumnKey> qb = dao
						.queryBuilder();
				qb.where().eq(DataColumns.COLUMN_TABLE_NAME,
						dataColumns.getTableName());
				PreparedQuery<DataColumns> query = qb.prepare();
				List<DataColumns> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<DataColumns, TableColumnKey> db = dao
						.deleteBuilder();
				db.where().eq(DataColumns.COLUMN_TABLE_NAME,
						dataColumns.getTableName());
				PreparedDelete<DataColumns> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example #13
Source File: GeoPackageExtensions.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * 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 #14
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DataColumnsDao getDataColumnsDao() {
	return createDao(DataColumns.class);
}
 
Example #15
Source File: DataColumnConstraintsDao.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * Delete the Data Columns Constraints, cascading
 * 
 * @param constraints
 *            data column constraints
 * @return deleted count
 * @throws SQLException
 *             upon failure
 */
public int deleteCascade(DataColumnConstraints constraints)
		throws SQLException {
	int count = 0;

	if (constraints != null) {

		// Check if the last remaining constraint with the constraint name
		// is being deleted
		List<DataColumnConstraints> remainingConstraints = queryByConstraintName(constraints
				.getConstraintName());
		if (remainingConstraints.size() == 1) {

			DataColumnConstraints remainingConstraint = remainingConstraints
					.get(0);

			// Compare the name, type, and value
			if (remainingConstraint.getConstraintName().equals(
					constraints.getConstraintName())
					&& remainingConstraint.getConstraintType().equals(
							constraints.getConstraintType())
					&& (remainingConstraint.getValue() == null ? constraints
							.getValue() == null : remainingConstraint
							.getValue().equals(constraints.getValue()))) {

				// Delete Data Columns
				DataColumnsDao dao = getDataColumnsDao();
				List<DataColumns> dataColumnsCollection = dao
						.queryByConstraintName(constraints
								.getConstraintName());
				if (!dataColumnsCollection.isEmpty()) {
					dao.delete(dataColumnsCollection);
				}
			}
		}

		// Delete
		count = delete(constraints);
	}
	return count;
}
 
Example #16
Source File: DataColumnsUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	DataColumnsDao dao = geoPackage.getDataColumnsDao();
	if (dao.isTableExists()) {
		List<DataColumns> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random data columns
			int random = (int) (Math.random() * results.size());
			DataColumns dataColumns = results.get(random);

			// Delete the data columns
			dao.delete(dataColumns);

			// Verify deleted
			DataColumns queryDataColumns = dao.queryForId(dataColumns
					.getId());
			TestCase.assertNull(queryDataColumns);

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random data columns
				random = (int) (Math.random() * results.size());
				dataColumns = results.get(random);

				// Find which data columns to delete
				QueryBuilder<DataColumns, TableColumnKey> qb = dao
						.queryBuilder();
				qb.where().eq(DataColumns.COLUMN_TABLE_NAME,
						dataColumns.getTableName());
				PreparedQuery<DataColumns> query = qb.prepare();
				List<DataColumns> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<DataColumns, TableColumnKey> db = dao
						.deleteBuilder();
				db.where().eq(DataColumns.COLUMN_TABLE_NAME,
						dataColumns.getTableName());
				PreparedDelete<DataColumns> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}