Search in sources :

Example 31 with IoxException

use of ch.interlis.iox.IoxException 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)

Example 32 with IoxException

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

the class ExtendedModel23Test method importXtf.

@Test
public void importXtf() throws Exception {
    EhiLogger.getInstance().setTraceFilter(false);
    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");
        {
            {
                File data = new File("test/data/ExtendedModel/ExtendedModel1.xtf");
                Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
                config.setFunction(Config.FC_IMPORT);
                config.setModels("BaseModel;ExtendedModel");
                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(Config.INHERITANCE_TRAFO_SMART1);
                Ili2db.readSettingsFromDb(config);
                Ili2db.run(config, null);
            }
        }
    } catch (Exception e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) File(java.io.File) IoxException(ch.interlis.iox.IoxException) IoxException(ch.interlis.iox.IoxException) Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) Test(org.junit.Test)

Aggregations

IoxException (ch.interlis.iox.IoxException)32 File (java.io.File)16 Test (org.junit.Test)16 SQLException (java.sql.SQLException)15 Config (ch.ehi.ili2db.gui.Config)14 Connection (java.sql.Connection)13 IomObject (ch.interlis.iom.IomObject)12 HashMap (java.util.HashMap)9 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)8 XtfReader (ch.interlis.iom_j.xtf.XtfReader)8 EndBasketEvent (ch.interlis.iox.EndBasketEvent)8 EndTransferEvent (ch.interlis.iox.EndTransferEvent)8 IoxEvent (ch.interlis.iox.IoxEvent)8 StartTransferEvent (ch.interlis.iox.StartTransferEvent)8 ConverterException (ch.ehi.ili2db.converter.ConverterException)7 ObjectEvent (ch.interlis.iox.ObjectEvent)7 StartBasketEvent (ch.interlis.iox.StartBasketEvent)7 ResultSet (java.sql.ResultSet)6 ResultSetMetaData (java.sql.ResultSetMetaData)6 ParseException (com.vividsolutions.jts.io.ParseException)5