isolConnection = (XIsolatedConnection) UnoRuntime.queryInterface(
XIsolatedConnection.class,
oDBSource);
XConnection connection = null;
XStatement statement = null;
final String tbl_name1 = "tst_table1";
final String tbl_name2 = "tst_table2";
final String col_name1 = "id1";
final String col_name2 = "id2";
try {
connection = isolConnection.getIsolatedConnection(user, password);
statement = connection.createStatement();
statement.executeUpdate("drop table if exists " + tbl_name1);
statement.executeUpdate("drop table if exists " + tbl_name2);
statement.executeUpdate("create table " + tbl_name1 + " (" +
col_name1 + " int)");
statement.executeUpdate("create table " + tbl_name2 + " (" +
col_name2 + " int)");
} catch (com.sun.star.sdbc.SQLException e) {
try {
shortWait();
connection = isolConnection.getIsolatedConnection(user,
password);
statement = connection.createStatement();
statement.executeUpdate("drop table if exists " + tbl_name1);
statement.executeUpdate("drop table if exists " + tbl_name2);
statement.executeUpdate("create table " + tbl_name1 + " (" +
col_name1 + " int)");
statement.executeUpdate("create table " + tbl_name2 + " (" +
col_name2 + " int)");
} catch (com.sun.star.sdbc.SQLException e2) {
e2.printStackTrace(log);
throw new StatusException(Status.failed("SQLException"));
}
}
XQueryDefinitionsSupplier querySuppl = (XQueryDefinitionsSupplier) UnoRuntime.queryInterface(
XQueryDefinitionsSupplier.class,
oDBSource);
XNameAccess defContainer = querySuppl.getQueryDefinitions();
XPropertySet queryProp = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, newQuery);
try {
final String query = "select * from " + tbl_name1 + ", " +
tbl_name2 + " where " + tbl_name1 + "." +
col_name1 + "=" + tbl_name2 + "." +
col_name2;
queryProp.setPropertyValue("Command", query);
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException(Status.failed(
"Couldn't set property value"));
} catch (com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace(log);
throw new StatusException(Status.failed(
"Couldn't set property value"));
} catch (com.sun.star.beans.PropertyVetoException e) {
e.printStackTrace(log);
throw new StatusException(Status.failed(
"Couldn't set property value"));
} catch (com.sun.star.beans.UnknownPropertyException e) {
e.printStackTrace(log);
throw new StatusException(Status.failed(
"Couldn't set property value"));
}
XNameContainer queryContainer = (XNameContainer) UnoRuntime.queryInterface(
XNameContainer.class,
defContainer);
try {
queryContainer.insertByName("Query1", newQuery);
store.store();
connection.close ();
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException(Status.failed("Couldn't insert query"));
} catch (com.sun.star.container.ElementExistException e) {
e.printStackTrace(log);