(4);
- for (String name : NAMES)
- {
- // create permission references as required, double checking for their existence first
- PermissionReference ref = new PermissionReferenceImpl();
- ref.setTypeUri(TYPE_URI_NEW);
- ref.setTypeName(TYPE_NAME_NEW);
- ref.setName(name);
-
- // it acts as its own key
- PermissionReference found = (PermissionReference) getHibernateTemplate().get(
- PermissionReferenceImpl.class,
- ref);
-
- if (found == null)
- {
- // it was not found, so create it
- getHibernateTemplate().save(ref);
- createdNames.add(QName.createQName(TYPE_URI_NEW, TYPE_NAME_NEW).toString() + "/" + name);
- }
- }
- return createdNames;
- }
-
- public int updatePermissionEntries()
- {
- HibernateCallback callback = new HibernateCallback()
- {
- public Object doInHibernate(Session session)
- {
- // flush any outstanding entities
- session.flush();
-
- Query query = session.getNamedQuery(HibernateHelper.QUERY_UPDATE_PERM_ENTRY_TYPE);
- query.setString("typeNameNew", TYPE_NAME_NEW)
- .setString("typeNameOld", TYPE_NAME_OLD)
- .setString("typeUriNew", TYPE_URI_NEW)
- .setString("typeUriOld", TYPE_URI_OLD)
- .setParameterList("names", NAMES);
- int updateCount = query.executeUpdate();
- return new Integer(updateCount);
- }
- };
- Integer updateCount = (Integer) getHibernateTemplate().execute(callback);
- // done
- return updateCount.intValue();
- }
- }
-}
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.admin.patch.impl;
+
+import org.alfresco.repo.admin.patch.AbstractPatch;
+import org.alfresco.service.cmr.admin.PatchException;
+import org.hibernate.SessionFactory;
+
+/**
+ * Roles defined in permissionsDefinition.xml moved from cm:content to sys:base.
+ * This effects the data stored in the node_perm_entry table.
+ *
+ * WILL NOT EXECUTE ANYMORE
+ *
+ * @author Derek Hulley
+ */
+public class ContentPermissionPatch extends AbstractPatch
+{
+ private static final String MSG_UPGRADE = "patch.contentPermission.upgrade";
+
+ public ContentPermissionPatch()
+ {
+ }
+
+ public void setSessionFactory(SessionFactory sessionFactory)
+ {
+ }
+
+ @Override
+ protected String applyInternal() throws Exception
+ {
+ throw new PatchException(MSG_UPGRADE);
+ }
+}
diff --git a/source/java/org/alfresco/repo/admin/patch/impl/GuestPersonPermissionPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/GuestPersonPermissionPatch.java
index e879b8d4ec..ab95ff71ad 100644
--- a/source/java/org/alfresco/repo/admin/patch/impl/GuestPersonPermissionPatch.java
+++ b/source/java/org/alfresco/repo/admin/patch/impl/GuestPersonPermissionPatch.java
@@ -64,7 +64,7 @@ public class GuestPersonPermissionPatch extends AbstractPatch
{
NodeRef personRef = personService.getPerson(guestId);
permissionService.setInheritParentPermissions(personRef, false);
- permissionService.deletePermission(personRef, guestId, PermissionService.CONSUMER, true);
+ permissionService.deletePermission(personRef, guestId, PermissionService.CONSUMER);
permissionService.setPermission(personRef, guestId, PermissionService.READ, true);
}
diff --git a/source/java/org/alfresco/repo/admin/patch/impl/PermissionDataPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/PermissionDataPatch.java
index 7ef13dd53a..8c815a7d1f 100644
--- a/source/java/org/alfresco/repo/admin/patch/impl/PermissionDataPatch.java
+++ b/source/java/org/alfresco/repo/admin/patch/impl/PermissionDataPatch.java
@@ -16,108 +16,35 @@
*/
package org.alfresco.repo.admin.patch.impl;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
-import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReference;
-import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReferenceImpl;
-import org.alfresco.service.namespace.NamespaceService;
-import org.hibernate.Query;
-import org.hibernate.Session;
+import org.alfresco.service.cmr.admin.PatchException;
import org.hibernate.SessionFactory;
-import org.springframework.orm.hibernate3.HibernateCallback;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* The roles defined in permissionsDefinition.xml moved from cm:folder to cm:cmobject.
* This effects the data stored in the node_perm_entry table.
*
* JIRA: {@link http://www.alfresco.org/jira/browse/AR-344 AR-344}
+ *
+ * WILL NOT EXECUTE ANYMORE
*
* @author Derek Hulley
*/
public class PermissionDataPatch extends AbstractPatch
{
- private static final String MSG_SUCCESS = "patch.updatePermissionData.result";
-
- private HibernateHelper helper;
+ private static final String MSG_UPGRADE = "patch.updatePermissionData.upgrade";
public PermissionDataPatch()
{
- helper = new HibernateHelper();
}
public void setSessionFactory(SessionFactory sessionFactory)
{
- this.helper.setSessionFactory(sessionFactory);
}
@Override
protected String applyInternal() throws Exception
{
- List createdNames = helper.createPermissionReferences();
- int updatedEntries = helper.updatePermissionEntries();
-
- // build the result message
- String msg = I18NUtil.getMessage(MSG_SUCCESS, createdNames, updatedEntries);
- // done
- return msg;
- }
-
- private static class HibernateHelper extends HibernateDaoSupport
- {
- private static final String TYPE_NAME_OLD = "folder";
- private static final String TYPE_NAME_NEW = "cmobject";
- private static final String[] NAMES = new String[] {"Coordinator", "Contributor", "Editor", "Guest"};
- private static final String QUERY_UPDATE_PERM_ENTRY_TYPENAME = "permission.patch.UpdatePermissionEntryTypeName";
-
- public List createPermissionReferences()
- {
- List createdNames = new ArrayList(4);
- for (String name : NAMES)
- {
- // create permission references as required, double checking for their existence first
- PermissionReference ref = new PermissionReferenceImpl();
- ref.setTypeUri(NamespaceService.CONTENT_MODEL_1_0_URI);
- ref.setTypeName(TYPE_NAME_NEW);
- ref.setName(name);
-
- // it acts as its own key
- PermissionReference found = (PermissionReference) getHibernateTemplate().get(
- PermissionReferenceImpl.class,
- ref);
-
- if (found == null)
- {
- // it was not found, so create it
- getHibernateTemplate().save(ref);
- createdNames.add(name);
- }
- }
- return createdNames;
- }
-
- public int updatePermissionEntries()
- {
- HibernateCallback callback = new HibernateCallback()
- {
- public Object doInHibernate(Session session)
- {
- // flush any outstanding entities
- session.flush();
-
- Query query = session.getNamedQuery(HibernateHelper.QUERY_UPDATE_PERM_ENTRY_TYPENAME);
- query.setString("typeNameNew", TYPE_NAME_NEW)
- .setString("typeNameOld", TYPE_NAME_OLD);
- int updateCount = query.executeUpdate();
- return new Integer(updateCount);
- }
- };
- Integer updateCount = (Integer) getHibernateTemplate().execute(callback);
- // done
- return updateCount.intValue();
- }
+ throw new PatchException(MSG_UPGRADE);
}
}
diff --git a/source/java/org/alfresco/repo/admin/patch/impl/SpacesRootPermissionPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/SpacesRootPermissionPatch.java
index 26f21356a3..ff9a03d2e0 100644
--- a/source/java/org/alfresco/repo/admin/patch/impl/SpacesRootPermissionPatch.java
+++ b/source/java/org/alfresco/repo/admin/patch/impl/SpacesRootPermissionPatch.java
@@ -62,7 +62,7 @@ public class SpacesRootPermissionPatch extends AbstractPatch
protected String applyInternal() throws Exception
{
NodeRef rootNodeRef = nodeService.getRootNode(spacesBootstrap.getStoreRef());
- permissionService.deletePermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER, true);
+ permissionService.deletePermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER);
permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true);
return I18NUtil.getMessage(MSG_SUCCESS);
diff --git a/source/java/org/alfresco/repo/admin/patch/impl/UpdateGuestPermissionPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/UpdateGuestPermissionPatch.java
index 14d9d5819c..58fd936812 100644
--- a/source/java/org/alfresco/repo/admin/patch/impl/UpdateGuestPermissionPatch.java
+++ b/source/java/org/alfresco/repo/admin/patch/impl/UpdateGuestPermissionPatch.java
@@ -1,123 +1,47 @@
-/*
- * Copyright (C) 2005 Alfresco, Inc.
- *
- * Licensed under the Mozilla Public License version 1.1
- * with a permitted attribution clause. You may obtain a
- * copy of the License at
- *
- * http://www.alfresco.org/legal/license.txt
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the
- * License.
- */
-package org.alfresco.repo.admin.patch.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.alfresco.i18n.I18NUtil;
-import org.alfresco.model.ContentModel;
-import org.alfresco.repo.admin.patch.AbstractPatch;
-import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReference;
-import org.alfresco.repo.security.permissions.impl.hibernate.PermissionReferenceImpl;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.springframework.orm.hibernate3.HibernateCallback;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-
-/**
- * The permission 'Guest' has been renamed to 'Consumer'.
- *
- * @author David Caruana
- */
-public class UpdateGuestPermissionPatch extends AbstractPatch
-{
- private static final String MSG_SUCCESS = "patch.updateGuestPermission.result";
-
- private HibernateHelper helper;
-
- public UpdateGuestPermissionPatch()
- {
- helper = new HibernateHelper();
- }
-
- public void setSessionFactory(SessionFactory sessionFactory)
- {
- this.helper.setSessionFactory(sessionFactory);
- }
-
- @Override
- protected String applyInternal() throws Exception
- {
- List createdNames = helper.createPermissionReferences();
- int updatedPermEntries = helper.updatePermissionEntries();
-
- // build the result message
- String msg = I18NUtil.getMessage(MSG_SUCCESS, createdNames, updatedPermEntries);
- // done
- return msg;
- }
-
- private static class HibernateHelper extends HibernateDaoSupport
- {
- private static final String NAME_OLD = "Guest";
- private static final String NAME_NEW = "Consumer";
- private static final String[] NAMES = new String[] {"Consumer"};
-
- private static final String QUERY_UPDATE_PERM_ENTRY_NAME = "permission.patch.UpdatePermissionName";
-
-
- public List createPermissionReferences()
- {
- List createdNames = new ArrayList(4);
- for (String name : NAMES)
- {
- // create permission references as required, double checking for their existence first
- PermissionReference ref = new PermissionReferenceImpl();
- ref.setTypeUri(ContentModel.TYPE_CMOBJECT.getNamespaceURI());
- ref.setTypeName(ContentModel.TYPE_CMOBJECT.getLocalName());
- ref.setName(name);
-
- // it acts as its own key
- PermissionReference found = (PermissionReference) getHibernateTemplate().get(
- PermissionReferenceImpl.class,
- ref);
-
- if (found == null)
- {
- // it was not found, so create it
- getHibernateTemplate().save(ref);
- createdNames.add(name);
- }
- }
- return createdNames;
- }
-
- public int updatePermissionEntries()
- {
- HibernateCallback callback = new HibernateCallback()
- {
- public Object doInHibernate(Session session)
- {
- // flush any outstanding entities
- session.flush();
-
- Query query = session.getNamedQuery(HibernateHelper.QUERY_UPDATE_PERM_ENTRY_NAME);
- query.setString("nameNew", NAME_NEW)
- .setString("nameOld", NAME_OLD);
- int updateCount = query.executeUpdate();
- return new Integer(updateCount);
- }
- };
- Integer updateCount = (Integer) getHibernateTemplate().execute(callback);
- // done
- return updateCount.intValue();
- }
-
- }
-}
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.admin.patch.impl;
+
+import org.alfresco.repo.admin.patch.AbstractPatch;
+import org.alfresco.service.cmr.admin.PatchException;
+import org.hibernate.SessionFactory;
+
+/**
+ * The permission 'Guest' has been renamed to 'Consumer'.
+ *
+ * WILL NOT EXECUTE ANYMORE
+ *
+ * @author David Caruana
+ */
+public class UpdateGuestPermissionPatch extends AbstractPatch
+{
+ private static final String MSG_UPGRADE = "patch.updateGuestPermission.upgrade";
+
+ public UpdateGuestPermissionPatch()
+ {
+ }
+
+ public void setSessionFactory(SessionFactory sessionFactory)
+ {
+ }
+
+ @Override
+ protected String applyInternal() throws Exception
+ {
+ throw new PatchException(MSG_UPGRADE);
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/DbAccessControlEntry.java b/source/java/org/alfresco/repo/domain/DbAccessControlEntry.java
new file mode 100644
index 0000000000..9983a57bc8
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/DbAccessControlEntry.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain;
+
+
+
+/**
+ * The interface against which permission entries are persisted
+ *
+ * @author andyh
+ */
+
+public interface DbAccessControlEntry
+{
+ /**
+ * @return Returns the identifier for this object
+ */
+ public long getId();
+
+ /**
+ * @return Returns the containing access control list
+ */
+ public DbAccessControlList getAccessControlList();
+
+ /**
+ * @param acl the accession control list to which entry belongs
+ */
+ public void setAccessControlList(DbAccessControlList acl);
+
+ /**
+ * @return Returns the permission to which this entry applies
+ */
+ public DbPermission getPermission();
+
+ /**
+ * @param permission the permission to which the entry applies
+ */
+ public void setPermission(DbPermission permission);
+
+ /**
+ * @return Returns the authority to which this entry applies
+ */
+ public DbAuthority getAuthority();
+
+ /**
+ * @param authority the authority to which this entry applies
+ */
+ public void setAuthority(DbAuthority authority);
+
+ /**
+ * @return Returns true if this permission is allowed
+ */
+ public boolean isAllowed();
+
+ /**
+ * Set if this permission is allowed, otherwise it is denied.
+ *
+ * @param allowed
+ */
+ public void setAllowed(boolean allowed);
+}
diff --git a/source/java/org/alfresco/repo/security/permissions/impl/hibernate/NodePermissionEntry.java b/source/java/org/alfresco/repo/domain/DbAccessControlList.java
similarity index 52%
rename from source/java/org/alfresco/repo/security/permissions/impl/hibernate/NodePermissionEntry.java
rename to source/java/org/alfresco/repo/domain/DbAccessControlList.java
index 9f13d179a1..891c98b77f 100644
--- a/source/java/org/alfresco/repo/security/permissions/impl/hibernate/NodePermissionEntry.java
+++ b/source/java/org/alfresco/repo/domain/DbAccessControlList.java
@@ -14,40 +14,21 @@
* language governing permissions and limitations under the
* License.
*/
-package org.alfresco.repo.security.permissions.impl.hibernate;
+package org.alfresco.repo.domain;
-import java.util.Set;
-
-import org.alfresco.repo.domain.NodeKey;
-import org.alfresco.service.cmr.repository.NodeRef;
/**
- * The interface to support persistence of node permission entries in hibernate
+ * The interface to support persistence of node access control entries in hibernate
*
* @author andyh
*/
-public interface NodePermissionEntry
+public interface DbAccessControlList
{
- /**
- * Get the node key.
- *
- * @return
- */
- public NodeKey getNodeKey();
+ public long getId();
- /**
- * Set the node key.
- *
- * @param key
- */
- public void setNodeKey(NodeKey key);
+ public Node getNode();
- /**
- * Get the node ref
- *
- * @return
- */
- public NodeRef getNodeRef();
+ public void setNode(Node node);
/**
* Get inheritance behaviour
@@ -62,9 +43,9 @@ public interface NodePermissionEntry
public void setInherits(boolean inherits);
/**
- * Get the permission entries set for the node
- * @return
+ * Delete the entries related to this access control list
+ *
+ * @return Returns the number of entries deleted
*/
- public Set getPermissionEntries();
-
+ public int deleteEntries();
}
diff --git a/source/java/org/alfresco/repo/security/permissions/impl/hibernate/Recipient.java b/source/java/org/alfresco/repo/domain/DbAuthority.java
similarity index 66%
rename from source/java/org/alfresco/repo/security/permissions/impl/hibernate/Recipient.java
rename to source/java/org/alfresco/repo/domain/DbAuthority.java
index 47c0a56112..485fa45ee1 100644
--- a/source/java/org/alfresco/repo/security/permissions/impl/hibernate/Recipient.java
+++ b/source/java/org/alfresco/repo/domain/DbAuthority.java
@@ -14,7 +14,7 @@
* language governing permissions and limitations under the
* License.
*/
-package org.alfresco.repo.security.permissions.impl.hibernate;
+package org.alfresco.repo.domain;
import java.io.Serializable;
import java.util.Set;
@@ -23,26 +23,27 @@ import java.util.Set;
* The interface against which recipients of permission are persisted
* @author andyh
*/
-public interface Recipient extends Serializable
+public interface DbAuthority extends Serializable
{
/**
- * Get the recipient.
- *
- * @return
+ * @return Returns the recipient
*/
public String getRecipient();
/**
- * Set the recipient
- *
- * @param recipient
+ * @param recipient the authority recipient
*/
public void setRecipient(String recipient);
/**
- * Get the external keys that map to this recipient.
- *
- * @return
+ * @return Returns the external keys associated with this authority
*/
public Set getExternalKeys();
+
+ /**
+ * Delete the access control entries related to this authority
+ *
+ * @return Returns the number of entries deleted
+ */
+ public int deleteEntries();
}
diff --git a/source/java/org/alfresco/repo/domain/DbPermission.java b/source/java/org/alfresco/repo/domain/DbPermission.java
new file mode 100644
index 0000000000..d1e741c2b5
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/DbPermission.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain;
+
+import java.io.Serializable;
+
+import org.alfresco.service.namespace.QName;
+
+/**
+ * The interface against which permission references are persisted in hibernate.
+ *
+ * @author andyh
+ */
+public interface DbPermission extends Serializable
+{
+ /**
+ * @return Returns the automatically assigned ID
+ */
+ public long getId();
+
+ /**
+ * @return Returns the qualified name of this permission
+ */
+ public QName getTypeQname();
+
+ /**
+ * @param qname the entity representing the qname for this instance
+ */
+ public void setTypeQname(QName qname);
+
+ /**
+ * @return Returns the permission name
+ */
+ public String getName();
+
+ /**
+ * @param name the name of the permission
+ */
+ public void setName(String name);
+}
diff --git a/source/java/org/alfresco/repo/domain/Node.java b/source/java/org/alfresco/repo/domain/Node.java
index 0779fe05de..c85eb73e07 100644
--- a/source/java/org/alfresco/repo/domain/Node.java
+++ b/source/java/org/alfresco/repo/domain/Node.java
@@ -33,38 +33,33 @@ import org.alfresco.service.namespace.QName;
public interface Node
{
/**
- * @return Returns the unique key for this node
+ * Convenience method to get the reference to the node
+ *
+ * @return Returns the reference to this node
*/
- public NodeKey getKey();
-
+ public NodeRef getNodeRef();
+
/**
- * @param key the unique node key
+ * @return Returns the auto-generated ID
*/
- public void setKey(NodeKey key);
+ public Long getId();
public Store getStore();
public void setStore(Store store);
+ public String getUuid();
+
+ public void setUuid(String uuid);
+
public QName getTypeQName();
public void setTypeQName(QName typeQName);
- /**
- * Set the status of the node. This is compulsory, but a node
- * status may exist without a node being present.
- *
- * @param nodeStatus
- */
- public void setStatus(NodeStatus nodeStatus);
-
- /**
- * Get the mandatory node status object
- *
- * @return
- */
- public NodeStatus getStatus();
-
+// public NodeStatus getStatus();
+//
+// public void setStatus(NodeStatus status);
+//
public Set getAspects();
/**
@@ -83,10 +78,7 @@ public interface Node
public Map getProperties();
- /**
- * Convenience method to get the reference to the node
- *
- * @return Returns the reference to this node
- */
- public NodeRef getNodeRef();
+ public DbAccessControlList getAccessControlList();
+
+// public void setAccessControlList(DbAccessControlList accessControlList);
}
diff --git a/source/java/org/alfresco/repo/domain/NodeKey.java b/source/java/org/alfresco/repo/domain/NodeKey.java
index 7d45956d72..9f6acef750 100644
--- a/source/java/org/alfresco/repo/domain/NodeKey.java
+++ b/source/java/org/alfresco/repo/domain/NodeKey.java
@@ -18,6 +18,8 @@ package org.alfresco.repo.domain;
import java.io.Serializable;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.util.EqualsHelper;
/**
@@ -36,14 +38,26 @@ public class NodeKey implements Serializable
public NodeKey()
{
}
+
+ public NodeKey(NodeRef nodeRef)
+ {
+ this(nodeRef.getStoreRef(), nodeRef.getId());
+ }
- public NodeKey(StoreKey storeKey, String guid)
- {
- setGuid(guid);
- setProtocol(storeKey.getProtocol());
- setIdentifier(storeKey.getIdentifier());
- }
-
+ public NodeKey(StoreRef storeRef, String guid)
+ {
+ setGuid(guid);
+ setProtocol(storeRef.getProtocol());
+ setIdentifier(storeRef.getIdentifier());
+ }
+
+ public NodeKey(StoreKey storeKey, String guid)
+ {
+ setGuid(guid);
+ setProtocol(storeKey.getProtocol());
+ setIdentifier(storeKey.getIdentifier());
+ }
+
public NodeKey(String protocol, String identifier, String guid)
{
setGuid(guid);
diff --git a/source/java/org/alfresco/repo/domain/NodeStatus.java b/source/java/org/alfresco/repo/domain/NodeStatus.java
index b6b2046958..4df06d8cf1 100644
--- a/source/java/org/alfresco/repo/domain/NodeStatus.java
+++ b/source/java/org/alfresco/repo/domain/NodeStatus.java
@@ -37,11 +37,13 @@ public interface NodeStatus
*/
public void setKey(NodeKey key);
+ public Node getNode();
+
+ public void setNode(Node node);
+
public String getChangeTxnId();
public void setChangeTxnId(String txnId);
- public void setDeleted(boolean deleted);
-
public boolean isDeleted();
}
diff --git a/source/java/org/alfresco/repo/domain/dao/QNameDaoComponent.java b/source/java/org/alfresco/repo/domain/dao/QNameDaoComponent.java
new file mode 100644
index 0000000000..c361216f98
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/dao/QNameDaoComponent.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain.dao;
+
+import org.alfresco.repo.domain.QNameEntity;
+import org.alfresco.service.namespace.QName;
+
+/**
+ * Service layer accessing persistent qname entities directly
+ *
+ * @author Derek Hulley
+ */
+public interface QNameDaoComponent
+{
+ /**
+ * Create a qname entity
+ *
+ * @param qname the qualified name to persist
+ * @return Returns either a newly created instance or an existing matching instance
+ */
+ public QNameEntity createQNameEntity(QName qname);
+
+ /**
+ * @param qname the qname to match
+ * @return Returns the entity if it exists, otherwise null
+ */
+ public QNameEntity getQNameEntity(QName qname);
+
+ /**
+ * @param namespaceUri the namespace URI
+ * @param localName the localname part
+ * @return Return the entity if it exists, otherwise null
+ */
+ public QNameEntity getQNameEntity(String namespaceUri, String localName);
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/DbAccessControlEntryImpl.java b/source/java/org/alfresco/repo/domain/hibernate/DbAccessControlEntryImpl.java
new file mode 100644
index 0000000000..88b2b76a0b
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/DbAccessControlEntryImpl.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import org.alfresco.repo.domain.DbAccessControlEntry;
+import org.alfresco.repo.domain.DbAccessControlList;
+import org.alfresco.repo.domain.DbAuthority;
+import org.alfresco.repo.domain.DbPermission;
+import org.alfresco.util.EqualsHelper;
+
+/**
+ * Persisted permission entries
+ *
+ * @author andyh
+ */
+public class DbAccessControlEntryImpl implements DbAccessControlEntry
+{
+ /** The object id */
+ private long id;
+
+ /** The container of these entries */
+ private DbAccessControlList accessControlList;
+
+ /** The permission to which this applies (non null - all is a special string) */
+ private DbPermission permission;
+
+ /** The recipient to which this applies (non null - all is a special string) */
+ private DbAuthority authority;
+
+ /** Is this permission allowed? */
+ private boolean allowed;
+
+ public DbAccessControlEntryImpl()
+ {
+ super();
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("DbAccessControlEntryImpl")
+ .append("[ id=").append(id)
+ .append(", acl=").append(accessControlList.getId())
+ .append(", permission=").append(permission.getId())
+ .append(", authority=").append(authority.getRecipient())
+ .append("]");
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (!(o instanceof DbAccessControlEntry))
+ {
+ return false;
+ }
+ DbAccessControlEntry other = (DbAccessControlEntry) o;
+ return (this.allowed == other.isAllowed())
+ && EqualsHelper.nullSafeEquals(this.accessControlList, other.getAccessControlList())
+ && EqualsHelper.nullSafeEquals(this.permission, other.getPermission())
+ && EqualsHelper.nullSafeEquals(this.authority, other.getAuthority());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int hashCode = accessControlList.hashCode();
+ if (permission != null)
+ {
+ hashCode = hashCode * 37 + permission.hashCode();
+ }
+ if (authority != null)
+ {
+ hashCode = hashCode * 37 + authority.hashCode();
+ }
+ hashCode = hashCode * 37 + (allowed ? 1 : 0);
+ return hashCode;
+ }
+
+ /**
+ * Factory method to create an entry and wire it in to the contained nodePermissionEntry
+ *
+ * @param accessControlList the list of entries that this one belongs to
+ * @param permission the mandatory permission association with this entry
+ * @param authority the mandatory authority
+ * @param allowed allowed or disallowed
+ * @return Returns an unpersisted entity
+ */
+ public static DbAccessControlEntryImpl create(
+ DbAccessControlList accessControlList,
+ DbPermission permission,
+ DbAuthority authority,
+ boolean allowed)
+ {
+ DbAccessControlEntryImpl accessControlEntry = new DbAccessControlEntryImpl();
+ accessControlEntry.setAccessControlList(accessControlList);
+ accessControlEntry.setPermission(permission);
+ accessControlEntry.setAuthority(authority);
+ accessControlEntry.setAllowed(allowed);
+ return accessControlEntry;
+ }
+
+ public long getId()
+ {
+ return id;
+ }
+
+ /**
+ * For Hibernate use
+ */
+ /* package */ void setId(long id)
+ {
+ this.id = id;
+ }
+
+ public DbAccessControlList getAccessControlList()
+ {
+ return accessControlList;
+ }
+
+ public void setAccessControlList(DbAccessControlList nodePermissionEntry)
+ {
+ this.accessControlList = nodePermissionEntry;
+ }
+
+ public DbPermission getPermission()
+ {
+ return permission;
+ }
+
+ public void setPermission(DbPermission permissionReference)
+ {
+ this.permission = permissionReference;
+ }
+
+ public DbAuthority getAuthority()
+ {
+ return authority;
+ }
+
+ public void setAuthority(DbAuthority recipient)
+ {
+ this.authority = recipient;
+ }
+
+ public boolean isAllowed()
+ {
+ return allowed;
+ }
+
+ public void setAllowed(boolean allowed)
+ {
+ this.allowed = allowed;
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/DbAccessControlListImpl.java b/source/java/org/alfresco/repo/domain/hibernate/DbAccessControlListImpl.java
new file mode 100644
index 0000000000..06692722e7
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/DbAccessControlListImpl.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import org.alfresco.repo.domain.DbAccessControlList;
+import org.alfresco.repo.domain.Node;
+import org.alfresco.util.EqualsHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.CallbackException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+/**
+ * The hibernate persisted class for node permission entries.
+ *
+ * @author andyh
+ */
+public class DbAccessControlListImpl extends LifecycleAdapter implements DbAccessControlList
+{
+ private static Log logger = LogFactory.getLog(DbAccessControlListImpl.class);
+
+ private long id;
+ private Node node;
+ private boolean inherits;
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("DbAccessControlListImpl")
+ .append("[ id=").append(id)
+ .append(", node=").append(node)
+ .append(", inherits=").append(inherits)
+ .append("]");
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (!(o instanceof DbAccessControlList))
+ {
+ return false;
+ }
+ DbAccessControlList other = (DbAccessControlList) o;
+
+ return (this.inherits == other.getInherits())
+ && (EqualsHelper.nullSafeEquals(this.node, other.getNode()));
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (node == null ? 0 : node.hashCode());
+ }
+
+ public int deleteEntries()
+ {
+ /*
+ * This can use a delete direct to the database as well, but then care must be taken
+ * to evict the instances from the session.
+ */
+
+ // bypass L2 cache and get all entries for this list
+ Query query = getSession()
+ .getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_AC_ENTRIES_FOR_AC_LIST)
+ .setLong("accessControlListId", this.id);
+ int count = HibernateHelper.deleteQueryResults(getSession(), query);
+ // done
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Deleted " + count + " access entries for access control list " + this.id);
+ }
+ return count;
+ }
+
+ /**
+ * Ensures that all this access control list's entries have been deleted.
+ */
+ public boolean onDelete(Session session) throws CallbackException
+ {
+ deleteEntries();
+ return super.onDelete(session);
+ }
+
+ public long getId()
+ {
+ return id;
+ }
+
+ /**
+ * Hibernate use
+ */
+ @SuppressWarnings("unused")
+ private void setId(long id)
+ {
+ this.id = id;
+ }
+
+ public Node getNode()
+ {
+ return node;
+ }
+
+ public void setNode(Node node)
+ {
+ this.node = node;
+ }
+
+ public DbAccessControlListImpl()
+ {
+ super();
+ }
+
+ public boolean getInherits()
+ {
+ return inherits;
+ }
+
+ public void setInherits(boolean inherits)
+ {
+ this.inherits = inherits;
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/DbAuthorityImpl.java b/source/java/org/alfresco/repo/domain/hibernate/DbAuthorityImpl.java
new file mode 100644
index 0000000000..5194057763
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/DbAuthorityImpl.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.alfresco.repo.domain.DbAuthority;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.CallbackException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+/**
+ * The persisted class for authorities.
+ *
+ * @author andyh
+ */
+public class DbAuthorityImpl extends LifecycleAdapter implements DbAuthority
+{
+ private static final long serialVersionUID = -5582068692208928127L;
+
+ private static Log logger = LogFactory.getLog(DbAuthorityImpl.class);
+
+ private String recipient;
+ private Set externalKeys = new HashSet();
+
+ public DbAuthorityImpl()
+ {
+ super();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if(this == o)
+ {
+ return true;
+ }
+ if(!(o instanceof DbAuthority))
+ {
+ return false;
+ }
+ DbAuthority other = (DbAuthority)o;
+ return this.getRecipient().equals(other.getRecipient());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getRecipient().hashCode();
+ }
+
+ public int deleteEntries()
+ {
+ /*
+ * This can use a delete direct to the database as well, but then care must be taken
+ * to evict the instances from the session.
+ */
+
+ // bypass L2 cache and get all entries for this list
+ Query query = getSession()
+ .getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_AC_ENTRIES_FOR_AUTHORITY)
+ .setString("recipient", this.recipient);
+ int count = HibernateHelper.deleteQueryResults(getSession(), query);
+ // done
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Deleted " + count + " access entries for access control list " + this.recipient);
+ }
+ return count;
+ }
+
+ /**
+ * Ensures that all this access control list's entries have been deleted.
+ */
+ public boolean onDelete(Session session) throws CallbackException
+ {
+ deleteEntries();
+ return super.onDelete(session);
+ }
+
+ public String getRecipient()
+ {
+ return recipient;
+ }
+
+ public void setRecipient(String recipient)
+ {
+ this.recipient = recipient;
+ }
+
+ public Set getExternalKeys()
+ {
+ return externalKeys;
+ }
+
+ // Hibernate
+ /* package */ void setExternalKeys(Set externalKeys)
+ {
+ this.externalKeys = externalKeys;
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/DbPermissionImpl.java b/source/java/org/alfresco/repo/domain/hibernate/DbPermissionImpl.java
new file mode 100644
index 0000000000..1e270483db
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/DbPermissionImpl.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import org.alfresco.repo.domain.DbPermission;
+import org.alfresco.service.namespace.QName;
+import org.alfresco.util.EqualsHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.CallbackException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+/**
+ * The persisted class for permissions.
+ *
+ * @author andyh
+ */
+public class DbPermissionImpl extends LifecycleAdapter implements DbPermission
+{
+ private static final long serialVersionUID = -6352566900815035461L;
+
+ private static Log logger = LogFactory.getLog(DbPermissionImpl.class);
+
+ private long id;
+ private QName typeQname;
+ private String name;
+
+ public DbPermissionImpl()
+ {
+ super();
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("PermissionImpl")
+ .append("[ id=").append(id)
+ .append(", typeQname=").append(typeQname)
+ .append(", name=").append(getName())
+ .append("]");
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if(this == o)
+ {
+ return true;
+ }
+ if(!(o instanceof DbPermission))
+ {
+ return false;
+ }
+ DbPermission other = (DbPermission)o;
+ return (EqualsHelper.nullSafeEquals(typeQname, other.getTypeQname()))
+ && (EqualsHelper.nullSafeEquals(name, other.getName()));
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return typeQname.hashCode() + (37 * name.hashCode());
+ }
+
+ public int deleteEntries()
+ {
+ /*
+ * This can use a delete direct to the database as well, but then care must be taken
+ * to evict the instances from the session.
+ */
+
+ // bypass L2 cache and get all entries for this list
+ Query query = getSession()
+ .getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_AC_ENTRIES_FOR_PERMISSION)
+ .setSerializable("permissionId", this.id);
+ int count = HibernateHelper.deleteQueryResults(getSession(), query);
+ // done
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Deleted " + count + " access entries for permission " + this.id);
+ }
+ return count;
+ }
+
+ /**
+ * Ensures that all this access control list's entries have been deleted.
+ */
+ public boolean onDelete(Session session) throws CallbackException
+ {
+ deleteEntries();
+ return super.onDelete(session);
+ }
+
+ public long getId()
+ {
+ return id;
+ }
+
+ /**
+ * For Hibernate use
+ */
+ @SuppressWarnings("unused")
+ private void setId(long id)
+ {
+ this.id = id;
+ }
+
+ public QName getTypeQname()
+ {
+ return typeQname;
+ }
+
+ public void setTypeQname(QName typeQname)
+ {
+ this.typeQname = typeQname;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Helper method to find a permission based on its natural key
+ *
+ * @param session the Hibernate session to use
+ * @param qname the type qualified name
+ * @param name the name of the permission
+ * @return Returns an existing instance or null if not found
+ */
+ public static DbPermission find(Session session, QName qname, String name)
+ {
+ Query query = session
+ .getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_PERMISSION)
+ .setString("permissionTypeQName", qname.toString())
+ .setString("permissionName", name);
+ return (DbPermission) query.uniqueResult();
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/HibernateHelper.java b/source/java/org/alfresco/repo/domain/hibernate/HibernateHelper.java
new file mode 100644
index 0000000000..86070d90a8
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/HibernateHelper.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import org.hibernate.CacheMode;
+import org.hibernate.ObjectDeletedException;
+import org.hibernate.Query;
+import org.hibernate.ScrollMode;
+import org.hibernate.ScrollableResults;
+import org.hibernate.Session;
+
+/**
+ * Helper methods related to Hibernate
+ *
+ * @author Derek Hulley
+ */
+public class HibernateHelper
+{
+ /**
+ * Helper method to scroll through the results of a query and delete all the
+ * results, performing batch flushes. This will handle large resultsets by
+ * pulling the results directly in from the query. For certain circumstances, it
+ * may be better to perform a bulk delete directly instead.
+ *
+ * @param session the session to use for the deletions
+ * @param query the query with all parameters set
+ * @return Returns the number of entities deleted, regardless of type
+ */
+ public static int deleteQueryResults(Session session, Query query)
+ {
+ ScrollableResults entities = query.setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);
+ int count = 0;
+ while (entities.next())
+ {
+ Object[] entityResults = entities.get();
+ for (Object object : entityResults)
+ {
+ try
+ {
+ session.delete(object);
+ }
+ catch (ObjectDeletedException e)
+ {
+ // ignore - it's what we wanted
+ }
+ if (++count % 50 == 0)
+ {
+ session.flush();
+ session.clear();
+ }
+ }
+ }
+ return count;
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java b/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java
index dd8b5b4838..86b8021c84 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java
+++ b/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java
@@ -41,6 +41,7 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
+import org.hibernate.exception.ConstraintViolationException;
/**
* Test persistence and retrieval of Hibernate-specific implementations of the
@@ -48,6 +49,7 @@ import org.alfresco.util.GUID;
*
* @author Derek Hulley
*/
+@SuppressWarnings("unused")
public class HibernateNodeTest extends BaseSpringTest
{
private static final String TEST_NAMESPACE = "http://www.alfresco.org/test/HibernateNodeTest";
@@ -62,7 +64,7 @@ public class HibernateNodeTest extends BaseSpringTest
{
store = new StoreImpl();
StoreKey storeKey = new StoreKey(StoreRef.PROTOCOL_WORKSPACE,
- "TestWorkspace@" + System.currentTimeMillis());
+ "TestWorkspace@" + System.currentTimeMillis() + " - " + System.nanoTime());
store.setKey(storeKey);
// persist so that it is present in the hibernate cache
getSession().save(store);
@@ -82,46 +84,13 @@ public class HibernateNodeTest extends BaseSpringTest
public void testGetStore() throws Exception
{
- NodeKey key = new NodeKey("Random Protocol", "Random Identifier", "AAA");
- // create the node status
- NodeStatus nodeStatus = new NodeStatusImpl();
- nodeStatus.setKey(key);
- nodeStatus.setDeleted(false);
- nodeStatus.setChangeTxnId("txn:123");
- getSession().save(nodeStatus);
// create a new Node
Node node = new NodeImpl();
- node.setKey(key);
- node.setStore(store); // not meaningful as it contradicts the key
- node.setTypeQName(ContentModel.TYPE_CONTAINER);
- node.setStatus(nodeStatus);
- // persist it
- try
- {
- Serializable id = getSession().save(node);
- fail("No store exists");
- }
- catch (Throwable e)
- {
- // expected
- }
- // this should not solve the problem
node.setStore(store);
- // persist it
- try
- {
- Serializable id = getSession().save(node);
- fail("Setting store does not persist protocol and identifier attributes");
- }
- catch (Throwable e)
- {
- // expected
- }
-
- // fix the key
- key = new NodeKey(store.getKey().getProtocol(), store.getKey().getIdentifier(), "AAA");
- node.setKey(key);
- // now it should work
+ node.setUuid(GUID.generate());
+ node.setTypeQName(ContentModel.TYPE_CONTAINER);
+
+ // now it should work
Serializable id = getSession().save(node);
// throw the reference away and get the a new one for the id
@@ -139,36 +108,42 @@ public class HibernateNodeTest extends BaseSpringTest
// create the node status
NodeStatus nodeStatus = new NodeStatusImpl();
nodeStatus.setKey(key);
- nodeStatus.setDeleted(false);
nodeStatus.setChangeTxnId("txn:123");
getSession().save(nodeStatus);
- // it must be able to exist without the node
- flushAndClear();
-
// create a new Node
Node node = new NodeImpl();
node.setStore(store);
- node.setKey(key);
- node.setStore(store); // not meaningful as it contradicts the key
+ node.setUuid(GUID.generate());
node.setTypeQName(ContentModel.TYPE_CONTAINER);
- node.setStatus(nodeStatus);
- Serializable id = getSession().save(node);
-
- // flush
+ Serializable nodeId = getSession().save(node);
+
+ // This should all be fine. The node does not HAVE to have a status.
flushAndClear();
-
- // is the status retrievable
- node = (Node) getSession().get(NodeImpl.class, id);
- nodeStatus = node.getStatus();
+
+ // set the node
+ nodeStatus = (NodeStatus) getSession().get(NodeStatusImpl.class, key);
+ nodeStatus.setNode(node);
+ flushAndClear();
+
+ // is the node retrievable?
+ nodeStatus = (NodeStatus) getSession().get(NodeStatusImpl.class, key);
+ node = nodeStatus.getNode();
+ assertNotNull("Node was not attached to status", node);
// change the values
nodeStatus.setChangeTxnId("txn:456");
- nodeStatus.setDeleted(true);
// delete the node
getSession().delete(node);
- // flush
- flushAndClear();
+ try
+ {
+ flushAndClear();
+ fail("Node status may not refer to non-existent node");
+ }
+ catch(ConstraintViolationException e)
+ {
+ // expected
+ }
}
/**
@@ -176,18 +151,11 @@ public class HibernateNodeTest extends BaseSpringTest
*/
public void testProperties() throws Exception
{
- NodeKey key = new NodeKey(store.getKey(), "AAA");
- // create the node status
- NodeStatus nodeStatus = new NodeStatusImpl();
- nodeStatus.setKey(key);
- nodeStatus.setDeleted(false);
- nodeStatus.setChangeTxnId("txn:123");
- getSession().save(nodeStatus);
// create a new Node
Node node = new NodeImpl();
- node.setKey(key);
+ node.setStore(store);
+ node.setUuid(GUID.generate());
node.setTypeQName(ContentModel.TYPE_CONTAINER);
- node.setStatus(nodeStatus);
// give it a property map
Map propertyMap = new HashMap(5);
QName propertyQName = QName.createQName("{}A");
@@ -213,19 +181,11 @@ public class HibernateNodeTest extends BaseSpringTest
*/
public void testAspects() throws Exception
{
- NodeKey key = new NodeKey(store.getKey(), GUID.generate());
- // create the node status
- NodeStatus nodeStatus = new NodeStatusImpl();
- nodeStatus.setKey(key);
- nodeStatus.setDeleted(false);
- nodeStatus.setChangeTxnId("txn:123");
- getSession().save(nodeStatus);
// make a real node
Node node = new NodeImpl();
- node.setKey(key);
node.setStore(store);
+ node.setUuid(GUID.generate());
node.setTypeQName(ContentModel.TYPE_CMOBJECT);
- node.setStatus(nodeStatus);
// add some aspects
QName aspect1 = QName.createQName(TEST_NAMESPACE, "1");
@@ -254,33 +214,20 @@ public class HibernateNodeTest extends BaseSpringTest
public void testNodeAssoc() throws Exception
{
- NodeKey sourceKey = new NodeKey(store.getKey(), GUID.generate());
// make a source node
- NodeStatus sourceNodeStatus = new NodeStatusImpl();
- sourceNodeStatus.setKey(sourceKey);
- sourceNodeStatus.setDeleted(false);
- sourceNodeStatus.setChangeTxnId("txn:123");
- getSession().save(sourceNodeStatus);
Node sourceNode = new NodeImpl();
- sourceNode.setKey(sourceKey);
sourceNode.setStore(store);
+ sourceNode.setUuid(GUID.generate());
sourceNode.setTypeQName(ContentModel.TYPE_CMOBJECT);
- sourceNode.setStatus(sourceNodeStatus);
- Serializable realNodeKey = getSession().save(sourceNode);
+ Serializable realNodeId = getSession().save(sourceNode);
// make a container node
- NodeKey targetKey = new NodeKey(store.getKey(), GUID.generate());
- NodeStatus targetNodeStatus = new NodeStatusImpl();
- targetNodeStatus.setKey(targetKey);
- targetNodeStatus.setDeleted(false);
- targetNodeStatus.setChangeTxnId("txn:123");
- getSession().save(targetNodeStatus);
Node targetNode = new NodeImpl();
- targetNode.setKey(targetKey);
targetNode.setStore(store);
+ targetNode.setStore(store);
+ targetNode.setUuid(GUID.generate());
targetNode.setTypeQName(ContentModel.TYPE_CONTAINER);
- targetNode.setStatus(targetNodeStatus);
- Serializable containerNodeKey = getSession().save(targetNode);
+ Serializable containerNodeId = getSession().save(targetNode);
// create an association between them
NodeAssoc assoc = new NodeAssocImpl();
@@ -299,13 +246,13 @@ public class HibernateNodeTest extends BaseSpringTest
getSession().clear();
// reload the source
- sourceNode = (Node) getSession().get(NodeImpl.class, sourceKey);
+ sourceNode = (Node) getSession().get(NodeImpl.class, realNodeId);
assertNotNull("Source node not found", sourceNode);
// check that the associations are present
assertEquals("Expected exactly 2 target assocs", 2, sourceNode.getTargetNodeAssocs().size());
// reload the target
- targetNode = (Node) getSession().get(NodeImpl.class, targetKey);
+ targetNode = (Node) getSession().get(NodeImpl.class, containerNodeId);
assertNotNull("Target node not found", targetNode);
// check that the associations are present
assertEquals("Expected exactly 2 source assocs", 2, targetNode.getSourceNodeAssocs().size());
@@ -314,32 +261,17 @@ public class HibernateNodeTest extends BaseSpringTest
public void testChildAssoc() throws Exception
{
// make a content node
- NodeKey key = new NodeKey(store.getKey(), GUID.generate());
- NodeStatus contentNodeStatus = new NodeStatusImpl();
- contentNodeStatus.setKey(key);
- contentNodeStatus.setDeleted(false);
- contentNodeStatus.setChangeTxnId("txn:123");
- getSession().save(contentNodeStatus);
Node contentNode = new NodeImpl();
- contentNode.setKey(key);
contentNode.setStore(store);
contentNode.setTypeQName(ContentModel.TYPE_CONTENT);
- contentNode.setStatus(contentNodeStatus);
- Serializable contentNodeKey = getSession().save(contentNode);
+ Serializable contentNodeId = getSession().save(contentNode);
// make a container node
- key = new NodeKey(store.getKey(), GUID.generate());
- NodeStatus containerNodeStatus = new NodeStatusImpl();
- containerNodeStatus.setKey(key);
- containerNodeStatus.setDeleted(false);
- containerNodeStatus.setChangeTxnId("txn:123");
- getSession().save(containerNodeStatus);
Node containerNode = new NodeImpl();
- containerNode.setKey(key);
containerNode.setStore(store);
+ containerNode.setUuid(GUID.generate());
containerNode.setTypeQName(ContentModel.TYPE_CONTAINER);
- containerNode.setStatus(containerNodeStatus);
- Serializable containerNodeKey = getSession().save(containerNode);
+ Serializable containerNodeId = getSession().save(containerNode);
// create an association to the content
ChildAssoc assoc1 = new ChildAssocImpl();
assoc1.setIsPrimary(true);
@@ -362,7 +294,7 @@ public class HibernateNodeTest extends BaseSpringTest
// flushAndClear();
// reload the container
- containerNode = (Node) getSession().get(NodeImpl.class, containerNodeKey);
+ containerNode = (Node) getSession().get(NodeImpl.class, containerNodeId);
assertNotNull("Node not found", containerNode);
// check
assertEquals("Expected exactly 2 children", 2, containerNode.getChildAssocs().size());
@@ -371,8 +303,8 @@ public class HibernateNodeTest extends BaseSpringTest
ChildAssoc assoc = (ChildAssoc) iterator.next();
// the node id must be known
assertNotNull("Node not populated on assoc", assoc.getChild());
- assertEquals("Node key on child assoc is incorrect", contentNodeKey,
- assoc.getChild().getKey());
+ assertEquals("Node key on child assoc is incorrect",
+ contentNodeId, assoc.getChild().getId());
}
// check that we can traverse the association from the child
@@ -397,20 +329,12 @@ public class HibernateNodeTest extends BaseSpringTest
*/
public void testCaching() throws Exception
{
- NodeKey key = new NodeKey(store.getKey(), GUID.generate());
-
// make a node
- NodeStatus nodeStatus = new NodeStatusImpl();
- nodeStatus.setKey(key);
- nodeStatus.setDeleted(false);
- nodeStatus.setChangeTxnId("txn:123");
- getSession().save(nodeStatus);
Node node = new NodeImpl();
- node.setKey(key);
node.setStore(store);
+ node.setUuid(GUID.generate());
node.setTypeQName(ContentModel.TYPE_CONTENT);
- node.setStatus(nodeStatus);
- getSession().save(node);
+ Serializable nodeId = getSession().save(node);
// add some aspects to the node
Set aspects = node.getAspects();
@@ -421,7 +345,7 @@ public class HibernateNodeTest extends BaseSpringTest
properties.put(ContentModel.PROP_NAME, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
// check that the session hands back the same instance
- Node checkNode = (Node) getSession().get(NodeImpl.class, key);
+ Node checkNode = (Node) getSession().get(NodeImpl.class, nodeId);
assertNotNull(checkNode);
assertTrue("Node retrieved was not same instance", checkNode == node);
@@ -448,7 +372,7 @@ public class HibernateNodeTest extends BaseSpringTest
txn.begin();
// check that the L2 cache hands back the same instance
- checkNode = (Node) getSession().get(NodeImpl.class, key);
+ checkNode = (Node) getSession().get(NodeImpl.class, nodeId);
assertNotNull(checkNode);
checkAspects = checkNode.getAspects();
diff --git a/source/java/org/alfresco/repo/domain/hibernate/LifecycleAdapter.java b/source/java/org/alfresco/repo/domain/hibernate/LifecycleAdapter.java
new file mode 100644
index 0000000000..54c202accc
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/LifecycleAdapter.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * Licensed under the Mozilla Public License version 1.1
+ * with a permitted attribution clause. You may obtain a
+ * copy of the License at
+ *
+ * http://www.alfresco.org/legal/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the
+ * License.
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import java.io.Serializable;
+
+import org.hibernate.CallbackException;
+import org.hibernate.Session;
+import org.hibernate.classic.Lifecycle;
+
+/**
+ * Helper base class providing lifecycle and other support
+ *
+ * @author Derek Hulley
+ */
+public abstract class LifecycleAdapter implements Lifecycle
+{
+ /** Helper */
+ private Session session;
+
+ /**
+ * @return Returns the session that this object was used in
+ */
+ protected Session getSession()
+ {
+ return session;
+ }
+
+ /**
+ * @return Returns NO_VETO always
+ */
+ public boolean onDelete(Session session) throws CallbackException
+ {
+ return NO_VETO;
+ }
+
+ /** NO OP */
+ public void onLoad(Session session, Serializable id)
+ {
+ this.session = session;
+ }
+
+ /** @return Returns NO_VETO always */
+ public boolean onSave(Session session) throws CallbackException
+ {
+ this.session = session;
+ return NO_VETO;
+ }
+
+ /** @return Returns NO_VETO always */
+ public boolean onUpdate(Session session) throws CallbackException
+ {
+ this.session = session;
+ return NO_VETO;
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/Node.hbm.xml b/source/java/org/alfresco/repo/domain/hibernate/Node.hbm.xml
index 133f2f13e7..10684f573b 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/Node.hbm.xml
+++ b/source/java/org/alfresco/repo/domain/hibernate/Node.hbm.xml
@@ -17,21 +17,41 @@
select-before-update="false"
lazy="true"
optimistic-lock="version" >
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+