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);
}
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;
}
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);
}
}
}
}
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);
}
}
}
}
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);
}
}
Aggregations