Search in sources :

Example 41 with Config

use of ch.ehi.ili2db.gui.Config 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 42 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class InheritanceSmart1Test method importXtfSubtypeFK.

@Test
public void importXtfSubtypeFK() 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");
        {
            File data = new File("test/data/InheritanceSmart1/SubtypeFKa.xtf");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_IMPORT);
            config.setCreateFk(Config.CREATE_FK_YES);
            config.setInheritanceTrafo(Config.INHERITANCE_TRAFO_SMART1);
            config.setDatasetName(DATASETNAME);
            config.setTidHandling(Config.TID_HANDLING_PROPERTY);
            config.setBasketHandling(Config.BASKET_HANDLING_READWRITE);
            // config.setCreatescript(data.getPath()+".sql");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            // subtype value
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_attrname.target, t_ili2db_attrname.sqlname FROM " + DBSCHEMA + ".t_ili2db_attrname WHERE t_ili2db_attrname.target = 'classa'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("b1", rs.getString(2));
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : Statement(java.sql.Statement) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) File(java.io.File) Test(org.junit.Test)

Example 43 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class InheritanceSmart1Test method importIliStructAttrFK.

@Test
public void importIliStructAttrFK() 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");
        {
            File data = new File("test/data/InheritanceSmart1/StructAttr1.ili");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_SCHEMAIMPORT);
            config.setCreateFk(Config.CREATE_FK_YES);
            config.setInheritanceTrafo(Config.INHERITANCE_TRAFO_SMART1);
            config.setDatasetName(DATASETNAME);
            config.setTidHandling(Config.TID_HANDLING_PROPERTY);
            config.setBasketHandling(Config.BASKET_HANDLING_READWRITE);
            config.setNameOptimization(Config.NAME_OPTIMIZATION_TOPIC);
            // config.setCreatescript(data.getPath()+".sql");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            // imported classes
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_classname.iliname, t_ili2db_classname.sqlname FROM " + DBSCHEMA + ".t_ili2db_classname WHERE t_ili2db_classname.iliname = 'StructAttr1.TopicA.StructA'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("topica_structa", rs.getString(2));
            }
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_classname.iliname, t_ili2db_classname.sqlname FROM " + DBSCHEMA + ".t_ili2db_classname WHERE t_ili2db_classname.iliname = 'StructAttr1.TopicB.StructA'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("topicb_structa", rs.getString(2));
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : Statement(java.sql.Statement) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) File(java.io.File) Test(org.junit.Test)

Example 44 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class InheritanceSmart1Test method importSmart1.

// config.setDeleteMode(Config.DELETE_DATA);
// EhiLogger.getInstance().setTraceFilter(false);
// --skipPolygonBuilding
// config.setDoItfLineTables(true);
// config.setAreaRef(config.AREA_REF_KEEP);
// --importTid
// config.setTidHandling(config.TID_HANDLING_PROPERTY);
@Test
public void importSmart1() 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");
        {
            File data = new File("test/data/InheritanceSmart1/Inheritance1a.xtf");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_IMPORT);
            config.setCreateFk(Config.CREATE_FK_YES);
            config.setInheritanceTrafo(Config.INHERITANCE_TRAFO_SMART1);
            config.setDatasetName(DATASETNAME);
            config.setTidHandling(Config.TID_HANDLING_PROPERTY);
            config.setBasketHandling(Config.BASKET_HANDLING_READWRITE);
            // config.setCreatescript(data.getPath()+".sql");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            // base class is empty (sub struct strategy or super class strategy)
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_inheritance.thisclass, t_ili2db_inheritance.baseclass FROM " + DBSCHEMA + ".t_ili2db_inheritance WHERE t_ili2db_inheritance.thisclass = 'Inheritance1.TestA.ClassA1'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals(null, rs.getString(2));
            }
            // base class is empty (sub struct strategy or super class strategy)
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_inheritance.thisclass, t_ili2db_inheritance.baseclass FROM " + DBSCHEMA + ".t_ili2db_inheritance WHERE t_ili2db_inheritance.thisclass = 'Inheritance1.TestC.ClassC1'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals(null, rs.getString(2));
            }
            // base class not empty (new class stragety)
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_inheritance.thisclass, t_ili2db_inheritance.baseclass FROM " + DBSCHEMA + ".t_ili2db_inheritance WHERE t_ili2db_inheritance.thisclass = 'Inheritance1.TestA.ClassA4b'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("Inheritance1.TestA.ClassA4", rs.getString(2));
            }
            // newClassStrategy
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_trafo.iliname, t_ili2db_trafo.setting FROM " + DBSCHEMA + ".t_ili2db_trafo WHERE t_ili2db_trafo.iliname = 'Inheritance1.TestA.ClassA1'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("newClass", rs.getString(2));
            }
            // subStructStrategy
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_trafo.iliname, t_ili2db_trafo.setting FROM " + DBSCHEMA + ".t_ili2db_trafo WHERE t_ili2db_trafo.iliname = 'Inheritance1.TestC.ClassC1'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("subClass", rs.getString(2));
            }
            // superClassStrategy
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_trafo.iliname, t_ili2db_trafo.setting FROM " + DBSCHEMA + ".t_ili2db_trafo WHERE t_ili2db_trafo.iliname = 'Inheritance1.TestA.ClassA4b'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("superClass", rs.getString(2));
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : Statement(java.sql.Statement) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) File(java.io.File) Test(org.junit.Test)

