Search in sources :

Example 1 with Ili2dbException

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

the class MetaAttrUtility method insertMetaAttributeEntry.

// Write meta-attribute into db
private static void insertMetaAttributeEntry(Connection conn, String schema, String ilielement, String attrname, String attrvalue) throws Ili2dbException {
    String sqlName = DbNames.META_ATTRIBUTES_TAB;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    try {
        String stmt = "INSERT INTO " + sqlName + " (" + DbNames.META_ATTRIBUTES_TAB_ILIELEMENT_COL + "," + DbNames.META_ATTRIBUTES_TAB_ATTRNAME_COL + "," + DbNames.META_ATTRIBUTES_TAB_ATTRVALUE_COL + ") VALUES (?, ?, ?)";
        EhiLogger.traceBackendCmd(stmt);
        PreparedStatement ps = conn.prepareStatement(stmt);
        ps.setString(1, ilielement);
        ps.setString(2, attrname);
        ps.setString(3, attrvalue);
        ps.executeUpdate();
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to insert meta-attribute", ex);
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) PreparedStatement(java.sql.PreparedStatement)

Example 2 with Ili2dbException

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

the class MetaAttrUtility method addMetaAttrsFromDb.

/**
 * Read meta-attributes from the db and add them to the ili2c metamodel.
 * @param td
 * @param conn
 * @param schema
 * @throws Ili2dbException
 */
public static void addMetaAttrsFromDb(TransferDescription td, Connection conn, String schema) throws Ili2dbException {
    String sqlName = DbNames.META_ATTRIBUTES_TAB;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    try {
        String stmt = "SELECT " + DbNames.META_ATTRIBUTES_TAB_ILIELEMENT_COL + ", " + DbNames.META_ATTRIBUTES_TAB_ATTRNAME_COL + ", " + DbNames.META_ATTRIBUTES_TAB_ATTRVALUE_COL + " " + "FROM " + sqlName;
        EhiLogger.traceBackendCmd(stmt);
        Statement dbstmt = conn.createStatement();
        ResultSet rs = dbstmt.executeQuery(stmt);
        while (rs.next()) {
            String ilielement = rs.getString(DbNames.META_ATTRIBUTES_TAB_ILIELEMENT_COL);
            String attrname = rs.getString(DbNames.META_ATTRIBUTES_TAB_ATTRNAME_COL);
            String attrvalue = rs.getString(DbNames.META_ATTRIBUTES_TAB_ATTRVALUE_COL);
            // Add meta-attr to the Element
            Element element = td.getElement(ilielement);
            // known element?
            if (element != null) {
                // meta-attr not yet set/defined?
                if (element.getMetaValue(attrname) == null) {
                    // set it to the read value
                    element.setMetaValue(attrname, attrvalue);
                }
            }
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to read meta-attributes table", ex);
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Element(ch.interlis.ili2c.metamodel.Element) ResultSet(java.sql.ResultSet)

Example 3 with Ili2dbException

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

the class NameMapping method readTableMappingTable.

public void readTableMappingTable(java.sql.Connection conn, String schema) throws Ili2dbException {
    String mapTableName = DbNames.CLASSNAME_TAB;
    if (schema != null) {
        mapTableName = schema + "." + mapTableName;
    }
    // create table
    String stmt = "SELECT " + DbNames.CLASSNAME_TAB_ILINAME_COL + ", " + DbNames.CLASSNAME_TAB_SQLNAME_COL + " FROM " + mapTableName;
    java.sql.Statement dbstmt = null;
    try {
        dbstmt = conn.createStatement();
        java.sql.ResultSet rs = dbstmt.executeQuery(stmt);
        while (rs.next()) {
            String iliname = rs.getString(DbNames.CLASSNAME_TAB_ILINAME_COL);
            String sqlname = rs.getString(DbNames.CLASSNAME_TAB_SQLNAME_COL);
            // EhiLogger.debug("map: "+iliname+"->"+sqlname);
            if (classNameIli2sql.get(iliname) == null) {
                sqlname = normalizeSqlName(sqlname);
                addTableNameMapping(iliname, sqlname);
            }
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to query mapping-table " + mapTableName, ex);
    } finally {
        if (dbstmt != null) {
            try {
                dbstmt.close();
            } catch (java.sql.SQLException ex) {
                throw new Ili2dbException("failed to close query of " + mapTableName, ex);
            }
        }
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException)

Example 4 with Ili2dbException

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

the class TrafoConfig method read.

private static HashMap<String, HashMap<String, String>> read(java.sql.Connection conn, String schema) throws Ili2dbException {
    HashMap<String, HashMap<String, String>> settings = new HashMap<String, HashMap<String, String>>();
    String sqlName = DbNames.TRAFO_TAB;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    if (DbUtility.tableExists(conn, new DbTableName(schema, DbNames.TRAFO_TAB))) {
        try {
            // select entries
            String insStmt = "SELECT " + DbNames.TRAFO_TAB_ILINAME_COL + "," + DbNames.TRAFO_TAB_TAG_COL + "," + DbNames.TRAFO_TAB_SETTING_COL + " FROM " + sqlName;
            EhiLogger.traceBackendCmd(insStmt);
            java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
            try {
                java.sql.ResultSet rs = insPrepStmt.executeQuery();
                while (rs.next()) {
                    int valIdx = 1;
                    String iliname = rs.getString(valIdx++);
                    String tag = rs.getString(valIdx++);
                    String value = rs.getString(valIdx++);
                    setSetting(settings, iliname, tag, value);
                }
            } catch (java.sql.SQLException ex) {
                throw new Ili2dbException("failed to read " + sqlName, ex);
            } finally {
                insPrepStmt.close();
            }
        } catch (java.sql.SQLException ex) {
            throw new Ili2dbException("failed to read " + sqlName, ex);
        }
    }
    return settings;
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) HashMap(java.util.HashMap) DbTableName(ch.ehi.sqlgen.repository.DbTableName)

Example 5 with Ili2dbException

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

the class ColumnNameMapping method readAttrMappingTableEntries.

private static HashSet<AttrMappingKey> readAttrMappingTableEntries(java.sql.Connection conn, String schema) throws Ili2dbException {
    HashSet<AttrMappingKey> ret = new HashSet<AttrMappingKey>();
    String sqlName = DbNames.ATTRNAME_TAB;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    try {
        String exstStmt = null;
        exstStmt = "SELECT " + DbNames.ATTRNAME_TAB_ILINAME_COL + "," + DbNames.ATTRNAME_TAB_OWNER_COL + "," + DbNames.ATTRNAME_TAB_TARGET_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);
                String owner = rs.getString(2);
                String target = rs.getString(3);
                ret.add(new AttrMappingKey(iliCode, owner, target));
            }
        } finally {
            exstPrepStmt.close();
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to read attr-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