Search in sources :

Example 16 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class InheritanceNoSmartTest method exportXtfStructAttrFK.

@Test
public void exportXtfStructAttrFK() 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/InheritanceNoSmart/CreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/InheritanceNoSmart/InsertIntoTable.sql"));
        File data = new File("test/data/InheritanceNoSmart/StructAttr1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("Inheritance1");
        config.setDatasetName(DATASETNAME);
        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>();
        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("17");
            Assert.assertNotNull(obj1);
            Assert.assertEquals("Inheritance1.TestB.ClassB1", obj1.getobjecttag());
        }
        {
            IomObject obj1 = objs.get("17");
            Assert.assertEquals("x2", obj1.getattrobj("s3b", 0).getattrvalue("attrB3b"));
        }
        {
            IomObject obj1 = objs.get("17");
            Assert.assertEquals("b2", obj1.getattrobj("s2", 0).getattrvalue("attrB2b"));
        }
        {
            IomObject obj1 = objs.get("17");
            Assert.assertEquals("b3a", obj1.getattrobj("s3a", 0).getattrvalue("attrB3"));
        }
        {
            IomObject obj1 = objs.get("17");
            Assert.assertEquals("b1", obj1.getattrobj("s1", 0).getattrvalue("attrB1"));
        }
    } 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) 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) Test(org.junit.Test)

Example 17 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class InheritanceSmart1Test method exportXtfStructAttrFK.

@Test
public void exportXtfStructAttrFK() 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/InheritanceSmart1/CreateTableXtfStructAttrFK.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/InheritanceSmart1/InsertIntoTableXtfStructAttrFK.sql"));
        File data = new File("test/data/InheritanceSmart1/StructAttr1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_EXPORT);
        config.setDatasetName(DATASETNAME);
        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("b3");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("StructAttr1.TopicB.ClassC", obj0.getobjecttag());
            Assert.assertEquals("StructAttr1.TopicB.StructA {name Claudia}", obj0.getattrobj("attr1", 0).toString());
        }
    } 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) 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) Test(org.junit.Test)

Example 18 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class InheritanceSmart1Test method exportSmart1.

@Test
public void exportSmart1() 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/InheritanceSmart1/CreateTableSmart1.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/InheritanceSmart1/InsertIntoTableSmart1.sql"));
        File data = new File("test/data/InheritanceSmart1/Inheritance1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setDatasetName(DATASETNAME);
        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("4");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Inheritance1.TestA.ClassA1", obj0.getobjecttag());
            Assert.assertEquals("a1", obj0.getattrvalue("attrA1"));
        }
        {
            IomObject obj0 = objs.get("8");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Inheritance1.TestA.ClassA4b", obj0.getobjecttag());
            Assert.assertEquals("a4", obj0.getattrvalue("attrA4"));
        }
    } 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) 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) Test(org.junit.Test)

Example 19 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class InheritanceSmart2Test method exportXtfStructAttrFK.

@Test
public void exportXtfStructAttrFK() 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/InheritanceSmart2/InitInheritanceSmart2Schema.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/InheritanceSmart2/InitInheritanceSmart2a.sql"));
        File data = new File("test/data/InheritanceSmart2/StructAttr1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_EXPORT);
        config.setDatasetName(DATASETNAME);
        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("2");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Inheritance2.TestA.ClassA3c", obj0.getobjecttag());
            Assert.assertEquals("attra3c-20", obj0.getattrvalue("attrA3c"));
        }
        {
            IomObject obj0 = objs.get("3");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Inheritance2.TestA.ClassB", 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) 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) Test(org.junit.Test)

Example 20 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class InheritanceSmart2Test method exportSmart2.

@Test
public void exportSmart2() 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/InheritanceSmart2/InitInheritanceSmart2Schema.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/InheritanceSmart2/InitInheritanceSmart2a.sql"));
        File data = new File("test/data/InheritanceSmart2/Inheritance2a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setDatasetName(DATASETNAME);
        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("1");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Inheritance2.TestA.ClassA3b", obj0.getobjecttag());
            Assert.assertEquals("attra3-10", obj0.getattrvalue("attrA3"));
            Assert.assertEquals("attra3b-10", obj0.getattrvalue("attrA3b"));
        }
        {
            IomObject obj0 = objs.get("2");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("Inheritance2.TestA.ClassA3c", 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) 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) Test(org.junit.Test)

Aggregations

IomObject (ch.interlis.iom.IomObject)66 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 HashMap (java.util.HashMap)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 XtfReader (ch.interlis.iom_j.xtf.XtfReader)30 Test (org.junit.Test)29 IoxException (ch.interlis.iox.IoxException)12 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)11 Iom_jObject (ch.interlis.iom_j.Iom_jObject)9 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)8 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)8 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)8 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)8