use of ini.trakem2.display.Ball in project TrakEM2 by trakem2.
the class DBLoader method updateInDatabase.
private void updateInDatabase(Ball ball, String key) throws Exception {
if (!connectToDatabase()) {
Utils.log("Not connected and can't connect to database.");
return;
}
try {
boolean autocommit = connection.getAutoCommit();
connection.setAutoCommit(false);
Statement st = connection.createStatement();
StringBuffer sb_query = new StringBuffer("UPDATE ab_zdisplayables SET ");
boolean update_all_points = false;
if (key.startsWith("INSERT INTO ab_ball_points ")) {
connection.prepareStatement(key).executeUpdate();
connection.commit();
// restore
connection.setAutoCommit(autocommit);
return;
} else if (key.equals("points")) {
update_all_points = true;
} else if (key.startsWith("UPDATE ab_ball_points")) {
// used to update points individually
connection.prepareStatement(key).executeUpdate();
connection.commit();
// restore
connection.setAutoCommit(autocommit);
return;
} else if (key.equals("layer_set_id")) {
sb_query.append("layer_set_id=").append(ball.getLayerSet().getId());
} else {
// Displayable level
connection.setAutoCommit(autocommit);
updateInDatabase((Displayable) ball, key);
return;
}
if (sb_query.length() > 28) {
// 28 is the length of the string 'UPDATE ab_zdisplayables SET '
st.addBatch(sb_query.toString());
}
if (update_all_points) {
// delete and re-add
st.addBatch("DELETE FROM ab_ball_points WHERE ball_id=" + ball.getId());
String[] s_points = ball.getPointsForSQL();
for (int i = 0; i < s_points.length; i++) {
st.addBatch(s_points[i]);
}
}
sb_query.append(" WHERE pipe_id=").append(ball.getId());
// commit
st.executeBatch();
connection.commit();
// restore
connection.setAutoCommit(autocommit);
} catch (SQLException sqle) {
IJError.print(sqle);
Exception next;
if (null != (next = sqle.getNextException())) {
IJError.print(next);
}
try {
connection.rollback();
// default ..
connection.setAutoCommit(true);
} catch (SQLException sqle2) {
IJError.print(sqle2);
}
}
}
use of ini.trakem2.display.Ball in project TrakEM2 by trakem2.
the class DBLoader method fetchBall.
private Ball fetchBall(Project project, long id) throws Exception {
// strange query, but can't distinguish between pipes and balls otherwise
ResultSet r = connection.prepareStatement("SELECT ab_displayables.id, title, ab_displayables.width, height, alpha, visible, color_red, color_green, color_blue, ab_zdisplayables.id, ab_ball_points.ball_id, ab_displayables.locked, m00, m10, m01, m11, m02, m12 FROM ab_zdisplayables, ab_displayables, ab_ball_points WHERE ab_zdisplayables.id=ab_displayables.id AND ab_zdisplayables.id=ab_ball_points.ball_id AND ab_zdisplayables.id=" + id).executeQuery();
Ball b = null;
if (r.next()) {
b = new Ball(project, id, r.getString("title"), (float) r.getDouble("width"), (float) r.getDouble("height"), r.getFloat("alpha"), r.getBoolean("visible"), new Color(r.getInt("color_red"), r.getInt("color_green"), r.getInt("color_blue")), r.getBoolean("locked"), new AffineTransform(r.getDouble("m00"), r.getDouble("m10"), r.getDouble("m01"), r.getDouble("m11"), r.getDouble("m02"), r.getDouble("m12")));
}
r.close();
return b;
}
Aggregations