idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
1,400
public int deleteCascade ( Metadata metadata ) throws SQLException { int count = 0 ; if ( metadata != null ) { MetadataReferenceDao dao = getMetadataReferenceDao ( ) ; dao . deleteByMetadata ( metadata . getId ( ) ) ; dao . removeMetadataParent ( metadata . getId ( ) ) ; count = delete ( metadata ) ; } return count ; }
Delete the Metadata cascading
1,401
public int deleteCascade ( Collection < Metadata > metadataCollection ) throws SQLException { int count = 0 ; if ( metadataCollection != null ) { for ( Metadata metadata : metadataCollection ) { count += deleteCascade ( metadata ) ; } } return count ; }
Delete the collection of Metadata cascading
1,402
public int deleteCascade ( PreparedQuery < Metadata > preparedDelete ) throws SQLException { int count = 0 ; if ( preparedDelete != null ) { List < Metadata > metadataList = query ( preparedDelete ) ; count = deleteCascade ( metadataList ) ; } return count ; }
Delete the Metadata matching the prepared query cascading
1,403
public int deleteByIdCascade ( Long id ) throws SQLException { int count = 0 ; if ( id != null ) { Metadata metadata = queryForId ( id ) ; if ( metadata != null ) { count = deleteCascade ( metadata ) ; } } return count ; }
Delete a Metadata by id cascading
1,404
private MetadataReferenceDao getMetadataReferenceDao ( ) throws SQLException { if ( metadataReferenceDao == null ) { metadataReferenceDao = DaoManager . createDao ( connectionSource , MetadataReference . class ) ; } return metadataReferenceDao ; }
Get or create a Metadata Reference DAO
1,405
public void setRow ( long id , TRow row ) { lock . lock ( ) ; try { RowCondition rowCondition = rows . remove ( id ) ; if ( rowCondition != null ) { rowCondition . row = row ; rowCondition . condition . signalAll ( ) ; } } finally { lock . unlock ( ) ; } }
Set the row id row and notify all waiting threads to retrieve the row .
1,406
public static UserMappingTable create ( String tableName , List < UserCustomColumn > additionalColumns ) { List < UserCustomColumn > columns = new ArrayList < > ( ) ; columns . addAll ( createRequiredColumns ( ) ) ; if ( additionalColumns != null ) { columns . addAll ( additionalColumns ) ; } return new UserMappingTable ( tableName , columns ) ; }
Create a user mapping table with the minimum required columns followed by the additional columns
1,407
public static UserCustomColumn createBaseIdColumn ( int index ) { return UserCustomColumn . createColumn ( index , COLUMN_BASE_ID , GeoPackageDataType . INTEGER , true , null ) ; }
Create a base id column
1,408
public static UserCustomColumn createRelatedIdColumn ( int index ) { return UserCustomColumn . createColumn ( index , COLUMN_RELATED_ID , GeoPackageDataType . INTEGER , true , null ) ; }
Create a related id column
1,409
public static String getAuthor ( String extensionName ) { String author = null ; if ( extensionName != null ) { author = extensionName . substring ( 0 , extensionName . indexOf ( EXTENSION_NAME_DIVIDER ) ) ; } return author ; }
Get the author from the beginning of the extension name
1,410
public static String getExtensionNameNoAuthor ( String extensionName ) { String value = null ; if ( extensionName != null ) { value = extensionName . substring ( extensionName . indexOf ( EXTENSION_NAME_DIVIDER ) + 1 , extensionName . length ( ) ) ; } return value ; }
Get the extension name with the author prefix removed
1,411
private static Properties initializeConfigurationProperties ( ) { Properties properties = new Properties ( ) ; InputStream in = GeoPackageProperties . class . getResourceAsStream ( "/" + PropertyConstants . PROPERTIES_FILE ) ; if ( in != null ) { try { properties . load ( in ) ; } catch ( Exception e ) { log . log ( Level . SEVERE , "Failed to load properties file: " + PropertyConstants . PROPERTIES_FILE , e ) ; } finally { try { in . close ( ) ; } catch ( IOException e ) { log . log ( Level . WARNING , "Failed to close properties file: " + PropertyConstants . PROPERTIES_FILE , e ) ; } } } else { log . log ( Level . SEVERE , "Failed to load properties, file not found: " + PropertyConstants . PROPERTIES_FILE ) ; } return properties ; }
Initialize the configuration properties
1,412
public void setOverlayEnabled ( boolean enabled ) { if ( enabled != this . enabled ) { if ( Build . VERSION . SDK_INT >= HONEYCOMB ) { layerize ( enabled ) ; } this . enabled = enabled ; if ( ! enabled ) { canvasDelegate . clearCache ( ) ; } invalidate ( ) ; } }
Set whether the pixel grid overlay is enabled .
1,413
public List < String > getTables ( String dataType ) throws SQLException { List < Contents > contents = getContents ( dataType ) ; List < String > tableNames = new ArrayList < String > ( ) ; for ( Contents content : contents ) { tableNames . add ( content . getTableName ( ) ) ; } return tableNames ; }
Get table names by data type
1,414
public List < Contents > getContents ( String dataType ) throws SQLException { List < Contents > contents = queryForEq ( Contents . COLUMN_DATA_TYPE , dataType ) ; return contents ; }
Get contents by data type
1,415
public List < String > getTables ( ) throws SQLException { List < Contents > contents = queryForAll ( ) ; List < String > tableNames = new ArrayList < String > ( ) ; for ( Contents content : contents ) { tableNames . add ( content . getTableName ( ) ) ; } return tableNames ; }
Get table names
1,416
public BoundingBox getBoundingBox ( Projection projection ) { BoundingBox boundingBox = null ; List < String > tables = null ; try { tables = getTables ( ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to query for contents tables" , e ) ; } for ( String table : tables ) { BoundingBox tableBoundingBox = getBoundingBox ( projection , table ) ; if ( tableBoundingBox != null ) { if ( boundingBox != null ) { boundingBox = boundingBox . union ( tableBoundingBox ) ; } else { boundingBox = tableBoundingBox ; } } } return boundingBox ; }
Get the bounding box for all tables in the provided projection
1,417
public BoundingBox getBoundingBox ( Projection projection , String table ) { BoundingBox boundingBox = null ; try { Contents contents = queryForId ( table ) ; boundingBox = contents . getBoundingBox ( projection ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to query for contents of table: " + table , e ) ; } return boundingBox ; }
Get the bounding box for the table in the provided projection
1,418
public int deleteCascade ( Contents contents ) throws SQLException { int count = 0 ; if ( contents != null ) { ContentsDataType dataType = contents . getDataType ( ) ; if ( dataType != null ) { switch ( dataType ) { case FEATURES : GeometryColumnsDao geometryColumnsDao = getGeometryColumnsDao ( ) ; if ( geometryColumnsDao . isTableExists ( ) ) { GeometryColumns geometryColumns = contents . getGeometryColumns ( ) ; if ( geometryColumns != null ) { geometryColumnsDao . delete ( geometryColumns ) ; } } break ; case TILES : case GRIDDED_COVERAGE : TileMatrixDao tileMatrixDao = getTileMatrixDao ( ) ; if ( tileMatrixDao . isTableExists ( ) ) { ForeignCollection < TileMatrix > tileMatrixCollection = contents . getTileMatrix ( ) ; if ( ! tileMatrixCollection . isEmpty ( ) ) { tileMatrixDao . delete ( tileMatrixCollection ) ; } } TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao ( ) ; if ( tileMatrixSetDao . isTableExists ( ) ) { TileMatrixSet tileMatrixSet = contents . getTileMatrixSet ( ) ; if ( tileMatrixSet != null ) { tileMatrixSetDao . delete ( tileMatrixSet ) ; } } break ; case ATTRIBUTES : dropTable ( contents . getTableName ( ) ) ; break ; } } else { dropTable ( contents . getTableName ( ) ) ; } count = delete ( contents ) ; } return count ; }
Delete the Contents cascading
1,419
public int deleteCascade ( Contents contents , boolean userTable ) throws SQLException { int count = deleteCascade ( contents ) ; if ( userTable ) { dropTable ( contents . getTableName ( ) ) ; } return count ; }
Delete the Contents cascading optionally including the user table
1,420
public int deleteCascade ( Collection < Contents > contentsCollection , boolean userTable ) throws SQLException { int count = 0 ; if ( contentsCollection != null ) { for ( Contents contents : contentsCollection ) { count += deleteCascade ( contents , userTable ) ; } } return count ; }
Delete the collection of Contents cascading optionally including the user table
1,421
public int deleteCascade ( PreparedQuery < Contents > preparedDelete , boolean userTable ) throws SQLException { int count = 0 ; if ( preparedDelete != null ) { List < Contents > contentsList = query ( preparedDelete ) ; count = deleteCascade ( contentsList , userTable ) ; } return count ; }
Delete the Contents matching the prepared query cascading optionally including the user table
1,422
public int deleteByIdCascade ( String id , boolean userTable ) throws SQLException { int count = 0 ; if ( id != null ) { Contents contents = queryForId ( id ) ; if ( contents != null ) { count = deleteCascade ( contents , userTable ) ; } else if ( userTable ) { dropTable ( id ) ; } } return count ; }
Delete a Contents by id cascading optionally including the user table
1,423
public int deleteIdsCascade ( Collection < String > idCollection , boolean userTable ) throws SQLException { int count = 0 ; if ( idCollection != null ) { for ( String id : idCollection ) { count += deleteByIdCascade ( id , userTable ) ; } } return count ; }
Delete the Contents with the provided ids cascading optionally including the user table
1,424
public void deleteTable ( String table ) { try { deleteByIdCascade ( table , true ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete table: " + table , e ) ; } }
Delete the table
1,425
private void verifyCreate ( Contents contents ) throws SQLException { ContentsDataType dataType = contents . getDataType ( ) ; if ( dataType != null ) { switch ( dataType ) { case FEATURES : GeometryColumnsDao geometryColumnsDao = getGeometryColumnsDao ( ) ; if ( ! geometryColumnsDao . isTableExists ( ) ) { throw new GeoPackageException ( "A data type of " + dataType . getName ( ) + " requires the " + GeometryColumns . class . getSimpleName ( ) + " table to first be created using the GeoPackage." ) ; } break ; case TILES : verifyTiles ( dataType ) ; break ; case GRIDDED_COVERAGE : verifyTiles ( dataType ) ; break ; case ATTRIBUTES : break ; default : throw new GeoPackageException ( "Unsupported data type: " + dataType ) ; } } if ( ! db . tableExists ( contents . getTableName ( ) ) ) { throw new GeoPackageException ( "No table exists for Content Table Name: " + contents . getTableName ( ) + ". Table must first be created." ) ; } }
Verify the tables are in the expected state for the Contents create
1,426
private void verifyTiles ( ContentsDataType dataType ) throws SQLException { TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao ( ) ; if ( ! tileMatrixSetDao . isTableExists ( ) ) { throw new GeoPackageException ( "A data type of " + dataType . getName ( ) + " requires the " + TileMatrixSet . class . getSimpleName ( ) + " table to first be created using the GeoPackage." ) ; } TileMatrixDao tileMatrixDao = getTileMatrixDao ( ) ; if ( ! tileMatrixDao . isTableExists ( ) ) { throw new GeoPackageException ( "A data type of " + dataType . getName ( ) + " requires the " + TileMatrix . class . getSimpleName ( ) + " table to first be created using the GeoPackage." ) ; } }
Verify the required tile tables exist
1,427
private GeometryColumnsDao getGeometryColumnsDao ( ) throws SQLException { if ( geometryColumnsDao == null ) { geometryColumnsDao = DaoManager . createDao ( connectionSource , GeometryColumns . class ) ; } return geometryColumnsDao ; }
Get or create a Geometry Columns DAO
1,428
private TileMatrixSetDao getTileMatrixSetDao ( ) throws SQLException { if ( tileMatrixSetDao == null ) { tileMatrixSetDao = DaoManager . createDao ( connectionSource , TileMatrixSet . class ) ; } return tileMatrixSetDao ; }
Get or create a Tile Matrix Set DAO
1,429
private TileMatrixDao getTileMatrixDao ( ) throws SQLException { if ( tileMatrixDao == null ) { tileMatrixDao = DaoManager . createDao ( connectionSource , TileMatrix . class ) ; } return tileMatrixDao ; }
Get or create a Tile Matrix DAO
1,430
public int deleteByMetadata ( long fileId ) throws SQLException { DeleteBuilder < MetadataReference , Void > db = deleteBuilder ( ) ; db . where ( ) . eq ( MetadataReference . COLUMN_FILE_ID , fileId ) ; int deleted = db . delete ( ) ; return deleted ; }
Delete metadata references with foreign keys to the metadata file id
1,431
public List < MetadataReference > queryByMetadataParent ( long parentId ) throws SQLException { QueryBuilder < MetadataReference , Void > qb = queryBuilder ( ) ; qb . where ( ) . eq ( MetadataReference . COLUMN_PARENT_ID , parentId ) ; List < MetadataReference > metadataReferences = qb . query ( ) ; return metadataReferences ; }
Query by the metadata parent ids
1,432
private void setFkWhere ( Where < MetadataReference , Void > where , long fileId , Long parentId ) throws SQLException { where . eq ( MetadataReference . COLUMN_FILE_ID , fileId ) ; if ( parentId == null ) { where . and ( ) . isNull ( MetadataReference . COLUMN_PARENT_ID ) ; } else { where . and ( ) . eq ( MetadataReference . COLUMN_PARENT_ID , parentId ) ; } }
Set the foreign key column criteria in the where clause
1,433
public void updateDefinition ( long srsId , String definition ) { connection . execSQL ( "UPDATE " + SpatialReferenceSystem . TABLE_NAME + " SET " + COLUMN_NAME + " = '" + definition + "' WHERE " + SpatialReferenceSystem . COLUMN_SRS_ID + " = " + srsId ) ; }
Update the extension definition
1,434
public String getDefinition ( long srsId ) { String definition = connection . querySingleTypedResult ( "SELECT " + COLUMN_NAME + " FROM " + SpatialReferenceSystem . TABLE_NAME + " WHERE " + SpatialReferenceSystem . COLUMN_SRS_ID + " = ?" , new String [ ] { String . valueOf ( srsId ) } ) ; return definition ; }
Get the extension definition
1,435
private void createColumn ( ) { connection . addColumn ( SpatialReferenceSystem . TABLE_NAME , COLUMN_NAME , COLUMN_DEF ) ; updateDefinition ( GeoPackageProperties . getIntegerProperty ( PropertyConstants . WGS_84 , PropertyConstants . SRS_ID ) , GeoPackageProperties . getProperty ( PropertyConstants . WGS_84 , PropertyConstants . DEFINITION_12_063 ) ) ; updateDefinition ( GeoPackageProperties . getIntegerProperty ( PropertyConstants . UNDEFINED_CARTESIAN , PropertyConstants . SRS_ID ) , GeoPackageProperties . getProperty ( PropertyConstants . UNDEFINED_CARTESIAN , PropertyConstants . DEFINITION_12_063 ) ) ; updateDefinition ( GeoPackageProperties . getIntegerProperty ( PropertyConstants . UNDEFINED_GEOGRAPHIC , PropertyConstants . SRS_ID ) , GeoPackageProperties . getProperty ( PropertyConstants . UNDEFINED_GEOGRAPHIC , PropertyConstants . DEFINITION_12_063 ) ) ; updateDefinition ( GeoPackageProperties . getIntegerProperty ( PropertyConstants . WEB_MERCATOR , PropertyConstants . SRS_ID ) , GeoPackageProperties . getProperty ( PropertyConstants . WEB_MERCATOR , PropertyConstants . DEFINITION_12_063 ) ) ; }
Create the extension column
1,436
public void removeExtension ( ) { try { if ( extensionsDao . isTableExists ( ) ) { extensionsDao . deleteByExtension ( EXTENSION_NAME ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete CRS WKT extension. GeoPackage: " + geoPackage . getName ( ) , e ) ; } }
Remove the extension . Leaves the column and values .
1,437
public void close ( T geoPackage ) { if ( geoPackage != null ) { try { geoPackage . close ( ) ; } catch ( Exception e ) { logger . log ( Level . SEVERE , "Error closing GeoPackage: " + geoPackage . getName ( ) , e ) ; if ( ! closeQuietly ) { throw e ; } } } }
Close the GeoPackage
1,438
public List < String > getTables ( ) { List < String > tables = new ArrayList < > ( ) ; List < Extensions > extensions = getExtensions ( EXTENSION_NAME ) ; if ( extensions != null ) { for ( Extensions extension : extensions ) { tables . add ( extension . getTableName ( ) ) ; } } return tables ; }
Get the feature tables registered with the extension
1,439
public void createRelationships ( String featureTable ) { createStyleRelationship ( featureTable ) ; createTableStyleRelationship ( featureTable ) ; createIconRelationship ( featureTable ) ; createTableIconRelationship ( featureTable ) ; }
Create style icon table style and table icon relationships for the feature table
1,440
public boolean hasRelationship ( String featureTable ) { return hasStyleRelationship ( featureTable ) || hasTableStyleRelationship ( featureTable ) || hasIconRelationship ( featureTable ) || hasTableIconRelationship ( featureTable ) ; }
Check if feature table has a style icon table style or table icon relationships
1,441
public void createStyleRelationship ( String featureTable ) { createStyleRelationship ( getMappingTableName ( TABLE_MAPPING_STYLE , featureTable ) , featureTable , featureTable , StyleTable . TABLE_NAME ) ; }
Create a style relationship for the feature table
1,442
public boolean hasStyleRelationship ( String featureTable ) { return hasStyleRelationship ( getMappingTableName ( TABLE_MAPPING_STYLE , featureTable ) , featureTable , StyleTable . TABLE_NAME ) ; }
Determine if a style relationship exists for the feature table
1,443
public void createTableStyleRelationship ( String featureTable ) { createStyleRelationship ( getMappingTableName ( TABLE_MAPPING_TABLE_STYLE , featureTable ) , featureTable , ContentsId . TABLE_NAME , StyleTable . TABLE_NAME ) ; }
Create a feature table style relationship
1,444
public boolean hasTableStyleRelationship ( String featureTable ) { return hasStyleRelationship ( getMappingTableName ( TABLE_MAPPING_TABLE_STYLE , featureTable ) , ContentsId . TABLE_NAME , StyleTable . TABLE_NAME ) ; }
Determine if a feature table style relationship exists
1,445
public void createIconRelationship ( String featureTable ) { createStyleRelationship ( getMappingTableName ( TABLE_MAPPING_ICON , featureTable ) , featureTable , featureTable , IconTable . TABLE_NAME ) ; }
Create an icon relationship for the feature table
1,446
public boolean hasIconRelationship ( String featureTable ) { return hasStyleRelationship ( getMappingTableName ( TABLE_MAPPING_ICON , featureTable ) , featureTable , IconTable . TABLE_NAME ) ; }
Determine if an icon relationship exists for the feature table
1,447
public void createTableIconRelationship ( String featureTable ) { createStyleRelationship ( getMappingTableName ( TABLE_MAPPING_TABLE_ICON , featureTable ) , featureTable , ContentsId . TABLE_NAME , IconTable . TABLE_NAME ) ; }
Create a feature table icon relationship
1,448
public boolean hasTableIconRelationship ( String featureTable ) { return hasStyleRelationship ( getMappingTableName ( TABLE_MAPPING_TABLE_ICON , featureTable ) , ContentsId . TABLE_NAME , IconTable . TABLE_NAME ) ; }
Determine if a feature table icon relationship exists
1,449
private boolean hasStyleRelationship ( String mappingTableName , String baseTable , String relatedTable ) { boolean has = false ; try { has = relatedTables . hasRelations ( baseTable , relatedTable , mappingTableName ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to check if Feature Style Relationship exists. Base Table: " + baseTable + ", Related Table: " + relatedTable + ", Mapping Table: " + mappingTableName , e ) ; } return has ; }
Check if the style extension relationship between a feature table and style extension table exists
1,450
private void createStyleRelationship ( String mappingTableName , String featureTable , String baseTable , String relatedTable ) { if ( ! hasStyleRelationship ( mappingTableName , baseTable , relatedTable ) ) { getOrCreate ( featureTable ) ; if ( baseTable . equals ( ContentsId . TABLE_NAME ) ) { if ( ! contentsId . has ( ) ) { contentsId . getOrCreateExtension ( ) ; } } StyleMappingTable mappingTable = new StyleMappingTable ( mappingTableName ) ; if ( relatedTable . equals ( StyleTable . TABLE_NAME ) ) { relatedTables . addAttributesRelationship ( baseTable , new StyleTable ( ) , mappingTable ) ; } else { relatedTables . addMediaRelationship ( baseTable , new IconTable ( ) , mappingTable ) ; } } }
Create a style extension relationship between a feature table and style extension table
1,451
public void deleteRelationships ( ) { List < String > tables = getTables ( ) ; for ( String table : tables ) { deleteRelationships ( table ) ; } }
Delete the style and icon table and row relationships for all feature tables
1,452
public void deleteRelationships ( String featureTable ) { deleteStyleRelationship ( featureTable ) ; deleteTableStyleRelationship ( featureTable ) ; deleteIconRelationship ( featureTable ) ; deleteTableIconRelationship ( featureTable ) ; }
Delete the style and icon table and row relationships for the feature table
1,453
private void deleteStyleRelationship ( String mappingTableName , String featureTable ) { relatedTables . removeRelationshipsWithMappingTable ( mappingTableName ) ; if ( ! hasRelationship ( featureTable ) ) { try { if ( extensionsDao . isTableExists ( ) ) { extensionsDao . deleteByExtension ( EXTENSION_NAME , featureTable ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete Feature Style extension. GeoPackage: " + geoPackage . getName ( ) + ", Feature Table: " + featureTable , e ) ; } } }
Delete a style extension feature table relationship and the mapping table
1,454
public void removeExtension ( ) { deleteRelationships ( ) ; geoPackage . deleteTable ( StyleTable . TABLE_NAME ) ; geoPackage . deleteTable ( IconTable . TABLE_NAME ) ; try { if ( extensionsDao . isTableExists ( ) ) { extensionsDao . deleteByExtension ( EXTENSION_NAME ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete Feature Style extension. GeoPackage: " + geoPackage . getName ( ) , e ) ; } }
Completely remove and delete the extension and all styles and icons
1,455
public List < String > getFeatureTables ( ) throws SQLException { List < String > tableNames = new ArrayList < String > ( ) ; List < GeometryColumns > geometryColumns = queryForAll ( ) ; for ( GeometryColumns geometryColumn : geometryColumns ) { tableNames . add ( geometryColumn . getTableName ( ) ) ; } return tableNames ; }
Get all the feature table names
1,456
public GeometryColumns queryForTableName ( String tableName ) throws SQLException { GeometryColumns geometryColumns = null ; if ( tableName != null ) { List < GeometryColumns > results = queryForEq ( GeometryColumns . COLUMN_TABLE_NAME , tableName ) ; if ( ! results . isEmpty ( ) ) { if ( results . size ( ) > 1 ) { throw new SQLException ( "More than one " + GeometryColumns . class . getSimpleName ( ) + " returned for Table Name: " + tableName ) ; } geometryColumns = results . get ( 0 ) ; } } return geometryColumns ; }
Query for the table name
1,457
public BoundingBox getBoundingBox ( Projection projection ) { BoundingBox boundingBox = getBoundingBox ( ) ; if ( projection != null ) { ProjectionTransform transform = getProjection ( ) . getTransformation ( projection ) ; if ( ! transform . isSameProjection ( ) ) { boundingBox = boundingBox . transform ( transform ) ; } } return boundingBox ; }
Get a bounding box in the provided projection
1,458
public void setBoundingBox ( BoundingBox boundingBox ) { setMinX ( boundingBox . getMinLongitude ( ) ) ; setMaxX ( boundingBox . getMaxLongitude ( ) ) ; setMinY ( boundingBox . getMinLatitude ( ) ) ; setMaxY ( boundingBox . getMaxLatitude ( ) ) ; }
Set a bounding box
1,459
private SpatialReferenceSystem getSrs ( long srsId ) { SpatialReferenceSystem srs ; try { srs = getSpatialReferenceSystemDao ( ) . queryForId ( srsId ) ; } catch ( SQLException e1 ) { throw new GeoPackageException ( "Failed to retrieve Spatial Reference System. SRS ID: " + srsId ) ; } if ( srs == null ) { throw new GeoPackageException ( "Spatial Reference System could not be found. SRS ID: " + srsId ) ; } return srs ; }
Get the Spatial Reference System by id
1,460
private void verifyTableExists ( BaseDaoImpl < ? , ? > dao ) { try { if ( ! dao . isTableExists ( ) ) { throw new GeoPackageException ( "Table or view does not exist for: " + dao . getDataClass ( ) . getSimpleName ( ) ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to detect if table or view exists for dao: " + dao . getDataClass ( ) . getSimpleName ( ) , e ) ; } }
Verify table or view exists
1,461
public static String toColorWithAlpha ( String red , String green , String blue ) { String defaultAlpha = "FF" ; if ( red != null && ! red . isEmpty ( ) && Character . isLowerCase ( red . charAt ( 0 ) ) ) { defaultAlpha = defaultAlpha . toLowerCase ( ) ; } return toColorWithAlpha ( red , green , blue , defaultAlpha ) ; }
Convert the hex color values to a hex color including an opaque alpha value of FF
1,462
public static int toColorWithAlpha ( int red , int green , int blue , int alpha ) { validateRGB ( red ) ; validateRGB ( green ) ; validateRGB ( blue ) ; int color = ( red & 0xff ) << 16 | ( green & 0xff ) << 8 | ( blue & 0xff ) ; if ( alpha != - 1 ) { validateRGB ( alpha ) ; color = ( alpha & 0xff ) << 24 | color ; } return color ; }
Convert the RBGA values to a color integer
1,463
public static String toHex ( int color ) { validateRGB ( color ) ; String hex = Integer . toHexString ( color ) . toUpperCase ( ) ; if ( hex . length ( ) == 1 ) { hex = "0" + hex ; } return hex ; }
Convert the RGB integer to a hex single color
1,464
public static int toRGB ( String color ) { validateHexSingle ( color ) ; if ( color . length ( ) == 1 ) { color += color ; } return Integer . parseInt ( color , 16 ) ; }
Convert the hex single color to a RBG integer
1,465
private static float hslConvert ( float t1 , float t2 , float hue ) { float value ; if ( hue < 0 ) { hue += 6 ; } if ( hue >= 6 ) { hue -= 6 ; } if ( hue < 1 ) { value = ( t2 - t1 ) * hue + t1 ; } else if ( hue < 3 ) { value = t2 ; } else if ( hue < 4 ) { value = ( t2 - t1 ) * ( 4 - hue ) + t1 ; } else { value = t1 ; } return value ; }
HSL convert helper method
1,466
private static String getHexSingle ( String hex , int colorIndex ) { validateHex ( hex ) ; if ( hex . startsWith ( "#" ) ) { hex = hex . substring ( 1 ) ; } int colorCharacters = 1 ; int numColors = hex . length ( ) ; if ( numColors > 4 ) { colorCharacters ++ ; numColors /= 2 ; } String color = null ; if ( colorIndex >= 0 || numColors > 3 ) { if ( numColors > 3 ) { colorIndex ++ ; } int startIndex = colorIndex ; if ( colorCharacters > 1 ) { startIndex *= 2 ; } color = hex . substring ( startIndex , startIndex + colorCharacters ) ; color = expandShorthandHexSingle ( color ) ; } return color ; }
Get the hex single color
1,467
public static String shorthandHex ( String color ) { validateHex ( color ) ; if ( color . length ( ) > 5 ) { StringBuilder shorthandColor = new StringBuilder ( ) ; int startIndex = 0 ; if ( color . startsWith ( "#" ) ) { shorthandColor . append ( "#" ) ; startIndex ++ ; } for ( ; startIndex < color . length ( ) ; startIndex += 2 ) { String shorthand = shorthandHexSingle ( color . substring ( startIndex , startIndex + 2 ) ) ; if ( shorthand . length ( ) > 1 ) { shorthandColor = null ; break ; } shorthandColor . append ( shorthand ) ; } if ( shorthandColor != null ) { color = shorthandColor . toString ( ) ; } } return color ; }
Shorthand the hex color if possible
1,468
public static String expandShorthandHex ( String color ) { validateHex ( color ) ; if ( color . length ( ) < 6 ) { StringBuilder expandColor = new StringBuilder ( ) ; int startIndex = 0 ; if ( color . startsWith ( "#" ) ) { expandColor . append ( "#" ) ; startIndex ++ ; } for ( ; startIndex < color . length ( ) ; startIndex ++ ) { String expand = expandShorthandHexSingle ( color . substring ( startIndex , startIndex + 1 ) ) ; expandColor . append ( expand ) ; } color = expandColor . toString ( ) ; } return color ; }
Expand the hex if it is in shorthand
1,469
public static String shorthandHexSingle ( String color ) { validateHexSingle ( color ) ; if ( color . length ( ) > 1 && Character . toUpperCase ( color . charAt ( 0 ) ) == Character . toUpperCase ( color . charAt ( 1 ) ) ) { color = color . substring ( 0 , 1 ) ; } return color ; }
Shorthand the hex single color if possible
1,470
public static String expandShorthandHexSingle ( String color ) { validateHexSingle ( color ) ; if ( color . length ( ) == 1 ) { color += color ; } return color ; }
Expand the hex single if it is in shorthand
1,471
public boolean has ( String tableName , String columnName ) { return has ( EXTENSION_NAME , tableName , columnName ) && connection . tableExists ( getRTreeTableName ( tableName , columnName ) ) ; }
Determine if the GeoPackage table and column has the extension
1,472
public boolean createFunctions ( String tableName , String columnName ) { boolean created = has ( tableName , columnName ) ; if ( created ) { createAllFunctions ( ) ; } return created ; }
Check if the table and column has the RTree extension and create the functions if needed
1,473
public Extensions create ( FeatureTable featureTable ) { return create ( featureTable . getTableName ( ) , featureTable . getGeometryColumn ( ) . getName ( ) , featureTable . getPkColumn ( ) . getName ( ) ) ; }
Create the RTree Index extension for the feature table . Creates the SQL functions loads the tree and creates the triggers .
1,474
public Extensions create ( String tableName , String geometryColumnName , String idColumnName ) { Extensions extension = getOrCreate ( tableName , geometryColumnName ) ; createAllFunctions ( ) ; createRTreeIndex ( tableName , geometryColumnName ) ; loadRTreeIndex ( tableName , geometryColumnName , idColumnName ) ; createAllTriggers ( tableName , geometryColumnName , idColumnName ) ; return extension ; }
Create the RTree Index extension for the feature table geometry column and id column . Creates the SQL functions loads the tree and creates the triggers .
1,475
public void createRTreeIndex ( String tableName , String geometryColumnName ) { String sqlName = GeoPackageProperties . getProperty ( SQL_PROPERTY , CREATE_PROPERTY ) ; executeSQL ( sqlName , tableName , geometryColumnName ) ; }
Create the RTree Index Virtual Table
1,476
public void createInsertTrigger ( String tableName , String geometryColumnName , String idColumnName ) { String sqlName = GeoPackageProperties . getProperty ( TRIGGER_PROPERTY , TRIGGER_INSERT_NAME ) ; executeSQL ( sqlName , tableName , geometryColumnName , idColumnName ) ; }
Create insert trigger
1,477
public void createUpdate1Trigger ( String tableName , String geometryColumnName , String idColumnName ) { String sqlName = GeoPackageProperties . getProperty ( TRIGGER_PROPERTY , TRIGGER_UPDATE1_NAME ) ; executeSQL ( sqlName , tableName , geometryColumnName , idColumnName ) ; }
Create update 1 trigger
1,478
public void createUpdate2Trigger ( String tableName , String geometryColumnName , String idColumnName ) { String sqlName = GeoPackageProperties . getProperty ( TRIGGER_PROPERTY , TRIGGER_UPDATE2_NAME ) ; executeSQL ( sqlName , tableName , geometryColumnName , idColumnName ) ; }
Create update 2 trigger
1,479
public void createUpdate3Trigger ( String tableName , String geometryColumnName , String idColumnName ) { String sqlName = GeoPackageProperties . getProperty ( TRIGGER_PROPERTY , TRIGGER_UPDATE3_NAME ) ; executeSQL ( sqlName , tableName , geometryColumnName , idColumnName ) ; }
Create update 3 trigger
1,480
public void createUpdate4Trigger ( String tableName , String geometryColumnName , String idColumnName ) { String sqlName = GeoPackageProperties . getProperty ( TRIGGER_PROPERTY , TRIGGER_UPDATE4_NAME ) ; executeSQL ( sqlName , tableName , geometryColumnName , idColumnName ) ; }
Create update 4 trigger
1,481
public void createDeleteTrigger ( String tableName , String geometryColumnName , String idColumnName ) { String sqlName = GeoPackageProperties . getProperty ( TRIGGER_PROPERTY , TRIGGER_DELETE_NAME ) ; executeSQL ( sqlName , tableName , geometryColumnName , idColumnName ) ; }
Create delete trigger
1,482
public void delete ( String tableName , String geometryColumnName ) { if ( has ( tableName , geometryColumnName ) ) { drop ( tableName , geometryColumnName ) ; try { extensionsDao . deleteByExtension ( EXTENSION_NAME , tableName , geometryColumnName ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete RTree Index extension. GeoPackage: " + geoPackage . getName ( ) + ", Table: " + tableName + ", Geometry Column: " + geometryColumnName , e ) ; } } }
Delete the RTree Index extension for the table and geometry column . Drops the triggers RTree table and deletes the extension .
1,483
public void delete ( String tableName ) { try { if ( extensionsDao . isTableExists ( ) ) { List < Extensions > extensions = extensionsDao . queryByExtension ( EXTENSION_NAME , tableName ) ; for ( Extensions extension : extensions ) { delete ( extension . getTableName ( ) , extension . getColumnName ( ) ) ; } } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete RTree Index extensions for table. GeoPackage: " + geoPackage . getName ( ) + ", Table: " + tableName , e ) ; } }
Delete all RTree Index extensions for the table . Drops the triggers RTree tables and deletes the extensions .
1,484
public void drop ( String tableName , String geometryColumnName ) { dropAllTriggers ( tableName , geometryColumnName ) ; dropRTreeIndex ( tableName , geometryColumnName ) ; }
Drop the the triggers and RTree table for the table and geometry column
1,485
public void dropRTreeIndex ( String tableName , String geometryColumnName ) { String sqlName = GeoPackageProperties . getProperty ( SQL_PROPERTY , DROP_PROPERTY ) ; try { executeSQL ( sqlName , tableName , geometryColumnName ) ; } catch ( Exception e ) { if ( e . getMessage ( ) . indexOf ( "no such module: rtree" ) > - 1 ) { sqlName = GeoPackageProperties . getProperty ( SQL_PROPERTY , DROP_FORCE_PROPERTY ) ; executeSQL ( sqlName , tableName , geometryColumnName ) ; } else { throw e ; } } }
Drop the RTree Index Virtual Table
1,486
public boolean dropTriggers ( String tableName , String columnName ) { boolean dropped = has ( tableName , columnName ) ; if ( dropped ) { dropAllTriggers ( tableName , columnName ) ; } return dropped ; }
Check if the table and column has the RTree extension and if found drop the triggers
1,487
public void dropAllTriggers ( String tableName , String geometryColumnName ) { dropInsertTrigger ( tableName , geometryColumnName ) ; dropUpdate1Trigger ( tableName , geometryColumnName ) ; dropUpdate2Trigger ( tableName , geometryColumnName ) ; dropUpdate3Trigger ( tableName , geometryColumnName ) ; dropUpdate4Trigger ( tableName , geometryColumnName ) ; dropDeleteTrigger ( tableName , geometryColumnName ) ; }
Drop Triggers that Maintain Spatial Index Values
1,488
public void dropTrigger ( String tableName , String geometryColumnName , String triggerName ) { String sqlName = GeoPackageProperties . getProperty ( TRIGGER_PROPERTY , TRIGGER_DROP_PROPERTY ) ; executeSQL ( sqlName , tableName , geometryColumnName , null , triggerName ) ; }
Drop the trigger for the table geometry column and trigger name
1,489
private void executeSQL ( String sqlName , String tableName , String geometryColumnName ) { executeSQL ( sqlName , tableName , geometryColumnName , null ) ; }
Execute the SQL for the SQL file name while substituting values for the table and geometry column
1,490
private void executeSQL ( String sqlName , String tableName , String geometryColumnName , String idColumnName , String triggerName ) { List < String > statements = ResourceIOUtils . parseSQLStatements ( SQL_DIRECTORY , sqlName ) ; for ( String statement : statements ) { String sql = substituteSqlArguments ( statement , tableName , geometryColumnName , idColumnName , triggerName ) ; executeSQL ( sql , triggerName != null ) ; } }
Execute the SQL for the SQL file name while substituting values for the table geometry column id column and trigger name
1,491
private String substituteSqlArguments ( String sql , String tableName , String geometryColumnName , String idColumnName , String triggerName ) { String substituted = sql ; substituted = substituted . replaceAll ( TABLE_SUBSTITUTE , tableName ) ; substituted = substituted . replaceAll ( GEOMETRY_COLUMN_SUBSTITUTE , geometryColumnName ) ; if ( idColumnName != null ) { substituted = substituted . replaceAll ( PK_COLUMN_SUBSTITUTE , idColumnName ) ; } if ( triggerName != null ) { substituted = substituted . replaceAll ( TRIGGER_SUBSTITUTE , triggerName ) ; } return substituted ; }
Replace the SQL arguments for the table geometry column id column and trigger name
1,492
protected GeometryEnvelope getEnvelope ( GeoPackageGeometryData data ) { GeometryEnvelope envelope = null ; if ( data != null ) { envelope = data . getOrBuildEnvelope ( ) ; } return envelope ; }
Get or build a geometry envelope from the Geometry Data
1,493
private String getRTreeTableName ( String tableName , String geometryColumnName ) { String sqlName = GeoPackageProperties . getProperty ( SQL_PROPERTY , TABLE_PROPERTY ) ; String rTreeTableName = substituteSqlArguments ( sqlName , tableName , geometryColumnName , null , null ) ; return rTreeTableName ; }
Get the RTree Table name for the feature table and geometry column
1,494
protected UserCustomTable getRTreeTable ( FeatureTable featureTable ) { List < UserCustomColumn > columns = new ArrayList < > ( ) ; columns . add ( UserCustomColumn . createPrimaryKeyColumn ( 0 , COLUMN_ID ) ) ; columns . add ( UserCustomColumn . createColumn ( 1 , COLUMN_MIN_X , GeoPackageDataType . FLOAT , false , null ) ) ; columns . add ( UserCustomColumn . createColumn ( 2 , COLUMN_MAX_X , GeoPackageDataType . FLOAT , false , null ) ) ; columns . add ( UserCustomColumn . createColumn ( 3 , COLUMN_MIN_Y , GeoPackageDataType . FLOAT , false , null ) ) ; columns . add ( UserCustomColumn . createColumn ( 4 , COLUMN_MAX_Y , GeoPackageDataType . FLOAT , false , null ) ) ; String rTreeTableName = getRTreeTableName ( featureTable . getTableName ( ) , featureTable . getGeometryColumn ( ) . getName ( ) ) ; UserCustomTable userCustomTable = new UserCustomTable ( rTreeTableName , columns ) ; return userCustomTable ; }
Get the RTree Table
1,495
private int execSQLScript ( String sqlScript ) { String path = GeoPackageProperties . getProperty ( PropertyConstants . SQL , "directory" ) ; List < String > statements = ResourceIOUtils . parseSQLStatements ( path , sqlScript ) ; for ( String statement : statements ) { db . execSQL ( statement ) ; } return statements . size ( ) ; }
Execute the SQL Script
1,496
public < TColumn extends UserColumn > void createTable ( UserTable < TColumn > table ) { if ( db . tableExists ( table . getTableName ( ) ) ) { throw new GeoPackageException ( "Table already exists and can not be created: " + table . getTableName ( ) ) ; } StringBuilder sql = new StringBuilder ( ) ; sql . append ( "CREATE TABLE " ) . append ( CoreSQLUtils . quoteWrap ( table . getTableName ( ) ) ) . append ( " (" ) ; List < ? extends UserColumn > columns = table . getColumns ( ) ; for ( int i = 0 ; i < columns . size ( ) ; i ++ ) { UserColumn column = columns . get ( i ) ; if ( i > 0 ) { sql . append ( "," ) ; } sql . append ( "\n " ) . append ( CoreSQLUtils . quoteWrap ( column . getName ( ) ) ) . append ( " " ) . append ( column . getTypeName ( ) ) ; if ( column . getMax ( ) != null ) { sql . append ( "(" ) . append ( column . getMax ( ) ) . append ( ")" ) ; } if ( column . isNotNull ( ) ) { sql . append ( " NOT NULL" ) ; } if ( column . isPrimaryKey ( ) ) { sql . append ( " PRIMARY KEY AUTOINCREMENT" ) ; } } List < UserUniqueConstraint < TColumn > > uniqueConstraints = table . getUniqueConstraints ( ) ; for ( int i = 0 ; i < uniqueConstraints . size ( ) ; i ++ ) { UserUniqueConstraint < TColumn > uniqueConstraint = uniqueConstraints . get ( i ) ; sql . append ( ",\n UNIQUE (" ) ; List < TColumn > uniqueColumns = uniqueConstraint . getColumns ( ) ; for ( int j = 0 ; j < uniqueColumns . size ( ) ; j ++ ) { TColumn uniqueColumn = uniqueColumns . get ( j ) ; if ( j > 0 ) { sql . append ( ", " ) ; } sql . append ( uniqueColumn . getName ( ) ) ; } sql . append ( ")" ) ; } sql . append ( "\n);" ) ; db . execSQL ( sql . toString ( ) ) ; }
Create the user defined table
1,497
public void createRequired ( ) { createSpatialReferenceSystem ( ) ; createContents ( ) ; try { SpatialReferenceSystemDao dao = DaoManager . createDao ( db . getConnectionSource ( ) , SpatialReferenceSystem . class ) ; dao . createWgs84 ( ) ; dao . createUndefinedCartesian ( ) ; dao . createUndefinedGeographic ( ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Error creating default required Spatial Reference Systems" , e ) ; } }
Create the minimum required GeoPackage tables
1,498
public static Object getValue ( Result result , int index , GeoPackageDataType dataType ) { Object value = null ; int type = result . getType ( index ) ; switch ( type ) { case FIELD_TYPE_INTEGER : value = getIntegerValue ( result , index , dataType ) ; break ; case FIELD_TYPE_FLOAT : value = getFloatValue ( result , index , dataType ) ; break ; case FIELD_TYPE_STRING : String stringValue = result . getString ( index ) ; if ( dataType != null && ( dataType == GeoPackageDataType . DATE || dataType == GeoPackageDataType . DATETIME ) ) { DateConverter converter = DateConverter . converter ( dataType ) ; try { value = converter . dateValue ( stringValue ) ; } catch ( Exception e ) { logger . log ( Level . WARNING , "Invalid " + dataType + " format: " + stringValue + ", String value used" , e ) ; value = stringValue ; } } else { value = stringValue ; } break ; case FIELD_TYPE_BLOB : value = result . getBlob ( index ) ; break ; case FIELD_TYPE_NULL : } return value ; }
Get the value from the cursor from the provided column
1,499
public static Object getIntegerValue ( Result result , int index , GeoPackageDataType dataType ) { Object value = null ; if ( dataType == null ) { dataType = GeoPackageDataType . INTEGER ; } switch ( dataType ) { case BOOLEAN : short booleanValue = result . getShort ( index ) ; value = booleanValue == 0 ? Boolean . FALSE : Boolean . TRUE ; break ; case TINYINT : value = ( byte ) result . getShort ( index ) ; break ; case SMALLINT : value = result . getShort ( index ) ; break ; case MEDIUMINT : value = result . getInt ( index ) ; break ; case INT : case INTEGER : value = result . getLong ( index ) ; break ; default : throw new GeoPackageException ( "Data Type " + dataType + " is not an integer type" ) ; } if ( result . wasNull ( ) ) { value = null ; } return value ; }
Get the integer value from the cursor of the column