Search in sources :

Example 31 with EndTransferEvent

use of ch.interlis.iox.EndTransferEvent in project ili2db by claeis.

the class TranslationTest method exportItf10.

@Test
public void exportItf10() 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/Translation/CreateTableItf10.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Translation/InsertIntoTableItf10.sql"));
        {
            File data = new File("test/data/Translation/ModelAsimple10a-out.itf");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_EXPORT);
            config.setDatasetName("ModelAsimple10");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            data = new File("test/data/Translation/ModelBsimple10a-out.itf");
            config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_EXPORT);
            config.setDatasetName("ModelBsimple10");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            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("21");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("20");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("22");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB2", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("25");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB3", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("26");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB2_geomB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("27");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB3_geomB", obj0.getobjecttag());
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) ItfReader(ch.interlis.iom_j.itf.ItfReader) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) Test(org.junit.Test)

Example 32 with EndTransferEvent

use of ch.interlis.iox.EndTransferEvent in project ili2db by claeis.

the class TranslationTest method exportItf10lineTable.

// @Test
public void exportItf10lineTable() throws Exception {
    Connection jdbcConnection = null;
    try {
        EhiLogger.getInstance().setTraceFilter(false);
        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/CreateTableItf10LineTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Translation/InsertIntoTableItf10LineTable.sql"));
        {
            File data = new File("test/data/Translation/ModelAsimple10a-out.itf");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_EXPORT);
            config.setDatasetName("ModelAsimple10");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
        }
        {
            File data = new File("test/data/Translation/ModelBsimple10a-out.itf");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_EXPORT);
            config.setDatasetName("ModelBsimple10");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            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("21");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("20");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("22");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB2", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("25");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB3", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("26");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB2_geomB", obj0.getobjecttag());
            }
            {
                IomObject obj0 = objs.get("27");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("ModelBsimple10.TopicB.ClassB3_geomB", obj0.getobjecttag());
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Statement(java.sql.Statement) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) ItfReader(ch.interlis.iom_j.itf.ItfReader) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File)

Example 33 with EndTransferEvent

use of ch.interlis.iox.EndTransferEvent in project ili2db by claeis.

the class Array23Test method exportSmartCustom.

