summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-18 13:17:49 (EDT)
committerEike Stepper2007-10-18 13:17:49 (EDT)
commit39d5f2065e505ffddb2bcc48f8a3fb43e915d986 (patch)
tree53024ce7f03593b29bad903dae7184e02f95770b
parent9b098c506129cf05b8d24bc2665d8bbd17dbeb48 (diff)
downloadcdo-39d5f2065e505ffddb2bcc48f8a3fb43e915d986.zip
cdo-39d5f2065e505ffddb2bcc48f8a3fb43e915d986.tar.gz
cdo-39d5f2065e505ffddb2bcc48f8a3fb43e915d986.tar.bz2
[206781] exception during initial commit after adding package
https://bugs.eclipse.org/bugs/show_bug.cgi?id=206781
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java74
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java11
2 files changed, 64 insertions, 21 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
index 71b5fe6..675dd58 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
@@ -47,6 +47,7 @@ import org.eclipse.net4j.util.io.CloseableIterator;
import org.eclipse.net4j.util.transaction.ITransaction;
import java.sql.Connection;
+import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
@@ -148,31 +149,68 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
{
for (CDOPackageImpl cdoPackage : cdoPackages)
{
- int id = getStore().getNextPackageID();
- PackageServerInfo.setDBID(cdoPackage, id);
- if (TRACER.isEnabled())
+ writePackage(cdoPackage);
+ }
+
+ Set<IDBTable> affectedTables = mapPackages(cdoPackages);
+ getStore().getDBAdapter().createTables(affectedTables, connection);
+ }
+
+ protected void writePackage(CDOPackageImpl cdoPackage)
+ {
+ int id = getStore().getNextPackageID();
+ PackageServerInfo.setDBID(cdoPackage, id);
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Inserting package: {0} --> {1}", cdoPackage, id);
+ }
+
+ String packageURI = cdoPackage.getPackageURI();
+ String name = cdoPackage.getName();
+ String ecore = cdoPackage.getEcore();
+ boolean dynamic = cdoPackage.isDynamic();
+ CDOIDRange metaIDRange = cdoPackage.getMetaIDRange();
+ long lb = metaIDRange == null ? 0L : metaIDRange.getLowerBound().getValue();
+ long ub = metaIDRange == null ? 0L : metaIDRange.getUpperBound().getValue();
+
+ String sql = "INSERT INTO " + CDODBSchema.PACKAGES + " VALUES (?, ?, ?, ?, ?, ?, ?)";
+ DBUtil.trace(sql);
+ PreparedStatement pstmt = null;
+
+ try
+ {
+ pstmt = connection.prepareStatement(sql);
+ pstmt.setInt(1, id);
+ pstmt.setString(2, packageURI);
+ pstmt.setString(3, name);
+ pstmt.setString(4, ecore);
+ pstmt.setBoolean(5, dynamic);
+ pstmt.setLong(6, lb);
+ pstmt.setLong(7, ub);
+
+ if (pstmt.execute())
{
- TRACER.format("Inserting package: {0} --> {1}", cdoPackage, id);
+ throw new DBException("No result set expected");
}
- String packageURI = cdoPackage.getPackageURI();
- String name = cdoPackage.getName();
- String ecore = cdoPackage.getEcore();
- boolean dynamic = cdoPackage.isDynamic();
- CDOIDRange metaIDRange = cdoPackage.getMetaIDRange();
- long lb = metaIDRange == null ? 0L : metaIDRange.getLowerBound().getValue();
- long ub = metaIDRange == null ? 0L : metaIDRange.getUpperBound().getValue();
- DBUtil.insertRow(connection, getStore().getDBAdapter(), CDODBSchema.PACKAGES, id, packageURI, name, ecore,
- dynamic, lb, ub);
-
- for (CDOClassImpl cdoClass : cdoPackage.getClasses())
+ if (pstmt.getUpdateCount() == 0)
{
- writeClass(cdoClass);
+ throw new DBException("No row inserted into table " + CDODBSchema.PACKAGES);
}
}
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(pstmt);
+ }
- Set<IDBTable> affectedTables = mapPackages(cdoPackages);
- getStore().getDBAdapter().createTables(affectedTables, connection);
+ for (CDOClassImpl cdoClass : cdoPackage.getClasses())
+ {
+ writeClass(cdoClass);
+ }
}
protected void writeClass(CDOClassImpl cdoClass)
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 6f1f4e8..97a1c4a 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
@@ -167,7 +167,7 @@ public final class DBUtil
builder.append(field.getTable());
String sql = builder.toString();
- if (TRACER.isEnabled()) TRACER.trace(sql);
+ trace(sql);
Statement statement = null;
ResultSet resultSet = null;
@@ -206,7 +206,7 @@ public final class DBUtil
public static int update(Connection connection, String sql)
{
- if (TRACER.isEnabled()) TRACER.trace(sql);
+ trace(sql);
Statement statement = null;
try
@@ -292,7 +292,7 @@ public final class DBUtil
}
String sql = builder.toString();
- if (TRACER.isEnabled()) TRACER.trace(sql);
+ trace(sql);
Statement statement = null;
ResultSet resultSet = null;
@@ -357,4 +357,9 @@ public final class DBUtil
select(connection, rowHandler, where, fields);
return result[0];
}
+
+ public static void trace(String sql)
+ {
+ if (TRACER.isEnabled()) TRACER.trace(sql);
+ }
}