use of ch.interlis.iox.IoxException in project ili2db by claeis.
the class MultipointTest method exportSmartCustom.
@Test
public void exportSmartCustom() 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/MultiPoint/CreateTableMultiPoint2a.sql"));
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/MultiPoint/InsertIntoTableMultiPoint2a.sql"));
File data = new File("test/data/MultiPoint/MultiPoint2a-out.xtf");
Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
config.setModels("MultiPoint2");
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));
// check oid
{
IomObject obj0 = objs.get("13");
Assert.assertNotNull(obj0);
Assert.assertEquals("13", obj0.getobjectoid());
}
// check objecttag
{
IomObject obj0 = objs.get("13");
Assert.assertNotNull(obj0);
Assert.assertEquals("MultiPoint2.TestA.ClassA1", obj0.getobjecttag());
}
// check values of attrnames
{
IomObject obj0 = objs.get("13");
Assert.assertNotNull(obj0);
Assert.assertEquals("MultiPoint2.MultiPoint2D {points [MultiPoint2.PointStruktur2D {coord COORD {C1 600030.0, C2 200020.0}}, MultiPoint2.PointStruktur2D {coord COORD {C1 600015.0, C2 200005.0}}]}", obj0.getattrobj("geom", 0).toString());
}
} 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 importXtfAttr.
@Test
public void importXtfAttr() 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 + "Datatypes23Attr.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();
}
String stmtTxt = "SELECT * FROM " + DBSCHEMA + ".classattr ORDER BY t_id ASC";
{
Assert.assertTrue(stmt.execute(stmtTxt));
ResultSet rs = stmt.getResultSet();
Assert.assertTrue(rs.next());
Assert.assertEquals("22", rs.getString("aI32id"));
Assert.assertEquals("t", rs.getString("aBoolean"));
Assert.assertEquals("15b6bcce-8772-4595-bf82-f727a665fbf3", rs.getString("aUuid"));
Assert.assertEquals("abc100", rs.getString("textLimited"));
Assert.assertEquals("Left", rs.getString("horizAlignment"));
Assert.assertEquals("mailto:ceis@localhost", rs.getString("uritext"));
Assert.assertEquals("5", rs.getString("numericInt"));
Assert.assertEquals("<x>\n" + " <a></a>\n" + " </x>", rs.getString("xmlbox"));
Assert.assertEquals("mehr.vier", rs.getString("aufzaehlung"));
Assert.assertEquals("09:00:00", rs.getString("aTime"));
Assert.assertEquals("abc200\n" + "end200", rs.getString("mtextLimited"));
Assert.assertEquals("chgAAAAAAAAA0azD", rs.getString("aStandardid"));
Assert.assertEquals("Grunddatensatz.Fixpunkte.LFP.Nummer", rs.getString("aAttribute"));
Assert.assertEquals("2002-09-24", rs.getString("aDate"));
Assert.assertEquals("Top", rs.getString("vertAlignment"));
Assert.assertEquals("ClassA", rs.getString("nametext"));
Assert.assertEquals("abc101", rs.getString("textUnlimited"));
Assert.assertEquals("6.0", rs.getString("numericDec"));
Assert.assertEquals("abc201\n" + "end201", rs.getString("mtextUnlimited"));
Assert.assertEquals("1900-01-01 12:30:05", rs.getString("aDateTime"));
}
{
// byte array
String stmtT = "SELECT binbox FROM " + DBSCHEMA + ".classattr ORDER BY t_id ASC";
Assert.assertTrue(stmt.execute(stmtT));
ResultSet rs = stmt.getResultSet();
Assert.assertTrue(rs.next());
byte[] bytes = (byte[]) rs.getObject("binbox");
Assert.assertFalse(rs.wasNull());
String wkbText = javax.xml.bind.DatatypeConverter.printBase64Binary(bytes);
Assert.assertEquals("AAAA", wkbText);
}
} 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 exportXtfSurface.
@Test
public void exportXtfSurface() 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_SURFACES));
DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader(INSERTINTOTABLES_SURFACES));
File data = new File(TEST_OUT + "Datatypes23Surface-out.xtf");
Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
config.setFunction(Config.FC_EXPORT);
config.setModels(DBSCHEMA);
config.setBasketHandling(null);
// config.setValidation(false);
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("Surface2.1");
Assert.assertNotNull(obj1);
Assert.assertEquals("Datatypes23.Topic.Surface2", obj1.getobjecttag());
IomObject surface = obj1.getattrobj("surfacearcs2d", 0);
Assert.assertEquals("MULTISURFACE {surface SURFACE {boundary [BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 2460001.0, C2 1045001.0}, COORD {C1 2460020.0, C2 1045015.0}, ARC {A1 2460010.0, A2 1045018.0, C1 2460001.0, C2 1045015.0}, COORD {C1 2460001.0, C2 1045001.0}]}}}, BOUNDARY {polyline POLYLINE {sequence SEGMENTS {segment [COORD {C1 2460005.0, C2 1045005.0}, COORD {C1 2460010.0, C2 1045010.0}, ARC {A1 2460007.0, A2 1045009.0, C1 2460005.0, C2 1045010.0}, COORD {C1 2460005.0, C2 1045005.0}]}}}]}}", surface.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 TransferToXtf method dumpStructs.
/**
* dumps all struct values of a given struct attr.
* @throws IoxException
*/
private void dumpStructs(StructWrapper structWrapper, FixIomObjectRefs fixref) throws IoxException {
Viewable baseClass = ((CompositionType) structWrapper.getParentAttr().getDomain()).getComponentType();
HashMap<String, IomObject> structelev = new HashMap<String, IomObject>();
HashSet<Viewable> structClassv = new HashSet<Viewable>();
String stmt = createQueryStmt4Type(baseClass, structWrapper);
EhiLogger.traceBackendCmd(stmt);
java.sql.Statement dbstmt = null;
try {
dbstmt = conn.createStatement();
java.sql.ResultSet rs = dbstmt.executeQuery(stmt);
while (rs.next()) {
String sqlid = rs.getString(1);
String structEleClass = null;
Viewable structClass = null;
String structEleSqlType = rs.getString(2);
structEleClass = ili2sqlName.mapSqlTableName(structEleSqlType);
if (structEleClass == null) {
throw new IoxException("unknown " + DbNames.T_TYPE_COL + " '" + structEleSqlType + "' in table " + getStructRootTableName(baseClass));
}
structClass = (Viewable) tag2class.get(structEleClass);
IomObject iomObj = structWrapper.getParent().addattrobj(structWrapper.getParentAttr().getName(), structEleClass);
structelev.put(sqlid, iomObj);
structClassv.add(structClass);
}
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to query structure elements " + baseClass.getScopedName(null), ex);
} finally {
if (dbstmt != null) {
try {
dbstmt.close();
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to close query of structure elements " + baseClass.getScopedName(null), ex);
}
}
}
Iterator<Viewable> classi = structClassv.iterator();
while (classi.hasNext()) {
Viewable aclass = classi.next();
dumpObjHelper(null, aclass, null, fixref, structWrapper, structelev);
}
}
use of ch.interlis.iox.IoxException in project ili2db by claeis.
the class DbUtilityExecuteSqlTest method dbUtilityExecuteSql_TwiceSemicolon_Ok.
// Es wird getestet ob das sql Skript fehlerfrei in die Datenbank importiert werden kann,
// wenn CREATE SEQUENCE mit 2 Semikolon: "test.t_ili2db_seq;;" beendet wird.
@Test
public void dbUtilityExecuteSql_TwiceSemicolon_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 + "ExecuteTwiceSemicolon.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();
}
}
}
Aggregations