summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-24 11:49:32 (EDT)
committerEike Stepper2007-08-24 11:49:32 (EDT)
commit4318cc64d042cba6824e4b9b8a51dcdfa9318212 (patch)
treec6f3d3d2b2198d96701efd918bb51f909ea0f21f
parent42283eb1344017e50ccac42aec4e27f1a5866ec6 (diff)
downloadcdo-4318cc64d042cba6824e4b9b8a51dcdfa9318212.zip
cdo-4318cc64d042cba6824e4b9b8a51dcdfa9318212.tar.gz
cdo-4318cc64d042cba6824e4b9b8a51dcdfa9318212.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java5
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java48
2 files changed, 23 insertions, 30 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java
index 600c558..f5507a1 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/Mapping.java
@@ -26,7 +26,6 @@ import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.ImplementationError;
import java.sql.Date;
-import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashSet;
import java.util.Set;
@@ -106,9 +105,9 @@ public abstract class Mapping implements IMapping
throw new DBException("Wrong update count: " + count);
}
}
- catch (SQLException ex)
+ catch (Exception ex)
{
- throw new DBException(ex);
+ throw new DBException("Problem with " + sql, ex);
}
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
index 81cb83a..70cdb47 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
@@ -19,7 +19,6 @@ import org.eclipse.net4j.util.ReflectUtil;
import javax.sql.DataSource;
import java.sql.Connection;
-import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@@ -184,41 +183,36 @@ public final class DBUtil
+ Arrays.asList(table.getFields()));
}
- String sql = table.sqlInsert();
- if (TRACER.isEnabled())
- {
- StringBuilder builder = new StringBuilder();
- builder.append("INSERT INTO ");
- builder.append(table);
- builder.append(" VALUES (");
+ StringBuilder builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(table);
+ builder.append(" VALUES (");
- for (int i = 0; i < fields.length; i++)
+ for (int i = 0; i < fields.length; i++)
+ {
+ if (i > 0)
{
- if (i > 0)
- {
- builder.append(", ");
- }
-
- builder.append(args[i]);
+ builder.append(", ");
}
- builder.append(")");
- TRACER.trace(builder.toString());
+ fields[i].appendValue(builder, args[i]);
}
- PreparedStatement statement = null;
+ builder.append(")");
+ String sql = builder.toString();
- try
+ if (TRACER.isEnabled())
{
- statement = connection.prepareStatement(sql);
- for (int i = 0; i < fields.length; i++)
- {
- IDBField field = fields[i];
- statement.setObject(i + 1, args[i], field.getType().getCode());
- }
+ TRACER.trace(sql);
+ }
- statement.execute();
- if (statement.getUpdateCount() == 0)
+ Statement statement = null;
+
+ try
+ {
+ statement = connection.createStatement();
+ int count = statement.executeUpdate(sql);
+ if (count == 0)
{
throw new DBException("No row inserted into table " + table);
}