summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-23 08:20:53 (EDT)
committerEike Stepper2007-08-23 08:20:53 (EDT)
commit823d55a2938dd97e08537014d25ed117849a9f7e (patch)
treeaa06399e5c5f4063c15dffc38a5885afb2d7d17e
parentf0b0152712066001f30d840980b5909e366e898b (diff)
downloadcdo-823d55a2938dd97e08537014d25ed117849a9f7e.zip
cdo-823d55a2938dd97e08537014d25ed117849a9f7e.tar.gz
cdo-823d55a2938dd97e08537014d25ed117849a9f7e.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java28
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java28
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java29
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMapping.java77
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMapping.java54
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java83
9 files changed, 306 insertions, 15 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java
new file mode 100644
index 0000000..4651b2f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java
@@ -0,0 +1,28 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.db;
+
+import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+
+import org.eclipse.net4j.db.IDBField;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IAttributeMapping
+{
+ public CDOFeature getFeature();
+
+ public IDBField getField();
+
+ public void appendValue(StringBuilder builder, CDORevisionImpl revision);
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
index 5581180..7795915 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.server.IStoreReader;
import org.eclipse.emf.cdo.server.IStoreWriter;
import java.sql.Connection;
+import java.sql.Statement;
/**
* @author Eike Stepper
@@ -21,4 +22,6 @@ import java.sql.Connection;
public interface IDBStoreAccessor extends IStoreReader, IStoreWriter
{
public Connection getConnection();
+
+ public Statement getStatement();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java
index 1508d1e..b95b7db 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java
@@ -12,10 +12,12 @@ package org.eclipse.emf.cdo.server.db;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
import org.eclipse.net4j.db.IDBSchema;
import org.eclipse.net4j.db.IDBTable;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -38,6 +40,10 @@ public interface IMappingStrategy
public IMapping getMapping(CDOClass cdoClass);
+ public List<IAttributeMapping> getAttributeMappings(CDOFeature[] features);
+
+ public List<IReferenceMapping> getReferenceMappings(CDOFeature[] features);
+
/**
* @return A collection of the affected tables.
*/
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java
new file mode 100644
index 0000000..a782bd3
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java
@@ -0,0 +1,28 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.db;
+
+import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+
+import org.eclipse.net4j.db.IDBTable;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IReferenceMapping
+{
+ public CDOFeature getFeature();
+
+ public IDBTable getTable();
+
+ public void writeReference(IMapping mapping, IDBStoreAccessor storeAccessor, CDORevisionImpl revision);
+}
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 3584bb8..0d62eb1 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
@@ -39,6 +39,7 @@ import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
@@ -49,13 +50,15 @@ public class DBStoreAccessor implements IDBStoreAccessor
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DBStoreAccessor.class);
- protected DBStore store;
+ private DBStore store;
- protected Object context;
+ private Object context;
- protected boolean reader;
+ private boolean reader;
- protected Connection connection;
+ private Connection connection;
+
+ private Statement statement;
private DBStoreAccessor(DBStore store, Object context, boolean reader) throws DBException
{
@@ -99,6 +102,7 @@ public class DBStoreAccessor implements IDBStoreAccessor
}
finally
{
+ DBUtil.close(statement);
DBUtil.close(connection);
}
}
@@ -138,6 +142,23 @@ public class DBStoreAccessor implements IDBStoreAccessor
return connection;
}
+ public Statement getStatement()
+ {
+ if (statement == null)
+ {
+ try
+ {
+ statement = getConnection().createStatement();
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+
+ return statement;
+ }
+
public void writePackages(CDOPackageImpl... cdoPackages)
{
for (CDOPackageImpl cdoPackage : cdoPackages)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMapping.java
index 00174a2..148d9ec 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMapping.java
@@ -12,22 +12,99 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.server.db.IAttributeMapping;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
+import org.eclipse.emf.cdo.server.db.IReferenceMapping;
+
+import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.IDBTable;
+
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
/**
* @author Eike Stepper
*/
public class HorizontalMapping extends FullInfoMapping
{
+ private IDBTable table;
+
+ private List<IAttributeMapping> attributeMappings;
+
+ private List<IReferenceMapping> referenceMappings;
+
public HorizontalMapping(IMappingStrategy mappingStrategy, CDOClass cdoClass)
{
super(mappingStrategy, cdoClass);
+ CDOFeature[] features = cdoClass.getAllFeatures();
+ attributeMappings = mappingStrategy.getAttributeMappings(features);
+ referenceMappings = mappingStrategy.getReferenceMappings(features);
}
@Override
public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
super.writeRevision(storeAccessor, revision);
+ writeAttributes(storeAccessor, revision);
+ writeReferences(storeAccessor, revision);
+ }
+
+ protected void writeAttributes(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ {
+ try
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(table);
+ builder.append(" VALUES (");
+ builder.append(revision.getID().getValue());
+ builder.append(", ");
+ builder.append(ServerInfo.getDBID(revision.getCDOClass()));
+ builder.append(", ");
+ builder.append(revision.getVersion());
+ builder.append(", ");
+ builder.append(new Date(revision.getCreated()));
+ builder.append(", ");
+ builder.append(new Date(revision.getRevised()));
+ builder.append(", ");
+ builder.append(revision.getResourceID().getValue());
+ builder.append(", ");
+ builder.append(revision.getContainerID().getValue());
+ builder.append(", ");
+ builder.append(revision.getContainingFeatureID());
+ builder.append(", ");
+
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ builder.append(", ");
+ attributeMapping.appendValue(builder, revision);
+ }
+
+ builder.append(")");
+ String sql = builder.toString();
+
+ Statement statement = storeAccessor.getStatement();
+ int count = statement.executeUpdate(sql);
+ if (count != 1)
+ {
+ throw new DBException("Wrong update count: " + count);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+
+ protected void writeReferences(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
+ {
+ for (IReferenceMapping referenceMapping : referenceMappings)
+ {
+ referenceMapping.writeReference(this, storeAccessor, revision);
+ }
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
index c3af05f..34b37e2 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
@@ -13,9 +13,11 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
import org.eclipse.emf.cdo.protocol.model.CDOType;
+import org.eclipse.emf.cdo.server.db.IAttributeMapping;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IMapping;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
+import org.eclipse.emf.cdo.server.db.IReferenceMapping;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.net4j.db.DBException;
@@ -28,6 +30,7 @@ import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.ImplementationError;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -101,6 +104,16 @@ public abstract class MappingStrategy implements IMappingStrategy
return mapping;
}
+ public List<IAttributeMapping> getAttributeMappings(CDOFeature[] features)
+ {
+ return null;
+ }
+
+ public List<IReferenceMapping> getReferenceMappings(CDOFeature[] features)
+ {
+ return null;
+ }
+
protected abstract IMapping createMapping(CDOClass cdoClass);
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMapping.java
index 209816b..10e6acf 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMapping.java
@@ -12,11 +12,18 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
-import org.eclipse.emf.cdo.server.IStoreWriter;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.server.db.IAttributeMapping;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMapping;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
+import org.eclipse.emf.cdo.server.db.IReferenceMapping;
+import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.IDBTable;
+
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
@@ -27,6 +34,12 @@ public class VerticalMapping extends IDInfoMapping
{
private List<IMapping> superMappings;
+ private IDBTable table;
+
+ private List<IAttributeMapping> attributeMappings;
+
+ private List<IReferenceMapping> referenceMappings;
+
public VerticalMapping(IMappingStrategy mappingStrategy, CDOClass cdoClass)
{
super(mappingStrategy, cdoClass);
@@ -43,6 +56,10 @@ public class VerticalMapping extends IDInfoMapping
superMappings.add(superMapping);
}
}
+
+ CDOFeature[] features = cdoClass.getFeatures();
+ attributeMappings = mappingStrategy.getAttributeMappings(features);
+ referenceMappings = mappingStrategy.getReferenceMappings(features);
}
public List<IMapping> getSuperMappings()
@@ -65,11 +82,42 @@ public class VerticalMapping extends IDInfoMapping
}
}
- protected void writeAttributes(IStoreWriter writer, CDORevisionImpl revision)
+ protected void writeAttributes(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
+ try
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(table);
+ builder.append(" VALUES (");
+ builder.append(revision.getID().getValue());
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ builder.append(", ");
+ attributeMapping.appendValue(builder, revision);
+ }
+
+ builder.append(")");
+ String sql = builder.toString();
+
+ Statement statement = storeAccessor.getStatement();
+ int count = statement.executeUpdate(sql);
+ if (count != 1)
+ {
+ throw new DBException("Wrong update count: " + count);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
}
- protected void writeReferences(IStoreWriter writer, CDORevisionImpl revision)
+ protected void writeReferences(IDBStoreAccessor storeAccessor, CDORevisionImpl revision)
{
+ for (IReferenceMapping referenceMapping : referenceMappings)
+ {
+ referenceMapping.writeReference(this, storeAccessor, revision);
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
index 4e8c0ef..7ce4c56 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
@@ -16,17 +16,79 @@ public enum DBType
DOUBLE(8), //
NUMERIC(2), //
DECIMAL(3), //
- CHAR(1), //
- VARCHAR(12), //
- LONGVARCHAR(-1, "LONG VARCHAR"), //
+ CHAR(1)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ builder.append("'");
+ builder.append(value);
+ builder.append("'");
+ }
+ }, //
+ VARCHAR(12)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ builder.append("'");
+ builder.append(value);
+ builder.append("'");
+ }
+ }, //
+ LONGVARCHAR(-1, "LONG VARCHAR")
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ builder.append("'");
+ builder.append(value);
+ builder.append("'");
+ }
+ }, //
DATE(91), //
TIME(92), //
TIMESTAMP(93), //
- BINARY(-2), //
- VARBINARY(-3), //
- LONGVARBINARY(-4, "LONG VARBINARY"), //
- BLOB(2004), //
- CLOB(2005); //
+ BINARY(-2)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }, //
+ VARBINARY(-3)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }, //
+ LONGVARBINARY(-4, "LONG VARBINARY")
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }, //
+ BLOB(2004)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }, //
+ CLOB(2005)
+ {
+ @Override
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }; //
private int code;
@@ -58,4 +120,9 @@ public enum DBType
{
return getKeyword();
}
+
+ public void appendValue(StringBuilder builder, Object value)
+ {
+ builder.append(value);
+ }
} \ No newline at end of file