Search in sources :

Example 16 with IoxException

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

the class DbUtilityExecuteSqlTest method dbUtilityExecuteSql_SingleSemicolon_Ok.

// Es wird getestet ob das sql Skript fehlerfrei in die Datenbank importiert werden kann,
// wenn CREATE SEQUENCE mit 1 Semikolon: "test.t_ili2db_seq;" beendet wird.
@Test
public void dbUtilityExecuteSql_SingleSemicolon_Ok() throws IoxException, SQLException {
    EhiLogger.getInstance().setTraceFilter(false);
    Connection jdbcConnection = null;
    ResultSet rs = null;
    try {
        Class driverClass = Class.forName("org.postgresql.Driver");
    } catch (ClassNotFoundException e1) {
        throw new IoxException(e1);
    }
    jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
    Statement stmt = jdbcConnection.createStatement();
    try {
        dropSchema(rs, stmt);
        createSchema(rs, stmt);
        // execute sql script
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader(TEST_IN + "ExecuteSingleSemicolon.sql"));
        // insert into table
        stmt.execute("INSERT INTO " + DBSCHEMA + ".class1 (" + ATTRNAME + ") VALUES ('a')");
        rs = stmt.executeQuery("SELECT " + ATTRNAME + " FROM " + DBSCHEMA + ".class1");
        ResultSetMetaData rsmd = rs.getMetaData();
        int columnCount = rsmd.getColumnCount();
        assertEquals(1, columnCount);
        while (rs.next()) {
            for (int i = 1; i <= columnCount; i++) {
                assertEquals("a", rs.getString(ATTRNAME));
            }
        }
    } catch (Exception e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
        if (rs != null) {
            rs.close();
        }
        if (stmt != null) {
            stmt.close();
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IoxException(ch.interlis.iox.IoxException) SQLException(java.sql.SQLException) IoxException(ch.interlis.iox.IoxException) Test(org.junit.Test)

Example 17 with IoxException

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

the class MultipointTest method importSmartCustom.

@Test
public void importSmartCustom() 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/MultiPoint/MultiPoint2a.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_IMPORT);
        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.setMultiLineTrafo(null);
        config.setMultiPointTrafo(config.MULTIPOINT_TRAFO_COALESCE);
        config.setMultilingualTrafo(null);
        config.setInheritanceTrafo(null);
        Ili2db.readSettingsFromDb(config);
        Ili2db.run(config, null);
        // assertions
        ResultSet rs = stmt.executeQuery("SELECT st_asewkt(geom) FROM multipoint.classa1;");
        ResultSetMetaData rsmd = rs.getMetaData();
        assertEquals(1, rsmd.getColumnCount());
        while (rs.next()) {
            assertEquals("SRID=21781;MULTIPOINT(600030 200020,600015 200005)", rs.getObject(1));
        }
    } catch (Exception e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) File(java.io.File) IoxException(ch.interlis.iox.IoxException) IoxException(ch.interlis.iox.IoxException) Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) Test(org.junit.Test)

Example 18 with IoxException

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

the class Datatypes23Test method exportXtfLine.

@Test
public void exportXtfLine() 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(CREATETABLES_LINES));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader(INSERTINTOTABLES_LINES));
        File data = new File(TEST_OUT + "Datatypes23Line-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_EXPORT);
        config.setModels(DBSCHEMA);
        config.setBasketHandling(null);
        Ili2db.readSettingsFromDb(config);
        try {
            Ili2db.run(config, null);
        } catch (Exception ex) {
            EhiLogger.logError(ex);
            Assert.fail();
        }
        // tests
        // 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("Line3.1");
            Assert.assertNotNull(obj1);
            Assert.assertEquals("Datatypes23.Topic.Line3", obj1.getobjecttag());
            IomObject lineSegment = obj1.getattrobj("straightsarcs3d", 0);
            Assert.assertEquals("POLYLINE {sequence SEGMENTS {segment [COORD {C1 2460001.0, C2 1045001.0, C3 300.0}, ARC {A1 2460005.0, A2 1045004.0, C1 2460006.0, C2 1045006.0, C3 300.0}, COORD {C1 2460010.0, C2 1045010.0, C3 300.0}]}}", lineSegment.toString());
        }
    } catch (SQLException e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) SQLException(java.sql.SQLException) IoxException(ch.interlis.iox.IoxException) 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 19 with IoxException

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

