mil.nga.geopackage.user.custom.UserCustomTableReader Java Examples

The following examples show how to use mil.nga.geopackage.user.custom.UserCustomTableReader. 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: GeoPackageImpl.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public UserCustomDao getUserCustomDao(String tableName) {
    UserCustomTable table = UserCustomTableReader.readTable(database,
            tableName);
    return getUserCustomDao(table);
}
 
Example #2
Source File: RelatedTablesCoreExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the primary key of a table
 * 
 * @param tableName
 *            table name
 * @return the column name
 */
public String getPrimaryKeyColumnName(String tableName) {
	UserCustomTable table = UserCustomTableReader
			.readTable(geoPackage.getDatabase(), tableName);
	UserCustomColumn pkColumn = table.getPkColumn();
	if (pkColumn == null) {
		throw new GeoPackageException(
				"Found no primary key for table " + tableName);
	}
	return pkColumn.getName();
}
 
Example #3
Source File: GeoPackageImpl.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public UserCustomDao getUserCustomDao(String tableName) {
	UserCustomTable table = UserCustomTableReader.readTable(database,
			tableName);
	return getUserCustomDao(table);
}
 
Example #4
Source File: NGAExtensions.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 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 #7
Source File: AlterTable.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Drop columns
 * 
 * @param db
 *            connection
 * @param tableName
 *            table name
 * @param columnNames
 *            column names
 */
public static void dropColumns(GeoPackageCoreConnection db,
		String tableName, Collection<String> columnNames) {
	UserCustomTable userTable = UserCustomTableReader.readTable(db,
			tableName);
	dropColumns(db, userTable, columnNames);
}
 
Example #8
Source File: AlterTable.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Alter columns
 * 
 * @param db
 *            connection
 * @param tableName
 *            table name
 * @param columns
 *            columns
 * @param <T>
 *            user column type
 */
public static <T extends UserColumn> void alterColumns(
		GeoPackageCoreConnection db, String tableName,
		Collection<UserCustomColumn> columns) {
	UserCustomTable userTable = UserCustomTableReader.readTable(db,
			tableName);
	alterColumns(db, userTable, columns);
}
 
Example #9
Source File: AlterTable.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Copy the table
 * 
 * @param db
 *            connection
 * @param tableName
 *            table name
 * @param newTableName
 *            new table name
 * @param transferContent
 *            transfer row content to the new table
 */
public static void copyTable(GeoPackageCoreConnection db, String tableName,
		String newTableName, boolean transferContent) {
	UserCustomTable userTable = UserCustomTableReader.readTable(db,
			tableName);
	copyTable(db, userTable, newTableName, transferContent);
}