diff options
author | Eike Stepper | 2007-08-23 19:48:27 +0000 |
---|---|---|
committer | Eike Stepper | 2007-08-23 19:48:27 +0000 |
commit | 82fcff9abc38b2a106e525be77f6ae9ec9b8f66e (patch) | |
tree | 12aa7f8143e45494a169d58c4425bcf0a5faa7ee /plugins | |
parent | 87be62c167c06842af9641e17adccb1e126790f0 (diff) | |
download | cdo-82fcff9abc38b2a106e525be77f6ae9ec9b8f66e.tar.gz cdo-82fcff9abc38b2a106e525be77f6ae9ec9b8f66e.tar.xz cdo-82fcff9abc38b2a106e525be77f6ae9ec9b8f66e.zip |
*** empty log message ***
Diffstat (limited to 'plugins')
13 files changed, 425 insertions, 542 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java index 32b3f18452..1a1d2b8092 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java @@ -14,7 +14,7 @@ import org.eclipse.emf.cdo.server.IStore; import org.eclipse.net4j.db.ConnectionProvider; import org.eclipse.net4j.db.IDBAdapter; - +import org.eclipse.net4j.db.IDBSchema; /** * @author Eike Stepper @@ -26,4 +26,6 @@ public interface IDBStore extends IStore public IDBAdapter getDBAdapter(); public ConnectionProvider getConnectionProvider(); + + public IDBSchema getSchema(); } 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 1508d1e5b3..0d7a8e92ff 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 @@ -10,14 +10,9 @@ **************************************************************************/ 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.net4j.db.IDBSchema; -import org.eclipse.net4j.db.IDBTable; - import java.util.Map; -import java.util.Set; /** * @author Eike Stepper @@ -26,8 +21,6 @@ public interface IMappingStrategy { public String getType(); - public IDBSchema getSchema(); - public IDBStore getStore(); public void setStore(IDBStore store); @@ -37,9 +30,4 @@ public interface IMappingStrategy public void setProperties(Map<String, String> properties); public IMapping getMapping(CDOClass cdoClass); - - /** - * @return A collection of the affected tables. - */ - public Set<IDBTable> map(CDOPackageImpl[] cdoPackages); } diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java index 648c152711..21e72354a3 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java @@ -20,6 +20,8 @@ import org.eclipse.net4j.db.ConnectionProvider; import org.eclipse.net4j.db.DBException; import org.eclipse.net4j.db.DBUtil; import org.eclipse.net4j.db.IDBAdapter; +import org.eclipse.net4j.db.IDBSchema; +import org.eclipse.net4j.internal.db.DBSchema; import java.sql.Connection; @@ -36,6 +38,8 @@ public class DBStore extends Store implements IDBStore private ConnectionProvider connectionProvider; + private IDBSchema schema; + private int nextPackageID; private int nextClassID; @@ -75,6 +79,16 @@ public class DBStore extends Store implements IDBStore return connectionProvider; } + public IDBSchema getSchema() + { + if (schema == null) + { + schema = createSchema(); + } + + return schema; + } + public boolean hasAuditSupport() { return true; @@ -119,13 +133,6 @@ public class DBStore extends Store implements IDBStore nextClassID = DBUtil.selectMaximum(connection, CDODBSchema.CLASSES_ID) + 1; nextFeatureID = DBUtil.selectMaximum(connection, CDODBSchema.FEATURES_ID) + 1; - // if (nextPackageID == 1) - // { - // PackageManager packageManager = - // (PackageManager)getRepository().getPackageManager(); - // writer.writePackages(packageManager.getCDOResourcePackage()); - // } - writer.release(); } finally @@ -133,4 +140,10 @@ public class DBStore extends Store implements IDBStore DBUtil.close(connection); } } + + protected IDBSchema createSchema() + { + String name = getRepository().getName(); + return new DBSchema(name); + } } diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FullInfoMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FullInfoMapping.java deleted file mode 100644 index 7efcb84c78..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FullInfoMapping.java +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * 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.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.db.IDBStoreAccessor; -import org.eclipse.emf.cdo.server.db.IMappingStrategy; - -/** - * @author Eike Stepper - */ -public abstract class FullInfoMapping extends IDInfoMapping -{ - public FullInfoMapping(IMappingStrategy mappingStrategy, CDOClass cdoClass) - { - super(mappingStrategy, cdoClass); - } - - @Override - public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision) - { - super.writeRevision(storeAccessor, revision); - writeFullInfo(storeAccessor, revision); - } - - protected void writeFullInfo(IDBStoreAccessor storeAccessor, CDORevisionImpl revision) - { - } -} 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 a4e73503af..693682a551 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 @@ -10,101 +10,21 @@ **************************************************************************/ 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 +public class HorizontalMapping extends ValueMapping { - private IDBTable table; - - private List<IAttributeMapping> attributeMappings; - - private List<IReferenceMapping> referenceMappings; - - public HorizontalMapping(IMappingStrategy mappingStrategy, CDOClass cdoClass) + public HorizontalMapping(HorizontalMappingStrategy mappingStrategy, CDOClass cdoClass) { - super(mappingStrategy, cdoClass); - CDOFeature[] features = cdoClass.getAllFeatures(); - attributeMappings = createAttributeMappings(features); - referenceMappings = createReferenceMappings(features); + super(mappingStrategy, cdoClass, cdoClass.getAllFeatures()); } @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) + public HorizontalMappingStrategy getMappingStrategy() { - for (IReferenceMapping referenceMapping : referenceMappings) - { - referenceMapping.writeReference(this, storeAccessor, revision); - } + return (HorizontalMappingStrategy)super.getMappingStrategy(); } } diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/IDInfoMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/IDInfoMapping.java deleted file mode 100644 index 6d90f77827..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/IDInfoMapping.java +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * 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.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.db.IDBStoreAccessor; -import org.eclipse.emf.cdo.server.db.IMappingStrategy; - -/** - * @author Eike Stepper - */ -public abstract class IDInfoMapping extends Mapping -{ - public IDInfoMapping(IMappingStrategy mappingStrategy, CDOClass cdoClass) - { - super(mappingStrategy, cdoClass); - } - - public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision) - { - writeIDInfo(storeAccessor, revision); - } - - protected void writeIDInfo(IDBStoreAccessor storeAccessor, CDORevisionImpl revision) - { - } -} 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 bdeea6204d..cab57d0d05 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 @@ -10,17 +10,28 @@ **************************************************************************/ 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.protocol.model.CDOPackage; +import org.eclipse.emf.cdo.protocol.model.CDOType; +import org.eclipse.emf.cdo.server.IRepository; +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.emf.cdo.server.internal.db.bundle.OM; +import org.eclipse.net4j.db.DBException; +import org.eclipse.net4j.db.DBType; +import org.eclipse.net4j.db.IDBField; import org.eclipse.net4j.db.IDBTable; +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.List; import java.util.Set; /** @@ -28,16 +39,21 @@ import java.util.Set; */ public abstract class Mapping implements IMapping { + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, Mapping.class); + private IMappingStrategy mappingStrategy; private CDOClass cdoClass; + private IDBTable table; + private Set<IDBTable> affectedTables = new HashSet(); public Mapping(IMappingStrategy mappingStrategy, CDOClass cdoClass) { this.mappingStrategy = mappingStrategy; this.cdoClass = cdoClass; + table = addTable(cdoClass.getName()); } public IMappingStrategy getMappingStrategy() @@ -50,18 +66,201 @@ public abstract class Mapping implements IMapping return cdoClass; } + public IDBTable getTable() + { + return table; + } + public Set<IDBTable> getAffectedTables() { return affectedTables; } - public List<IAttributeMapping> createAttributeMappings(CDOFeature[] features) + protected void appendFullInfo(StringBuilder builder, CDORevisionImpl revision) { - return null; + 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()); } - public List<IReferenceMapping> createReferenceMappings(CDOFeature[] features) + protected void executeSQL(IDBStoreAccessor storeAccessor, String sql) throws DBException { - return null; + try + { + 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 String mangleTableName(String name, int attempt) + { + return mappingStrategy.getStore().getDBAdapter().mangleTableName(name, attempt); + } + + protected String mangleFieldName(String name, int attempt) + { + return mappingStrategy.getStore().getDBAdapter().mangleFieldName(name, attempt); + } + + protected IDBTable addReferenceTable(String tableName, boolean withFeature) + { + IDBTable table = addTable(tableName); + if (withFeature) + { + table.addField("cdo_feature", DBType.INTEGER); + } + + table.addField("cdo_idx", DBType.INTEGER); + table.addField("cdo_source", DBType.BIGINT); + table.addField("cdo_target", DBType.BIGINT); + return table; + } + + protected IDBTable addTable(String name) + { + for (int attempt = 0;; ++attempt) + { + String tableName = mangleTableName(name, attempt); + + try + { + return mappingStrategy.getStore().getSchema().addTable(tableName); + } + catch (DBException ignore) + { + if (TRACER.isEnabled()) + { + TRACER.format("{0}. attempt to add table: {1} ({2})", attempt, tableName, ignore.getMessage()); + } + } + } + } + + protected IDBField addField(CDOFeature cdoFeature, IDBTable table) throws DBException + { + for (int attempt = 0;; ++attempt) + { + String fieldName = mangleFieldName(cdoFeature.getName(), attempt); + DBType fieldType = getDBType(cdoFeature.getType()); + + try + { + return table.addField(fieldName, fieldType); + } + catch (DBException ignore) + { + if (TRACER.isEnabled()) + { + TRACER.format("{0}. attempt to add field: {1} ({2})", attempt, fieldName, ignore.getMessage()); + } + } + } + } + + protected DBType getDBType(CDOType type) + { + if (type == CDOType.BOOLEAN || type == CDOType.BOOLEAN_OBJECT) + { + return DBType.BOOLEAN; + } + else if (type == CDOType.BYTE || type == CDOType.BYTE_OBJECT) + { + return DBType.SMALLINT; + } + else if (type == CDOType.CHAR || type == CDOType.CHARACTER_OBJECT) + { + return DBType.CHAR; + } + else if (type == CDOType.DATE) + { + return DBType.DATE; + } + else if (type == CDOType.DOUBLE || type == CDOType.DOUBLE_OBJECT) + { + return DBType.DOUBLE; + } + else if (type == CDOType.FLOAT || type == CDOType.FLOAT_OBJECT) + { + return DBType.FLOAT; + } + else if (type == CDOType.INT || type == CDOType.INTEGER_OBJECT) + { + return DBType.INTEGER; + } + else if (type == CDOType.LONG || type == CDOType.INTEGER_OBJECT) + { + return DBType.BIGINT; + } + else if (type == CDOType.OBJECT) + { + return DBType.BIGINT; + } + else if (type == CDOType.SHORT || type == CDOType.SHORT_OBJECT) + { + return DBType.SMALLINT; + } + else if (type == CDOType.STRING) + { + return DBType.LONGVARCHAR; + } + + throw new ImplementationError("Unrecognized CDOType: " + type); + } + + protected IDBField mapReference(CDOClass cdoClass, CDOFeature cdoFeature, ToMany mapping) + { + switch (mapping) + { + case PER_REFERENCE: + return mapReferenceTable(cdoFeature, cdoClass.getName() + "_" + cdoFeature.getName() + "_refs", false); + case PER_CLASS: + return mapReferenceTable(cdoClass, cdoClass.getName() + "_refs", true); + case PER_PACKAGE: + CDOPackage cdoPackage = cdoClass.getContainingPackage(); + return mapReferenceTable(cdoPackage, cdoPackage.getName() + "_refs", true); + case PER_REPOSITORY: + IRepository repository = mappingStrategy.getStore().getRepository(); + return mapReferenceTable(repository, repository.getName() + "_refs", true); + case LIKE_ATTRIBUTES: + return mapReferenceSerialized(cdoClass, cdoFeature); + default: + throw new IllegalArgumentException("Invalid mapping: " + mapping); + } + } + + protected IDBField mapReferenceSerialized(CDOClass cdoClass, CDOFeature cdoFeature) + { + // TODO Implement method HorizontalMappingStrategy.mapReferenceSerialized() + throw new UnsupportedOperationException("Not yet implemented"); + } + + protected IDBField mapReferenceTable(Object key, String tableName, boolean withFeature) + { + IDBTable table = referenceTables.get(key); + if (table == null) + { + table = addReferenceTable(tableName, withFeature); + referenceTables.put(key, table); + } + + return table.getField(0); } } 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 c3af05f366..4291476f6f 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 @@ -11,21 +11,12 @@ 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.IDBStore; import org.eclipse.emf.cdo.server.db.IMapping; import org.eclipse.emf.cdo.server.db.IMappingStrategy; -import org.eclipse.emf.cdo.server.internal.db.bundle.OM; -import org.eclipse.net4j.db.DBException; import org.eclipse.net4j.db.DBType; -import org.eclipse.net4j.db.IDBField; -import org.eclipse.net4j.db.IDBSchema; import org.eclipse.net4j.db.IDBTable; -import org.eclipse.net4j.internal.db.DBSchema; -import org.eclipse.net4j.internal.util.om.trace.ContextTracer; -import org.eclipse.net4j.util.ImplementationError; import java.util.HashMap; import java.util.Map; @@ -35,16 +26,10 @@ import java.util.Map; */ public abstract class MappingStrategy implements IMappingStrategy { - public static final int FULL_NUMBER_OF_FIELDS = 8; - - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, MappingStrategy.class); - private IDBStore store; private Map<String, String> properties; - private IDBSchema schema; - public MappingStrategy() { } @@ -74,16 +59,6 @@ public abstract class MappingStrategy implements IMappingStrategy this.properties = properties; } - public IDBSchema getSchema() - { - if (schema == null) - { - schema = createSchema(); - } - - return schema; - } - public IMapping getMapping(CDOClass cdoClass) { IMapping mapping = ClassServerInfo.getMapping(cdoClass); @@ -109,37 +84,7 @@ public abstract class MappingStrategy implements IMappingStrategy return getType(); } - protected String mangleTableName(String name, int attempt) - { - return store.getDBAdapter().mangleTableName(name, attempt); - } - - protected String mangleFieldName(String name, int attempt) - { - return store.getDBAdapter().mangleFieldName(name, attempt); - } - - protected IDBSchema createSchema() - { - String name = store.getRepository().getName(); - return new DBSchema(name); - } - - protected IDBTable addReferenceTable(String tableName, boolean withFeature) - { - IDBTable table = addTable(tableName); - if (withFeature) - { - table.addField("cdo_feature", DBType.INTEGER); - } - - table.addField("cdo_idx", DBType.INTEGER); - table.addField("cdo_source", DBType.BIGINT); - table.addField("cdo_target", DBType.BIGINT); - return table; - } - - protected int initTable(IDBTable table, boolean full) + protected void initTable(IDBTable table, boolean full) { table.addField("cdo_id", DBType.BIGINT); if (full) @@ -151,105 +96,6 @@ public abstract class MappingStrategy implements IMappingStrategy table.addField("cdo_resource", DBType.BIGINT); table.addField("cdo_container", DBType.BIGINT); table.addField("cdo_feature", DBType.INTEGER); - return FULL_NUMBER_OF_FIELDS; } - - return 1; - } - - protected IDBTable addTable(CDOClass cdoClass) - { - return addTable(cdoClass.getName()); - } - - protected IDBTable addTable(String name) - { - for (int attempt = 0;; ++attempt) - { - String tableName = mangleTableName(name, attempt); - - try - { - return getSchema().addTable(tableName); - } - catch (DBException ignore) - { - if (TRACER.isEnabled()) - { - TRACER.format("{0}. attempt to add table: {1} ({2})", attempt, tableName, ignore.getMessage()); - } - } - } - } - - protected IDBField addField(CDOFeature cdoFeature, IDBTable table) throws DBException - { - for (int attempt = 0;; ++attempt) - { - String fieldName = mangleFieldName(cdoFeature.getName(), attempt); - DBType fieldType = getDBType(cdoFeature.getType()); - - try - { - return table.addField(fieldName, fieldType); - } - catch (DBException ignore) - { - if (TRACER.isEnabled()) - { - TRACER.format("{0}. attempt to add field: {1} ({2})", attempt, fieldName, ignore.getMessage()); - } - } - } - } - - protected DBType getDBType(CDOType type) - { - if (type == CDOType.BOOLEAN || type == CDOType.BOOLEAN_OBJECT) - { - return DBType.BOOLEAN; - } - else if (type == CDOType.BYTE || type == CDOType.BYTE_OBJECT) - { - return DBType.SMALLINT; - } - else if (type == CDOType.CHAR || type == CDOType.CHARACTER_OBJECT) - { - return DBType.CHAR; - } - else if (type == CDOType.DATE) - { - return DBType.DATE; - } - else if (type == CDOType.DOUBLE || type == CDOType.DOUBLE_OBJECT) - { - return DBType.DOUBLE; - } - else if (type == CDOType.FLOAT || type == CDOType.FLOAT_OBJECT) - { - return DBType.FLOAT; - } - else if (type == CDOType.INT || type == CDOType.INTEGER_OBJECT) - { - return DBType.INTEGER; - } - else if (type == CDOType.LONG || type == CDOType.INTEGER_OBJECT) - { - return DBType.BIGINT; - } - else if (type == CDOType.OBJECT) - { - return DBType.BIGINT; - } - else if (type == CDOType.SHORT || type == CDOType.SHORT_OBJECT) - { - return DBType.SMALLINT; - } - else if (type == CDOType.STRING) - { - return DBType.LONGVARCHAR; - } - - throw new ImplementationError("Unrecognized CDOType: " + type); } }
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java index d3f3c4677c..86a6eda645 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootMapping.java @@ -10,16 +10,31 @@ **************************************************************************/ 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.db.IDBStoreAccessor; import org.eclipse.emf.cdo.server.db.IMappingStrategy; /** * @author Eike Stepper */ -public class RootMapping extends FullInfoMapping +public class RootMapping extends Mapping { public RootMapping(IMappingStrategy mappingStrategy, CDOClass cdoClass) { super(mappingStrategy, cdoClass); } + + public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision) + { + StringBuilder builder = new StringBuilder(); + builder.append("INSERT INTO "); + builder.append(getTable()); + builder.append(" VALUES ("); + builder.append(revision.getID().getValue()); + builder.append(", "); + appendFullInfo(builder, revision); + builder.append(")"); + executeSQL(storeAccessor, builder.toString()); + } } diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StandardMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StandardMappingStrategy.java index f45cd46082..72d57d8910 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StandardMappingStrategy.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/StandardMappingStrategy.java @@ -12,13 +12,10 @@ package org.eclipse.emf.cdo.server.internal.db; import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl; import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl; -import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl; import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl; import org.eclipse.emf.cdo.protocol.CDOID; import org.eclipse.emf.cdo.protocol.model.CDOClass; import org.eclipse.emf.cdo.protocol.model.CDOFeature; -import org.eclipse.emf.cdo.protocol.model.CDOPackage; -import org.eclipse.emf.cdo.server.IRepository; import org.eclipse.emf.cdo.server.internal.db.bundle.OM; import org.eclipse.net4j.db.DBUtil; @@ -32,9 +29,7 @@ import java.sql.Date; import java.text.MessageFormat; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; /** @@ -91,108 +86,70 @@ public abstract class StandardMappingStrategy extends MappingStrategy return toOne; } - public Set<IDBTable> map(CDOPackageImpl[] cdoPackages) - { - Set<IDBTable> affectedTables = new HashSet(); - for (CDOPackageImpl cdoPackage : cdoPackages) - { - PackageServerInfo.setSchema(cdoPackage, getSchema()); - if (TRACER.isEnabled()) - { - TRACER.format("Mapped package: {0} --> {1}", cdoPackage, getSchema()); - } - } - - for (CDOPackageImpl cdoPackage : cdoPackages) - { - for (CDOClass cdoClass : cdoPackage.getClasses()) - { - if (TRACER.isEnabled()) - { - TRACER.format("Mapping features of class {0}", cdoClass); - } - - for (CDOFeature cdoFeature : cdoClass.getAllFeatures()) - { - IDBField field = mapFeature(cdoClass, cdoFeature, affectedTables); - if (field != null) - { - ((FeatureServerInfo)cdoFeature.getServerInfo()).addField(cdoClass, field); - affectedTables.add(field.getTable()); - if (TRACER.isEnabled()) - { - TRACER.format("Mapped feature: {0} --> {1}", cdoFeature, field); - } - } - } - } - } - - return affectedTables; - } - - /** - * @param affectedTables - * Can be used to indicate the creation or modification of additional - * tables. There is no need to add the table of the returned field to - * this set of affected tables. The framework takes care of that. - */ - protected abstract IDBField mapFeature(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables); - - protected IDBField mapAttribute(CDOClass cdoClass, CDOFeature cdoFeature) - { - // IDBTable table = ClassServerInfo.getTable(cdoClass); - // if (table == null) - // { - // table = addTable(cdoClass); - // initTable(table, true); - // ClassServerInfo.setTable(cdoClass, table); - // } - // - // return addField(cdoFeature, table); - - // TODO Implement method StandardMappingStrategy.mapAttribute() - throw new UnsupportedOperationException("Not yet implemented"); - } - - protected IDBField mapReference(CDOClass cdoClass, CDOFeature cdoFeature, ToMany mapping) - { - switch (mapping) - { - case PER_REFERENCE: - return mapReferenceTable(cdoFeature, cdoClass.getName() + "_" + cdoFeature.getName() + "_refs", false); - case PER_CLASS: - return mapReferenceTable(cdoClass, cdoClass.getName() + "_refs", true); - case PER_PACKAGE: - CDOPackage cdoPackage = cdoClass.getContainingPackage(); - return mapReferenceTable(cdoPackage, cdoPackage.getName() + "_refs", true); - case PER_REPOSITORY: - IRepository repository = getStore().getRepository(); - return mapReferenceTable(repository, repository.getName() + "_refs", true); - case LIKE_ATTRIBUTES: - return mapReferenceSerialized(cdoClass, cdoFeature); - default: - throw new IllegalArgumentException("Invalid mapping: " + mapping); - } - } - - protected IDBField mapReferenceSerialized(CDOClass cdoClass, CDOFeature cdoFeature) - { - // TODO Implement method HorizontalMappingStrategy.mapReferenceSerialized() - throw new UnsupportedOperationException("Not yet implemented"); - } - - protected IDBField mapReferenceTable(Object key, String tableName, boolean withFeature) - { - IDBTable table = referenceTables.get(key); - if (table == null) - { - table = addReferenceTable(tableName, withFeature); - referenceTables.put(key, table); - } - - return table.getField(0); - } + // public Set<IDBTable> map(CDOPackageImpl[] cdoPackages) + // { + // Set<IDBTable> affectedTables = new HashSet(); + // for (CDOPackageImpl cdoPackage : cdoPackages) + // { + // PackageServerInfo.setSchema(cdoPackage, getSchema()); + // if (TRACER.isEnabled()) + // { + // TRACER.format("Mapped package: {0} --> {1}", cdoPackage, getSchema()); + // } + // } + // + // for (CDOPackageImpl cdoPackage : cdoPackages) + // { + // for (CDOClass cdoClass : cdoPackage.getClasses()) + // { + // if (TRACER.isEnabled()) + // { + // TRACER.format("Mapping features of class {0}", cdoClass); + // } + // + // for (CDOFeature cdoFeature : cdoClass.getAllFeatures()) + // { + // IDBField field = mapFeature(cdoClass, cdoFeature, affectedTables); + // if (field != null) + // { + // ((FeatureServerInfo)cdoFeature.getServerInfo()).addField(cdoClass, field); + // affectedTables.add(field.getTable()); + // if (TRACER.isEnabled()) + // { + // TRACER.format("Mapped feature: {0} --> {1}", cdoFeature, field); + // } + // } + // } + // } + // } + // + // return affectedTables; + // } + // + // /** + // * @param affectedTables + // * Can be used to indicate the creation or modification of additional + // * tables. There is no need to add the table of the returned field to + // * this set of affected tables. The framework takes care of that. + // */ + // protected abstract IDBField mapFeature(CDOClass cdoClass, CDOFeature + // cdoFeature, Set<IDBTable> affectedTables); + // + // protected IDBField mapAttribute(CDOClass cdoClass, CDOFeature cdoFeature) + // { + // IDBTable table = ClassServerInfo.getTable(cdoClass); + // if (table == null) + // { + // table = addTable(cdoClass); + // initTable(table, true); + // ClassServerInfo.setTable(cdoClass, table); + // } + // + // return addField(cdoFeature, table); + // + // // TODO Implement method StandardMappingStrategy.mapAttribute() + // throw new UnsupportedOperationException("Not yet implemented"); + // } protected ClassMapping getClassMapping(CDOClass cdoClass) { diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java new file mode 100644 index 0000000000..9df7fc0134 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ValueMapping.java @@ -0,0 +1,90 @@ +/*************************************************************************** + * 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.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 java.util.List; + +/** + * @author Eike Stepper + */ +public class ValueMapping extends Mapping +{ + private List<IAttributeMapping> attributeMappings; + + private List<IReferenceMapping> referenceMappings; + + public ValueMapping(IMappingStrategy mappingStrategy, CDOClass cdoClass, CDOFeature[] features) + { + super(mappingStrategy, cdoClass); + attributeMappings = createAttributeMappings(features); + referenceMappings = createReferenceMappings(features); + } + + public List<IAttributeMapping> createAttributeMappings(CDOFeature[] features) + { + return null; + } + + public List<IReferenceMapping> createReferenceMappings(CDOFeature[] features) + { + return null; + } + + public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision) + { + if (attributeMappings != null) + { + writeAttributes(storeAccessor, revision); + } + + if (referenceMappings != null) + { + writeReferences(storeAccessor, revision); + } + } + + protected void writeAttributes(IDBStoreAccessor storeAccessor, CDORevisionImpl revision) + { + StringBuilder builder = new StringBuilder(); + builder.append("INSERT INTO "); + builder.append(getTable()); + builder.append(" VALUES ("); + builder.append(revision.getID().getValue()); + builder.append(", "); + appendFullInfo(builder, revision); + builder.append(", "); + + for (IAttributeMapping attributeMapping : attributeMappings) + { + builder.append(", "); + attributeMapping.appendValue(builder, revision); + } + + builder.append(")"); + executeSQL(storeAccessor, builder.toString()); + } + + 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/VerticalMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMapping.java index 51dc913a59..e4b2398f94 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,37 +12,22 @@ 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.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; /** * @author Eike Stepper */ -public class VerticalMapping extends IDInfoMapping +public class VerticalMapping extends ValueMapping { private List<IMapping> superMappings; - private IDBTable table; - - private List<IAttributeMapping> attributeMappings; - - private List<IReferenceMapping> referenceMappings; - - public VerticalMapping(IMappingStrategy mappingStrategy, CDOClass cdoClass) + public VerticalMapping(VerticalMappingStrategy mappingStrategy, CDOClass cdoClass) { - super(mappingStrategy, cdoClass); + super(mappingStrategy, cdoClass, cdoClass.getFeatures()); for (CDOClass superType : cdoClass.getSuperTypes()) { IMapping superMapping = mappingStrategy.getMapping(superType); @@ -56,10 +41,12 @@ public class VerticalMapping extends IDInfoMapping superMappings.add(superMapping); } } + } - CDOFeature[] features = cdoClass.getFeatures(); - attributeMappings = createAttributeMappings(features); - referenceMappings = createReferenceMappings(features); + @Override + public VerticalMappingStrategy getMappingStrategy() + { + return (VerticalMappingStrategy)super.getMappingStrategy(); } public List<IMapping> getSuperMappings() @@ -71,16 +58,6 @@ public class VerticalMapping extends IDInfoMapping public void writeRevision(IDBStoreAccessor storeAccessor, CDORevisionImpl revision) { super.writeRevision(storeAccessor, revision); - if (attributeMappings != null) - { - writeAttributes(storeAccessor, revision); - } - - if (referenceMappings != null) - { - writeReferences(storeAccessor, revision); - } - if (superMappings != null) { for (IMapping superMapping : superMappings) @@ -89,43 +66,4 @@ public class VerticalMapping extends IDInfoMapping } } } - - 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(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/VerticalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java index 79f8790b21..47898ecab0 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java @@ -11,20 +11,18 @@ 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.server.db.IMapping; -import org.eclipse.net4j.db.IDBField; import org.eclipse.net4j.db.IDBSchema; import org.eclipse.net4j.db.IDBTable; -import java.util.Set; - /** * @author Eike Stepper */ public class VerticalMappingStrategy extends StandardMappingStrategy { + private IDBTable rootTable; + public VerticalMappingStrategy() { throw new UnsupportedOperationException(); @@ -35,30 +33,21 @@ public class VerticalMappingStrategy extends StandardMappingStrategy return "vertical"; } - @Override - protected IMapping createMapping(CDOClass cdoClass) + public IDBTable getRootTable() { - return new VerticalMapping(this, cdoClass); - } + if (rootTable == null) + { + IDBSchema schema = getStore().getSchema(); + rootTable = schema.addTable("cdo_revisions"); + initTable(rootTable, true); + } - @Override - protected IDBSchema createSchema() - { - IDBSchema schema = super.createSchema(); - IDBTable table = schema.addTable("CDO_REVISIONS"); - initTable(table, true); - return schema; + return rootTable; } @Override - protected IDBField mapFeature(CDOClass cdoClass, CDOFeature cdoFeature, Set<IDBTable> affectedTables) + protected IMapping createMapping(CDOClass cdoClass) { - if (cdoFeature.getContainingClass() != cdoClass) - { - return null; - } - - // TODO Implement method enclosing_type.enclosing_method() - throw new UnsupportedOperationException("Not yet implemented"); + return new VerticalMapping(this, cdoClass); } } |