Search in sources :

Example 21 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class InheritanceSmart1Test method exportXtfRefAttrFK.

@Test
public void exportXtfRefAttrFK() 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/CreateTableXtfRefAttrFK.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/InheritanceSmart1/InsertIntoTableXtfRefAttrFK.sql"));
        File data = new File("test/data/InheritanceSmart1/RefAttr1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_EXPORT);
        config.setDatasetName(DATASETNAME);
        // config.setValidation(false);
        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("b.3");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("RefAttr1.TopicA.ClassB", obj0.getobjecttag());
            Assert.assertEquals("RefAttr1.TopicA.StructA11 {ref -> a11.1 REF {}}", obj0.getattrobj("struct", 0).toString());
        }
        {
            IomObject obj0 = objs.get("b.1");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("RefAttr1.TopicA.ClassB", obj0.getobjecttag());
            Assert.assertEquals("RefAttr1.TopicA.StructA1 {ref -> a1.1 REF {}}", obj0.getattrobj("struct", 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 22 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class MultilineTest method exportSmartChbaseStrokeArcs.

// @Test
public void exportSmartChbaseStrokeArcs() throws Exception {
    Connection jdbcConnection = null;
    try {
        Class driverClass = Class.forName("org.postgresql.Driver");
        jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
        stmt = jdbcConnection.createStatement();
        if (false) {
            stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
            DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/MultiSurface/CreateTableMultiSurface1a.sql"));
            DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/MultiSurface/InsertIntoTableMultiSurface1a.sql"));
        }
        File data = new File("test/data/MultiLine/MultiLine1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("MultiLine1");
        config.setFunction(Config.FC_EXPORT);
        Ili2db.readSettingsFromDb(config);
        Ili2db.run(config, null);
        if (false) {
            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 oid
            {
                IomObject obj0 = objs.get("o1");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("o1", obj0.getobjectoid());
            }
            // check objecttag
            {
                IomObject obj0 = objs.get("o1");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("MultiSurface1.TestA.ClassA1", obj0.getobjecttag());
            }
            // check values of attrnames
            {
                IomObject obj0 = objs.get("o1");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("COORD {C1 600031.0, C2 200021.0}", obj0.getattrobj("point", 0).toString());
                Assert.assertEquals("GeometryCHLV03_V1.MultiSurface {Surfaces [GeometryCHLV03_V1.SurfaceStructure {Surface MULTISURFACE {surface SURFACE {boundary BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 600030.0, C2 200020.0}, COORD {C1 600045.0, C2 200040.0}, COORD {C1 600010.0, C2 200040.0}, COORD {C1 600030.0, C2 200020.0}]}}}}}}, GeometryCHLV03_V1.SurfaceStructure {Surface MULTISURFACE {surface SURFACE {boundary BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 600015.0, C2 200005.0}, COORD {C1 600040.0, C2 200010.0}, COORD {C1 600010.0, C2 200020.0}, COORD {C1 600005.0, C2 200010.0}, COORD {C1 600015.0, C2 200005.0}]}}}}}}]}", obj0.getattrobj("geom", 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)

Example 23 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class MultilineTest method exportSmartChbaseSingleGeom.

// @Test
public void exportSmartChbaseSingleGeom() throws Exception {
    Connection jdbcConnection = null;
    try {
        Class driverClass = Class.forName("org.postgresql.Driver");
        jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
        stmt = jdbcConnection.createStatement();
        if (false) {
            stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
            DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/MultiSurface/CreateTableSingleGeom.sql"));
            DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/MultiSurface/InsertIntoTableSingleGeom.sql"));
        }
        File data = new File("test/data/MultiLine/MultiLine1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("MultiLine1");
        config.setFunction(Config.FC_EXPORT);
        Ili2db.readSettingsFromDb(config);
        Ili2db.run(config, null);
        if (false) {
            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 oid
            {
                IomObject obj0 = objs.get("o1");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("o1", obj0.getobjectoid());
            }
            // check objecttag
            {
                IomObject obj0 = objs.get("o1");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("MultiSurface1.TestA.ClassA1", obj0.getobjecttag());
            }
            // check values of attrnames
            {
                IomObject obj0 = objs.get("o1");
                Assert.assertNotNull(obj0);
                Assert.assertEquals("COORD {C1 600031.0, C2 200021.0}", obj0.getattrobj("point", 0).toString());
                Assert.assertEquals("GeometryCHLV03_V1.MultiSurface {Surfaces [GeometryCHLV03_V1.SurfaceStructure {Surface MULTISURFACE {surface SURFACE {boundary BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 600030.0, C2 200020.0}, COORD {C1 600045.0, C2 200040.0}, COORD {C1 600010.0, C2 200040.0}, COORD {C1 600030.0, C2 200020.0}]}}}}}}, GeometryCHLV03_V1.SurfaceStructure {Surface MULTISURFACE {surface SURFACE {boundary BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 600015.0, C2 200005.0}, COORD {C1 600040.0, C2 200010.0}, COORD {C1 600010.0, C2 200020.0}, COORD {C1 600005.0, C2 200010.0}, COORD {C1 600015.0, C2 200005.0}]}}}}}}]}", obj0.getattrobj("geom", 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)

Example 24 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class MultisurfaceTest method exportSmartChbaseSingleGeom.

@Test
public void exportSmartChbaseSingleGeom() 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/MultiSurface/CreateTableSingleGeom.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/MultiSurface/InsertIntoTableSingleGeom.sql"));
        File data = new File("test/data/MultiSurface/MultiSurface1a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("MultiSurface1");
        config.setFunction(Config.FC_EXPORT);
        config.setCreateFk(config.CREATE_FK_YES);
        config.setBasketHandling(config.BASKET_HANDLING_READWRITE);
        config.setCatalogueRefTrafo(null);
        config.setMultiSurfaceTrafo(config.MULTISURFACE_TRAFO_COALESCE);
        config.setOneGeomPerTable(true);
        config.setMultilingualTrafo(null);
        config.setInheritanceTrafo(null);
        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 oid
        {
            IomObject obj0 = objs.get("o1");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("o1", obj0.getobjectoid());
        }
        // check objecttag
        {
            IomObject obj0 = objs.get("o1");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("MultiSurface1.TestA.ClassA1", obj0.getobjecttag());
        }
        // check values of attrnames
        {
            IomObject obj0 = objs.get("o1");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("COORD {C1 600031.0, C2 200021.0}", obj0.getattrobj("point", 0).toString());
            Assert.assertEquals("GeometryCHLV03_V1.MultiSurface {Surfaces [GeometryCHLV03_V1.SurfaceStructure {Surface MULTISURFACE {surface SURFACE {boundary BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 600030.0, C2 200020.0}, COORD {C1 600045.0, C2 200040.0}, COORD {C1 600010.0, C2 200040.0}, COORD {C1 600030.0, C2 200020.0}]}}}}}}, GeometryCHLV03_V1.SurfaceStructure {Surface MULTISURFACE {surface SURFACE {boundary BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 600015.0, C2 200005.0}, COORD {C1 600040.0, C2 200010.0}, COORD {C1 600010.0, C2 200020.0}, COORD {C1 600005.0, C2 200010.0}, COORD {C1 600015.0, C2 200005.0}]}}}}}}]}", obj0.getattrobj("geom", 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 25 with XtfReader

use of ch.interlis.iom_j.xtf.XtfReader in project ili2db by claeis.

the class Naming1smart1Test 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/Naming1smart1/CreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/Naming1smart1/InsertIntoTable.sql"));
        File data = new File("test/data/Naming1smart1/Naming1a-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 a1 = objs.get("a1");
        Assert.assertNotNull(a1);
        Assert.assertEquals("Naming1.TestAttr.ClassA1", a1.getobjecttag());
        Assert.assertEquals("a1 first", a1.getattrvalue("attr1"));
        Assert.assertEquals("a1 second", a1.getattrvalue("Attr1"));
        IomObject a2 = objs.get("a2");
        Assert.assertNotNull(a2);
        Assert.assertEquals("Naming1.TestAttr.ClassA1a", a2.getobjecttag());
        Assert.assertEquals("a2 first", a2.getattrvalue("attr1"));
        Assert.assertEquals("a2 second", a2.getattrvalue("Attr1"));
        Assert.assertEquals("a2", a2.getattrvalue("attrA"));
        IomObject a3 = objs.get("a3");
        Assert.assertNotNull(a3);
        Assert.assertEquals("Naming1.TestAttr.ClassA1b", a3.getobjecttag());
        Assert.assertEquals("a3 first", a3.getattrvalue("attr1"));
        Assert.assertEquals("a3 second", a3.getattrvalue("Attr1"));
        Assert.assertEquals("a3", a3.getattrvalue("attrA"));
        IomObject c1 = objs.get("c1");
        Assert.assertNotNull(c1);
        Assert.assertEquals("Naming1.TestClass.ClassA1", c1.getobjecttag());
        Assert.assertEquals("attr1", c1.getattrvalue("attr1"));
        IomObject c2 = objs.get("c2");
        Assert.assertNotNull(c2);
        Assert.assertEquals("Naming1.TestClass.Classa1", c2.getobjecttag());
        Assert.assertEquals("attrA'", c2.getattrvalue("attrA"));
    } 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

XtfReader (ch.interlis.iom_j.xtf.XtfReader)31 Connection (java.sql.Connection)31 HashMap (java.util.HashMap)31 Config (ch.ehi.ili2db.gui.Config)30 IomObject (ch.interlis.iom.IomObject)30 EndBasketEvent (ch.interlis.iox.EndBasketEvent)30 EndTransferEvent (ch.interlis.iox.EndTransferEvent)30 IoxEvent (ch.interlis.iox.IoxEvent)30 ObjectEvent (ch.interlis.iox.ObjectEvent)30 StartBasketEvent (ch.interlis.iox.StartBasketEvent)30 StartTransferEvent (ch.interlis.iox.StartTransferEvent)30 File (java.io.File)30 Test (org.junit.Test)25 IoxException (ch.interlis.iox.IoxException)8 SQLException (java.sql.SQLException)5 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)4 StdLogEvent (ch.ehi.basics.logging.StdLogEvent)1 ConverterException (ch.ehi.ili2db.converter.ConverterException)1 SqlColumnConverter (ch.ehi.ili2db.converter.SqlColumnConverter)1 CustomMapping (ch.ehi.ili2db.fromili.CustomMapping)1