use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromIli method updateSettings.
public static void updateSettings(java.sql.Connection conn, Config settings, String schema) throws Ili2dbException {
String sqlName = DbNames.SETTINGS_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
try {
// insert entries
String insStmt = "INSERT INTO " + sqlName + " (" + DbNames.SETTINGS_TAB_TAG_COL + "," + DbNames.SETTINGS_TAB_SETTING_COL + ") VALUES (?,?)";
EhiLogger.traceBackendCmd(insStmt);
java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
try {
java.util.Iterator entri = settings.getValues().iterator();
while (entri.hasNext()) {
String tag = (String) entri.next();
insPrepStmt.clearParameters();
insPrepStmt.setString(1, tag);
insPrepStmt.setString(2, settings.getValue(tag));
insPrepStmt.executeUpdate();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert setting", ex);
} finally {
insPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update settings-table " + sqlName, ex);
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromIli method generatModelEles.
private void generatModelEles(java.util.List<Element> modelEles, int pass) throws Ili2dbException {
Iterator modeli = modelEles.iterator();
while (modeli.hasNext()) {
Object modelo = modeli.next();
if (modelo instanceof Model) {
Model model = (Model) modelo;
// generateModel(model);
} else if (modelo instanceof Topic) {
// generateTopic((Topic)modelo);
} else if (modelo instanceof Domain) {
if (pass == 2) {
generateDomain((Domain) modelo);
visitedElements.add((Domain) modelo);
}
} else if (modelo instanceof Viewable) {
if (modelo instanceof Table && ((Table) modelo).isIli1LineAttrStruct()) {
// skip it
} else if ((modelo instanceof View) && !isTransferableView(modelo)) {
// skip it
} else {
try {
ViewableWrapper wrapper = class2wrapper.get((Viewable) modelo);
if (wrapper != null) {
generateViewable(wrapper, pass);
}
if (pass == 2) {
visitedElements.add((Viewable) modelo);
}
} catch (Ili2dbException ex) {
throw new Ili2dbException("mapping of " + ((Viewable) modelo).getScopedName(null) + " failed", ex);
}
}
} else if (modelo instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) modelo;
if (attr.getDomainResolvingAll() instanceof SurfaceOrAreaType) {
generateItfLineTable(attr, pass);
} else if (attr.getDomainResolvingAll() instanceof EnumerationType) {
if (pass == 2) {
visitedEnums.add(attr);
}
} else {
// skip it
}
} else {
// skip it
}
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromIli method updateInheritanceTable.
public void updateInheritanceTable(java.sql.Connection conn, String schema) throws Ili2dbException {
String sqlName = DbNames.INHERIT_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
// String stmt="CREATE TABLE "+tabname+" ("+thisClassCol+" VARCHAR2(30) NOT NULL,"+baseClassCol+" VARCHAR2(30) NULL)";
HashSet<String> exstEntries = readInheritanceTable(conn, schema);
try {
// insert entries
String stmt = "INSERT INTO " + sqlName + " (" + DbNames.INHERIT_TAB_THIS_COL + "," + DbNames.INHERIT_TAB_BASE_COL + ") VALUES (?,?)";
EhiLogger.traceBackendCmd(stmt);
java.sql.PreparedStatement ps = conn.prepareStatement(stmt);
String thisClass = null;
try {
for (Object aclass : visitedElements) {
if (aclass instanceof Viewable) {
thisClass = ((Viewable) aclass).getScopedName(null);
if (!exstEntries.contains(thisClass)) {
Viewable base = (Viewable) ((Viewable) aclass).getExtending();
ps.setString(1, thisClass);
if (base != null) {
ps.setString(2, base.getScopedName(null));
} else {
ps.setNull(2, java.sql.Types.VARCHAR);
}
ps.executeUpdate();
}
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert inheritance-relation for class " + thisClass, ex);
} finally {
ps.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update inheritance-table " + sqlName, ex);
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromXtf method readExistingSqlObjIds.
private Long readExistingSqlObjIds(boolean isItf, String bid) throws Ili2dbException {
StringBuilder topicQName = new StringBuilder();
Long basketSqlId = Ili2db.getBasketSqlIdFromBID(bid, conn, schema, colT_ID, topicQName);
if (basketSqlId == null) {
// new basket
return null;
}
Topic topic = TransferToXtf.getTopicDef(td, topicQName.toString());
if (topic == null) {
throw new Ili2dbException("unkown topic " + topicQName.toString());
}
Model model = (Model) topic.getContainer();
// for all Viewables
Iterator iter = null;
if (isItf) {
ArrayList itftablev = ModelUtilities.getItfTables(td, model.getName(), topic.getName());
iter = itftablev.iterator();
} else {
iter = getXtfTables(td, topic).iterator();
}
HashSet<String> visitedTables = new HashSet<String>();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof Viewable) {
if ((obj instanceof View) && !TransferFromIli.isTransferableView(obj)) {
// skip it
} else if (!TransferToXtf.suppressViewable((Viewable) obj)) {
Viewable aclass = (Viewable) obj;
if (aclass.isAbstract()) {
throw new IllegalArgumentException("unexpected abstract viewable " + aclass.getScopedName(null));
}
// get sql name
DbTableName sqlName = recConv.getSqlType(aclass);
ViewableWrapper wrapper = recConv.getViewableWrapper(sqlName.getName());
ViewableWrapper base = wrapper.getExtending();
while (base != null) {
wrapper = base;
base = wrapper.getExtending();
}
sqlName = wrapper.getSqlTable();
if (!visitedTables.contains(sqlName.getQName())) {
visitedTables.add(sqlName.getQName());
// if table exists?
if (DbUtility.tableExists(conn, sqlName)) {
// dump it
EhiLogger.logState(aclass.getScopedName(null) + " read ids...");
readObjectSqlIds(!wrapper.includesMultipleTypes(), sqlName, basketSqlId);
} else {
// skip it
EhiLogger.traceUnusualState(aclass.getScopedName(null) + "...skipped; no table " + sqlName + " in db");
}
}
}
} else if (obj instanceof AttributeDef) {
if (isItf) {
AttributeDef attr = (AttributeDef) obj;
// get sql name
DbTableName sqlName = getSqlTableNameItfLineTable(attr);
// if table exists?
if (DbUtility.tableExists(conn, sqlName)) {
// dump it
EhiLogger.logState(attr.getContainer().getScopedName(null) + "_" + attr.getName() + " read ids...");
readObjectSqlIds(isItf, sqlName, basketSqlId);
} else {
// skip it
EhiLogger.traceUnusualState(attr.getScopedName(null) + "...skipped; no table " + sqlName + " in db");
}
}
}
}
return basketSqlId;
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromXtf method deleteObjectsOfBasket.
private void deleteObjectsOfBasket(long basketSqlId, String topicQName) throws Ili2dbException {
boolean isItf = false;
Topic topic = TransferToXtf.getTopicDef(td, topicQName);
if (topic == null) {
throw new Ili2dbException("unkown topic " + topicQName.toString());
}
Model model = (Model) topic.getContainer();
// for all Viewables
// see also export
Iterator iter = null;
if (isItf) {
ArrayList itftablev = ModelUtilities.getItfTables(td, model.getName(), topic.getName());
iter = itftablev.iterator();
} else {
// get transferable viewables of topic
iter = topic.getViewables().iterator();
}
HashSet<ViewableWrapper> visitedTables = new HashSet<ViewableWrapper>();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof Viewable) {
if ((obj instanceof View) && !TransferFromIli.isTransferableView(obj)) {
// skip it
} else if (!TransferToXtf.suppressViewable((Viewable) obj)) {
Viewable aclass1 = (Viewable) obj;
ViewableWrapper wrapper = class2wrapper.get(aclass1);
while (wrapper != null) {
{
if (!visitedTables.contains(wrapper)) {
visitedTables.add(wrapper);
// if table exists?
// get sql name
DbTableName sqlName = wrapper.getSqlTable();
if (DbUtility.tableExists(conn, sqlName)) {
// delete it
dropRecords(sqlName, basketSqlId);
} else {
// skip it; no table
}
}
}
for (ViewableWrapper secondary : wrapper.getSecondaryTables()) {
if (!visitedTables.contains(secondary)) {
visitedTables.add(secondary);
// if table exists?
// get sql name
DbTableName sqlName = secondary.getSqlTable();
if (DbUtility.tableExists(conn, sqlName)) {
// delete it
dropRecords(sqlName, basketSqlId);
} else {
// skip it; no table
}
}
}
wrapper = wrapper.getExtending();
}
}
} else if (obj instanceof AttributeDef) {
if (isItf) {
AttributeDef attr = (AttributeDef) obj;
// get sql name
DbTableName sqlName = getSqlTableNameItfLineTable(attr);
// if table exists?
if (DbUtility.tableExists(conn, sqlName)) {
dropRecords(sqlName, basketSqlId);
} else {
// skip it; no table
}
}
}
}
dropExistingStructEles(topicQName, basketSqlId);
String sqlName = DbNames.IMPORTS_BASKETS_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
java.sql.PreparedStatement getstmt = null;
try {
String stmt = "DELETE FROM " + sqlName + " WHERE " + DbNames.IMPORTS_BASKETS_TAB_BASKET_COL + "= ?";
EhiLogger.traceBackendCmd(stmt);
getstmt = conn.prepareStatement(stmt);
getstmt.setLong(1, basketSqlId);
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);
}
}
}
}
Aggregations