Search in sources :

Example 26 with Ili2dbException

use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.

the class TransferFromXtf method deleteObjectsOfExistingDataset.

private void deleteObjectsOfExistingDataset(long datasetSqlId, Config config) throws Ili2dbException {
    // get basket id, topicname
    String schema = config.getDbschema();
    String colT_ID = config.getColT_ID();
    if (colT_ID == null) {
        colT_ID = DbNames.T_ID_COL;
    }
    String sqlName = DbNames.BASKETS_TAB;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    java.sql.PreparedStatement getstmt = null;
    try {
        String stmt = "SELECT " + colT_ID + "," + DbNames.BASKETS_TAB_TOPIC_COL + " FROM " + sqlName + " WHERE " + DbNames.BASKETS_TAB_DATASET_COL + "= ?";
        EhiLogger.traceBackendCmd(stmt);
        getstmt = conn.prepareStatement(stmt);
        getstmt.setLong(1, datasetSqlId);
        java.sql.ResultSet res = getstmt.executeQuery();
        while (res.next()) {
            long sqlId = res.getLong(1);
            String topicQName = res.getString(2);
            deleteObjectsOfBasket(sqlId, topicQName);
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to query " + sqlName, ex);
    } finally {
        if (getstmt != null) {
            try {
                getstmt.close();
                getstmt = null;
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
        }
    }
    try {
        String stmt = "DELETE FROM " + sqlName + " WHERE " + DbNames.BASKETS_TAB_DATASET_COL + "= ?";
        EhiLogger.traceBackendCmd(stmt);
        getstmt = conn.prepareStatement(stmt);
        getstmt.setLong(1, datasetSqlId);
        getstmt.executeUpdate();
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to delete from " + sqlName, ex);
    } finally {
        if (getstmt != null) {
            try {
                getstmt.close();
                getstmt = null;
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) PreparedStatement(java.sql.PreparedStatement)

Example 27 with Ili2dbException

use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.

the class DbExtMetaInfo method saveTableTab.

private void saveTableTab(Connection conn, String schemaName) throws Ili2dbException {
    DbTableName tabName = new DbTableName(schemaName, DbNames.META_INFO_TABLE_TAB);
    String sqlName = tabName.getQName();
    HashMap<String, HashMap<String, String>> exstEntries = readTableTab(conn, sqlName);
    try {
        // insert entries
        String insStmt = "INSERT INTO " + sqlName + " (" + DbNames.META_INFO_TABLE_TAB_TABLENAME_COL + "," + DbNames.META_INFO_TABLE_TAB_TAG_COL + "," + DbNames.META_INFO_TABLE_TAB_SETTING_COL + ") VALUES (?,?,?)";
        EhiLogger.traceBackendCmd(insStmt);
        java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
        try {
            for (String table : tabInfo.keySet()) {
                HashMap<String, String> exstValues = exstEntries.get(table);
                if (exstValues == null) {
                    exstValues = new HashMap<String, String>();
                }
                HashMap<String, String> newValues = tabInfo.get(table);
                for (String tag : newValues.keySet()) {
                    if (!exstValues.containsKey(tag)) {
                        String value = newValues.get(tag);
                        insPrepStmt.setString(1, table);
                        insPrepStmt.setString(2, tag);
                        insPrepStmt.setString(3, value);
                        insPrepStmt.executeUpdate();
                    }
                }
            }
        } catch (java.sql.SQLException ex) {
            throw new Ili2dbException("failed to insert meta info values to " + sqlName, ex);
        } finally {
            insPrepStmt.close();
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to update meta-info table " + sqlName, ex);
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) HashMap(java.util.HashMap) DbTableName(ch.ehi.sqlgen.repository.DbTableName)

Example 28 with Ili2dbException

use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.

the class DbExtMetaInfo method readColumnTab.

private HashMap<ColKey, HashMap<String, String>> readColumnTab(Connection conn, String sqlName) throws Ili2dbException {
    HashMap<ColKey, HashMap<String, String>> exstEntries = new HashMap<ColKey, HashMap<String, String>>();
    try {
        // insert entries
        String selStmt = "SELECT " + DbNames.META_INFO_COLUMN_TAB_TABLENAME_COL + "," + DbNames.META_INFO_COLUMN_TAB_SUBTYPE_COL + "," + DbNames.META_INFO_COLUMN_TAB_COLUMNNAME_COL + "," + DbNames.META_INFO_COLUMN_TAB_TAG_COL + "," + DbNames.META_INFO_COLUMN_TAB_SETTING_COL + " FROM " + sqlName;
        EhiLogger.traceBackendCmd(selStmt);
        java.sql.PreparedStatement selPrepStmt = conn.prepareStatement(selStmt);
        ResultSet rs = selPrepStmt.executeQuery();
        try {
            while (rs.next()) {
                String table = rs.getString(1);
                String subtype = rs.getString(2);
                String col = rs.getString(3);
                String tag = rs.getString(4);
                String val = rs.getString(5);
                ColKey colKey = new ColKey(table, subtype, col);
                HashMap<String, String> exstValues = exstEntries.get(colKey);
                if (exstValues == null) {
                    exstValues = new HashMap<String, String>();
                    exstEntries.put(colKey, exstValues);
                }
                exstValues.put(tag, val);
            }
        } catch (java.sql.SQLException ex) {
            throw new Ili2dbException("failed to read meta info values from " + sqlName, ex);
        } finally {
            selPrepStmt.close();
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to read meta-info table " + sqlName, ex);
    }
    return exstEntries;
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet)

Example 29 with Ili2dbException

use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.

the class NameMapping method updateTableMappingTable.

public void updateTableMappingTable(java.sql.Connection conn, String schema) throws Ili2dbException {
    HashSet<String> exstEntries = readTableMappingTableEntries(conn, schema);
    String mapTabName = DbNames.CLASSNAME_TAB;
    if (schema != null) {
        mapTabName = schema + "." + mapTabName;
    }
    // create table
    try {
        // insert mapping entries
        String stmt = "INSERT INTO " + mapTabName + " (" + DbNames.CLASSNAME_TAB_ILINAME_COL + "," + DbNames.CLASSNAME_TAB_SQLNAME_COL + ") VALUES (?,?)";
        EhiLogger.traceBackendCmd(stmt);
        java.sql.PreparedStatement ps = conn.prepareStatement(stmt);
        String iliname = null;
        String sqlname = null;
        try {
            java.util.Iterator<String> entri = classNameIli2sql.keySet().iterator();
            while (entri.hasNext()) {
                iliname = entri.next();
                if (!exstEntries.contains(iliname)) {
                    sqlname = classNameIli2sql.get(iliname);
                    ps.setString(1, iliname);
                    ps.setString(2, sqlname);
                    ps.executeUpdate();
                }
            }
        } catch (java.sql.SQLException ex) {
            throw new Ili2dbException("failed to insert classname-mapping " + iliname, ex);
        } finally {
            ps.close();
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to update mapping-table " + mapTabName, ex);
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException)

Example 30 with Ili2dbException

use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.

the class NameMapping method readTableMappingTableEntries.

private static HashSet<String> readTableMappingTableEntries(java.sql.Connection conn, String schema) throws Ili2dbException {
    HashSet<String> ret = new HashSet<String>();
    String sqlName = DbNames.CLASSNAME_TAB;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    try {
        String exstStmt = null;
        exstStmt = "SELECT " + DbNames.CLASSNAME_TAB_ILINAME_COL + " FROM " + sqlName;
        EhiLogger.traceBackendCmd(exstStmt);
        java.sql.PreparedStatement exstPrepStmt = conn.prepareStatement(exstStmt);
        try {
            java.sql.ResultSet rs = exstPrepStmt.executeQuery();
            while (rs.next()) {
                String iliCode = rs.getString(1);
                ret.add(iliCode);
            }
        } finally {
            exstPrepStmt.close();
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to read class-mapping-table " + sqlName, ex);
    }
    return ret;
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) HashSet(java.util.HashSet)

Aggregations

Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)31 SQLException (java.sql.SQLException)13 DbTableName (ch.ehi.sqlgen.repository.DbTableName)10 HashSet (java.util.HashSet)10 Iterator (java.util.Iterator)8 HashMap (java.util.HashMap)7 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)6 Viewable (ch.interlis.ili2c.metamodel.Viewable)6 PreparedStatement (java.sql.PreparedStatement)5 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)4 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)4 Model (ch.interlis.ili2c.metamodel.Model)4 Domain (ch.interlis.ili2c.metamodel.Domain)3 Topic (ch.interlis.ili2c.metamodel.Topic)3 View (ch.interlis.ili2c.metamodel.View)3 IomObject (ch.interlis.iom.IomObject)3 ResultSet (java.sql.ResultSet)3 ArrayList (java.util.ArrayList)3 DbTable (ch.ehi.sqlgen.repository.DbTable)2 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)2