mil.nga.geopackage.extension.related.ExtendedRelationsDao Java Examples

The following examples show how to use mil.nga.geopackage.extension.related.ExtendedRelationsDao. 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: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createExtendedRelationsTable() {
	verifyWritable();

	boolean created = false;
	ExtendedRelationsDao dao = getExtendedRelationsDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createExtendedRelations() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException("Failed to check if "
				+ ExtendedRelation.class.getSimpleName()
				+ " table exists and create it", e);
	}
	return created;
}
 
Example #2
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 #3
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ExtendedRelationsDao getExtendedRelationsDao() {
	return createDao(ExtendedRelation.class);
}
 
Example #4
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Get a Extended Relations DAO
 * 
 * @return extended relations dao
 * @since 3.0.1
 */
public ExtendedRelationsDao getExtendedRelationsDao();