the class Datatypes23Test method exportXtfAttr.

@Test
public void exportXtfAttr() 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(CREATETABLES_ATTRS));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader(INSERTINTOTABLES_ATTRS));
        File data = new File(TEST_OUT + "Datatypes23Attr-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_EXPORT);
        config.setModels(DBSCHEMA);
        config.setBasketHandling(null);
        Ili2db.readSettingsFromDb(config);
        try {
            Ili2db.run(config, null);
        } catch (Exception ex) {
            EhiLogger.logError(ex);
            Assert.fail();
        }
        // tests
        // 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("ClassAttr.1");
            Assert.assertNotNull(obj1);
            Assert.assertEquals("Datatypes23.Topic.ClassAttr", obj1.getobjecttag());
            // datatypes23
            Assert.assertEquals("22", obj1.getattrvalue("aI32id"));
            Assert.assertEquals("true", obj1.getattrvalue("aBoolean"));
            Assert.assertEquals("15b6bcce-8772-4595-bf82-f727a665fbf3", obj1.getattrvalue("aUuid"));
            Assert.assertEquals("abc100", obj1.getattrvalue("textLimited"));
            Assert.assertEquals("Left", obj1.getattrvalue("horizAlignment"));
            Assert.assertEquals("mailto:ceis@localhost", obj1.getattrvalue("uritext"));
            Assert.assertEquals("5", obj1.getattrvalue("numericInt"));
            Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n" + "							<a></a>\n" + "						</x>", obj1.getattrvalue("xmlbox"));
            Assert.assertEquals("mehr.vier", obj1.getattrvalue("aufzaehlung"));
            Assert.assertEquals("09:00:00.000", obj1.getattrvalue("aTime"));
            Assert.assertEquals("abc200\n" + "end200", obj1.getattrvalue("mtextLimited"));
            Assert.assertEquals("AAAA", obj1.getattrvalue("binbox"));
            Assert.assertEquals("chgAAAAAAAAA0azD", obj1.getattrvalue("aStandardid"));
            Assert.assertEquals("Grunddatensatz.Fixpunkte.LFP.Nummer", obj1.getattrvalue("aAttribute"));
            Assert.assertEquals("2002-09-24", obj1.getattrvalue("aDate"));
            Assert.assertEquals("Top", obj1.getattrvalue("vertAlignment"));
            Assert.assertEquals("ClassA", obj1.getattrvalue("nametext"));
            Assert.assertEquals("abc101", obj1.getattrvalue("textUnlimited"));
            Assert.assertEquals("6.0", obj1.getattrvalue("numericDec"));
            Assert.assertEquals("abc201\n" + "end201", obj1.getattrvalue("mtextUnlimited"));
            Assert.assertEquals("1900-01-01T12:30:05.000", obj1.getattrvalue("aDateTime"));
            Assert.assertEquals("DM01AVCH24D.FixpunkteKategorie1.LFP1", obj1.getattrvalue("aClass"));
        }
    } catch (SQLException e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) SQLException(java.sql.SQLException) IoxException(ch.interlis.iox.IoxException) 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 20 with IoxException

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

the class Datatypes23Test method importXtfLine.

