Search in sources :

Example 1 with CoreConnection

use of org.sqlite.core.CoreConnection in project com.revolsys.open by revolsys.

the class GeoPackageRecordStore method initializeDo.

@Override
@PostConstruct
public void initializeDo() {
    super.initializeDo();
    setUsesSchema(false);
    final String filter = "WHERE NOT (NAME LIKE 'GPKG%' OR NAME LIKE 'RTREE%' OR NAME LIKE 'SQLITE%')";
    setSchemaTablePermissionsSql("select  '/' \"SCHEMA_NAME\", name \"TABLE_NAME\", 'ALL' \"PRIVILEGE\", '' \"REMARKS\"  from sqlite_master " + filter + " union all " + "select  '/' \"SCHEMA_NAME\", name \"TABLE_NAME\", 'ALL' \"PRIVILEGE\", '' \"REMARKS\"  from sqlite_temp_master " + filter);
    addFieldAdder("BOOLEAN", DataTypes.BOOLEAN);
    addFieldAdder("TINYINT", DataTypes.BYTE);
    addFieldAdder("SMALLINT", DataTypes.SHORT);
    addFieldAdder("MEDIUMINT", DataTypes.INT);
    addFieldAdder("INT", DataTypes.LONG);
    addFieldAdder("BIG_INTEGER", DataTypes.LONG);
    addFieldAdder("FLOAT", DataTypes.FLOAT);
    addFieldAdder("DOUBLE", DataTypes.DOUBLE);
    addFieldAdder("REAL", DataTypes.DOUBLE);
    addFieldAdder("TEXT", DataTypes.STRING);
    addFieldAdder("BLOB", DataTypes.BLOB);
    addFieldAdder("DATE", DataTypes.SQL_DATE);
    addFieldAdder("DATETIME", DataTypes.DATE_TIME);
    final GeoPackageGeometryFieldAdder geometryAdder = new GeoPackageGeometryFieldAdder();
    addFieldAdder("GEOMETRY", geometryAdder);
    addFieldAdder("POINT", geometryAdder);
    addFieldAdder("LINESTRING", geometryAdder);
    addFieldAdder("POLYGON", geometryAdder);
    addFieldAdder("GEOMETRYCOLLECTION", geometryAdder);
    addFieldAdder("MULTIPOINT", geometryAdder);
    addFieldAdder("MULTILINESTRING", geometryAdder);
    addFieldAdder("MULTIPOLYGON", geometryAdder);
    super.initialize();
    try (JdbcConnection connection = getJdbcConnection(true)) {
        final CoreConnection sqliteConnection = (CoreConnection) ((DelegatingConnection<?>) connection.getConnection()).getInnermostDelegate();
        final DB db = sqliteConnection.db();
        db.enable_load_extension(true);
        try {
            db._exec("select load_extension('libgpkg')");
        } finally {
            db.enable_load_extension(false);
        }
    } catch (final SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : CoreConnection(org.sqlite.core.CoreConnection) SQLException(java.sql.SQLException) JdbcConnection(com.revolsys.jdbc.JdbcConnection) DB(org.sqlite.core.DB) PostConstruct(javax.annotation.PostConstruct)

Aggregations

JdbcConnection (com.revolsys.jdbc.JdbcConnection)1 SQLException (java.sql.SQLException)1 PostConstruct (javax.annotation.PostConstruct)1 CoreConnection (org.sqlite.core.CoreConnection)1 DB (org.sqlite.core.DB)1