Search in sources :

Example 1 with DbTableName

use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.

the class MetaAttrUtility method addMetaAttributesTable.

// Create meta-attributes table
public static void addMetaAttributesTable(DbSchema schema) {
    DbTable tab = new DbTable();
    tab.setName(new DbTableName(schema.getName(), DbNames.META_ATTRIBUTES_TAB));
    DbColVarchar ilielementCol = new DbColVarchar();
    ilielementCol.setName(DbNames.META_ATTRIBUTES_TAB_ILIELEMENT_COL);
    ilielementCol.setNotNull(true);
    ilielementCol.setSize(255);
    tab.addColumn(ilielementCol);
    DbColVarchar attrnameCol = new DbColVarchar();
    attrnameCol.setName(DbNames.META_ATTRIBUTES_TAB_ATTRNAME_COL);
    attrnameCol.setNotNull(true);
    attrnameCol.setSize(1024);
    tab.addColumn(attrnameCol);
    DbColVarchar attrvalueCol = new DbColVarchar();
    attrvalueCol.setName(DbNames.META_ATTRIBUTES_TAB_ATTRVALUE_COL);
    attrvalueCol.setNotNull(true);
    attrvalueCol.setSize(1024);
    tab.addColumn(attrvalueCol);
    schema.addTable(tab);
}
Also used : DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) DbTableName(ch.ehi.sqlgen.repository.DbTableName) DbTable(ch.ehi.sqlgen.repository.DbTable)

Example 2 with DbTableName

use of ch.ehi.sqlgen.repository.DbTableName 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 3 with DbTableName

use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.

the class FgdbSequenceBasedIdGen method initDbDefs.

@Override
public void initDbDefs(ch.ehi.sqlgen.generator.Generator gen) {
    String sqlName = SQL_ILI2DB_SEQ_NAME;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    String stmt = "CREATE SEQUENCE " + sqlName + ";";
    if (gen instanceof GeneratorJdbc) {
        ((GeneratorJdbc) gen).addCreateLine(((GeneratorJdbc) gen).new Stmt(stmt));
        ((GeneratorJdbc) gen).addDropLine(((GeneratorJdbc) gen).new Stmt("DROP SEQUENCE " + sqlName + ";"));
    }
    try {
        if (sequenceExists(new DbTableName(schema, sqlName))) {
            return;
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    EhiLogger.traceBackendCmd(stmt);
    java.sql.PreparedStatement updstmt = null;
    try {
        updstmt = conn.prepareStatement(stmt);
        updstmt.execute();
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to create sequence " + sqlName, ex);
    } finally {
        if (updstmt != null) {
            try {
                updstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
        }
    }
}
Also used : GeneratorJdbc(ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc) IOException(java.io.IOException) DbTableName(ch.ehi.sqlgen.repository.DbTableName) Stmt(ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc.Stmt)

Example 4 with DbTableName

use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.

the class GpkgSequenceBasedIdGen method initDbDefs.

@Override
public void initDbDefs(ch.ehi.sqlgen.generator.Generator gen) {
    String sqlName = SQL_ILI2DB_SEQ_NAME;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    String stmt = "CREATE SEQUENCE " + sqlName + ";";
    if (gen instanceof GeneratorJdbc) {
        ((GeneratorJdbc) gen).addCreateLine(((GeneratorJdbc) gen).new Stmt(stmt));
        ((GeneratorJdbc) gen).addDropLine(((GeneratorJdbc) gen).new Stmt("DROP SEQUENCE " + sqlName + ";"));
    }
    try {
        if (sequenceExists(new DbTableName(schema, sqlName))) {
            return;
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    EhiLogger.traceBackendCmd(stmt);
    java.sql.PreparedStatement updstmt = null;
    try {
        updstmt = conn.prepareStatement(stmt);
        updstmt.execute();
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to create sequence " + sqlName, ex);
    } finally {
        if (updstmt != null) {
            try {
                updstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
        }
    }
}
Also used : GeneratorJdbc(ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc) IOException(java.io.IOException) DbTableName(ch.ehi.sqlgen.repository.DbTableName) Stmt(ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc.Stmt)

Example 5 with DbTableName

use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.

the class FromIliRecordConverter method addParentRef.

private void addParentRef(Viewable parentTable, AttributeDef attr) {
    CompositionType type = (CompositionType) attr.getDomainResolvingAll();
    Table structClass = type.getComponentType();
    // if abstract struct, might have multiple tables!
    for (ViewableWrapper structWrapper : getStructWrappers(structClass)) {
        DbTableName structClassSqlName = structWrapper.getSqlTable();
        // find struct table
        DbTable dbTable = schema.findTable(structClassSqlName);
        // add ref attr
        String refAttrSqlName = ili2sqlName.mapIliAttributeDefReverse(attr, structClassSqlName.getName(), class2wrapper.get(parentTable).getSqlTablename());
        DbColId dbParentId = new DbColId();
        dbParentId.setName(refAttrSqlName);
        // values of other struct attrs will have NULL
        dbParentId.setNotNull(false);
        dbParentId.setPrimaryKey(false);
        StringBuffer cmt = new StringBuffer();
        String cmtSep = "";
        if (attr.getDocumentation() != null) {
            cmt.append(cmtSep + attr.getDocumentation());
            cmtSep = nl;
        }
        cmt.append(cmtSep + "@iliname " + attr.getContainer().getScopedName(null) + "." + attr.getName());
        cmtSep = nl;
        if (cmt.length() > 0) {
            dbParentId.setComment(cmt.toString());
        }
        if (createFk) {
            dbParentId.setReferencedTable(class2wrapper.get(parentTable).getSqlTable());
        }
        if (createFkIdx) {
            dbParentId.setIndex(true);
        }
        dbTable.addColumn(dbParentId);
    }
}
Also used : DbTable(ch.ehi.sqlgen.repository.DbTable) Table(ch.interlis.ili2c.metamodel.Table) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) DbColId(ch.ehi.sqlgen.repository.DbColId) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) DbTableName(ch.ehi.sqlgen.repository.DbTableName) DbTable(ch.ehi.sqlgen.repository.DbTable)

Aggregations

DbTableName (ch.ehi.sqlgen.repository.DbTableName)33 DbTable (ch.ehi.sqlgen.repository.DbTable)11 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)10 DbColVarchar (ch.ehi.sqlgen.repository.DbColVarchar)10 Iterator (java.util.Iterator)10 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)9 SQLException (java.sql.SQLException)8 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)7 GeneratorJdbc (ch.ehi.sqlgen.generator_impl.jdbc.GeneratorJdbc)6 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)4 Viewable (ch.interlis.ili2c.metamodel.Viewable)4 StdLogEvent (ch.ehi.basics.logging.StdLogEvent)3 ConverterException (ch.ehi.ili2db.converter.ConverterException)3 SqlColumnConverter (ch.ehi.ili2db.converter.SqlColumnConverter)3 CustomMapping (ch.ehi.ili2db.fromili.CustomMapping)3 ModelElementSelector (ch.ehi.ili2db.fromili.ModelElementSelector)3