@Test
public void importXtfLine() throws Exception {
    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_OUT + "Datatypes23Line.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setFunction(Config.FC_IMPORT);
        config.setCreateFk(config.CREATE_FK_YES);
        config.setCreateNumChecks(true);
        config.setTidHandling(Config.TID_HANDLING_PROPERTY);
        config.setBasketHandling(config.BASKET_HANDLING_READWRITE);
        config.setCatalogueRefTrafo(null);
        config.setMultiSurfaceTrafo(null);
        config.setMultilingualTrafo(null);
        config.setInheritanceTrafo(null);
        // Ili2db.readSettingsFromDb(config);
        try {
            Ili2db.run(config, null);
        } catch (Exception ex) {
            EhiLogger.logError(ex);
            Assert.fail();
        }
        // imported polyline
        {
            ResultSet rs = stmt.executeQuery("SELECT st_asewkt(straightsarcs2d) FROM datatypes23.line2 WHERE t_ili_tid = 'Line2.0';");
            ResultSetMetaData rsmd = rs.getMetaData();
            assertEquals(1, rsmd.getColumnCount());
            while (rs.next()) {
                assertEquals(null, rs.getObject(1));
            }
        }
        {
            ResultSet rs = stmt.executeQuery("SELECT st_asewkt(straightsarcs2d) FROM datatypes23.line2 WHERE t_ili_tid = 'Line2.1';");
            ResultSetMetaData rsmd = rs.getMetaData();
            assertEquals(1, rsmd.getColumnCount());
            while (rs.next()) {
                assertEquals("SRID=21781;COMPOUNDCURVE(CIRCULARSTRING(2460001 1045001,2460005 1045004,2460006 1045006),(2460006 1045006,2460010 1045010))", rs.getObject(1));
            }
        }
        {
            ResultSet rs = stmt.executeQuery("SELECT st_asewkt(straightsarcs3d) FROM datatypes23.line3 WHERE t_ili_tid = 'Line3.1';");
            ResultSetMetaData rsmd = rs.getMetaData();
            assertEquals(1, rsmd.getColumnCount());
            while (rs.next()) {
                assertEquals("SRID=21781;COMPOUNDCURVE(CIRCULARSTRING(2460001 1045001 300,2460005 1045004 0,2460006 1045006 300),(2460006 1045006 300,2460010 1045010 300))", rs.getObject(1));
            }
        }
        {
            ResultSet rs = stmt.executeQuery("SELECT st_asewkt(straights2d) FROM datatypes23.simpleline2 WHERE t_ili_tid = 'SimpleLine2.0';");
            ResultSetMetaData rsmd = rs.getMetaData();
            assertEquals(1, rsmd.getColumnCount());
            while (rs.next()) {
                assertEquals(null, rs.getObject(1));
            }
        }
        {
            ResultSet rs = stmt.executeQuery("SELECT st_asewkt(straights2d) FROM datatypes23.simpleline2 WHERE t_ili_tid = 'SimpleLine2.1';");
            ResultSetMetaData rsmd = rs.getMetaData();
            assertEquals(1, rsmd.getColumnCount());
            while (rs.next()) {
                assertEquals("SRID=21781;COMPOUNDCURVE((2460001 1045001,2460010 1045010))", rs.getObject(1));
            }
        }
        {
            ResultSet rs = stmt.executeQuery("SELECT st_asewkt(straights3d) FROM datatypes23.simpleline3 WHERE t_ili_tid = 'SimpleLine3.1';");
            ResultSetMetaData rsmd = rs.getMetaData();
            assertEquals(1, rsmd.getColumnCount());
            while (rs.next()) {
                assertEquals("SRID=21781;COMPOUNDCURVE((2460001 1045001 300,2460010 1045010 300))", rs.getObject(1));
            }
        }
    } catch (SQLException e) {
        throw new IoxException(e);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) Config(ch.ehi.ili2db.gui.Config) ResultSet(java.sql.ResultSet) File(java.io.File) IoxException(ch.interlis.iox.IoxException) SQLException(java.sql.SQLException) IoxException(ch.interlis.iox.IoxException) 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