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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
Aggregations