mil.nga.geopackage.extension.NGAExtensions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geopackage-core Show documentation
Show all versions of geopackage-core Show documentation
Core functionality for GeoPackage implementations
package mil.nga.geopackage.extension;
import java.sql.SQLException;
import mil.nga.geopackage.GeoPackageCore;
import mil.nga.geopackage.GeoPackageException;
import mil.nga.geopackage.extension.index.FeatureTableCoreIndex;
import mil.nga.geopackage.extension.index.GeometryIndex;
import mil.nga.geopackage.extension.index.GeometryIndexDao;
import mil.nga.geopackage.extension.index.TableIndex;
import mil.nga.geopackage.extension.index.TableIndexDao;
import mil.nga.geopackage.extension.link.FeatureTileLink;
import mil.nga.geopackage.extension.link.FeatureTileLinkDao;
import mil.nga.geopackage.extension.link.FeatureTileTableCoreLinker;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
/**
* NGA extension management class for deleting extensions for a table or in a
* GeoPackage
*
* @author osbornb
* @since 1.1.0
*/
public class NGAExtensions {
/**
* Delete all NGA table extensions for the table within the GeoPackage
*
* @param geoPackage
* @param table
*/
public static void deleteTableExtensions(GeoPackageCore geoPackage,
String table) {
deleteGeometryIndex(geoPackage, table);
deleteFeatureTileLink(geoPackage, table);
// Delete future extensions for the table here
}
/**
* Delete all NGA extensions including custom extension tables for the
* GeoPackage
*
* @param geoPackage
*/
public static void deleteExtensions(GeoPackageCore geoPackage) {
deleteExtensions(geoPackage, false);
}
/**
* Delete all NGA extensions including custom extension tables for the
* GeoPackage
*
* @param geoPackage
* @param ignoreErrors
* true to ignore errors when deleting tables
*/
public static void deleteExtensions(GeoPackageCore geoPackage,
boolean ignoreErrors) {
deleteGeometryIndexExtension(geoPackage, ignoreErrors);
deleteFeatureTileLinkExtension(geoPackage, ignoreErrors);
// Delete future extension tables here
}
/**
* Delete the Geometry Index extension for the table
*
* @param geoPackage
* @param table
* @since 1.1.5
*/
public static void deleteGeometryIndex(GeoPackageCore geoPackage,
String table) {
TableIndexDao tableIndexDao = geoPackage.getTableIndexDao();
ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
try {
if (tableIndexDao.isTableExists()) {
tableIndexDao.deleteByIdCascade(table);
}
if (extensionsDao.isTableExists()) {
extensionsDao.deleteByExtension(
FeatureTableCoreIndex.EXTENSION_NAME, table);
}
} catch (SQLException e) {
throw new GeoPackageException(
"Failed to delete Table Index. GeoPackage: "
+ geoPackage.getName() + ", Table: " + table, e);
}
}
/**
* Delete the Geometry Index extension including the extension entries and
* custom tables
*
* @param geoPackage
* @param ignoreErrors
* @since 1.1.5
*/
public static void deleteGeometryIndexExtension(GeoPackageCore geoPackage,
boolean ignoreErrors) {
GeometryIndexDao geometryIndexDao = geoPackage.getGeometryIndexDao();
TableIndexDao tableIndexDao = geoPackage.getTableIndexDao();
ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
ConnectionSource connectionSource = geoPackage.getDatabase()
.getConnectionSource();
try {
if (geometryIndexDao.isTableExists()) {
TableUtils.dropTable(connectionSource, GeometryIndex.class,
ignoreErrors);
}
if (tableIndexDao.isTableExists()) {
TableUtils.dropTable(connectionSource, TableIndex.class,
ignoreErrors);
}
if (extensionsDao.isTableExists()) {
extensionsDao.deleteByExtension(
FeatureTableCoreIndex.EXTENSION_NAME);
}
} catch (SQLException e) {
throw new GeoPackageException(
"Failed to delete Table Index extension and tables. GeoPackage: "
+ geoPackage.getName(), e);
}
}
/**
* Delete the Feature Tile Link extensions for the table
*
* @param geoPackage
* @param table
* @since 1.1.5
*/
public static void deleteFeatureTileLink(GeoPackageCore geoPackage,
String table) {
FeatureTileLinkDao featureTileLinkDao = geoPackage
.getFeatureTileLinkDao();
try {
if (featureTileLinkDao.isTableExists()) {
featureTileLinkDao.deleteByTableName(table);
}
} catch (SQLException e) {
throw new GeoPackageException(
"Failed to delete Feature Tile Link. GeoPackage: "
+ geoPackage.getName() + ", Table: " + table, e);
}
}
/**
* Delete the Feature Tile Link extension including the extension entries
* and custom tables
*
* @param geoPackage
* @param ignoreErrors
* @since 1.1.5
*/
public static void deleteFeatureTileLinkExtension(
GeoPackageCore geoPackage, boolean ignoreErrors) {
FeatureTileLinkDao featureTileLinkDao = geoPackage
.getFeatureTileLinkDao();
ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
ConnectionSource connectionSource = geoPackage.getDatabase()
.getConnectionSource();
try {
if (featureTileLinkDao.isTableExists()) {
TableUtils.dropTable(connectionSource, FeatureTileLink.class,
ignoreErrors);
}
if (extensionsDao.isTableExists()) {
extensionsDao.deleteByExtension(
FeatureTileTableCoreLinker.EXTENSION_NAME);
}
} catch (SQLException e) {
throw new GeoPackageException(
"Failed to delete Feature Tile Link extension and table. GeoPackage: "
+ geoPackage.getName(), e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy