use of ch.interlis.iom.IomObject in project ili2db by claeis.
the class Dataset23NoSmartTest method exportDataset.
@Test
public void exportDataset() throws Exception {
Connection jdbcConnection = null;
try {
Class driverClass = Class.forName("org.postgresql.Driver");
jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Dataset23NoSmart/CreateTable.sql"));
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Dataset23NoSmart/InsertIntoTable.sql"));
File data = new File("test/data/Dataset23NoSmart/Dataset1-out.xtf");
Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
config.setDatasetName(DATASETNAME_A);
config.setFunction(Config.FC_EXPORT);
Ili2db.readSettingsFromDb(config);
Ili2db.run(config, null);
HashMap<String, IomObject> objs = new HashMap<String, IomObject>();
XtfReader reader = new XtfReader(data);
IoxEvent event = null;
do {
event = reader.read();
if (event instanceof StartTransferEvent) {
} else if (event instanceof StartBasketEvent) {
} else if (event instanceof ObjectEvent) {
IomObject iomObj = ((ObjectEvent) event).getIomObject();
if (iomObj.getobjectoid() != null) {
objs.put(iomObj.getobjectoid(), iomObj);
}
} else if (event instanceof EndBasketEvent) {
} else if (event instanceof EndTransferEvent) {
}
} while (!(event instanceof EndTransferEvent));
{
IomObject obj0 = objs.get("6");
Assert.assertNotNull(obj0);
Assert.assertEquals("Dataset1.TestA.ClassA1b", obj0.getobjecttag());
Assert.assertEquals("a1", obj0.getattrvalue("attr1"));
}
} finally {
if (jdbcConnection != null) {
jdbcConnection.close();
}
}
}
use of ch.interlis.iom.IomObject in project ili2db by claeis.
the class Datatypes10Test method exportItfWithSkipPolygonBuilding.
@Test
public void exportItfWithSkipPolygonBuilding() throws Exception {
Connection jdbcConnection = null;
try {
Class driverClass = Class.forName("org.postgresql.Driver");
jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
stmt = jdbcConnection.createStatement();
stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Datatypes10/CreateTable.sql"));
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Datatypes10/InsertIntoTable.sql"));
File data = new File("test/data/Datatypes10/Datatypes10a-ltout.itf");
Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
config.setModels("Datatypes10");
config.setFunction(Config.FC_EXPORT);
Ili2db.readSettingsFromDb(config);
Ili2db.run(config, null);
// read objects of db and write objectValue to HashMap
HashMap<String, IomObject> objs = new HashMap<String, IomObject>();
ItfReader reader = new ItfReader(data);
IoxEvent event = null;
do {
event = reader.read();
if (event instanceof StartTransferEvent) {
} else if (event instanceof StartBasketEvent) {
} else if (event instanceof ObjectEvent) {
IomObject iomObj = ((ObjectEvent) event).getIomObject();
if (iomObj.getobjectoid() != null) {
objs.put(iomObj.getobjectoid(), iomObj);
}
} else if (event instanceof EndBasketEvent) {
} else if (event instanceof EndTransferEvent) {
}
} while (!(event instanceof EndTransferEvent));
{
IomObject obj0 = objs.get("10");
Assert.assertNotNull(obj0);
Assert.assertEquals("Datatypes10.Topic.OtherTable", obj0.getobjecttag());
}
{
IomObject obj1 = objs.get("11");
Assert.assertNotNull(obj1);
Assert.assertEquals("Datatypes10.Topic.OtherTable", obj1.getobjecttag());
}
} finally {
if (jdbcConnection != null) {
jdbcConnection.close();
}
}
}
use of ch.interlis.iom.IomObject in project ili2db by claeis.
the class Datatypes23Test method exportXtfSurface.
@Test
public void exportXtfSurface() throws Exception {
Connection jdbcConnection = null;
try {
Class driverClass = Class.forName("org.postgresql.Driver");
jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader(CREATETABLES_SURFACES));
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader(INSERTINTOTABLES_SURFACES));
File data = new File(TEST_OUT + "Datatypes23Surface-out.xtf");
Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
config.setFunction(Config.FC_EXPORT);
config.setModels(DBSCHEMA);
config.setBasketHandling(null);
// config.setValidation(false);
Ili2db.readSettingsFromDb(config);
try {
Ili2db.run(config, null);
} catch (Exception ex) {
EhiLogger.logError(ex);
Assert.fail();
}
// tests
// read objects of db and write objectValue to HashMap
HashMap<String, IomObject> objs = new HashMap<String, IomObject>();
XtfReader reader = new XtfReader(data);
IoxEvent event = null;
do {
event = reader.read();
if (event instanceof StartTransferEvent) {
} else if (event instanceof StartBasketEvent) {
} else if (event instanceof ObjectEvent) {
IomObject iomObj = ((ObjectEvent) event).getIomObject();
if (iomObj.getobjectoid() != null) {
objs.put(iomObj.getobjectoid(), iomObj);
}
} else if (event instanceof EndBasketEvent) {
} else if (event instanceof EndTransferEvent) {
}
} while (!(event instanceof EndTransferEvent));
{
IomObject obj1 = objs.get("Surface2.1");
Assert.assertNotNull(obj1);
Assert.assertEquals("Datatypes23.Topic.Surface2", obj1.getobjecttag());
IomObject surface = obj1.getattrobj("surfacearcs2d", 0);
Assert.assertEquals("MULTISURFACE {surface SURFACE {boundary [BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 2460001.0, C2 1045001.0}, COORD {C1 2460020.0, C2 1045015.0}, ARC {A1 2460010.0, A2 1045018.0, C1 2460001.0, C2 1045015.0}, COORD {C1 2460001.0, C2 1045001.0}]}}}, BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 2460005.0, C2 1045005.0}, COORD {C1 2460010.0, C2 1045010.0}, ARC {A1 2460007.0, A2 1045009.0, C1 2460005.0, C2 1045010.0}, COORD {C1 2460005.0, C2 1045005.0}]}}}]}}", surface.toString());
}
} catch (SQLException e) {
throw new IoxException(e);
} finally {
if (jdbcConnection != null) {
jdbcConnection.close();
}
}
}
use of ch.interlis.iom.IomObject in project ili2db by claeis.
the class TranslationTest method exportXtf23.
@Test
public void exportXtf23() throws Exception {
Connection jdbcConnection = null;
try {
Class driverClass = Class.forName("org.postgresql.Driver");
jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
Statement stmt = jdbcConnection.createStatement();
stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Translation/CreateTableXtf23.sql"));
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Translation/InsertIntoTableXtf23.sql"));
EhiLogger.getInstance().setTraceFilter(false);
File data = new File("test/data/Translation/EnumOka-out.xtf");
Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
config.setFunction(Config.FC_EXPORT);
config.setCreateFk(config.CREATE_FK_YES);
config.setTidHandling(Config.TID_HANDLING_PROPERTY);
config.setBasketHandling(config.BASKET_HANDLING_READWRITE);
config.setCatalogueRefTrafo(null);
config.setMultiSurfaceTrafo(null);
config.setMultilingualTrafo(null);
config.setInheritanceTrafo(null);
config.setDatasetName("EnumOka");
Ili2db.readSettingsFromDb(config);
Ili2db.run(config, null);
HashMap<String, IomObject> objs = new HashMap<String, IomObject>();
XtfReader reader = new XtfReader(data);
IoxEvent event = null;
do {
event = reader.read();
if (event instanceof StartTransferEvent) {
} else if (event instanceof StartBasketEvent) {
} else if (event instanceof ObjectEvent) {
IomObject iomObj = ((ObjectEvent) event).getIomObject();
if (iomObj.getobjectoid() != null) {
objs.put(iomObj.getobjectoid(), iomObj);
}
} else if (event instanceof EndBasketEvent) {
} else if (event instanceof EndTransferEvent) {
}
} while (!(event instanceof EndTransferEvent));
{
IomObject obj0 = objs.get("o1");
Assert.assertNotNull(obj0);
Assert.assertEquals("EnumOkA.TopicA.ClassA", obj0.getobjecttag());
}
{
IomObject obj0 = objs.get("o2");
Assert.assertNotNull(obj0);
Assert.assertEquals("EnumOkA.TopicA.ClassA", obj0.getobjecttag());
Assert.assertEquals("a2.a21", obj0.getattrvalue("attrA"));
}
{
IomObject obj0 = objs.get("x1");
Assert.assertNotNull(obj0);
Assert.assertEquals("EnumOkB.TopicB.ClassB", obj0.getobjecttag());
}
{
IomObject obj0 = objs.get("x2");
Assert.assertNotNull(obj0);
Assert.assertEquals("EnumOkB.TopicB.ClassB", obj0.getobjecttag());
Assert.assertEquals("b2.b21", obj0.getattrvalue("attrB"));
}
} finally {
if (jdbcConnection != null) {
jdbcConnection.close();
}
}
}
use of ch.interlis.iom.IomObject in project ili2db by claeis.
the class TransferToXtf method doBasket.
private boolean doBasket(String filename, IoxWriter iomFile, Topic topic, Long basketSqlId, String basketXtfId) throws IoxException {
Model model = (Model) topic.getContainer();
boolean referrs = false;
StartBasketEvent iomBasket = null;
delayedObjects = new ArrayList<FixIomObjectRefs>();
// for all Viewables
Iterator iter = null;
if (iomFile instanceof ItfWriter) {
ArrayList itftablev = ModelUtilities.getItfTables(td, model.getName(), topic.getName());
iter = itftablev.iterator();
} else {
iter = topic.getViewables().iterator();
}
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof Viewable) {
if ((obj instanceof View) && !TransferFromIli.isTransferableView(obj)) {
// skip it
} else if (!suppressViewable((Viewable) obj)) {
Viewable aclass = (Viewable) obj;
if (languageFilter != null) {
aclass = (Viewable) aclass.getTranslationOfOrSame();
}
ViewableWrapper wrapper = class2wrapper.get(aclass);
// get sql name
DbTableName sqlName = recConv.getSqlType(wrapper.getViewable());
// if table exists?
if (DbUtility.tableExists(conn, sqlName)) {
// dump it
EhiLogger.logState(aclass.getScopedName(null) + "...");
if (iomBasket == null) {
iomBasket = new StartBasketEvent(topic.getScopedName(null), basketXtfId);
if (languageFilter != null) {
iomBasket = (StartBasketEvent) languageFilter.filter(iomBasket);
}
if (exportBaseModelFilter != null) {
iomBasket = (StartBasketEvent) exportBaseModelFilter.filter(iomBasket);
}
if (validator != null)
validator.validate(iomBasket);
iomFile.write(iomBasket);
}
dumpObject(iomFile, aclass, basketSqlId);
} else {
// skip it
EhiLogger.traceUnusualState(aclass.getScopedName(null) + "...skipped; no table " + sqlName + " in db");
}
}
} else if (obj instanceof AttributeDef) {
if (iomFile instanceof ItfWriter) {
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() + "...");
if (iomBasket == null) {
iomBasket = new StartBasketEvent(topic.getScopedName(null), topic.getScopedName(null));
if (languageFilter != null) {
iomBasket = (StartBasketEvent) languageFilter.filter(iomBasket);
}
if (exportBaseModelFilter != null) {
iomBasket = (StartBasketEvent) exportBaseModelFilter.filter(iomBasket);
}
if (validator != null)
validator.validate(iomBasket);
iomFile.write(iomBasket);
}
dumpItfTableObject(iomFile, attr, basketSqlId);
} else {
// skip it
EhiLogger.traceUnusualState(attr.getScopedName(null) + "...skipped; no table " + sqlName + " in db");
}
}
}
}
if (iomBasket != null) {
// fix forward references
for (FixIomObjectRefs fixref : delayedObjects) {
boolean skipObj = false;
for (IomObject ref : fixref.getRefs()) {
long sqlid = fixref.getTargetSqlid(ref);
if (sqlidPool.containsSqlid(sqlid)) {
// fix it
ref.setobjectrefoid(sqlidPool.getXtfid(sqlid));
} else {
// object in another basket
Viewable aclass = fixref.getTargetClass(ref);
// read object
String tid = readObjectTid(aclass, sqlid);
if (tid == null) {
EhiLogger.logError("unknown referenced object " + aclass.getScopedName(null) + " sqlid " + fixref.getTargetSqlid(ref) + " referenced from " + fixref.getRoot().getobjecttag() + " TID " + fixref.getRoot().getobjectoid());
referrs = true;
skipObj = true;
} else {
// fix reference
ref.setobjectrefoid(tid);
}
}
}
if (!skipObj) {
ObjectEvent objEvent = new ObjectEvent(fixref.getRoot());
if (languageFilter != null) {
objEvent = (ObjectEvent) languageFilter.filter(objEvent);
}
if (exportBaseModelFilter != null) {
objEvent = (ObjectEvent) exportBaseModelFilter.filter(objEvent);
}
if (objEvent != null) {
if (validator != null)
validator.validate(objEvent);
iomFile.write(objEvent);
}
}
}
EndBasketEvent endBasket = new EndBasketEvent();
if (languageFilter != null) {
endBasket = (EndBasketEvent) languageFilter.filter(endBasket);
}
if (exportBaseModelFilter != null) {
endBasket = (EndBasketEvent) exportBaseModelFilter.filter(endBasket);
}
if (validator != null)
validator.validate(endBasket);
iomFile.write(endBasket);
saveObjStat(iomBasket.getBid(), basketSqlId, filename, iomBasket.getType());
}
return referrs;
}
Aggregations