Implement exportNode() method to export a node into a different

(relational) database than its default one. (The database must
contain a compatible table.)
This commit is contained in:
hns 2003-04-16 13:32:38 +00:00
parent 01016e6236
commit 61274e4350

View file

@ -433,11 +433,11 @@ public final class NodeManager {
////////////////////////////////////////////////////////////////////////
/**
* Insert a new node in the embedded database or a relational database table, depending
* on its db mapping.
* Insert a new node in the embedded database or a relational database table,
* depending on its db mapping.
*/
public void insertNode(IDatabase db, ITransaction txn, Node node)
throws Exception {
throws IOException, SQLException, ClassNotFoundException {
// Transactor tx = (Transactor) Thread.currentThread ();
// tx.timer.beginEvent ("insertNode "+node);
DbMapping dbm = node.getDbMapping();
@ -445,6 +445,43 @@ public final class NodeManager {
if ((dbm == null) || !dbm.isRelational()) {
db.saveNode(txn, node.getID(), node);
} else {
insertRelationalNode(node, dbm, dbm.getConnection());
dbm.notifyDataChange();
}
// tx.timer.endEvent ("insertNode "+node);
}
/**
* Insert a node into a different (relational) database than its default one.
*/
public void exportNode(Node node, DbSource dbs)
throws IOException, SQLException, ClassNotFoundException {
if (node == null) {
throw new IllegalArgumentException("Node can't be null in exportNode");
}
DbMapping dbm = node.getDbMapping();
if (dbs == null) {
throw new IllegalArgumentException("DbSource can't be null in exportNode");
} else if ((dbm == null) || !dbm.isRelational()) {
throw new SQLException("Can't export into non-relational database");
} else {
insertRelationalNode(node, dbm, dbs.getConnection());
}
}
/**
* Insert a node into a relational database.
*/
protected void insertRelationalNode(Node node, DbMapping dbm, Connection con)
throws ClassNotFoundException, SQLException {
if (con == null) {
throw new NullPointerException("Error inserting relational node: Connection is null");
}
// app.logEvent ("inserting relational node: "+node.getID ());
DbColumn[] columns = dbm.getColumns();
@ -468,7 +505,7 @@ public final class NodeManager {
b1.append(b2.toString());
b1.append(" )");
Connection con = dbm.getConnection();
// Connection con = dbm.getConnection();
PreparedStatement stmt = con.prepareStatement(b1.toString());
if (logSql) {
@ -581,22 +618,14 @@ public final class NodeManager {
}
stmt.executeUpdate();
} catch (Exception x) {
x.printStackTrace();
throw x;
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception ignore) {
}
} catch (Exception ignore) {}
}
}
dbm.notifyDataChange();
}
// tx.timer.endEvent ("insertNode "+node);
}
/**
@ -604,7 +633,7 @@ public final class NodeManager {
* on its database mapping.
*/
public void updateNode(IDatabase db, ITransaction txn, Node node)
throws Exception {
throws IOException, SQLException, ClassNotFoundException {
// Transactor tx = (Transactor) Thread.currentThread ();
// tx.timer.beginEvent ("updateNode "+node);
DbMapping dbm = node.getDbMapping();
@ -771,9 +800,6 @@ public final class NodeManager {
}
stmt.executeUpdate();
} catch (Exception x) {
x.printStackTrace();
throw x;
} finally {
if (stmt != null) {
try {