@Test
public void exportSmartCustom() 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/Array/Array23CreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Array/Array23InsertIntoTable.sql"));
        File data = new File("test/data/Array/Array23a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("Array23");
        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));
        // check values of array
        {
            IomObject obj0 = objs.get("13");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Array23.TestA.Auto", obj0.getobjecttag());
            Assert.assertEquals(2, obj0.getattrvaluecount("Farben"));
            Assert.assertEquals("Rot", obj0.getattrobj("Farben", 0).getattrvalue("Wert"));
            Assert.assertEquals("Blau", obj0.getattrobj("Farben", 1).getattrvalue("Wert"));
        }
        {
            IomObject obj0 = objs.get("14");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Array23.TestA.Auto", obj0.getobjecttag());
            Assert.assertEquals(0, obj0.getattrvaluecount("Farben"));
        }
        {
            IomObject obj0 = objs.get("100");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Array23.TestA.Datatypes", obj0.getobjecttag());
            Assert.assertEquals(0, obj0.getattrvaluecount("aUuid"));
            Assert.assertEquals(0, obj0.getattrvaluecount("aBoolean"));
            Assert.assertEquals(0, obj0.getattrvaluecount("aTime"));
            Assert.assertEquals(0, obj0.getattrvaluecount("aDate"));
            Assert.assertEquals(0, obj0.getattrvaluecount("aDateTime"));
            Assert.assertEquals(0, obj0.getattrvaluecount("numericInt"));
            Assert.assertEquals(0, obj0.getattrvaluecount("numericDec"));
        }
        {
            IomObject obj0 = objs.get("101");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Array23.TestA.Datatypes", obj0.getobjecttag());
            Assert.assertEquals(1, obj0.getattrvaluecount("aUuid"));
            Assert.assertEquals("15b6bcce-8772-4595-bf82-f727a665fbf3", obj0.getattrobj("aUuid", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("aBoolean"));
            Assert.assertEquals("true", obj0.getattrobj("aBoolean", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("aTime"));
            Assert.assertEquals("09:00:00.000", obj0.getattrobj("aTime", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("aDate"));
            Assert.assertEquals("2002-09-24", obj0.getattrobj("aDate", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("aDateTime"));
            Assert.assertEquals("1900-01-01T12:30:05.000", obj0.getattrobj("aDateTime", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("numericInt"));
            Assert.assertEquals("5", obj0.getattrobj("numericInt", 0).getattrvalue("Value"));
            Assert.assertEquals(1, obj0.getattrvaluecount("numericDec"));
            Assert.assertEquals("6.0", obj0.getattrobj("numericDec", 0).getattrvalue("Value"));
        }
    } catch (Exception e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) SQLException(java.sql.SQLException) IoxException(ch.interlis.iox.IoxException) Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) IoxException(ch.interlis.iox.IoxException) Test(org.junit.Test)

Example 34 with EndTransferEvent

use of ch.interlis.iox.EndTransferEvent in project ili2db by claeis.

the class ExtendedModel23Test method exportXtfBase.

@Test
public void exportXtfBase() 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/ExtendedModel/ExtendedModelCreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/ExtendedModel/ExtendedModelInsertIntoTable.sql"));
        File data = new File("test/data/ExtendedModel/ExtendedModel1-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("BaseModel;ExtendedModel");
        config.setExportModels("BaseModel");
        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("32");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("BaseModel.TestA.ClassA2", obj0.getobjecttag());
            Assert.assertEquals("rot", obj0.getattrvalue("farbe"));
            Assert.assertEquals("33", obj0.getattrobj("a3", 0).getobjectrefoid());
            Assert.assertEquals(null, obj0.getattrvalue("wert"));
            Assert.assertEquals(null, obj0.getattrobj("ap1", 0));
        }
    } catch (Exception e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) IoxException(ch.interlis.iox.IoxException) Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) IoxException(ch.interlis.iox.IoxException) Test(org.junit.Test)

Example 35 with EndTransferEvent

use of ch.interlis.iox.EndTransferEvent in project ili2db by claeis.

the class ExtendedModel23Test method exportXtfOriginal.

@Test
public void exportXtfOriginal() 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/ExtendedModel/ExtendedModelCreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/ExtendedModel/ExtendedModelInsertIntoTable.sql"));
        File data = new File("test/data/ExtendedModel/ExtendedModel1-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("BaseModel;ExtendedModel");
        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("32");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("ExtendedModel.TestAp.ClassA2", obj0.getobjecttag());
            Assert.assertEquals("rot.dunkel", obj0.getattrvalue("farbe"));
            Assert.assertEquals("33", obj0.getattrobj("a3", 0).getobjectrefoid());
            Assert.assertEquals("1.1", obj0.getattrvalue("wert"));
            Assert.assertEquals("34", obj0.getattrobj("ap1", 0).getobjectrefoid());
        }
    } catch (Exception e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) IoxException(ch.interlis.iox.IoxException) Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) IoxException(ch.interlis.iox.IoxException) Test(org.junit.Test)

Aggregations

IomObject (ch.interlis.iom.IomObject)35 EndBasketEvent (ch.interlis.iox.EndBasketEvent)35 EndTransferEvent (ch.interlis.iox.EndTransferEvent)35 IoxEvent (ch.interlis.iox.IoxEvent)35 StartTransferEvent (ch.interlis.iox.StartTransferEvent)35 File (java.io.File)35 Config (ch.ehi.ili2db.gui.Config)34 ObjectEvent (ch.interlis.iox.ObjectEvent)34 StartBasketEvent (ch.interlis.iox.StartBasketEvent)34 Connection (java.sql.Connection)34 HashMap (java.util.HashMap)34 XtfReader (ch.interlis.iom_j.xtf.XtfReader)30 Test (org.junit.Test)28 IoxException (ch.interlis.iox.IoxException)8 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)5 ItfReader (ch.interlis.iom_j.itf.ItfReader)5 SQLException (java.sql.SQLException)5 Statement (java.sql.Statement)2 ConverterException (ch.ehi.ili2db.converter.ConverterException)1 ObjectPoolManager (ch.ehi.iox.objpool.ObjectPoolManager)1