diff options
26 files changed, 1099 insertions, 458 deletions
diff --git a/features/org.eclipse.emf.cdo.server.hibernate-feature/feature.xml b/features/org.eclipse.emf.cdo.server.hibernate-feature/feature.xml index 9de19d66ac..1b115010f4 100644 --- a/features/org.eclipse.emf.cdo.server.hibernate-feature/feature.xml +++ b/features/org.eclipse.emf.cdo.server.hibernate-feature/feature.xml @@ -12,7 +12,7 @@ <feature id="org.eclipse.emf.cdo.server.hibernate" label="%featureName" - version="4.2.0.qualifier" + version="4.2.1.qualifier" provider-name="%providerName" license-feature="org.eclipse.emf.cdo.license" license-feature-version="0.0.0"> diff --git a/features/org.eclipse.emf.cdo.tests.hibernate-feature/feature.xml b/features/org.eclipse.emf.cdo.tests.hibernate-feature/feature.xml index a6b3492a33..0b8074b47c 100644 --- a/features/org.eclipse.emf.cdo.tests.hibernate-feature/feature.xml +++ b/features/org.eclipse.emf.cdo.tests.hibernate-feature/feature.xml @@ -12,7 +12,7 @@ <feature id="org.eclipse.emf.cdo.tests.hibernate" label="%featureName" - version="4.2.0.qualifier" + version="4.2.1.qualifier" provider-name="%providerName" license-feature="org.eclipse.emf.cdo.license" license-feature-version="0.0.0"> @@ -43,6 +43,6 @@ download-size="0" install-size="0" version="0.0.0" - unpack="false"/> <!-- Used to be true --> + unpack="false"/> </feature> diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF index 6937c17fca..ea7f705695 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.emf.cdo.server.hibernate;singleton:=true -Bundle-Version: 4.2.0.qualifier +Bundle-Version: 4.2.1.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin @@ -14,42 +14,44 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.emf.cdo.common;bundle-version="[4.0.0,5.0.0)", org.eclipse.emf.cdo.server;bundle-version="[4.0.0,5.0.0)";visibility:=reexport, org.eclipse.net4j.db;bundle-version="[4.0.0,5.0.0)";visibility:=reexport -Export-Package: org.eclipse.emf.cdo.server.hibernate;version="4.2.0", - org.eclipse.emf.cdo.server.internal.hibernate;version="4.2.0";x-friends:="org.eclipse.emf.cdo.server.hibernate.teneo,org.eclipse.emf.cdo.tests.hibernate", - org.eclipse.emf.cdo.server.internal.hibernate.bundle;version="4.2.0";x-internal:=true, - org.eclipse.emf.cdo.server.internal.hibernate.info;version="4.2.0";x-friends:="org.eclipse.emf.cdo.server.hibernate.teneo,org.eclipse.emf.cdo.tests.hibernate", - org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;version="4.2.0";x-friends:="org.eclipse.emf.cdo.server.hibernate.teneo,org.eclipse.emf.cdo.tests.hibernate" -Import-Package: org.apache.log4j;version="[1.2.12, 1.3.0)", +Export-Package: org.eclipse.emf.cdo.server.hibernate;version="4.2.1", + org.eclipse.emf.cdo.server.internal.hibernate;version="4.2.1";x-friends:="org.eclipse.emf.cdo.server.hibernate.teneo,org.eclipse.emf.cdo.tests.hibernate", + org.eclipse.emf.cdo.server.internal.hibernate.bundle;version="4.2.1";x-internal:=true, + org.eclipse.emf.cdo.server.internal.hibernate.info;version="4.2.1";x-friends:="org.eclipse.emf.cdo.server.hibernate.teneo,org.eclipse.emf.cdo.tests.hibernate", + org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;version="4.2.1";x-friends:="org.eclipse.emf.cdo.server.hibernate.teneo,org.eclipse.emf.cdo.tests.hibernate" +Import-Package: org.apache.log4j;version="[1.2.12,1.3.0)", + org.eclipse.emf.teneo;version="[2.0.1,3.0.0)", + org.eclipse.emf.teneo.annotations.mapper;version="[2.0.1,3.0.0)", + org.eclipse.emf.teneo.annotations.pamodel;version="[2.0.1,3.0.0)", + org.eclipse.emf.teneo.extension;version="[2.0.1,3.0.0)", + org.eclipse.emf.teneo.hibernate;version="[2.0.1,3.0.0)", + org.eclipse.emf.teneo.hibernate.auditing;version="[2.0.1,3.0.0)", + org.eclipse.emf.teneo.hibernate.auditing.model.teneoauditing;version="[2.0.1,3.0.0)", + org.eclipse.emf.teneo.hibernate.mapper;version="[2.0.1,3.0.0)", + org.eclipse.emf.teneo.util;version="[2.0.1,3.0.0)", org.hibernate;version="[4.0.0,5.0.0)", - org.hibernate.service;version="[4.0.0,5.0.0)", - org.hibernate.event.service.spi;version="[4.0.0,5.0.0)", - org.hibernate.internal;version="[4.0.0,5.0.0)", - org.hibernate.event.spi;version="[4.0.0,5.0.0)", - org.hibernate.collection.spi;version="[4.0.0,5.0.0)", - org.hibernate.metamodel.binding;version="[4.0.0,5.0.0)", - org.hibernate.engine.spi;version="[4.0.0,5.0.0)", - org.hibernate.event.internal;version="[4.0.0,5.0.0)", org.hibernate.cfg;version="[4.0.0,5.0.0)", + org.hibernate.collection.internal;version="[4.0.0,5.0.0)", + org.hibernate.collection.spi;version="[4.0.0,5.0.0)", org.hibernate.criterion;version="[4.0.0,5.0.0)", org.hibernate.engine;version="[4.0.0,5.0.0)", + org.hibernate.engine.spi;version="[4.0.0,5.0.0)", + org.hibernate.event.internal;version="[4.0.0,5.0.0)", + org.hibernate.event.service.spi;version="[4.0.0,5.0.0)", + org.hibernate.event.spi;version="[4.0.0,5.0.0)", org.hibernate.id;version="[4.0.0,5.0.0)", + org.hibernate.internal;version="[4.0.0,5.0.0)", org.hibernate.mapping;version="[4.0.0,5.0.0)", org.hibernate.metadata;version="[4.0.0,5.0.0)", + org.hibernate.metamodel.binding;version="[4.0.0,5.0.0)", + org.hibernate.persister.collection;version="[4.0.0,5.0.0)", org.hibernate.persister.entity;version="[4.0.0,5.0.0)", org.hibernate.property;version="[4.0.0,5.0.0)", org.hibernate.proxy;version="[4.0.0,5.0.0)", + org.hibernate.service;version="[4.0.0,5.0.0)", org.hibernate.tool.hbm2ddl;version="[4.0.0,5.0.0)", org.hibernate.tuple;version="[4.0.0,5.0.0)", org.hibernate.tuple.component;version="[4.0.0,5.0.0)", org.hibernate.tuple.entity;version="[4.0.0,5.0.0)", org.hibernate.type;version="[4.0.0,5.0.0)", - org.hibernate.usertype;version="[4.0.0,5.0.0)", - org.eclipse.emf.teneo;version="[2.0.1, 3.0.0)", - org.eclipse.emf.teneo.util;version="[2.0.1, 3.0.0)", - org.eclipse.emf.teneo.extension;version="[2.0.1, 3.0.0)", - org.eclipse.emf.teneo.annotations.mapper;version="[2.0.1, 3.0.0)", - org.eclipse.emf.teneo.annotations.pamodel;version="[2.0.1, 3.0.0)", - org.eclipse.emf.teneo.hibernate;version="[2.0.1, 3.0.0)", - org.eclipse.emf.teneo.hibernate.mapper;version="[2.0.1, 3.0.0)", - org.eclipse.emf.teneo.hibernate.auditing;version="[2.0.1, 3.0.0)", - org.eclipse.emf.teneo.hibernate.auditing.model.teneoauditing;version="[2.0.1, 3.0.0)" + org.hibernate.usertype;version="[4.0.0,5.0.0)" diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java index 99b780eb64..d436bd1ec0 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java @@ -27,7 +27,6 @@ import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.teneo.hibernate.auditing.model.teneoauditing.TeneoAuditEntry; -import org.hibernate.Hibernate; import org.hibernate.Query; import org.hibernate.ScrollMode; import org.hibernate.ScrollableResults; @@ -43,17 +42,6 @@ import java.lang.reflect.Array; */ public class HibernateQueryHandler implements IQueryHandler { - /** - * @deprecated use {@link IHibernateStore#QUERY_LANGUAGE} - */ - @Deprecated - public static final String QUERY_LANGUAGE = IHibernateStore.QUERY_LANGUAGE; - - /** - * @deprecated use {@link IHibernateStore#FIRST_RESULT} - */ - @Deprecated - public static final String FIRST_RESULT = IHibernateStore.FIRST_RESULT; private HibernateStoreAccessor hibernateStoreAccessor; @@ -75,124 +63,130 @@ public class HibernateQueryHandler implements IQueryHandler // get a transaction, the hibernateStoreAccessor is placed in a threadlocal // so all db access uses the same session. final Session session = hibernateStoreAccessor.getHibernateSession(); - - // create the query - final Query query = session.createQuery(info.getQueryString()); - query.setReadOnly(true); - - // get the parameters with some parameter conversion - int firstResult = -1; - boolean cacheResults = true; - for (String key : info.getParameters().keySet()) + try { - if (key.compareToIgnoreCase(IHibernateStore.CACHE_RESULTS) == 0) - { - try - { - cacheResults = (Boolean)info.getParameters().get(key); - } - catch (ClassCastException e) - { - throw new IllegalArgumentException( - "Parameter " + IHibernateStore.CACHE_RESULTS + " must be a boolean. errorMessage " + e.getMessage()); //$NON-NLS-1$ - } - } - else if (key.compareToIgnoreCase(IHibernateStore.FIRST_RESULT) == 0) + // create the query + final Query query = session.createQuery(info.getQueryString()); + query.setReadOnly(true); + + // get the parameters with some parameter conversion + int firstResult = -1; + boolean cacheResults = true; + for (String key : info.getParameters().keySet()) { - final Object o = info.getParameters().get(key); - if (o != null) + if (key.compareToIgnoreCase(IHibernateStore.CACHE_RESULTS) == 0) { try { - firstResult = (Integer)o; + cacheResults = (Boolean)info.getParameters().get(key); } catch (ClassCastException e) { - throw new IllegalArgumentException("Parameter firstResult must be an integer but it is a " + o //$NON-NLS-1$ - + " class " + o.getClass().getName()); //$NON-NLS-1$ + throw new IllegalArgumentException( + "Parameter " + IHibernateStore.CACHE_RESULTS + " must be a boolean. errorMessage " + e.getMessage()); //$NON-NLS-1$ } } - } - else - { - // in case the parameter is a CDOID get the object from the db - final Object param = info.getParameters().get(key); - if (param instanceof CDOID && HibernateUtil.getInstance().isStoreCreatedID((CDOID)param)) + else if (key.compareToIgnoreCase(IHibernateStore.FIRST_RESULT) == 0) { - final CDOID id = (CDOID)param; - final String entityName = HibernateUtil.getInstance().getEntityName(id); - final Serializable idValue = HibernateUtil.getInstance().getIdValue(id); - final CDORevision revision = (CDORevision)session.get(entityName, idValue); - query.setEntity(key, revision); - if (cacheResults) + final Object o = info.getParameters().get(key); + if (o != null) { - addToRevisionCache(revision); + try + { + firstResult = (Integer)o; + } + catch (ClassCastException e) + { + throw new IllegalArgumentException("Parameter firstResult must be an integer but it is a " + o //$NON-NLS-1$ + + " class " + o.getClass().getName()); //$NON-NLS-1$ + } } } else { - query.setParameter(key, param); + // in case the parameter is a CDOID get the object from the db + final Object param = info.getParameters().get(key); + if (param instanceof CDOID && HibernateUtil.getInstance().isStoreCreatedID((CDOID)param)) + { + final CDOID id = (CDOID)param; + final String entityName = HibernateUtil.getInstance().getEntityName(id); + final Serializable idValue = HibernateUtil.getInstance().getIdValue(id); + final CDORevision revision = (CDORevision)session.get(entityName, idValue); + query.setEntity(key, revision); + if (cacheResults) + { + addToRevisionCache(revision); + } + } + else + { + query.setParameter(key, param); + } } } - } - // set the first result - if (firstResult > -1) - { - query.setFirstResult(firstResult); - } + // set the first result + if (firstResult > -1) + { + query.setFirstResult(firstResult); + } - // the max result - if (info.getMaxResults() != CDOQueryInfo.UNLIMITED_RESULTS) - { - query.setMaxResults(info.getMaxResults()); - } + // the max result + if (info.getMaxResults() != CDOQueryInfo.UNLIMITED_RESULTS) + { + query.setMaxResults(info.getMaxResults()); + } - final ScrollableResults scroller = query.scroll(ScrollMode.FORWARD_ONLY); + final ScrollableResults scroller = query.scroll(ScrollMode.FORWARD_ONLY); - // and go for the query - // future extension: support iterate, scroll through a parameter - int i = 0; - try - { - while (scroller.next()) + // and go for the query + // future extension: support iterate, scroll through a parameter + int i = 0; + try { - Object[] os = scroller.get(); - Object o; - if (os.length == 1) - { - o = handleAuditEntries(os[0]); - } - else + while (scroller.next()) { - o = handleAuditEntries(os); - } + Object[] os = scroller.get(); + Object o; + if (os.length == 1) + { + o = handleAuditEntries(os[0]); + } + else + { + o = handleAuditEntries(os); + } - final boolean addOneMore = context.addResult(o); - if (cacheResults && o instanceof CDORevision) - { - addToRevisionCache((CDORevision)o); - } - if (o instanceof InternalCDORevision) - { - ((InternalCDORevision)o).freeze(); - } + final boolean addOneMore = context.addResult(o); + if (cacheResults && o instanceof CDORevision) + { + addToRevisionCache((CDORevision)o); + } + if (o instanceof InternalCDORevision) + { + ((InternalCDORevision)o).freeze(); + } - // clear the session every 1000 results or so - if (i++ % 1000 == 0) - { - session.clear(); - } + // clear the session every 1000 results or so + if (i++ % 1000 == 0) + { + session.clear(); + } - if (!addOneMore) - { - return; + if (!addOneMore) + { + return; + } } } + finally + { + scroller.close(); + } } finally { - scroller.close(); + session.close(); } } @@ -264,11 +258,8 @@ public class HibernateQueryHandler implements IQueryHandler final Object value = internalRevision.getValue(feature); if (value instanceof WrappedHibernateList) { - Hibernate.initialize(((WrappedHibernateList)value).getDelegate()); - } - else - { - Hibernate.initialize(value); + // force the size to be cached + ((WrappedHibernateList)value).size(); } } } diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java index 09f6233a70..226e0a7cca 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java @@ -48,7 +48,6 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta; import org.eclipse.emf.cdo.spi.server.InternalCommitContext; import org.eclipse.emf.cdo.spi.server.Store; import org.eclipse.emf.cdo.spi.server.StoreAccessor; -import org.eclipse.emf.cdo.spi.server.StoreChunkReader; import org.eclipse.net4j.util.HexUtil; import org.eclipse.net4j.util.ObjectUtil; @@ -126,6 +125,8 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS private boolean errorOccured; + private int currentListChunk = -1; + private HibernateRawCommitContext rawCommitContext = new HibernateRawCommitContext(); public void addToRevisionCache(Object object) @@ -326,9 +327,7 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS } /** - * Note: the Hibernate store does not support the {@link StoreChunkReader} concept!. - * - * @return a {@link HibernateStoreChunkReader} (which throws UnsupportedOperationExceptions for most methods + * @return a {@link HibernateStoreChunkReader} */ public HibernateStoreChunkReader createChunkReader(InternalCDORevision revision, EStructuralFeature feature) { @@ -376,47 +375,54 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS { return null; } - - if (getStore().isAuditing() && getStore().getHibernateAuditHandler().getCDOAuditHandler().isAudited(id)) + currentListChunk = listChunk; + try { - InternalCDORevision revision = getStore().getHibernateAuditHandler().readRevision(getHibernateSession(), id, - branchPoint.getTimeStamp()); - // found one, use it - if (revision != null) + if (getStore().isAuditing() && getStore().getHibernateAuditHandler().getCDOAuditHandler().isAudited(id)) { + InternalCDORevision revision = getStore().getHibernateAuditHandler().readRevision(getHibernateSession(), id, + branchPoint.getTimeStamp()); + // found one, use it + if (revision != null) + { + + if (cache != null) + { + cache.addRevision(revision); + } + revision.freeze(); - if (cache != null) + return revision; + } + } + + final InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(id); + if (revision == null) + { + final CDOClassifierRef classifierRef = CDOIDUtil.getClassifierRef(id); + if (classifierRef == null) { - cache.addRevision(revision); + throw new IllegalArgumentException("This CDOID type of " + id + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$ } - revision.freeze(); - return revision; + final EClass eClass = HibernateUtil.getInstance().getEClass(classifierRef); + return new DetachedCDORevision(eClass, id, branchPoint.getBranch(), 0, 0); } - } - final InternalCDORevision revision = HibernateUtil.getInstance().getCDORevision(id); - if (revision == null) - { - final CDOClassifierRef classifierRef = CDOIDUtil.getClassifierRef(id); - if (classifierRef == null) + revision.setBranchPoint(getStore().getMainBranchHead()); + revision.freeze(); + + if (cache != null) { - throw new IllegalArgumentException("This CDOID type of " + id + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$ + cache.addRevision(revision); } - final EClass eClass = HibernateUtil.getInstance().getEClass(classifierRef); - return new DetachedCDORevision(eClass, id, branchPoint.getBranch(), 0, 0); + return revision; } - - revision.setBranchPoint(getStore().getMainBranchHead()); - revision.freeze(); - - if (cache != null) + finally { - cache.addRevision(revision); + currentListChunk = -1; } - - return revision; } public Pair<Integer, Long> createBranch(int branchID, BranchInfo branchInfo) @@ -896,6 +902,8 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS // order is 1) insert, 2) update and then delete // this order is the most stable! Do not change it without testing + // System.err.println(getStore().getMappingXml()); + final List<InternalCDORevision> repairContainerIDs = new ArrayList<InternalCDORevision>(); final List<InternalCDORevision> repairResourceIDs = new ArrayList<InternalCDORevision>(); for (InternalCDORevision revision : context.getNewObjects()) @@ -1415,4 +1423,9 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS protected void doUnpassivate() throws Exception { } + + public int getCurrentListChunk() + { + return currentListChunk; + } } diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreChunkReader.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreChunkReader.java index 30cef28086..5bc577cea2 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreChunkReader.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreChunkReader.java @@ -7,15 +7,29 @@ * * Contributors: * Eike Stepper - initial API and implementation + * Martin Taal - Implementation */ package org.eclipse.emf.cdo.server.internal.hibernate; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDOList; import org.eclipse.emf.cdo.common.revision.CDORevision; import org.eclipse.emf.cdo.server.hibernate.IHibernateStoreChunkReader; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.WrappedHibernateList; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; import org.eclipse.emf.cdo.spi.server.StoreChunkReader; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.collection.spi.PersistentCollection; +import org.hibernate.engine.spi.CollectionEntry; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.persister.collection.QueryableCollection; + import java.util.List; /** @@ -34,22 +48,187 @@ public class HibernateStoreChunkReader extends StoreChunkReader implements IHibe return (HibernateStoreAccessor)super.getAccessor(); } - @Override - public void addSimpleChunk(int index) + public List<Chunk> executeRead() { - // super.addSimpleChunk(index); - throw new UnsupportedOperationException(); // TODO Implement me + // get a transaction, the hibernateStoreAccessor is placed in a threadlocal + // so all db access uses the same session. + final Session session = getAccessor().getHibernateSession(); + + // reread the revision as it is probably unreferenced + final InternalCDORevision latestRevision = getLatestRevision(session); + Object value = latestRevision.getValue(getFeature()); + if (value instanceof WrappedHibernateList) + { + value = ((WrappedHibernateList)value).getDelegate(); + } + + // hibernate details... + boolean useExtraLazyMode = false; + boolean standardCDOList = false; + QueryableCollection persister = null; + CollectionEntry entry = null; + if (value instanceof PersistentCollection) + { + final PersistentCollection persistentCollection = (PersistentCollection)value; + persister = (QueryableCollection)((SessionFactoryImplementor)session.getSessionFactory()) + .getCollectionPersister(persistentCollection.getRole()); + entry = ((SessionImplementor)session).getPersistenceContext().getCollectionEntry(persistentCollection); + + useExtraLazyMode = !persister.getElementType().isEntityType(); + if (useExtraLazyMode && ((PersistentCollection)value).hasQueuedOperations()) + { + session.flush(); + } + } + else + { + standardCDOList = true; + } + + final List<Chunk> chunks = getChunks(); + for (Chunk chunk : chunks) + { + final int startIndex = chunk.getStartIndex(); + final int maxElements = chunk.size(); + if (standardCDOList) + { + // for eattributes just read them all, no chunking there... + final CDOList list = (CDOList)value; + if (startIndex >= list.size()) + { + return chunks; + } + for (int i = startIndex; i < startIndex + maxElements; i++) + { + if (i >= list.size()) + { + break; + } + addToChunk(chunk, i - startIndex, list.get(i)); + } + } + else if (useExtraLazyMode) + { + if (getFeature() instanceof EReference) + { + for (int i = startIndex; i < startIndex + maxElements; i++) + { + final Object object = persister.getElementByIndex(entry.getLoadedKey(), i, (SessionImplementor)session, + latestRevision); + // could happen if the index > size) + if (object == null) + { + continue; + } + addToChunk(chunk, i - startIndex, object); + } + } + else + { + // for eattributes just read them all, no chunking there... + final List<?> list = (List<?>)value; + if (startIndex >= list.size()) + { + return chunks; + } + for (int i = startIndex; i < startIndex + maxElements; i++) + { + if (i >= list.size()) + { + break; + } + addToChunk(chunk, i - startIndex, list.get(i)); + } + } + } + else + { + final Query filterQuery = session.createFilter(value, ""); + filterQuery.setMaxResults(maxElements); + filterQuery.setFirstResult(startIndex); + int i = 0; + for (Object object : filterQuery.list()) + { + addToChunk(chunk, i++, object); + } + } + } + return chunks; } - @Override - public void addRangedChunk(int fromIndex, int toIndex) + private InternalCDORevision getLatestRevision(Session session) { - // super.addRangedChunk(fromIndex, toIndex); - throw new UnsupportedOperationException(); // TODO Implement me + final CDOID id = getRevision().getID(); + + final HibernateStore store = getAccessor().getStore(); + + if (store.isAuditing() && store.getHibernateAuditHandler().getCDOAuditHandler().isAudited(id)) + { + InternalCDORevision revision = store.getHibernateAuditHandler().readRevision(session, id, + getRevision().getTimeStamp()); + // found one, use it + if (revision != null) + { + return revision; + } + } + + return HibernateUtil.getInstance().getCDORevision(id); } - public List<Chunk> executeRead() + private void addToRevisionCache(Object revision) + { + final InternalCDORevision internalRevision = (InternalCDORevision)revision; + for (EStructuralFeature feature : internalRevision.getEClass().getEAllStructuralFeatures()) + { + if (!isMappedFeature(internalRevision, feature)) + { + continue; + } + + if (feature.isMany() || feature instanceof EReference) + { + final Object value = internalRevision.getValue(feature); + if (value instanceof WrappedHibernateList) + { + // force the size to be cached + ((WrappedHibernateList)value).size(); + } + } + } + + getAccessor().addToRevisionCache(revision); + } + + private void addToChunk(Chunk chunk, int i, Object object) { - throw new UnsupportedOperationException(); // TODO Implement me + if (object instanceof CDORevision) + { + addToRevisionCache(object); + chunk.add(i, HibernateUtil.getInstance().getCDOID(object)); + } + else + { + chunk.add(i, object); + } } + + private boolean isMappedFeature(InternalCDORevision revision, EStructuralFeature feature) + { + try + { + int featureID = revision.getClassInfo().getEClass().getFeatureID(feature); + revision.getClassInfo().getPersistentFeatureIndex(featureID); + return true; + } + catch (IllegalArgumentException ex) + { + return false; + } + catch (ArrayIndexOutOfBoundsException ex) + { + return false; + } + } + } diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java index ebb7ae1a67..ff096ac048 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java @@ -14,6 +14,7 @@ package org.eclipse.emf.cdo.server.internal.hibernate; import org.eclipse.emf.cdo.CDOObject; import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.common.id.CDOIDExternal; +import org.eclipse.emf.cdo.common.id.CDOIDString; import org.eclipse.emf.cdo.common.id.CDOIDTemp; import org.eclipse.emf.cdo.common.id.CDOIDUtil; import org.eclipse.emf.cdo.common.model.CDOClassifierRef; @@ -658,6 +659,10 @@ public class HibernateUtil */ public Serializable getIdValue(CDOID id) { + if (id instanceof CDOIDString) + { + return ((CDOIDString)id).getStringValue(); + } return CDOIDUtil.getLong(id); } diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeSetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeSetter.java index 66138c66ee..9e611bb069 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeSetter.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOManyAttributeSetter.java @@ -64,7 +64,7 @@ public class CDOManyAttributeSetter extends CDOPropertySetter @SuppressWarnings("unchecked") List<Object> valueList = (List<Object>)value; - final WrappedHibernateList whl = new WrappedHibernateList(); + final WrappedHibernateList whl = new WrappedHibernateList(revision, getEStructuralFeature()); whl.setDelegate(valueList); super.set(target, whl, factory); } 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 index 54dc030bd8..d587f2bc78 100644 --- 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 @@ -64,7 +64,7 @@ public class CDOManyReferenceSetter extends CDOPropertySetter @SuppressWarnings("unchecked") List<Object> valueList = (List<Object>)value; - final WrappedHibernateList whl = new WrappedHibernateList(); + final WrappedHibernateList whl = new WrappedHibernateList(revision, getEStructuralFeature()); whl.setDelegate(valueList); super.set(target, whl, factory); } diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java index c54b8ebbc6..97950b6e1a 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/WrappedHibernateList.java @@ -16,15 +16,26 @@ import org.eclipse.emf.cdo.common.model.CDOModelUtil; import org.eclipse.emf.cdo.common.model.CDOType; import org.eclipse.emf.cdo.common.revision.CDOListFactory; import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionUtil; +import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreChunkReader; +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.revision.CDOReferenceAdjuster; import org.eclipse.emf.cdo.spi.common.revision.InternalCDOList; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EEnumLiteral; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; +import org.hibernate.collection.internal.AbstractPersistentCollection; +import org.hibernate.engine.spi.CollectionEntry; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.proxy.HibernateProxy; import java.util.ArrayList; @@ -46,8 +57,25 @@ public class WrappedHibernateList implements InternalCDOList private boolean frozen; - public WrappedHibernateList() + private int cachedSize = -1; + + private final EStructuralFeature eFeature; + + private final InternalCDORevision owner; + + private Chunk cachedChunk; + + private int currentListChunk = -1; + + public WrappedHibernateList(InternalCDORevision owner, EStructuralFeature eFeature) { + this.owner = owner; + this.eFeature = eFeature; + final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor(); + if (accessor != null) + { + currentListChunk = accessor.getCurrentListChunk(); + } } public void move(int newPosition, Object object) @@ -140,7 +168,7 @@ public class WrappedHibernateList implements InternalCDOList if (classifier instanceof EClass) { - WrappedHibernateList wrapped = new WrappedHibernateList(); + WrappedHibernateList wrapped = new WrappedHibernateList(owner, eFeature); wrapped.setDelegate(list); return wrapped; } @@ -152,9 +180,57 @@ public class WrappedHibernateList implements InternalCDOList */ public List<Object> getDelegate() { + if (delegate instanceof AbstractPersistentCollection && !((AbstractPersistentCollection)delegate).wasInitialized() + && !hasOpenSession()) + { + // use a dummy auto-expanding list + setDelegate(new ArrayList<Object>() + { + private static final long serialVersionUID = 1L; + + @Override + public Object set(int index, Object element) + { + ensureSize(index); + return super.set(index, element); + } + + @Override + public Object get(int index) + { + ensureSize(index); + final Object o = super.get(index); + if (o == null) + { + return CDORevisionUtil.UNINITIALIZED; + } + return o; + } + + private void ensureSize(int index) + { + if (index >= size()) + { + for (int i = size() - 1; i <= index; i++) + { + add(null); + } + } + } + + }); + } + return delegate; } + protected boolean hasOpenSession() + { + final AbstractPersistentCollection persistentCollection = (AbstractPersistentCollection)delegate; + final SessionImplementor session = persistentCollection.getSession(); + return session != null && session.isOpen(); + } + /** * @param delegate * the delegate to set @@ -201,22 +277,28 @@ public class WrappedHibernateList implements InternalCDOList return result; } - protected CDOID getCDOID(Object o) + protected Object getCDOValue(Object o) { if (o instanceof CDOID) { - return (CDOID)o; + return o; + } + + if (o instanceof HibernateProxy || o instanceof CDORevision) + { + return HibernateUtil.getInstance().getCDOID(o); } - return HibernateUtil.getInstance().getCDOID(o); + // primitive type + return o; } - protected List<CDOID> getCDOIDs(Collection<?> c) + protected List<Object> getCDOValues(Collection<?> c) { - List<CDOID> newC = new ArrayList<CDOID>(); + List<Object> newC = new ArrayList<Object>(); for (Object o : c) { - newC.add(getCDOID(o)); + newC.add(getCDOValue(o)); } return newC; @@ -225,25 +307,25 @@ public class WrappedHibernateList implements InternalCDOList public void add(int index, Object element) { checkFrozen(); - getDelegate().add(index, getCDOID(element)); + getDelegate().add(index, getCDOValue(element)); } public boolean add(Object o) { checkFrozen(); - return getDelegate().add(getCDOID(o)); + return getDelegate().add(getCDOValue(o)); } public boolean addAll(Collection<? extends Object> c) { checkFrozen(); - return getDelegate().addAll(getCDOIDs(c)); + return getDelegate().addAll(getCDOValues(c)); } public boolean addAll(int index, Collection<? extends Object> c) { checkFrozen(); - return getDelegate().addAll(index, getCDOIDs(c)); + return getDelegate().addAll(index, getCDOValues(c)); } public void clear() @@ -254,12 +336,12 @@ public class WrappedHibernateList implements InternalCDOList public boolean contains(Object o) { - return getDelegate().contains(getCDOID(o)); + return getDelegate().contains(getCDOValue(o)); } public boolean containsAll(Collection<?> c) { - return getDelegate().containsAll(getCDOIDs(c)); + return getDelegate().containsAll(getCDOValues(c)); } public Object get(int index) @@ -275,14 +357,72 @@ public class WrappedHibernateList implements InternalCDOList public Object get(int index, boolean resolve) { - // Since delegate is a hibernate list, it is never a CDOElementProxy - // so the parameter resolve can be ignored + // if the collection is not initialized then always return + // uninitialized to prevent loading it aggresively + if (!resolve && currentListChunk > -1 && eFeature instanceof EReference + && getDelegate() instanceof AbstractPersistentCollection) + { + final AbstractPersistentCollection collection = (AbstractPersistentCollection)getDelegate(); + if (!collection.wasInitialized()) + { + final Object chunkedValue = getChunkedValue(index); + if (chunkedValue != null) + { + return chunkedValue; + } + return CDORevisionUtil.UNINITIALIZED; + } + } + return get(index); } + private Object getChunkedValue(int index) + { + if (index >= currentListChunk) + { + return null; + } + readInitialChunk(index); + if (cachedChunk != null) + { + // note index must be within the range as the chunk + // is read again if index is too large. + return cachedChunk.get(index); + } + return null; + } + + private void readInitialChunk(int index) + { + + if (cachedChunk != null) + { + if (index < cachedChunk.size()) + { + // a valid chunk + return; + } + // a not valid chunk + // reread it + cachedChunk = null; + } + final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor(); + if (accessor == null) + { + return; + } + if (currentListChunk > -1) + { + final HibernateStoreChunkReader chunkReader = accessor.createChunkReader(owner, eFeature); + chunkReader.addRangedChunk(0, currentListChunk); + cachedChunk = chunkReader.executeRead().get(0); + } + } + public int indexOf(Object o) { - return getDelegate().indexOf(getCDOID(o)); + return getDelegate().indexOf(getCDOValue(o)); } public boolean isEmpty() @@ -297,7 +437,7 @@ public class WrappedHibernateList implements InternalCDOList public int lastIndexOf(Object o) { - return getDelegate().lastIndexOf(getCDOID(o)); + return getDelegate().lastIndexOf(getCDOValue(o)); } public ListIterator<Object> listIterator() @@ -319,33 +459,62 @@ public class WrappedHibernateList implements InternalCDOList public boolean remove(Object o) { checkFrozen(); - return getDelegate().remove(getCDOID(o)); + return getDelegate().remove(getCDOValue(o)); } public boolean removeAll(Collection<?> c) { checkFrozen(); - return getDelegate().removeAll(getCDOIDs(c)); + return getDelegate().removeAll(getCDOValues(c)); } public boolean retainAll(Collection<?> c) { - return getDelegate().retainAll(getCDOIDs(c)); + return getDelegate().retainAll(getCDOValues(c)); } public Object set(int index, Object element) { checkFrozen(); + + if (element == CDORevisionUtil.UNINITIALIZED) + { + return null; + } + if (element instanceof CDOID) { return getDelegate().set(index, element); } - return getDelegate().set(index, getCDOID(element)); + return getDelegate().set(index, getCDOValue(element)); } public int size() { + if (cachedSize != -1) + { + return cachedSize; + } + if (getDelegate() instanceof AbstractPersistentCollection) + { + final AbstractPersistentCollection collection = (AbstractPersistentCollection)getDelegate(); + if (collection.wasInitialized()) + { + cachedSize = -1; + return getDelegate().size(); + } + final SessionImplementor session = collection.getSession(); + CollectionEntry entry = session.getPersistenceContext().getCollectionEntry(collection); + CollectionPersister persister = entry.getLoadedPersister(); + if (collection.hasQueuedOperations()) + { + session.flush(); + } + cachedSize = persister.getSize(entry.getLoadedKey(), session); + return cachedSize; + } + return getDelegate().size(); } @@ -475,6 +644,8 @@ public class WrappedHibernateList implements InternalCDOList private void checkFrozen() { + // a frozen check always implies a modification + cachedSize = -1; if (frozen) { throw new IllegalStateException("Cannot modify a frozen list"); @@ -485,4 +656,9 @@ public class WrappedHibernateList implements InternalCDOList { getDelegate().set(i, value); } + + CDORevision getOwner() + { + return owner; + } } diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.tests.hibernate/META-INF/MANIFEST.MF index ccea76679e..0ef441cb1a 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.emf.cdo.tests.hibernate;singleton:=true -Bundle-Version: 4.1.100.qualifier +Bundle-Version: 4.1.101.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin @@ -20,11 +20,10 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", com.mysql.jdbc;bundle-version="[5.1.7,6.0.0)", org.dom4j;bundle-version="[1.6.1,2.0.0)", javax.persistence;bundle-version="[2.0.0,3.0.0)" -Export-Package: mappings;version="4.1.100";x-friends:="org.eclipse.emf.cdo.tests.hudson", - org.eclipse.emf.cdo.tests.hibernate;version="4.1.100";x-friends:="org.eclipse.emf.cdo.tests.hudson", - org.eclipse.emf.cdo.tests.hibernate.model.HibernateTest;version="4.1.100", - org.eclipse.emf.cdo.tests.hibernate.model.HibernateTest.impl;version="4.1.100", - org.eclipse.emf.cdo.tests.hibernate.model.HibernateTest.util;version="4.1.100" +Export-Package: org.eclipse.emf.cdo.tests.hibernate;version="4.1.101";x-friends:="org.eclipse.emf.cdo.tests.hudson", + org.eclipse.emf.cdo.tests.hibernate.model.HibernateTest;version="4.1.101", + org.eclipse.emf.cdo.tests.hibernate.model.HibernateTest.impl;version="4.1.101", + org.eclipse.emf.cdo.tests.hibernate.model.HibernateTest.util;version="4.1.101" Import-Package: org.hibernate.cfg;version="[4.0.0,5.0.0)", org.eclipse.emf.teneo;version="[2.0.1,3.0.0)", org.eclipse.emf.cdo.server.hibernate;version="[4.0.0,5.0.0)", diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/build.properties b/plugins/org.eclipse.emf.cdo.tests.hibernate/build.properties index 7b11911fe5..731ef791f3 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/build.properties +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/build.properties @@ -20,7 +20,10 @@ bin.includes = META-INF/,\ about.ini,\ about.mappings,\ about.properties,\ - modeling32.png + modeling32.png,\ + src/log4j.properties,\ + src/app.properties,\ + src/org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml src.includes = about.html,\ copyright.txt,\ CDO AllTests (Hibernate).launch,\ diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties index 0d6dc563cd..1ecf9eb2a7 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/app.properties @@ -1,9 +1,14 @@ +# Teneo options +teneo.mapping.set_proxy=true +teneo.mapping.cascade_policy_on_non_containment=PERSIST,MERGE +teneo.mapping.persistence_xml.parse.lenient=true +teneo.runtime.elist_efficient_size_operation=true + +# Hibernate options hibernate.hbm2ddl.auto=create-drop hibernate.show_sql=false hibernate.connection.pool_size=10 -teneo.mapping.set_proxy=true - # ----------------------------------------------------------- # DEFAULT SETTINGS FOR IN MEMORY HSQLDB DATABASE. # @@ -27,7 +32,4 @@ hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider #hibernate.connection.url=jdbc:mysql://localhost:3306/cdohibernate #hibernate.connection.username=root #hibernate.connection.password=root -#hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect - -teneo.mapping.cascade_policy_on_non_containment=PERSIST,MERGE -teneo.mapping.persistence_xml.parse.lenient=true
\ No newline at end of file +#hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/mappings/product.hbm.xml b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/mappings/product.hbm.xml deleted file mode 100644 index 174d68a56f..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/mappings/product.hbm.xml +++ /dev/null @@ -1,218 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> - -<hibernate-mapping auto-import="false"> - <class entity-name="Address" abstract="false" lazy="false" discriminator-value="Address" table="`address`"> - <meta attribute="eclassName">Address</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler"> - <meta attribute="syntheticId">true</meta> - <generator class="native"/> - </id> - <discriminator column="`dtype`" type="string"/> - <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler"> - <meta attribute="syntheticVersion">true</meta> - </version> - <property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String"> - <column not-null="false" unique="false" name="`name`"/> - </property> - <property name="street" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String"> - <column not-null="false" unique="false" name="`street`"/> - </property> - <property name="city" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String"> - <column not-null="false" unique="false" name="`city`"/> - </property> - </class> - <subclass entity-name="Company" abstract="false" lazy="false" extends="Address" discriminator-value="Company"> - <meta attribute="eclassName">Company</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <list name="categories" lazy="true" cascade="all,delete-orphan"> - <key update="true" foreign-key="company_categories"> - <column name="`company_categories_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`company_categories_idx`"/> - <one-to-many entity-name="Category"/> - </list> - <list name="suppliers" lazy="true" cascade="all,delete-orphan"> - <key update="true" foreign-key="company_suppliers"> - <column name="`company_suppliers_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`company_suppliers_idx`"/> - <one-to-many entity-name="Supplier"/> - </list> - <list name="customers" lazy="true" cascade="all,delete-orphan"> - <key update="true" foreign-key="company_customers"> - <column name="`company_customers_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`company_customers_idx`"/> - <one-to-many entity-name="Customer"/> - </list> - <list name="purchaseOrders" lazy="true" cascade="all,delete-orphan"> - <key update="true" foreign-key="company_purchaseorders"> - <column name="`company_purchaseorders_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`company_purchaseorders_idx`"/> - <one-to-many entity-name="PurchaseOrder"/> - </list> - <list name="salesOrders" lazy="true" cascade="all,delete-orphan"> - <key update="true" foreign-key="company_salesorders"> - <column name="`company_salesorders_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`company_salesorders_idx`"/> - <one-to-many entity-name="SalesOrder"/> - </list> - </subclass> - <subclass entity-name="Supplier" abstract="false" lazy="false" extends="Address" discriminator-value="Supplier"> - <meta attribute="eclassName">Supplier</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <list name="purchaseOrders" lazy="true"> - <key update="true"> - <column name="`purchaseorder_supplier_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`supplier_purchaseorders_idx`"/> - <one-to-many entity-name="PurchaseOrder"/> - </list> - </subclass> - <subclass entity-name="Customer" abstract="false" lazy="false" extends="Address" discriminator-value="Customer"> - <meta attribute="eclassName">Customer</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <list name="salesOrders" lazy="true"> - <key update="true"> - <column name="`salesorder_customer_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`customer_salesorders_idx`"/> - <one-to-many entity-name="SalesOrder"/> - </list> - </subclass> - <class entity-name="Order" abstract="false" lazy="false" discriminator-value="Order" table="`order`"> - <meta attribute="eclassName">Order</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler"> - <meta attribute="syntheticId">true</meta> - <generator class="native"/> - </id> - <discriminator column="`dtype`" type="string"/> - <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler"> - <meta attribute="syntheticVersion">true</meta> - </version> - <list name="orderDetails" lazy="true" cascade="all,delete-orphan"> - <key update="true"> - <column name="`orderdetail_order_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`order_orderdetails_idx`"/> - <one-to-many entity-name="OrderDetail"/> - </list> - </class> - <class entity-name="OrderDetail" abstract="false" lazy="false" discriminator-value="OrderDetail" table="`orderdetail`"> - <meta attribute="eclassName">OrderDetail</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler"> - <meta attribute="syntheticId">true</meta> - <generator class="native"/> - </id> - <discriminator column="`dtype`" type="string"/> - <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler"> - <meta attribute="syntheticVersion">true</meta> - </version> - <many-to-one name="order" entity-name="Order" foreign-key="orderdetail_order" lazy="false" insert="false" update="false" not-null="false"> - <column not-null="false" unique="false" name="`orderdetail_order_e_id`"/> - </many-to-one> - <many-to-one name="product" entity-name="Product" foreign-key="orderdetail_product" lazy="false" insert="false" update="false" not-null="false"> - <column not-null="false" unique="false" name="`orderdetail_product_e_id`"/> - </many-to-one> - <property name="price" lazy="false" insert="true" update="true" not-null="false" unique="false" type="float"> - <column not-null="false" unique="false" name="`price`"/> - </property> - </class> - <subclass entity-name="PurchaseOrder" abstract="false" lazy="false" extends="Order" discriminator-value="PurchaseOrder"> - <meta attribute="eclassName">PurchaseOrder</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <property name="date" lazy="false" insert="true" update="true" not-null="false" unique="false" type="timestamp"> - <column not-null="false" unique="false" name="`date`"/> - </property> - <many-to-one name="supplier" entity-name="Supplier" foreign-key="purchaseorder_supplier" lazy="false" insert="false" update="false" not-null="false"> - <column not-null="false" unique="false" name="`purchaseorder_supplier_e_id`"/> - </many-to-one> - </subclass> - <subclass entity-name="SalesOrder" abstract="false" lazy="false" extends="Order" discriminator-value="SalesOrder"> - <meta attribute="eclassName">SalesOrder</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <property name="id" lazy="false" insert="true" update="true" not-null="false" unique="false" type="int"> - <column not-null="false" unique="false" name="`id`"/> - </property> - <many-to-one name="customer" entity-name="Customer" foreign-key="salesorder_customer" lazy="false" insert="false" update="false" not-null="false"> - <column not-null="false" unique="false" name="`salesorder_customer_e_id`"/> - </many-to-one> - </subclass> - <class entity-name="Category" abstract="false" lazy="false" discriminator-value="Category" table="`category`"> - <meta attribute="eclassName">Category</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler"> - <meta attribute="syntheticId">true</meta> - <generator class="native"/> - </id> - <discriminator column="`dtype`" type="string"/> - <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler"> - <meta attribute="syntheticVersion">true</meta> - </version> - <property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String"> - <column not-null="false" unique="false" name="`name`"/> - </property> - <list name="categories" lazy="true" cascade="all,delete-orphan"> - <key update="true" foreign-key="category_categories"> - <column name="`category_categories_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`category_categories_idx`"/> - <one-to-many entity-name="Category"/> - </list> - <list name="products" lazy="true" cascade="all,delete-orphan"> - <key update="true" foreign-key="category_products"> - <column name="`category_products_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`category_products_idx`"/> - <one-to-many entity-name="Product"/> - </list> - </class> - <class entity-name="Product" abstract="false" lazy="false" discriminator-value="Product" table="`product`"> - <meta attribute="eclassName">Product</meta> - <meta attribute="epackage">http://www.eclipse.org/emf/CDO/tests/model1/1.0.0</meta> - <tuplizer entity-mode="pojo" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <tuplizer entity-mode="dynamic-map" class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/> - <id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler"> - <meta attribute="syntheticId">true</meta> - <generator class="native"/> - </id> - <discriminator column="`dtype`" type="string"/> - <version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler"> - <meta attribute="syntheticVersion">true</meta> - </version> - <property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String"> - <column not-null="false" unique="false" name="`name`"/> - </property> - <list name="orderDetails" lazy="true"> - <key update="true"> - <column name="`orderdetail_product_e_id`" not-null="false" unique="false"/> - </key> - <list-index column="`product_orderdetails_idx`"/> - <one-to-many entity-name="OrderDetail"/> - </list> - </class> -</hibernate-mapping> diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java index 8068e16f5e..cf375525d3 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/AllTestsHibernate.java @@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.tests.AllConfigs; import org.eclipse.emf.cdo.tests.AttributeTest; import org.eclipse.emf.cdo.tests.BackupTest; import org.eclipse.emf.cdo.tests.CommitInfoTest; +import org.eclipse.emf.cdo.tests.CrossReferenceTest; import org.eclipse.emf.cdo.tests.DynamicXSDTest; import org.eclipse.emf.cdo.tests.EMFCompareTest; import org.eclipse.emf.cdo.tests.ExternalReferenceTest; @@ -44,9 +45,13 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_351393_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_352204_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_359966_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_362270_Test; +import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_362270b_Test; +import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_362270c_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_365832_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_381472_Test; import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_390185_Test; +import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_400236_Test; +import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_405191_Test; import org.eclipse.emf.cdo.tests.config.IRepositoryConfig; import org.eclipse.emf.cdo.tests.config.IScenario; import org.eclipse.emf.cdo.tests.config.impl.ConfigTest; @@ -78,12 +83,13 @@ public class AllTestsHibernate extends AllConfigs protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses, IScenario scenario) { // testClasses.clear(); - // testClasses.add(HibernateBugzilla_380987_Test.class); + // testClasses.add(HibernateQueryTest.class); // if (true) // { // return; // } + testClasses.add(HibernateChunkingTest.class); testClasses.add(Hibernate_Failure_Test.class); testClasses.add(Hibernate_Export_Test.class); testClasses.add(HibernateBugzilla_381013_Test.class); @@ -92,8 +98,6 @@ public class AllTestsHibernate extends AllConfigs testClasses.add(HibernateBugzilla_387752_Test.class); testClasses.add(HibernateBugzilla_387752_True_Test.class); - // testClasses.add(HibernateBugzilla_387752_Test.class); - testClasses.add(HibernateBugzilla_333473_Test.class); testClasses.add(HibernateTimeStampTest.class); @@ -104,14 +108,27 @@ public class AllTestsHibernate extends AllConfigs testClasses.add(HibernateQueryNoCachingTest.class); testClasses.add(HibernateBugzilla_301104_Test.class); - testClasses.add(HibernateBugzilla_362270_Test.class); - super.initTestClasses(testClasses, scenario); + // remove as it tries to persist an eannotation + testClasses.remove(Bugzilla_400236_Test.class); + + testClasses.add(HibernateBugzilla_362270b_Test.class); + testClasses.remove(Bugzilla_362270b_Test.class); + + testClasses.add(HibernateBugzilla_362270c_Test.class); + testClasses.remove(Bugzilla_362270c_Test.class); + + testClasses.add(HibernateBugzilla_405191_Test.class); + testClasses.remove(Bugzilla_405191_Test.class); + // for some reason this test needs to be done first... testClasses.remove(Bugzilla_306998_Test.class); testClasses.add(0, Bugzilla_306998_Test.class); + testClasses.remove(CrossReferenceTest.class); + testClasses.add(HibernateCrossReferenceTest.class); + testClasses.add(HibernateBugzilla_356181_Test.class); // the hb store throws an error on deadlocked transaction @@ -123,6 +140,9 @@ public class AllTestsHibernate extends AllConfigs if (scenario.getCapabilities().contains(IRepositoryConfig.CAPABILITY_AUDITING)) { + // need to add additional auditing annotations + testClasses.remove(HibernateBugzilla_405191_Test.class); + testClasses.add(HibernateBugzilla_395684_Test.class); testClasses.add(CDOObjectHistoryTest.class); @@ -313,7 +333,7 @@ public class AllTestsHibernate extends AllConfigs { final IRepositoryConfig repConfig = getRepositoryConfig(); final HibernateConfig hbConfig = (HibernateConfig)repConfig; - final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/external_model1_4.persistence.xml"; + final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml"; hbConfig.getAdditionalProperties().put(HibernateStore.PERSISTENCE_XML, persistenceXML); super.doSetUp(); diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_362270_Test.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_362270b_Test.java index 86899a6cfb..894fb053fb 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_362270_Test.java +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_362270b_Test.java @@ -11,7 +11,7 @@ package org.eclipse.emf.cdo.tests.hibernate; import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore; -import org.eclipse.emf.cdo.tests.ExternalReferenceTest; +import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_362270b_Test; import org.eclipse.emf.cdo.tests.config.IRepositoryConfig; /** @@ -19,34 +19,15 @@ import org.eclipse.emf.cdo.tests.config.IRepositoryConfig; * * @author Martin Taal */ -public class HibernateBugzilla_362270_Test extends ExternalReferenceTest +public class HibernateBugzilla_362270b_Test extends Bugzilla_362270b_Test { - @Override - public void testOneXMIResourceManyViewsOnOneResourceSet() throws Exception - { - } - - @Override - public void testUsingObjectsBetweenSameTransaction() throws Exception - { - } - - @Override - public void testManyViewsOnOneResourceSet() throws Exception - { - } - - @Override - public void testXRefExternalObject() throws Exception - { - } @Override protected void doSetUp() throws Exception { final IRepositoryConfig repConfig = getRepositoryConfig(); final HibernateConfig hbConfig = (HibernateConfig)repConfig; - final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/external_model1_4.persistence.xml"; + final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml"; hbConfig.getAdditionalProperties().put(HibernateStore.PERSISTENCE_XML, persistenceXML); super.doSetUp(); diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_362270c_Test.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_362270c_Test.java new file mode 100644 index 0000000000..922d5397d9 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_362270c_Test.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012 Eike Stepper (Berlin, 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: + * Martin Taal + */ +package org.eclipse.emf.cdo.tests.hibernate; + +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore; +import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_362270c_Test; +import org.eclipse.emf.cdo.tests.config.IRepositoryConfig; + +/** + * Read external reference annotation. + * + * @author Martin Taal + */ +public class HibernateBugzilla_362270c_Test extends Bugzilla_362270c_Test +{ + + @Override + protected void doSetUp() throws Exception + { + final IRepositoryConfig repConfig = getRepositoryConfig(); + final HibernateConfig hbConfig = (HibernateConfig)repConfig; + final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml"; + hbConfig.getAdditionalProperties().put(HibernateStore.PERSISTENCE_XML, persistenceXML); + + super.doSetUp(); + } + + @Override + protected void doTearDown() throws Exception + { + final IRepositoryConfig repConfig = getRepositoryConfig(); + final HibernateConfig hbConfig = (HibernateConfig)repConfig; + hbConfig.getAdditionalProperties().clear(); + super.doTearDown(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_405191_Test.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_405191_Test.java new file mode 100644 index 0000000000..5023118e61 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateBugzilla_405191_Test.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012 Eike Stepper (Berlin, 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: + * Martin Taal + */ +package org.eclipse.emf.cdo.tests.hibernate; + +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore; +import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_405191_Test; +import org.eclipse.emf.cdo.tests.config.IRepositoryConfig; + +/** + * @author Martin Taal + */ +public class HibernateBugzilla_405191_Test extends Bugzilla_405191_Test +{ + + @Override + protected void doSetUp() throws Exception + { + final IRepositoryConfig repConfig = getRepositoryConfig(); + final HibernateConfig hbConfig = (HibernateConfig)repConfig; + final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml"; + hbConfig.getAdditionalProperties().put(HibernateStore.PERSISTENCE_XML, persistenceXML); + + super.doSetUp(); + } + + @Override + protected void doTearDown() throws Exception + { + final IRepositoryConfig repConfig = getRepositoryConfig(); + final HibernateConfig hbConfig = (HibernateConfig)repConfig; + hbConfig.getAdditionalProperties().clear(); + super.doTearDown(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateChunkingTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateChunkingTest.java new file mode 100644 index 0000000000..ff0667d759 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateChunkingTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2007-2013 Eike Stepper (Berlin, 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 - Changes for hibernate + */ +package org.eclipse.emf.cdo.tests.hibernate; + +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.tests.AbstractCDOTest; +import org.eclipse.emf.cdo.tests.model1.Company; +import org.eclipse.emf.cdo.tests.model1.Customer; +import org.eclipse.emf.cdo.tests.model1.SalesOrder; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.net4j.util.io.IOUtil; + +import org.eclipse.emf.common.util.EList; + +import java.util.Iterator; + +/** + * @author Eike Stepper + */ +public class HibernateChunkingTest extends AbstractCDOTest +{ + public void testReadNative() throws Exception + { + { + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.createResource(getResourcePath("/test1")); + + Company company = getModel1Factory().createCompany(); + company.setName("company"); + resource.getContents().add(company); + + for (int i = 0; i < 100; i++) + { + SalesOrder salesOrder = getModel1Factory().createSalesOrder(); + salesOrder.setId(i); + company.getSalesOrders().add(salesOrder); + } + + transaction.commit(); + session.close(); + } + + clearCache(getRepository().getRevisionManager()); + + CDOSession session = openSession(); + session.options().setCollectionLoadingPolicy(CDOUtil.createCollectionLoadingPolicy(10, 10)); + + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.getResource(getResourcePath("/test1")); + + Company company = (Company)resource.getContents().get(0); + EList<SalesOrder> salesOrders = company.getSalesOrders(); + int i = 0; + for (Iterator<SalesOrder> it = salesOrders.iterator(); it.hasNext();) + { + IOUtil.OUT().println(i++); + SalesOrder salesOrder = it.next(); + IOUtil.OUT().println(salesOrder); + } + } + + public void testWriteNative() throws Exception + { + { + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.createResource(getResourcePath("/test1")); + + Customer customer = getModel1Factory().createCustomer(); + customer.setName("customer"); + resource.getContents().add(customer); + + for (int i = 0; i < 100; i++) + { + SalesOrder salesOrder = getModel1Factory().createSalesOrder(); + salesOrder.setId(i); + salesOrder.setCustomer(customer); + resource.getContents().add(salesOrder); + } + + transaction.commit(); + session.close(); + } + + clearCache(getRepository().getRevisionManager()); + + CDOSession session = openSession(); + session.options().setCollectionLoadingPolicy(CDOUtil.createCollectionLoadingPolicy(10, 10)); + + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.getResource(getResourcePath("/test1")); + + Customer customer = (Customer)resource.getContents().get(0); + EList<SalesOrder> salesOrders = customer.getSalesOrders(); + for (int i = 50; i < 70; i++) + { + SalesOrder salesOrder = getModel1Factory().createSalesOrder(); + salesOrder.setId(i + 1000); + resource.getContents().add(salesOrder); + salesOrders.set(i, salesOrder); + } + + transaction.commit(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateCrossReferenceTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateCrossReferenceTest.java new file mode 100644 index 0000000000..efb1fd6bfc --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateCrossReferenceTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 2011, 2012 Eike Stepper (Berlin, 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: + * Martin Taal + */ +package org.eclipse.emf.cdo.tests.hibernate; + +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore; +import org.eclipse.emf.cdo.tests.CrossReferenceTest; +import org.eclipse.emf.cdo.tests.config.IRepositoryConfig; + +/** + * Tests with a separate annotations.xml. + * + * @author Martin Taal + */ +public class HibernateCrossReferenceTest extends CrossReferenceTest +{ + + @Override + protected void doSetUp() throws Exception + { + final IRepositoryConfig repConfig = getRepositoryConfig(); + final HibernateConfig hbConfig = (HibernateConfig)repConfig; + final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml"; + hbConfig.getAdditionalProperties().put(HibernateStore.PERSISTENCE_XML, persistenceXML); + + super.doSetUp(); + } + + @Override + protected void doTearDown() throws Exception + { + final IRepositoryConfig repConfig = getRepositoryConfig(); + final HibernateConfig hbConfig = (HibernateConfig)repConfig; + hbConfig.getAdditionalProperties().clear(); + super.doTearDown(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateExternalAnnotationTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateExternalAnnotationTest.java index 98c7a64897..728ca46147 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateExternalAnnotationTest.java +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateExternalAnnotationTest.java @@ -48,7 +48,7 @@ public class HibernateExternalAnnotationTest extends AbstractCDOTest { final IRepositoryConfig repConfig = getRepositoryConfig(); final HibernateConfig hbConfig = (HibernateConfig)repConfig; - final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/external_model1_4.persistence.xml"; + final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml"; hbConfig.getAdditionalProperties().put(HibernateStore.PERSISTENCE_XML, persistenceXML); super.doSetUp(); diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateExternalReferenceTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateExternalReferenceTest.java index 780394368b..e202726d0f 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateExternalReferenceTest.java +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateExternalReferenceTest.java @@ -63,7 +63,7 @@ public class HibernateExternalReferenceTest extends ExternalReferenceTest { final IRepositoryConfig repConfig = getRepositoryConfig(); final HibernateConfig hbConfig = (HibernateConfig)repConfig; - final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/external_model1_4.persistence.xml"; + final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml"; hbConfig.getAdditionalProperties().put(HibernateStore.PERSISTENCE_XML, persistenceXML); super.doSetUp(); diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateLazyLoadTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateLazyLoadTest.java new file mode 100644 index 0000000000..f6eed9d92f --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateLazyLoadTest.java @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2009-2013 Eike Stepper (Berlin, 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: + * Martin Taal + */ +package org.eclipse.emf.cdo.tests.hibernate; + +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.server.hibernate.IHibernateStore; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.tests.AbstractCDOTest; +import org.eclipse.emf.cdo.tests.model1.Customer; +import org.eclipse.emf.cdo.tests.model1.Order; +import org.eclipse.emf.cdo.tests.model1.OrderDetail; +import org.eclipse.emf.cdo.tests.model1.Product1; +import org.eclipse.emf.cdo.tests.model1.SalesOrder; +import org.eclipse.emf.cdo.tests.model1.Supplier; +import org.eclipse.emf.cdo.tests.model1.VAT; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.util.CommitException; +import org.eclipse.emf.cdo.view.CDOQuery; + +import org.eclipse.net4j.util.WrappedException; + +import java.util.ArrayList; +import java.util.List; + +/** + * Test lazy load behavior of hibernate + * + * @author Martin Taal + */ +public class HibernateLazyLoadTest extends AbstractCDOTest +{ + private static final int NUM_OF_PRODUCTS = 10; + + private static final int NUM_OF_CUSTOMERS = 2; + + private static final int NUM_OF_PRODUCTS_CUSTOMER = NUM_OF_PRODUCTS / NUM_OF_CUSTOMERS; + + private static final int NUM_OF_SALES_ORDERS = 5; + + private static final int NUM_OF_SUPPLIERS = 5; + + @Override + public void doSetUp() throws Exception + { + org.eclipse.emf.cdo.tests.model1.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(1); + org.eclipse.emf.cdo.tests.model1.legacy.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(1); + super.doSetUp(); + } + + @Override + public void doTearDown() throws Exception + { + org.eclipse.emf.cdo.tests.model1.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(0); + org.eclipse.emf.cdo.tests.model1.legacy.Model1Package.eINSTANCE.getSupplier_Preferred().setLowerBound(0); + super.doTearDown(); + } + + public void testSimpleQueries() throws Exception + { + msg("Opening session"); + CDOSession session = openSession(); + + createTestSet(session); + + session.close(); + session = openSession(); + msg("Opening transaction for querying"); + CDOTransaction transaction = session.openTransaction(); + + clearCache(getRepository().getRevisionManager()); + + { + msg("Query for products"); + CDOQuery cdoQuery = transaction.createQuery("hql", "from SalesOrder"); + addCacheParameter(cdoQuery); + cdoQuery.setMaxResults(1); + final List<SalesOrder> orders = cdoQuery.getResult(SalesOrder.class); + System.err.println(orders.get(0).getOrderDetails().get(0).getPrice()); + System.err.println(orders.get(0).getCustomer().getName()); + assertEquals(orders.size(), 1); + } + + transaction.commit(); + enableConsole(); + } + + private void createTestSet(CDOSession session) + { + disableConsole(); + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(); + + msg("Creating resource"); + CDOResource resource = transaction.createResource(getResourcePath("/test1")); + + fillResource(resource); + + try + { + msg("Committing"); + transaction.commit(); + } + catch (CommitException ex) + { + throw WrappedException.wrap(ex); + } + + enableConsole(); + } + + private void fillResource(CDOResource resource) + { + msg("Creating Testset"); + final List<Product1> products = new ArrayList<Product1>(); + for (int i = 0; i < NUM_OF_PRODUCTS; i++) + { + products.add(createProduct(i)); + } + + resource.getContents().addAll(products); + + int productCounter = 0; + for (int i = 0; i < NUM_OF_CUSTOMERS; i++) + { + final Customer customer = getModel1Factory().createCustomer(); + customer.setCity("City " + i); + customer.setName(i + ""); + customer.setStreet("Street " + i); + resource.getContents().add(customer); + + final List<Product1> customerProducts = products.subList(productCounter, productCounter + + NUM_OF_PRODUCTS_CUSTOMER); + for (int k = 0; k < NUM_OF_SALES_ORDERS; k++) + { + resource.getContents().add(createSalesOrder(i * 10 + k, customer, customerProducts)); + } + + productCounter += NUM_OF_PRODUCTS_CUSTOMER; + } + + final List<Supplier> suppliers = new ArrayList<Supplier>(); + for (int i = 0; i < NUM_OF_SUPPLIERS; i++) + { + suppliers.add(createSupplier(i)); + } + + resource.getContents().addAll(suppliers); + } + + private Supplier createSupplier(int i) + { + Supplier supplier = getModel1Factory().createSupplier(); + supplier.setCity("City " + i); + supplier.setName(i + ""); + supplier.setStreet("Street " + i); + // supplier.setPreferred(false); // will be persisted with its default value + return supplier; + } + + private SalesOrder createSalesOrder(int num, Customer customer, List<Product1> products) + { + SalesOrder salesOrder = getModel1Factory().createSalesOrder(); + salesOrder.setCustomer(customer); + salesOrder.setId(num); + createOrderDetail(salesOrder, num, products); + return salesOrder; + } + + private List<OrderDetail> createOrderDetail(Order order, int index, List<Product1> products) + { + final List<OrderDetail> orderDetails = new ArrayList<OrderDetail>(); + int count = 0; + for (Product1 product : products) + { + OrderDetail orderDetail = getModel1Factory().createOrderDetail(); + orderDetail.setOrder(order); + orderDetail.setPrice(count++ * index * 1.1f); + orderDetail.setProduct(product); + } + + return orderDetails; + } + + private Product1 createProduct(int index) + { + Product1 product = getModel1Factory().createProduct1(); + product.setDescription("Description " + index); + product.setName("" + index); + if (index < 10) + { + product.setVat(VAT.VAT15); + } + else + { + product.setVat(VAT.VAT7); + } + + return product; + } + + protected void addCacheParameter(CDOQuery query) + { + query.setParameter(IHibernateStore.CACHE_RESULTS, true); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateQueryTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateQueryTest.java index d7176a6930..8ecaf6c17e 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateQueryTest.java +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateQueryTest.java @@ -265,6 +265,7 @@ public class HibernateQueryTest extends AbstractCDOTest orderQuery.setParameter("od", orderDetail); final List<SalesOrder> sos = orderQuery.getResult(SalesOrder.class); assertEquals(1, sos.size()); + assertNotNull(sos.get(0).getCustomer().getName()); assertEquals(orderDetail.getOrder(), sos.get(0)); } } diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateXATransactionTest.java b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateXATransactionTest.java index 1872e434db..99823357c1 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateXATransactionTest.java +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/HibernateXATransactionTest.java @@ -26,7 +26,7 @@ public class HibernateXATransactionTest extends XATransactionTest { final IRepositoryConfig repConfig = getRepositoryConfig(); final HibernateConfig hbConfig = (HibernateConfig)repConfig; - final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/external_model1_4.persistence.xml"; + final String persistenceXML = "org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml"; hbConfig.getAdditionalProperties().put(HibernateStore.PERSISTENCE_XML, persistenceXML); super.doSetUp(); diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/external_model1_4.persistence.xml b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml index 72f7426704..d180ab06d2 100644 --- a/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/external_model1_4.persistence.xml +++ b/plugins/org.eclipse.emf.cdo.tests.hibernate/src/org/eclipse/emf/cdo/tests/hibernate/cdo_hibernate.persistence.xml @@ -2,6 +2,21 @@ <persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <epackage namespace-uri="http://www.eclipse.org/emf/CDO/tests/model6/1.0.0"> + + <eclass name="UnsettableAttributes"> + <property name="attrJavaClass"> + <type type="string"/> + </property> + </eclass> + + <eclass name="RefSingleNonContainedNPL"> + <property name="element"> + <external>org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDExternalUserType</external> + </property> + </eclass> + </epackage> + <epackage namespace-uri="http://www.eclipse.org/emf/CDO/tests/model4/1.0.0"> <eclass name="GenRefSingleNonContained"> @@ -9,10 +24,21 @@ <external>org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDExternalUserType</external> </property> </eclass> + + <eclass name="RefSingleNonContainedNPL"> + <property name="element"> + <external>org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDExternalUserType</external> + </property> + </eclass> </epackage> <epackage namespace-uri="http://www.eclipse.org/emf/CDO/tests/model1/1.0.0"> + <eclass name="Company"> + <property name="customers"> + <external>org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDExternalUserType</external> + </property> + </eclass> <eclass name="SalesOrder"> <property name="customer"> <external>org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDExternalUserType</external> |