Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2008-10-29 19:01:19 -0400
committerMartin Taal2008-10-29 19:01:19 -0400
commit71eff24bb817f62556c4b09b49981bc359f9d970 (patch)
tree0eb7bf0f40bd1354e2b77e256eb90f1e3fa3f759
parent9d855434c432f9b642b90ad5a967c6e20b5181f3 (diff)
downloadcdo-71eff24bb817f62556c4b09b49981bc359f9d970.tar.gz
cdo-71eff24bb817f62556c4b09b49981bc359f9d970.tar.xz
cdo-71eff24bb817f62556c4b09b49981bc359f9d970.zip
Added support for resourcenodes
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml69
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java77
2 files changed, 123 insertions, 23 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml
index 3bca46e40e..77f946f262 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/resource.hbm.xml
@@ -1,28 +1,59 @@
<?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="CDOResource" abstract="false" lazy="false" discriminator-value="cdoresource" table="`cdo_resources`">
- <meta attribute="eclassName">CDOResource</meta>
+ <class entity-name="CDOResourceNode" abstract="false" lazy="false"
+ discriminator-value="cdoresourcenode" table="`cdo_resources_structure`">
+ <meta attribute="eclassName">CDOResourceNode</meta>
<meta attribute="epackage">http://www.eclipse.org/emf/CDO/resource/2.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.cdo.server.internal.hibernate.tuplizer.CDOSyntheticIdPropertyHandler">
+ <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.cdo.server.internal.hibernate.tuplizer.CDOSyntheticIdPropertyHandler">
<meta attribute="syntheticId">true</meta>
- <generator class="native"/>
+ <generator class="native" />
</id>
- <discriminator column="`dtype`" type="string"/>
- <version name="e_version" column="e_version" access="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticVersionPropertyHandler">
+ <discriminator column="`dtype`" type="string" />
+ <version name="e_version" column="e_version"
+ access="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOSyntheticVersionPropertyHandler">
<meta attribute="syntheticVersion">true</meta>
</version>
- <property name="path" type="string" not-null="true" length="255" />
- <list name="contents" lazy="true" cascade="all,delete-orphan">
- <key/>
- <list-index/>
- <element type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType">
- <column name="entityName"/>
- <column name="idString"/>
- <column name="idBinary" length="1000"/>
- </element>
- </list>
+ <property name="containerID" type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType">
+ <column name="contID_Entity" unique-key="resourcepath"/>
+ <column name="contID_ID" unique-key="resourcepath"/>
+ <column name="contID_class" unique-key="resourcepath"/>
+ </property>
+ <property name="name" type="string" length="255">
+ <column name="name" unique-key="resourcepath"/>
+ </property>
+ <many-to-one name="folder" entity-name="CDOResourceFolder"
+ column="folderid" />
+ <subclass entity-name="CDOResourceFolder" abstract="false"
+ lazy="false" discriminator-value="cdoresourcefolder">
+ <meta attribute="eclassName">CDOResourceFolder</meta>
+ <meta attribute="epackage">http://www.eclipse.org/emf/CDO/resource/2.0.0</meta>
+ <list name="nodes" lazy="true" cascade="all"
+ inverse="true">
+ <key column="folderid" />
+ <list-index />
+ <one-to-many entity-name="CDOResourceNode" />
+ </list>
+ </subclass>
+ <subclass entity-name="CDOResource" abstract="false" lazy="false"
+ discriminator-value="cdoresource">
+ <meta attribute="eclassName">CDOResource</meta>
+ <meta attribute="epackage">http://www.eclipse.org/emf/CDO/resource/2.0.0</meta>
+ <list name="contents" lazy="true" cascade="all,delete-orphan">
+ <key />
+ <list-index />
+ <element
+ type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType">
+ <column name="entityName" />
+ <column name="idString" />
+ <column name="idBinary" length="1000" />
+ </element>
+ </list>
+ </subclass>
</class>
-</hibernate-mapping>
+</hibernate-mapping> \ No newline at end of file
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 d94fd752ab..fe6b0c33f8 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
@@ -13,10 +13,12 @@ package org.eclipse.emf.cdo.server.internal.hibernate;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDTemp;
+import org.eclipse.emf.cdo.common.id.CDOID.Type;
import org.eclipse.emf.cdo.common.model.CDOClassRef;
import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.common.model.CDOPackage;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
+import org.eclipse.emf.cdo.common.model.resource.CDOResourceNodeClass;
import org.eclipse.emf.cdo.common.query.CDOQueryInfo;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
@@ -25,20 +27,26 @@ import org.eclipse.emf.cdo.server.IQueryContext;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.ITransaction;
+import org.eclipse.emf.cdo.server.StoreUtil;
import org.eclipse.emf.cdo.server.hibernate.IHibernateStoreAccessor;
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.bundle.OM;
import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.PersistableListHolder;
+import org.eclipse.emf.cdo.spi.common.AbstractCDOIDLong;
import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
+import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.collection.CloseableIterator;
import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.hibernate.Criteria;
import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Expression;
import java.util.ArrayList;
import java.util.Arrays;
@@ -212,8 +220,10 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
public CDOID readResourceID(CDOID folderID, String name, long timeStamp)
{
- // TODO: implement HibernateStoreAccessor.readResourceID(folderID, name, timeStamp)
- throw new UnsupportedOperationException();
+ IStoreAccessor.QueryResourcesContext.ExactMatch context = StoreUtil.createExactMatchContext(folderID, name,
+ timeStamp);
+ queryResources(context);
+ return context.getResourceID();
// if (timeStamp != CDOProtocolView.UNSPECIFIED_DATE)
// {
@@ -276,8 +286,67 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
*/
public void queryResources(QueryResourcesContext context)
{
- // TODO: implement HibernateStoreAccessor.queryResources(context)
- throw new UnsupportedOperationException();
+ // logic description
+ CDOID folderID = context.getFolderID();
+ String name = context.getName();
+ boolean exactMatch = context.exactMatch();
+
+ CDOIDHibernate cdoID = null;
+ if (folderID.getType().equals(Type.NULL))
+ {
+ cdoID = null;
+ }
+ else if (folderID instanceof CDOIDHibernate)
+ {
+ cdoID = (CDOIDHibernate)folderID;
+ }
+ else if (folderID != null)
+ {
+ final long l = ((AbstractCDOIDLong)folderID).getLongValue();
+ cdoID = CDOIDHibernateFactoryImpl.getInstance().createCDOID(l, CDOResourceNodeClass.NAME);
+ }
+ final Session session = getHibernateSession();
+ final Criteria criteria = session.createCriteria(CDOResourceNodeClass.NAME);
+ if (cdoID == null)
+ {
+ criteria.add(Expression.isNull("containerID"));
+ }
+ else
+ {
+ criteria.add(Expression.eq("containerID", cdoID));
+ }
+ List<?> result = criteria.list();
+ for (Object o : result)
+ {
+ final CDORevision revision = (CDORevision)o;
+ String revisionName = (String)revision.getData().get(getResourceNameFeature(), 0);
+ boolean match = exactMatch || revisionName == null || name == null ? ObjectUtil.equals(revisionName, name)
+ : revisionName.startsWith(name);
+
+ if (match && !context.addResource(revision.getID()))
+ {
+ // No more results allowed
+ break;
+ }
+ }
+ //
+ // final Criteria c2 = session.createCriteria(CDOResourceNodeClass.NAME);
+ // for (Object o : c2.list())
+ // {
+ // final CDORevision cr = (CDORevision)o;
+ // System.err.println(cr.getData().get(getResourceNameFeature(), 0));
+ // System.err.println(cr.getData().getContainerID());
+ // }
+ }
+
+ private CDOFeature getResourceNameFeature()
+ {
+ return getResourceNodeClass().getCDONameFeature();
+ }
+
+ private CDOResourceNodeClass getResourceNodeClass()
+ {
+ return getStore().getRepository().getPackageManager().getCDOResourcePackage().getCDOResourceNodeClass();
}
/**

Back to the top