diff options
author | Eike Stepper | 2008-08-08 21:40:58 +0000 |
---|---|---|
committer | Eike Stepper | 2008-08-08 21:40:58 +0000 |
commit | 47a483d842c3fc4d3b005e3b722ba9e7f2a4eff3 (patch) | |
tree | 8cc64a5821845b4e084d95689138b8229df72483 /plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer | |
parent | feb16534f639544ee1e34f41f94d625c93af48ca (diff) | |
download | cdo-47a483d842c3fc4d3b005e3b722ba9e7f2a4eff3.tar.gz cdo-47a483d842c3fc4d3b005e3b722ba9e7f2a4eff3.tar.xz cdo-47a483d842c3fc4d3b005e3b722ba9e7f2a4eff3.zip |
This commit was manufactured by cvs2svn to create tagcommitters/smcduff/merge-238414committers/smcduff/merge-238414
'simone_merge_238414_before_merge_from_HEAD_to'.
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer')
25 files changed, 0 insertions, 2695 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDMetaRangeUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDMetaRangeUserType.java deleted file mode 100644 index 15a6f9213a..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDMetaRangeUserType.java +++ /dev/null @@ -1,131 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2008 - 2008 Martin Taal and others - * 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: - * Martin Taal - initial api - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.id.CDOIDMeta; -import org.eclipse.emf.cdo.common.id.CDOIDMetaRange; -import org.eclipse.emf.cdo.common.id.CDOIDUtil; - -import org.hibernate.Hibernate; -import org.hibernate.usertype.UserType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; - -/** - * @author Martin Taal - */ -public class CDOIDMetaRangeUserType implements UserType -{ - private static final int[] SQL_TYPES = { Types.INTEGER, Types.INTEGER }; - - public CDOIDMetaRangeUserType() - { - } - - public int[] sqlTypes() - { - return SQL_TYPES; - } - - public Class<?> returnedClass() - { - return CDOIDMetaRange.class; - } - - public boolean isMutable() - { - return true; - } - - public Object deepCopy(Object value) - { - if (value == null) - { - return null; - } - - CDOIDMetaRange cdoRange = (CDOIDMetaRange)value; - CDOIDMeta newCdoIDMeta = CDOIDUtil.createMeta(((CDOIDMeta)cdoRange.getLowerBound()).getLongValue()); - return CDOIDUtil.createMetaRange(newCdoIDMeta, cdoRange.size()); - } - - public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException - { - Integer start = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[0]); - if (rs.wasNull()) - { - return null; - } - - Integer size = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[1]); - if (rs.wasNull()) - { - return null; - } - - CDOIDMeta newCdoIDMeta = CDOIDUtil.createMeta(start); - return CDOIDUtil.createMetaRange(newCdoIDMeta, size); - } - - public void nullSafeSet(PreparedStatement statement, Object value, int index) throws SQLException - { - if (value != null) - { - CDOIDMetaRange cdoRange = (CDOIDMetaRange)value; - statement.setLong(index, ((CDOIDMeta)cdoRange.getLowerBound()).getLongValue()); - statement.setInt(index + 1, cdoRange.size()); - } - else - { - statement.setNull(index, Types.INTEGER); - statement.setNull(index + 1, Types.INTEGER); - } - } - - public Serializable disassemble(Object value) - { - return (Serializable)value; - } - - public Object assemble(Serializable cachedValue, Object owner) - { - return cachedValue; - } - - public Object replace(Object original, Object target, Object owner) - { - return original; - } - - public boolean equals(Object x, Object y) - { - if (x == y) - { - return true; - } - - if (x == null || y == null) - { - return false; - } - - return x.equals(y); - } - - public int hashCode(Object x) - { - return x.hashCode(); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertyGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertyGetter.java deleted file mode 100644 index cd8c67db80..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertyGetter.java +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.server.hibernate.id.CDOIDHibernate; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; - -/** - * @author Martin Taal - */ -public class CDOIDPropertyGetter extends CDOPropertyGetter -{ - private static final long serialVersionUID = 1L; - - public CDOIDPropertyGetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - @Override - public Object get(Object target) throws HibernateException - { - InternalCDORevision revision = (InternalCDORevision)target; - if (!(revision.getID() instanceof CDOIDHibernate)) - { - return null; - } - - CDOIDHibernate cdoID = (CDOIDHibernate)revision.getID(); - if (isVirtualProperty()) - { - return cdoID.getId(); - } - else - { - Object id = super.get(target); - // TODO: does this make sense? - // if (cdoID.getId() == null) - // { - // cdoID.setId((Serializable)id); - // } - return id; - } - } - - @Override - protected boolean isVirtualPropertyAllowed() - { - return true; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java deleted file mode 100644 index bdfc2947c9..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertySetter.java +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.id.CDOID; -import org.eclipse.emf.cdo.common.id.CDOIDTemp; -import org.eclipse.emf.cdo.server.hibernate.id.CDOIDHibernate; -import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateCommitContext; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; -import org.hibernate.engine.SessionFactoryImplementor; - -import java.io.Serializable; - -/** - * @author Martin Taal - */ -public class CDOIDPropertySetter extends CDOPropertySetter -{ - private static final long serialVersionUID = 1L; - - public CDOIDPropertySetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException - { - if (value == null) - { - return; - } - - HibernateCommitContext hcc = null; - if (HibernateThreadContext.isHibernateCommitContextSet()) - { - hcc = HibernateThreadContext.getHibernateCommitContext(); - } - InternalCDORevision revision = (InternalCDORevision)target; - CDOID cdoID = revision.getID(); - if (cdoID == null) - { - CDOIDHibernate newCDOID = CDOIDHibernateFactoryImpl.getInstance().createCDOID((Serializable)value, - revision.getCDOClass().getName()); - revision.setID(newCDOID); - if (hcc != null) - { - hcc.setNewID(cdoID, newCDOID); - } - } - else if (cdoID instanceof CDOIDTemp) - { - CDOIDHibernate newCDOID = CDOIDHibernateFactoryImpl.getInstance().createCDOID((Serializable)value, - revision.getCDOClass().getName()); - revision.setID(newCDOID); - if (hcc != null) - { - hcc.getCommitContext().addIDMapping((CDOIDTemp)cdoID, newCDOID); - hcc.setNewID(cdoID, newCDOID); - } - } - else - { - CDOIDHibernate hbCDOID = (CDOIDHibernate)revision.getID(); - if (!hbCDOID.getId().equals(value)) - { - throw new IllegalStateException("Current id and new id are different " + value + "/" + hbCDOID.getId()); - } - - } - if (!isVirtualProperty()) - { - super.set(target, value, factory); - } - } - - @Override - protected boolean isVirtualPropertyAllowed() - { - return true; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDUserType.java deleted file mode 100644 index e03ec49bed..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDUserType.java +++ /dev/null @@ -1,180 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2008 - 2008 Martin Taal and others - * 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: - * Martin Taal - initial api - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.id.CDOID; -import org.eclipse.emf.cdo.common.id.CDOIDTemp; -import org.eclipse.emf.cdo.common.revision.CDORevision; -import org.eclipse.emf.cdo.server.hibernate.id.CDOIDHibernate; -import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; - -import org.eclipse.net4j.util.WrappedException; - -import org.hibernate.Hibernate; -import org.hibernate.usertype.UserType; - -import java.io.Serializable; -import java.lang.reflect.Constructor; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.HashMap; - -/** - * Persists a CDOID in the DB. - */ -public class CDOIDUserType implements UserType -{ - /** - * 1) entityname, 2) id, 3) id class name - */ - private static final int[] SQL_TYPES = { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }; - - /** Constructor by id */ - private final HashMap<String, Constructor<?>> constructors = new HashMap<String, Constructor<?>>(); - - public CDOIDUserType() - { - } - - public int[] sqlTypes() - { - return SQL_TYPES; - } - - public Class<?> returnedClass() - { - return CDOID.class; - } - - public boolean isMutable() - { - return false; - } - - public Object deepCopy(Object value) - { - return value; - } - - public boolean equals(Object x, Object y) - { - if (x == y) - { - return true; - } - - if (x == null || y == null) - { - return false; - } - - return x.equals(y); - } - - public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException - { - String entityName = (String)Hibernate.STRING.nullSafeGet(rs, names[0]); - if (rs.wasNull()) - { - return null; - } - - String idStr = (String)Hibernate.STRING.nullSafeGet(rs, names[1]); - if (rs.wasNull()) - { - return null; - } - - String idClassName = (String)Hibernate.STRING.nullSafeGet(rs, names[2]); - if (rs.wasNull()) - { - return null; - } - - Serializable id = getId(idStr, idClassName); - return CDOIDHibernateFactoryImpl.getInstance().createCDOID(id, entityName); - } - - public void nullSafeSet(PreparedStatement statement, Object value, int index) throws SQLException - { - if (value == null) - { - statement.setNull(index, Types.VARCHAR); - statement.setNull(index, Types.VARCHAR); - statement.setNull(index, Types.VARCHAR); - } - - if (value != null) - { - CDOIDHibernate cdoID; - if (value instanceof CDOIDTemp) - { - cdoID = HibernateUtil.getInstance().getCDOIDHibernate((CDOID)value); - } - else if (value instanceof CDORevision) - { - cdoID = (CDOIDHibernate)((CDORevision)value).getID(); - } - else - { - cdoID = (CDOIDHibernate)value; - } - - statement.setString(index, cdoID.getEntityName()); - statement.setString(index + 1, cdoID.getId().toString()); - statement.setString(index + 2, cdoID.getId().getClass().getName()); - } - } - - public Serializable disassemble(Object value) - { - return (Serializable)value; - } - - public Object assemble(Serializable cachedValue, Object owner) - { - return cachedValue; - } - - public Object replace(Object original, Object target, Object owner) - { - return original; - } - - public int hashCode(Object x) - { - return x.hashCode(); - } - - /** Creates an id object of the correct type */ - private Serializable getId(String idStr, String idType) - { - try - { - Constructor<?> constructor = constructors.get(idType); - if (constructor == null) - { - Class<?> idClass = this.getClass().getClassLoader().loadClass(idType); - constructor = idClass.getConstructor(new Class[] { String.class }); - constructors.put(idType, constructor); - } - - return (Serializable)constructor.newInstance(new Object[] { idStr }); - } - catch (Exception e) - { - throw WrappedException.wrap(e); - } - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java deleted file mode 100644 index c23fd4fcf6..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Springsite B.V. and others - * 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: - * Martin Taal - initial API and implementation - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.EmptyInterceptor; - -/** - * Resolves entitynames, todo: use entityname strategy! - * - * @author Martin Taal - */ -public class CDOInterceptor extends EmptyInterceptor -{ - private static final long serialVersionUID = 1L; - - public CDOInterceptor() - { - } - - @Override - public String getEntityName(Object object) - { - InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(object); - return revision.getCDOClass().getName(); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java deleted file mode 100644 index 6987480051..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceGetter.java +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal and others - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.eclipse.net4j.util.collection.MoveableArrayList; -import org.eclipse.net4j.util.collection.MoveableList; - -import org.hibernate.HibernateException; -import org.hibernate.collection.PersistentCollection; - -/** - * @author Martin Taal - */ -// Howto handle hibernate lists: -// - a new owner: the owner is persisted and its lists are replaced with hibernate -// persistentlist, the hibernate persitentlist will have a delegate (internally) which is the list which was previously -// present in the owner. -// - an existing owner: the owner is read from the db and hibernate will set a persistentlist -// directly -// -// The solution also needs to handle the following: -// - cdo does not have direct java references but stores cdoids in the list while hibernate expects real java object -// references. -// - cdo uses a moveablearraylist and not the standard arraylist -// -// The solution: -// - never return null when hibernate asks for the current value of the manyreference, always -// return a MoveableArrayList so that hibernate uses that as the delegate, set the MoveableArrayList -public class CDOManyReferenceGetter extends CDOPropertyGetter -{ - private static final long serialVersionUID = 1L; - - public CDOManyReferenceGetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - @Override - public Object get(Object target) throws HibernateException - { - // Check if there is already a persistentcollection - PersistentCollection collection = PersistableListHolder.getInstance().getListMapping(target, getCDOFeature()); - if (collection != null) - { - return collection; - } - - // Not yet, get the moveablearraylist - @SuppressWarnings("unchecked") - MoveableList<Object> list = (MoveableList<Object>)super.get(target); - if (list == null) - { - // TODO: what initial size? - list = new MoveableArrayList<Object>(10); - InternalCDORevision revision = (InternalCDORevision)target; - revision.setValue(getCDOFeature(), list); - } - - // Wrap the moveablearraylist - HibernateMoveableListWrapper wrapper = new HibernateMoveableListWrapper(); - wrapper.setDelegate(list); - - // And return it - return wrapper; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceSetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceSetter.java deleted file mode 100644 index 6e4f178a24..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyReferenceSetter.java +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.hibernate.HibernateException; -import org.hibernate.collection.PersistentCollection; -import org.hibernate.collection.PersistentList; -import org.hibernate.engine.SessionFactoryImplementor; - -/** - * @author Martin Taal - */ -public class CDOManyReferenceSetter extends CDOPropertySetter -{ - private static final long serialVersionUID = 1L; - - public CDOManyReferenceSetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException - { - // Do some checking - if (!(value instanceof PersistentList)) - { - throw new IllegalArgumentException("Value is not a persistentlist but a " + value.getClass().getName()); - } - - // Only set it in the listholder - PersistableListHolder.getInstance().putListMapping(target, getCDOFeature(), (PersistentCollection)value); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyGetter.java deleted file mode 100644 index f23c77ca08..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyGetter.java +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionPropertyAccessor.CDORevisionSetter; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; -import org.hibernate.engine.SessionImplementor; -import org.hibernate.property.Getter; - -import java.lang.reflect.Method; -import java.util.Map; - -/** - * TODO How does this differ from {@link CDORevisionSetter}? Both needed? - * - * @author Martin Taal - */ -public class CDOPropertyGetter extends CDOPropertyHandler implements Getter -{ - private static final long serialVersionUID = 1L; - - public CDOPropertyGetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - public Object get(Object target) throws HibernateException - { - InternalCDORevision revision = (InternalCDORevision)target; - return revision.getValue(getCDOFeature()); - } - - @SuppressWarnings("unchecked") - public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) throws HibernateException - { - return get(target); - } - - public Method getMethod() - { - return null; - } - - public String getMethodName() - { - return null; - } - - @SuppressWarnings("unchecked") - public Class getReturnType() - { - return Object.class; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyHandler.java deleted file mode 100644 index a9f263a609..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyHandler.java +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.model.CDOFeature; -import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM; - -import org.eclipse.net4j.util.om.trace.ContextTracer; - -/** - * @author Martin Taal - */ -public abstract class CDOPropertyHandler -{ - private final ContextTracer tracer = new ContextTracer(OM.DEBUG, this.getClass()); - - private CDORevisionTuplizer tuplizer; - - private CDOFeature cdoFeature; - - private boolean virtualProperty = false; - - public CDOPropertyHandler(CDORevisionTuplizer tuplizer, String propertyName) - { - this.tuplizer = tuplizer; - cdoFeature = tuplizer.getCDOClass().lookupFeature(propertyName); - if (getTracer().isEnabled()) - { - getTracer().trace( - "Created " + this.getClass().getName() + " for cdoClass/feature: " + tuplizer.getCDOClass().getName() + "." - + propertyName); - } - - if (cdoFeature == null) - { - if (isVirtualPropertyAllowed()) - { - virtualProperty = true; - if (getTracer().isEnabled()) - { - getTracer().trace("This is a virtual property"); - } - } - else - { - throw new IllegalStateException("Feature not found: " + propertyName); - } - } - } - - protected ContextTracer getTracer() - { - return tracer; - } - - public CDORevisionTuplizer getTuplizer() - { - return tuplizer; - } - - public CDOFeature getCDOFeature() - { - return cdoFeature; - } - - protected boolean isVirtualPropertyAllowed() - { - return false; - } - - /** - * @return the virtualProperty - */ - public boolean isVirtualProperty() - { - return virtualProperty; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertySetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertySetter.java deleted file mode 100644 index af4e604821..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertySetter.java +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionPropertyAccessor.CDORevisionSetter; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; -import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.property.Setter; - -import java.lang.reflect.Method; - -/** - * TODO How does this differ from {@link CDORevisionSetter}? Both needed? - * - * @author Martin Taal - */ -public class CDOPropertySetter extends CDOPropertyHandler implements Setter -{ - private static final long serialVersionUID = 1L; - - public CDOPropertySetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - public Method getMethod() - { - return null; - } - - public String getMethodName() - { - return null; - } - - public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException - { - InternalCDORevision revision = (InternalCDORevision)target; - revision.setValue(getCDOFeature(), value); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceGetter.java deleted file mode 100644 index e4ef4d174a..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceGetter.java +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.id.CDOID; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; - -import org.hibernate.HibernateException; - -/** - * @author Martin Taal - */ -public class CDOReferenceGetter extends CDOPropertyGetter -{ - private static final long serialVersionUID = 1L; - - public CDOReferenceGetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - @Override - public Object get(Object target) throws HibernateException - { - final Object o = super.get(target); - if (o instanceof CDOID) - { - return HibernateUtil.getInstance().getCDORevision((CDOID)o); - } - - return o; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceSetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceSetter.java deleted file mode 100644 index 1726c14a30..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceSetter.java +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.revision.CDORevision; - -import org.hibernate.HibernateException; -import org.hibernate.engine.SessionFactoryImplementor; - -/** - * @author Martin Taal - */ -public class CDOReferenceSetter extends CDOPropertySetter -{ - private static final long serialVersionUID = 1L; - - public CDOReferenceSetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException - { - if (value == null) - { - super.set(target, null, factory); - } - else - { - CDORevision cdoValue = (CDORevision)value; - super.set(target, cdoValue.getID(), factory); - } - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java deleted file mode 100644 index 5db1c10a9a..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 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.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.model.CDOClass; -import org.eclipse.emf.cdo.common.revision.CDORevisionUtil; -import org.eclipse.emf.cdo.server.IRepository; -import org.eclipse.emf.cdo.server.IRevisionManager; -import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.mapping.PersistentClass; -import org.hibernate.tuple.Instantiator; - -import java.io.Serializable; - -/** - * @author Eike Stepper - */ -public class CDORevisionInstantiator implements Instantiator -{ - private static final long serialVersionUID = 1L; - - private CDOClass cdoClass; - - private IRevisionManager revisionManager; - - public CDORevisionInstantiator(CDORevisionTuplizer tuplizer, PersistentClass mappingInfo) - { - cdoClass = tuplizer.getCDOClass(); - HibernateStore hbStore = HibernateStore.getCurrentHibernateStore(); - IRepository repository = hbStore.getRepository(); - revisionManager = repository.getRevisionManager(); - } - - public Object instantiate() - { - // TODO CDO can't create a revision w/o CDOID - return instantiate(null); - } - - public Object instantiate(Serializable id) - { - return CDORevisionUtil.create(revisionManager, cdoClass, CDOIDHibernateFactoryImpl.getInstance().createCDOID(id, - cdoClass.getName())); - } - - public boolean isInstance(Object object) - { - return object instanceof InternalCDORevision; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionLazyInitializer.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionLazyInitializer.java deleted file mode 100644 index 0a1c9143cc..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionLazyInitializer.java +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 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.hibernate.tuplizer; - -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.engine.SessionImplementor; -import org.hibernate.proxy.AbstractLazyInitializer; - -import java.io.Serializable; - -/** - * @author Eike Stepper - */ -public class CDORevisionLazyInitializer extends AbstractLazyInitializer implements Serializable -{ - private static final long serialVersionUID = 1L; - - CDORevisionLazyInitializer(String entityName, Serializable id, SessionImplementor session) - { - super(entityName, id, session); - } - - public InternalCDORevision getRevision() - { - return (InternalCDORevision)getImplementation(); - } - - @SuppressWarnings("unchecked") - public Class getPersistentClass() - { - throw new UnsupportedOperationException(); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionPropertyAccessor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionPropertyAccessor.java deleted file mode 100644 index 62dd956bfd..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionPropertyAccessor.java +++ /dev/null @@ -1,155 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 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.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.model.CDOFeature; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; -import org.hibernate.PropertyNotFoundException; -import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.engine.SessionImplementor; -import org.hibernate.property.Getter; -import org.hibernate.property.PropertyAccessor; -import org.hibernate.property.Setter; - -import java.lang.reflect.Method; -import java.util.Map; - -/** - * @author Eike Stepper - */ -public class CDORevisionPropertyAccessor implements PropertyAccessor -{ - private CDORevisionTuplizer tuplizer; - - public CDORevisionPropertyAccessor(CDORevisionTuplizer tuplizer) - { - this.tuplizer = tuplizer; - } - - public CDORevisionTuplizer getTuplizer() - { - return tuplizer; - } - - @SuppressWarnings("unchecked") - public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException - { - return new CDORevisionGetter(this, propertyName); - } - - @SuppressWarnings("unchecked") - public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException - { - return new CDORevisionSetter(this, propertyName); - } - - /** - * @author Eike Stepper - */ - public static class BaseAccessor - { - private CDORevisionPropertyAccessor propertyAccessor; - - private CDOFeature cdoFeature; - - public BaseAccessor(CDORevisionPropertyAccessor propertyAccessor, String propertyName) - { - this.propertyAccessor = propertyAccessor; - cdoFeature = propertyAccessor.getTuplizer().getCDOClass().lookupFeature(propertyName); - if (cdoFeature == null) - { - throw new IllegalStateException("Feature not found: " + propertyName); - } - } - - public CDORevisionPropertyAccessor getPropertyAccessor() - { - return propertyAccessor; - } - - public CDOFeature getCDOFeature() - { - return cdoFeature; - } - } - - /** - * @author Eike Stepper - */ - public static class CDORevisionGetter extends BaseAccessor implements Getter - { - private static final long serialVersionUID = 1L; - - public CDORevisionGetter(CDORevisionPropertyAccessor propertyAccessor, String propertyName) - { - super(propertyAccessor, propertyName); - } - - public Object get(Object target) throws HibernateException - { - InternalCDORevision revision = (InternalCDORevision)target; - return revision.getValue(getCDOFeature()); - } - - @SuppressWarnings("unchecked") - public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) throws HibernateException - { - return get(target); - } - - public Method getMethod() - { - return null; - } - - public String getMethodName() - { - return null; - } - - @SuppressWarnings("unchecked") - public Class getReturnType() - { - return Object.class; - } - } - - /** - * @author Eike Stepper - */ - public static class CDORevisionSetter extends BaseAccessor implements Setter - { - private static final long serialVersionUID = 1L; - - public CDORevisionSetter(CDORevisionPropertyAccessor propertyAccessor, String propertyName) - { - super(propertyAccessor, propertyName); - } - - public Method getMethod() - { - return null; - } - - public String getMethodName() - { - return null; - } - - public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException - { - InternalCDORevision revision = (InternalCDORevision)target; - revision.setValue(getCDOFeature(), value); - } - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxy.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxy.java deleted file mode 100644 index 2da981e109..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxy.java +++ /dev/null @@ -1,302 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 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.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.id.CDOID; -import org.eclipse.emf.cdo.common.id.CDOIDProvider; -import org.eclipse.emf.cdo.common.id.CDOIDTemp; -import org.eclipse.emf.cdo.common.model.CDOClass; -import org.eclipse.emf.cdo.common.model.CDOFeature; -import org.eclipse.emf.cdo.common.revision.CDORevision; -import org.eclipse.emf.cdo.common.revision.CDORevisionData; -import org.eclipse.emf.cdo.common.revision.CDORevisionResolver; -import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.eclipse.net4j.util.collection.MoveableList; -import org.eclipse.net4j.util.io.ExtendedDataOutput; - -import org.hibernate.proxy.HibernateProxy; -import org.hibernate.proxy.LazyInitializer; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Map; - -/** - * @author Eike Stepper - */ -public class CDORevisionProxy implements HibernateProxy, InternalCDORevision, Serializable -{ - private static final long serialVersionUID = 1L; - - private CDORevisionLazyInitializer li; - - CDORevisionProxy(CDORevisionLazyInitializer li) - { - this.li = li; - } - - public Object writeReplace() - { - return this; - } - - public LazyInitializer getHibernateLazyInitializer() - { - return li; - } - - public void add(CDOFeature feature, int index, Object value) - { - li.getRevision().add(feature, index, value); - } - - public void adjustReferences(Map<CDOIDTemp, CDOID> idMappings) - { - li.getRevision().adjustReferences(idMappings); - } - - public void clear(CDOFeature feature) - { - li.getRevision().clear(feature); - } - - public CDORevisionDelta compare(CDORevision origin) - { - return li.getRevision().compare(origin); - } - - public boolean contains(CDOFeature feature, Object value) - { - return li.getRevision().contains(feature, value); - } - - public Object get(CDOFeature feature, int index) - { - return li.getRevision().get(feature, index); - } - - public CDOClass getCDOClass() - { - return li.getRevision().getCDOClass(); - } - - public CDOID getContainerID() - { - return li.getRevision().getContainerID(); - } - - public int getContainingFeatureID() - { - return li.getRevision().getContainingFeatureID(); - } - - public long getCreated() - { - return li.getRevision().getCreated(); - } - - public CDORevisionData getData() - { - return li.getRevision().getData(); - } - - public CDOID getID() - { - return li.getRevision().getID(); - } - - public MoveableList<Object> getList(CDOFeature feature, int size) - { - return li.getRevision().getList(feature, size); - } - - public MoveableList<Object> getList(CDOFeature feature) - { - return li.getRevision().getList(feature); - } - - public CDOID getResourceID() - { - return li.getRevision().getResourceID(); - } - - public long getRevised() - { - return li.getRevision().getRevised(); - } - - public CDORevision getRevision() - { - return li.getRevision().getRevision(); - } - - public CDORevisionResolver getRevisionResolver() - { - return li.getRevision().getRevisionResolver(); - } - - public Object getValue(CDOFeature feature) - { - return li.getRevision().getValue(feature); - } - - public int getVersion() - { - return li.getRevision().getVersion(); - } - - public int hashCode(CDOFeature feature) - { - return li.getRevision().hashCode(feature); - } - - public int indexOf(CDOFeature feature, Object value) - { - return li.getRevision().indexOf(feature, value); - } - - public boolean isCurrent() - { - return li.getRevision().isCurrent(); - } - - public boolean isEmpty(CDOFeature feature) - { - return li.getRevision().isEmpty(feature); - } - - public boolean isResource() - { - return li.getRevision().isResource(); - } - - public boolean isSet(CDOFeature feature) - { - return li.getRevision().isSet(feature); - } - - public boolean isTransactional() - { - return li.getRevision().isTransactional(); - } - - public boolean isValid(long timeStamp) - { - return li.getRevision().isValid(timeStamp); - } - - public int lastIndexOf(CDOFeature feature, Object value) - { - return li.getRevision().lastIndexOf(feature, value); - } - - public void merge(CDORevisionDelta delta) - { - li.getRevision().merge(delta); - } - - public Object move(CDOFeature feature, int targetIndex, int sourceIndex) - { - return li.getRevision().move(feature, targetIndex, sourceIndex); - } - - public Object remove(CDOFeature feature, int index) - { - return li.getRevision().remove(feature, index); - } - - public Object set(CDOFeature feature, int index, Object value) - { - return li.getRevision().set(feature, index, value); - } - - public void setContainerID(CDOID containerID) - { - li.getRevision().setContainerID(containerID); - } - - public void setContainingFeatureID(int containingFeatureID) - { - li.getRevision().setContainingFeatureID(containingFeatureID); - } - - public void setCreated(long created) - { - li.getRevision().setCreated(created); - } - - public void setID(CDOID id) - { - li.getRevision().setID(id); - } - - public void setListSize(CDOFeature feature, int size) - { - li.getRevision().setListSize(feature, size); - } - - public void setResourceID(CDOID resourceID) - { - li.getRevision().setResourceID(resourceID); - } - - public void setRevised(long revised) - { - li.getRevision().setRevised(revised); - } - - public int setTransactional() - { - return li.getRevision().setTransactional(); - } - - public void setUntransactional() - { - li.getRevision().setUntransactional(); - } - - public Object setValue(CDOFeature feature, Object value) - { - return li.getRevision().setValue(feature, value); - } - - public void setVersion(int version) - { - li.getRevision().setVersion(version); - } - - public int size(CDOFeature feature) - { - return li.getRevision().size(feature); - } - - public <T> T[] toArray(CDOFeature feature, T[] array) - { - return li.getRevision().toArray(feature, array); - } - - public Object[] toArray(CDOFeature feature) - { - return li.getRevision().toArray(feature); - } - - public void unset(CDOFeature feature) - { - li.getRevision().unset(feature); - } - - public void write(ExtendedDataOutput out, CDOIDProvider idProvider, int referenceChunk) throws IOException - { - li.getRevision().write(out, idProvider, referenceChunk); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyFactory.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyFactory.java deleted file mode 100644 index 320f6e1469..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 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.hibernate.tuplizer; - -import org.hibernate.HibernateException; -import org.hibernate.engine.SessionImplementor; -import org.hibernate.proxy.HibernateProxy; -import org.hibernate.proxy.ProxyFactory; -import org.hibernate.type.AbstractComponentType; - -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.Set; - -/** - * @author Eike Stepper - */ -public class CDORevisionProxyFactory implements ProxyFactory -{ - private String entityName; - - public CDORevisionProxyFactory() - { - } - - @SuppressWarnings("unchecked") - public void postInstantiate(String entityName, Class persistentClass, Set interfaces, Method getIdentifierMethod, - Method setIdentifierMethod, AbstractComponentType componentIdType) throws HibernateException - { - this.entityName = entityName; - } - - public HibernateProxy getProxy(Serializable id, SessionImplementor session) throws HibernateException - { - return new CDORevisionProxy(new CDORevisionLazyInitializer(entityName, id, session)); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java deleted file mode 100644 index aaafdc0aa7..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionTuplizer.java +++ /dev/null @@ -1,293 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Eike Stepper, Germany, and others - * 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 - * Martin Taal - changed handling of propertygetters/setters - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.model.CDOClass; -import org.eclipse.emf.cdo.common.model.CDOFeature; -import org.eclipse.emf.cdo.common.model.CDOPackage; -import org.eclipse.emf.cdo.common.model.resource.CDOResourcePackage; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore; -import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.eclipse.net4j.util.om.trace.ContextTracer; - -import org.hibernate.EntityMode; -import org.hibernate.HibernateException; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.property.Getter; -import org.hibernate.property.Setter; -import org.hibernate.proxy.ProxyFactory; -import org.hibernate.tuple.Instantiator; -import org.hibernate.tuple.entity.AbstractEntityTuplizer; -import org.hibernate.tuple.entity.EntityMetamodel; - -/** - * @author Eike Stepper - */ -public class CDORevisionTuplizer extends AbstractEntityTuplizer -{ - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDORevisionTuplizer.class); - - private CDOClass cdoClass; - - public CDORevisionTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) - { - super(entityMetamodel, mappingInfo); - if (TRACER.isEnabled()) - { - TRACER.trace("Created CDORevisionTuplizer for entity " + mappingInfo.getEntityName()); - } - - initCDOClass(mappingInfo); - } - - private void initCDOClass(PersistentClass mappingInfo) - { - if (cdoClass != null) - { - return; - } - - HibernateStore hbStore = HibernateStore.getCurrentHibernateStore(); - - // find the CDOClass/Package - // TODO: error handling if meta attribute not present - // TODO: error handling if entityname not set - String entityName = mappingInfo.getEntityName(); - String ePackageURI = mappingInfo.getMetaAttribute("epackage").getValue(); - - if (TRACER.isEnabled()) - { - TRACER.trace("EntityName/packageURI " + entityName + " " + ePackageURI); - } - - for (CDOPackage cdoPackage : hbStore.getPackageHandler().getCDOPackages()) - { - if (cdoPackage.getPackageURI().compareTo(ePackageURI) != 0) - { - continue; - } - - for (CDOClass localCdoClass : cdoPackage.getClasses()) - { - if (localCdoClass.getName().compareTo(entityName) == 0) - { - cdoClass = localCdoClass; - break; - } - } - } - - if (cdoClass == null && ePackageURI.compareTo(CDOResourcePackage.PACKAGE_URI) == 0) - { - for (CDOClass localCdoClass : hbStore.getRepository().getPackageManager().getCDOResourcePackage().getClasses()) - { - if (localCdoClass.getName().compareTo(entityName) == 0) - { - cdoClass = localCdoClass; - if (TRACER.isEnabled()) - { - TRACER.trace("Class is CDOResource class"); - } - - break; - } - } - } - - if (cdoClass == null) - { - throw new IllegalArgumentException("The mapped class " + mappingInfo.getEntityName()); - } - } - - // MT: probably not required as the property getter/setter do all the work - // /* - // * (non-Javadoc) - // * - // * @see org.hibernate.tuple.entity.AbstractEntityTuplizer#getVersion(java.lang.Object) - // */ - // @Override - // public Object getVersion(Object entity) throws HibernateException - // { - // if (entity instanceof CDORevision) - // { - // final CDORevision cdoRevision = (CDORevision)entity; - // return cdoRevision.getVersion(); - // } - // throw new IllegalArgumentException("Entity of type: " + entity.getClass().getName() - // + " not supported by this tuplizer"); - // } - // - // @Override - // public Serializable getIdentifier(Object entity) throws HibernateException - // { - // if (entity instanceof CDORevision) - // { - // final CDOID cdoID = ((CDORevision)entity).getID(); - // if (cdoID instanceof CDOIDHibernate) - // { - // return ((CDOIDHibernate)cdoID).getId(); - // } - // } - // throw new IllegalArgumentException("Entity of type: " + entity.getClass().getName() - // + " not supported by this tuplizer"); - // } - // - // @Override - // public void setIdentifier(Object entity, Serializable id) throws HibernateException - // { - // if (entity instanceof InternalCDORevision) - // { - // final InternalCDORevision cdoRevision = (InternalCDORevision)entity; - // final CDOID cdoID = cdoRevision.getID(); - // if (cdoID == null) - // { - // CDOIDHibernate hid = (CDOIDHibernate)HibernateStore.CDOID_OBJECT_FACTORY.createCDOIDObject(null); - // hid.setId(id); - // cdoRevision.setID(hid); - // return; - // } - // else if (cdoID instanceof CDOIDHibernate) - // { - // ((CDOIDHibernate)cdoID).setId(id); - // return; - // } - // } - // throw new IllegalArgumentException("Entity of type: " + entity.getClass().getName() - // + " not supported by this tuplizer"); - // } - - @Override - public EntityMode getEntityMode() - { - return EntityMode.MAP; - } - - public CDOClass getCDOClass() - { - return cdoClass; - } - - @Override - protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) - { - initCDOClass(mappedEntity); - if (TRACER.isEnabled()) - { - TRACER.trace("Building property getter for " + cdoClass.getName() + "." + mappedProperty.getName()); - } - - if (mappedProperty.isBackRef()) - { - return mappedProperty.getGetter(mappedEntity.getMappedClass()); - } - else if (mappedProperty == mappedEntity.getIdentifierProperty()) - { - return new CDOIDPropertyGetter(this, mappedProperty.getName()); - } - else if (mappedProperty == mappedEntity.getVersion()) - { - return new CDOVersionPropertyGetter(this, mappedProperty.getName()); - } - - CDOFeature cdoFeature = getCDOClass().lookupFeature(mappedProperty.getName()); - if (cdoFeature.isReference() && cdoFeature.isMany()) - { - return new CDOManyReferenceGetter(this, mappedProperty.getName()); - } - else if (cdoFeature.isReference()) - { - return new CDOReferenceGetter(this, mappedProperty.getName()); - } - - return new CDOPropertyGetter(this, mappedProperty.getName()); - } - - @Override - protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) - { - initCDOClass(mappedEntity); - if (TRACER.isEnabled()) - { - TRACER.trace("Building property setter for " + cdoClass.getName() + "." + mappedProperty.getName()); - } - - if (mappedProperty.isBackRef()) - { - return mappedProperty.getSetter(mappedEntity.getMappedClass()); - } - else if (mappedProperty == mappedEntity.getIdentifierProperty()) - { - return new CDOIDPropertySetter(this, mappedProperty.getName()); - } - else if (mappedProperty == mappedEntity.getVersion()) - { - return new CDOVersionPropertySetter(this, mappedProperty.getName()); - } - - CDOFeature cdoFeature = getCDOClass().lookupFeature(mappedProperty.getName()); - if (cdoFeature.isReference() && cdoFeature.isMany()) - { - return new CDOManyReferenceSetter(this, mappedProperty.getName()); - } - else if (cdoFeature.isReference()) - { - return new CDOReferenceSetter(this, mappedProperty.getName()); - } - - return new CDOPropertySetter(this, mappedProperty.getName()); - } - - @Override - protected Instantiator buildInstantiator(PersistentClass mappingInfo) - { - return new CDORevisionInstantiator(this, mappingInfo); - } - - @Override - protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) - { - ProxyFactory pf = new CDORevisionProxyFactory(); - - try - { - pf.postInstantiate(getEntityName(), null, null, null, null, null); - } - catch (HibernateException ex) - { - OM.LOG.error("Could not create proxy factory for " + getEntityName(), ex); - pf = null; - } - - return pf; - } - - @SuppressWarnings("unchecked") - public Class getMappedClass() - { - return InternalCDORevision.class; - } - - @SuppressWarnings("unchecked") - public Class getConcreteProxyClass() - { - return InternalCDORevision.class; - } - - public boolean isInstrumented() - { - return false; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticIdPropertyHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticIdPropertyHandler.java deleted file mode 100644 index 3e19ef47e2..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticIdPropertyHandler.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * <copyright> - * - * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others - * 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: - * Martin Taal - * </copyright> - * - * $Id: CDOSyntheticIdPropertyHandler.java,v 1.5 2008-06-15 20:47:36 mtaal Exp $ - */ - -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.id.CDOID; -import org.eclipse.emf.cdo.common.id.CDOIDTemp; -import org.eclipse.emf.cdo.server.hibernate.id.CDOIDHibernate; -import org.eclipse.emf.cdo.server.hibernate.internal.id.CDOIDHibernateFactoryImpl; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateCommitContext; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; -import org.hibernate.PropertyNotFoundException; -import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.engine.SessionImplementor; -import org.hibernate.property.Getter; -import org.hibernate.property.PropertyAccessor; -import org.hibernate.property.Setter; - -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.Map; - -/** - * Is only used for synthetic id's. - * - * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.5 $ - */ -@SuppressWarnings("unchecked") -public class CDOSyntheticIdPropertyHandler implements Getter, Setter, PropertyAccessor -{ - private static final long serialVersionUID = 1L; - - public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException - { - return this; - } - - public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException - { - return this; - } - - public Object get(Object owner) throws HibernateException - { - InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(owner); - if (revision == null) - { - return null; - } - - if (!(revision.getID() instanceof CDOIDHibernate)) - { - return null; - } - - CDOIDHibernate cdoID = (CDOIDHibernate)revision.getID(); - return cdoID.getId(); - } - - public Object getForInsert(Object arg0, Map arg1, SessionImplementor arg2) throws HibernateException - { - return get(arg0); - } - - public Method getMethod() - { - return null; - } - - public String getMethodName() - { - return null; - } - - public Class getReturnType() - { - return null; - } - - public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException - { - if (value == null) - { - return; - } - - HibernateCommitContext hcc = null; - if (HibernateThreadContext.isHibernateCommitContextSet()) - { - hcc = HibernateThreadContext.getHibernateCommitContext(); - } - - InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(target); - CDOID cdoID = revision.getID(); - if (cdoID == null) - { - CDOIDHibernate newCDOID = CDOIDHibernateFactoryImpl.getInstance().createCDOID((Serializable)value, - revision.getCDOClass().getName()); - revision.setID(newCDOID); - if (hcc != null) - { - hcc.setNewID(cdoID, newCDOID); - } - } - else if (cdoID instanceof CDOIDTemp) - { - CDOIDHibernate newCDOID = CDOIDHibernateFactoryImpl.getInstance().createCDOID((Serializable)value, - revision.getCDOClass().getName()); - revision.setID(newCDOID); - if (hcc != null) - { - hcc.getCommitContext().addIDMapping((CDOIDTemp)cdoID, newCDOID); - hcc.setNewID(cdoID, newCDOID); - } - } - else - { - CDOIDHibernate hbCDOID = (CDOIDHibernate)revision.getID(); - if (!hbCDOID.getId().equals(value)) - { - throw new IllegalStateException("Current id and new id are different " + value + "/" + hbCDOID.getId()); - } - } - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticVersionPropertyHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticVersionPropertyHandler.java deleted file mode 100644 index c998ea2f44..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOSyntheticVersionPropertyHandler.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * <copyright> - * - * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others - * 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: - * Martin Taal - * </copyright> - * - * $Id: CDOSyntheticVersionPropertyHandler.java,v 1.3 2008-06-03 09:45:56 estepper Exp $ - */ - -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; -import org.hibernate.PropertyNotFoundException; -import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.engine.SessionImplementor; -import org.hibernate.property.Getter; -import org.hibernate.property.PropertyAccessor; -import org.hibernate.property.Setter; - -import java.lang.reflect.Method; -import java.util.Map; - -/** - * Reads the version from the internal version cache. - * - * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> - * @version $Revision: 1.3 $ - */ -@SuppressWarnings("unchecked") -public class CDOSyntheticVersionPropertyHandler implements Getter, Setter, PropertyAccessor -{ - private static final long serialVersionUID = 1L; - - public CDOSyntheticVersionPropertyHandler() - { - } - - public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException - { - return this; - } - - public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException - { - return this; - } - - public Object get(Object owner) throws HibernateException - { - InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(owner); - if (revision == null) - { - return null; - } - - return revision.getVersion(); - } - - /** - * Reads the version from the versioncache - */ - public Object getForInsert(Object owner, Map mergeMap, SessionImplementor session) throws HibernateException - { - return get(owner); - } - - public Method getMethod() - { - return null; - } - - public String getMethodName() - { - return null; - } - - /** Returns Integer.class */ - public Class getReturnType() - { - return Integer.class; - } - - /** Sets the version in the internal version cache */ - public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException - { - InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(target); - revision.setVersion(((Number)value).intValue()); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOTypeUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOTypeUserType.java deleted file mode 100644 index ee5b80f891..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOTypeUserType.java +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2008 - 2008 Martin Taal and others - * 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: - * Martin Taal - initial api - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.model.CDOModelUtil; -import org.eclipse.emf.cdo.common.model.CDOType; - -import org.hibernate.Hibernate; -import org.hibernate.usertype.UserType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; - -/** - * @author Martin Taal - */ -public class CDOTypeUserType implements UserType -{ - private static final int[] SQL_TYPES = { Types.INTEGER }; - - public CDOTypeUserType() - { - } - - public int[] sqlTypes() - { - return SQL_TYPES; - } - - public Class<?> returnedClass() - { - return CDOType.class; - } - - public boolean isMutable() - { - return false; - } - - public Object deepCopy(Object value) - { - return value; - } - - public boolean equals(Object x, Object y) - { - if (x == y) - { - return true; - } - - if (x == null || y == null) - { - return false; - } - - return x.equals(y); - } - - public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException - { - Integer value = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[0]); - if (rs.wasNull()) - { - return null; - } - - if (value == null) - { - return null; - } - - return CDOModelUtil.getType(value); - } - - public void nullSafeSet(PreparedStatement statement, Object value, int index) throws SQLException - { - if (value != null) - { - statement.setInt(index, ((CDOType)value).getTypeID()); - } - else - { - statement.setNull(index, Types.INTEGER); - } - } - - public Serializable disassemble(Object value) - { - return (Serializable)value; - } - - public Object assemble(Serializable cachedValue, Object owner) - { - return cachedValue; - } - - public Object replace(Object original, Object target, Object owner) - { - return original; - } - - public int hashCode(Object x) - { - return x.hashCode(); - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertyGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertyGetter.java deleted file mode 100644 index 2f366219fa..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertyGetter.java +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; - -/** - * @author Martin Taal - */ -public class CDOVersionPropertyGetter extends CDOPropertyGetter -{ - private static final long serialVersionUID = 1L; - - public CDOVersionPropertyGetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - @Override - public Object get(Object target) throws HibernateException - { - InternalCDORevision revision = (InternalCDORevision)target; - if (isVirtualProperty()) - { - return revision.getVersion(); - } - - Object version = super.get(target); - // TODO: does this make sense? - // revision.setVersion(((Number)value).intValue()); - return version; - } - - @Override - protected boolean isVirtualPropertyAllowed() - { - return true; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertySetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertySetter.java deleted file mode 100644 index c0b7a9e019..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertySetter.java +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.spi.common.InternalCDORevision; - -import org.hibernate.HibernateException; -import org.hibernate.engine.SessionFactoryImplementor; - -/** - * @author Martin Taal - */ -public class CDOVersionPropertySetter extends CDOPropertySetter -{ - private static final long serialVersionUID = 1L; - - public CDOVersionPropertySetter(CDORevisionTuplizer tuplizer, String propertyName) - { - super(tuplizer, propertyName); - } - - @Override - public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException - { - InternalCDORevision revision = (InternalCDORevision)target; - revision.setVersion(((Number)value).intValue()); - if (!isVirtualProperty()) - { - super.set(target, value, factory); - } - } - - @Override - protected boolean isVirtualPropertyAllowed() - { - return true; - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java deleted file mode 100644 index 9234a5d54d..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java +++ /dev/null @@ -1,325 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2008 - 2008 Martin Taal and others - * 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: - * Martin Taal - initial api - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.id.CDOID; -import org.eclipse.emf.cdo.common.revision.CDORevision; -import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; - -import org.eclipse.net4j.util.collection.MoveableList; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -/** - * Wraps a moveable list so that hibernate always sees an object view while cdo always sees a cdoid view. - * - * @author Martin Taal - */ -public class HibernateMoveableListWrapper implements List<Object> -{ - private MoveableList<Object> delegate; - - public HibernateMoveableListWrapper() - { - } - - /** - * @return the delegate - */ - public MoveableList<Object> getDelegate() - { - return delegate; - } - - /** - * @param delegate - * the delegate to set - */ - public void setDelegate(MoveableList<Object> delegate) - { - this.delegate = delegate; - } - - protected Object getObject(Object o) - { - if (o == null) - { - return null; - } - - // is already resolved - if (!(o instanceof CDOID)) - { - return o; - } - - return HibernateUtil.getInstance().getCDORevision((CDOID)o); - } - - protected List<Object> getObjects(List<?> cdoIDs) - { - List<Object> result = new ArrayList<Object>(); - for (Object o : cdoIDs) - { - result.add(getObject(o)); - } - - return result; - } - - protected CDOID getCDOID(Object o) - { - CDORevision cdoRevision = (CDORevision)o; - return cdoRevision.getID(); - } - - protected List<CDOID> getCDOIDs(Collection<?> c) - { - List<CDOID> newC = new ArrayList<CDOID>(); - for (Object o : c) - { - newC.add(getCDOID(o)); - } - - return newC; - } - - public void add(int index, Object element) - { - getDelegate().add(index, getCDOID(element)); - } - - public boolean add(Object o) - { - return getDelegate().add(getCDOID(o)); - } - - public boolean addAll(Collection<? extends Object> c) - { - return getDelegate().addAll(getCDOIDs(c)); - } - - public boolean addAll(int index, Collection<? extends Object> c) - { - return getDelegate().addAll(index, getCDOIDs(c)); - } - - public void clear() - { - getDelegate().clear(); - } - - public boolean contains(Object o) - { - return getDelegate().contains(getCDOID(o)); - } - - public boolean containsAll(Collection<?> c) - { - return getDelegate().containsAll(getCDOIDs(c)); - } - - public Object get(int index) - { - return getObject(getDelegate().get(index)); - } - - public int indexOf(Object o) - { - return getDelegate().indexOf(getCDOID(o)); - } - - public boolean isEmpty() - { - return getDelegate().isEmpty(); - } - - public Iterator<Object> iterator() - { - return new CDOHibernateIterator(getDelegate().iterator()); - } - - public int lastIndexOf(Object o) - { - return getDelegate().lastIndexOf(getCDOID(o)); - } - - public ListIterator<Object> listIterator() - { - return new CDOHibernateListIterator(getDelegate().listIterator()); - } - - public ListIterator<Object> listIterator(int index) - { - return new CDOHibernateListIterator(getDelegate().listIterator(index)); - } - - public Object remove(int index) - { - return getDelegate().remove(index); - } - - public boolean remove(Object o) - { - return getDelegate().remove(getCDOID(o)); - } - - public boolean removeAll(Collection<?> c) - { - return getDelegate().removeAll(getCDOIDs(c)); - } - - public boolean retainAll(Collection<?> c) - { - return getDelegate().retainAll(getCDOIDs(c)); - } - - public Object set(int index, Object element) - { - return getDelegate().set(index, getCDOID(element)); - } - - public int size() - { - return getDelegate().size(); - } - - public List<Object> subList(int fromIndex, int toIndex) - { - return getObjects(getDelegate().subList(fromIndex, toIndex)); - } - - public Object[] toArray() - { - Object[] result = new Object[size()]; - int i = 0; - for (Object o : this) - { - result[i++] = o; - } - - return result; - } - - @SuppressWarnings("unchecked") - public <T> T[] toArray(T[] a) - { - int i = 0; - for (Object o : this) - { - a[i++] = (T)o; - } - - return a; - } - - private static final class CDOHibernateIterator implements Iterator<Object> - { - private final Iterator<?> delegate; - - public CDOHibernateIterator(Iterator<?> delegate) - { - this.delegate = delegate; - } - - public boolean hasNext() - { - return delegate.hasNext(); - } - - public Object next() - { - Object o = delegate.next(); - if (o instanceof CDOID) - { - return HibernateUtil.getInstance().getCDORevision((CDOID)o); - } - - return o; - } - - public void remove() - { - delegate.remove(); - } - } - - private static final class CDOHibernateListIterator implements ListIterator<Object> - { - private final ListIterator<Object> delegate; - - public CDOHibernateListIterator(ListIterator<Object> delegate) - { - this.delegate = delegate; - } - - public void add(Object o) - { - delegate.add(((CDORevision)o).getID()); - } - - public boolean hasNext() - { - return delegate.hasNext(); - } - - public boolean hasPrevious() - { - return delegate.hasPrevious(); - } - - public Object next() - { - Object o = delegate.next(); - if (o instanceof CDOID) - { - return HibernateUtil.getInstance().getCDORevision((CDOID)delegate.next()); - } - - return o; - } - - public int nextIndex() - { - return delegate.nextIndex(); - } - - public Object previous() - { - Object o = delegate.previous(); - if (o instanceof CDOID) - { - return HibernateUtil.getInstance().getCDORevision((CDOID)delegate.next()); - } - - return o; - } - - public int previousIndex() - { - return delegate.previousIndex(); - } - - public void remove() - { - delegate.remove(); - } - - public void set(Object o) - { - delegate.set(((CDORevision)o).getID()); - } - } -} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/PersistableListHolder.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/PersistableListHolder.java deleted file mode 100644 index 108747dca9..0000000000 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/PersistableListHolder.java +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004 - 2008 Martin Taal and others - * 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: - * Martin Taal - copied from CDORevisionPropertyHandler and adapted - **************************************************************************/ -package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; - -import org.eclipse.emf.cdo.common.model.CDOFeature; -import org.eclipse.emf.cdo.common.revision.CDORevision; -import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM; - -import org.eclipse.net4j.util.om.trace.ContextTracer; - -import org.hibernate.collection.PersistentCollection; - -import java.util.HashMap; -import java.util.Map; - -/** - * Keeps mappings from object/feature combinations to a hibernate persistable list. This works because the write action - * is done in one thread. - * - * @author Martin Taal - */ -public class PersistableListHolder -{ - private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, PersistableListHolder.class); - - private static PersistableListHolder instance = new PersistableListHolder(); - - private ThreadLocal<Map<Key, PersistentCollection>> listMapping = new ThreadLocal<Map<Key, PersistentCollection>>(); - - public PersistableListHolder() - { - } - - public void putListMapping(Object target, CDOFeature cdoFeature, PersistentCollection collection) - { - Key key = new Key(target, cdoFeature); - getListMapping().put(key, collection); - if (TRACER.isEnabled()) - { - TRACER.trace("Stored hb list in threadlocal: " + ((CDORevision)target).getCDOClass().getName() + "." - + cdoFeature.getName()); - } - } - - public PersistentCollection getListMapping(Object target, CDOFeature cdoFeature) - { - Key key = new Key(target, cdoFeature); - return getListMapping().get(key); - } - - private Map<Key, PersistentCollection> getListMapping() - { - if (listMapping.get() == null) - { - listMapping.set(new HashMap<Key, PersistentCollection>()); - } - - return listMapping.get(); - } - - public static PersistableListHolder getInstance() - { - return instance; - } - - public static void setInstance(PersistableListHolder instance) - { - PersistableListHolder.instance = instance; - } - - private static final class Key - { - private Object owner; - - private CDOFeature cdoFeature; - - public Key(Object owner, CDOFeature cdoFeature) - { - this.owner = owner; - this.cdoFeature = cdoFeature; - } - - @Override - public boolean equals(Object obj) - { - if (!(obj instanceof Key)) - { - return false; - } - - Key otherKey = (Key)obj; - // the owner is uniquely present in mem, the same applies for the cdoFeature - // therefore == is allowed - return owner == otherKey.owner && cdoFeature == otherKey.cdoFeature; - } - - @Override - public int hashCode() - { - return owner.hashCode() + cdoFeature.hashCode(); - } - } -} |