Example 45 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class InheritanceSmart1Test method importIliSubtypeFK.

@Test
public void importIliSubtypeFK() 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");
        {
            File data = new File("test/data/InheritanceSmart1/SubtypeFK.ili");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_SCHEMAIMPORT);
            config.setCreateFk(Config.CREATE_FK_YES);
            config.setInheritanceTrafo(Config.INHERITANCE_TRAFO_SMART1);
            config.setDatasetName(DATASETNAME);
            config.setTidHandling(Config.TID_HANDLING_PROPERTY);
            config.setBasketHandling(Config.BASKET_HANDLING_READWRITE);
            // config.setCreatescript(data.getPath()+".sql");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            // subtype class import
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_classname.iliname, t_ili2db_classname.sqlname FROM " + DBSCHEMA + ".t_ili2db_classname WHERE t_ili2db_classname.iliname = 'SubtypeFK23.Topic.bc1'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("bc1", rs.getString(2));
            }
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_classname.iliname, t_ili2db_classname.sqlname FROM " + DBSCHEMA + ".t_ili2db_classname WHERE t_ili2db_classname.iliname = 'SubtypeFK23.Topic.ClassA'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("classa", rs.getString(2));
            }
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_classname.iliname, t_ili2db_classname.sqlname FROM " + DBSCHEMA + ".t_ili2db_classname WHERE t_ili2db_classname.iliname = 'SubtypeFK23.Topic.ClassB'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("classb", rs.getString(2));
            }
            Assert.assertTrue(stmt.execute("SELECT t_ili2db_classname.iliname, t_ili2db_classname.sqlname FROM " + DBSCHEMA + ".t_ili2db_classname WHERE t_ili2db_classname.iliname = 'SubtypeFK23.Topic.ClassC'"));
            {
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("classc", rs.getString(2));
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : Statement(java.sql.Statement) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) File(java.io.File) Test(org.junit.Test)

Aggregations

Config (ch.ehi.ili2db.gui.Config)207 File (java.io.File)162 Test (org.junit.Test)154 Connection (java.sql.Connection)118 ResultSet (java.sql.ResultSet)72 Statement (java.sql.Statement)44 HashMap (java.util.HashMap)40 IomObject (ch.interlis.iom.IomObject)34 EndBasketEvent (ch.interlis.iox.EndBasketEvent)34 EndTransferEvent (ch.interlis.iox.EndTransferEvent)34 IoxEvent (ch.interlis.iox.IoxEvent)34 ObjectEvent (ch.interlis.iox.ObjectEvent)34 StartBasketEvent (ch.interlis.iox.StartBasketEvent)34 StartTransferEvent (ch.interlis.iox.StartTransferEvent)34 FgdbDriver (ch.ehi.ili2fgdb.jdbc.FgdbDriver)33 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)32 XtfReader (ch.interlis.iom_j.xtf.XtfReader)30 IoxException (ch.interlis.iox.IoxException)15 SQLException (java.sql.SQLException)12 ResultSetMetaData (java.sql.ResultSetMetaData)10