From 602440a9836202567705651a5e1470fb84bdc15a Mon Sep 17 00:00:00 2001 From: Britt Park Date: Wed, 25 Apr 2007 18:35:26 +0000 Subject: [PATCH] Interim checkin for ListAttribute support. Should fix build breakage also. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5551 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/attributes-service-context.xml | 8 + config/alfresco/avm-services-context.xml | 8 +- config/alfresco/bootstrap-context.xml | 7 + .../alfresco/repo/attributes/Attribute.java | 44 ++- .../repo/attributes/AttributeConverter.java | 8 + .../repo/attributes/AttributeImpl.java | 53 +++- .../repo/attributes/AttributeServiceTest.java | 27 +- .../repo/attributes/AttributeValue.java | 49 ++++ .../repo/attributes/ListAttribute.java | 34 +++ .../repo/attributes/ListAttributeImpl.java | 251 ++++++++++++++++++ .../repo/attributes/ListAttributeValue.java | 198 ++++++++++++++ .../alfresco/repo/attributes/ListEntry.java | 53 ++++ .../repo/attributes/ListEntryDAO.java | 75 ++++++ .../repo/attributes/ListEntryImpl.java | 106 ++++++++ .../repo/attributes/MapAttributeImpl.java | 14 + .../repo/attributes/MapAttributeValue.java | 5 + .../alfresco/repo/attributes/MapEntryDAO.java | 7 + .../hibernate/AttributeDAOHibernate.java | 22 ++ .../attributes/hibernate/Attributes.hbm.xml | 17 +- .../hibernate/ListEntryDAOHibernate.java | 100 +++++++ .../hibernate/MapEntryDAOHibernate.java | 10 + .../java/org/alfresco/repo/avm/AVMDAOs.java | 8 + .../repo/avm/locking/AVMLockingBootstrap.java | 61 +++++ .../cmr/attributes/AttributeService.java | 1 - 24 files changed, 1156 insertions(+), 10 deletions(-) create mode 100644 source/java/org/alfresco/repo/attributes/ListAttribute.java create mode 100644 source/java/org/alfresco/repo/attributes/ListAttributeImpl.java create mode 100644 source/java/org/alfresco/repo/attributes/ListAttributeValue.java create mode 100644 source/java/org/alfresco/repo/attributes/ListEntry.java create mode 100644 source/java/org/alfresco/repo/attributes/ListEntryDAO.java create mode 100644 source/java/org/alfresco/repo/attributes/ListEntryImpl.java create mode 100644 source/java/org/alfresco/repo/attributes/hibernate/ListEntryDAOHibernate.java create mode 100644 source/java/org/alfresco/repo/avm/locking/AVMLockingBootstrap.java diff --git a/config/alfresco/attributes-service-context.xml b/config/alfresco/attributes-service-context.xml index e4329c35a9..1ed9d275fa 100644 --- a/config/alfresco/attributes-service-context.xml +++ b/config/alfresco/attributes-service-context.xml @@ -25,6 +25,9 @@ + + + @@ -42,4 +45,9 @@ + + + + + \ No newline at end of file diff --git a/config/alfresco/avm-services-context.xml b/config/alfresco/avm-services-context.xml index 5c28dedd9a..2eaa7d371d 100644 --- a/config/alfresco/avm-services-context.xml +++ b/config/alfresco/avm-services-context.xml @@ -87,7 +87,7 @@ - + @@ -125,6 +125,9 @@ + + + @@ -254,8 +257,7 @@ - + diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index dd062783d4..46a5e6535c 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -67,6 +67,13 @@ + + + + + + + diff --git a/source/java/org/alfresco/repo/attributes/Attribute.java b/source/java/org/alfresco/repo/attributes/Attribute.java index 77a67f5f47..c1fbd5a334 100644 --- a/source/java/org/alfresco/repo/attributes/Attribute.java +++ b/source/java/org/alfresco/repo/attributes/Attribute.java @@ -27,6 +27,7 @@ package org.alfresco.repo.attributes; import java.io.Serializable; import java.util.Collection; +import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -36,7 +37,7 @@ import org.alfresco.repo.domain.DbAccessControlList; * Interface for polymorphic attributes. * @author britt */ -public interface Attribute extends Serializable +public interface Attribute extends Serializable, Iterable { public static enum Type implements Serializable { @@ -49,7 +50,8 @@ public interface Attribute extends Serializable DOUBLE, STRING, SERIALIZABLE, - MAP + MAP, + LIST }; /** @@ -232,4 +234,42 @@ public interface Attribute extends Serializable * @return The values. */ public Collection values(); + + /** + * Add an attribute to a list attribute. + * @param attr + */ + public void add(Attribute attr); + + /** + * Add an attribute to a list attribute at a given position. + * @param index The offset. + * @param attr The attribute. + */ + public void add(int index, Attribute attr); + + /** + * Get the size of a List of a Map. + * @return + */ + public int size(); + + /** + * Get an iterator over a list's entries. + * @return + */ + public Iterator iterator(); + + /** + * Get an Attribute from a List. + * @param index The offset. + * @return The Attribute or null. + */ + public Attribute get(int index); + + /** + * Remove an entry from a list. + * @param index The entry to remove. + */ + public void remove(int index); } diff --git a/source/java/org/alfresco/repo/attributes/AttributeConverter.java b/source/java/org/alfresco/repo/attributes/AttributeConverter.java index 716ebe794c..61c7c4db5c 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeConverter.java +++ b/source/java/org/alfresco/repo/attributes/AttributeConverter.java @@ -83,6 +83,10 @@ public class AttributeConverter { return new MapAttributeImpl((MapAttribute)from); } + case LIST : + { + return new ListAttributeImpl((ListAttribute)from); + } default : { throw new AlfrescoRuntimeException("Invalid Attribute Type: " + from.getType()); @@ -134,6 +138,10 @@ public class AttributeConverter { return new MapAttributeValue((MapAttribute)from); } + case LIST : + { + return new ListAttributeValue((ListAttribute)from); + } default : { throw new AlfrescoRuntimeException("Invalid Attribute Type: " + from.getType()); diff --git a/source/java/org/alfresco/repo/attributes/AttributeImpl.java b/source/java/org/alfresco/repo/attributes/AttributeImpl.java index 2f887071ec..48a3bae8aa 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/AttributeImpl.java @@ -27,6 +27,7 @@ package org.alfresco.repo.attributes; import java.io.Serializable; import java.util.Collection; +import java.util.Iterator; import java.util.Set; import java.util.Map.Entry; @@ -110,7 +111,7 @@ public abstract class AttributeImpl implements Attribute */ public Attribute get(String key) { - throw new AttributeMethodNotImplemented("Not MapValue"); + throw new AttributeMethodNotImplemented("Not Map or List"); } /* (non-Javadoc) @@ -174,7 +175,7 @@ public abstract class AttributeImpl implements Attribute */ public void put(String key, Attribute value) { - throw new AttributeMethodNotImplemented("Not MapValue"); + throw new AttributeMethodNotImplemented("Not Map or List."); } /* (non-Javadoc) @@ -346,4 +347,52 @@ public abstract class AttributeImpl implements Attribute { fACL = acl; } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#add(org.alfresco.repo.attributes.Attribute) + */ + public void add(Attribute attr) + { + throw new AttributeMethodNotImplemented("Not a List."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#add(int, org.alfresco.repo.attributes.Attribute) + */ + public void add(int index, Attribute attr) + { + throw new AttributeMethodNotImplemented("Not a List."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#iterator() + */ + public Iterator iterator() + { + throw new AttributeMethodNotImplemented("Not a List."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#size() + */ + public int size() + { + throw new AttributeMethodNotImplemented("Not a List or Map."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#get(int) + */ + public Attribute get(int index) + { + throw new AttributeMethodNotImplemented("Not a List."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#remove(int) + */ + public void remove(int index) + { + throw new AttributeMethodNotImplemented("Not a List."); + } } diff --git a/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java b/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java index 1db703836a..e536b9d373 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java +++ b/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java @@ -103,7 +103,8 @@ public class AttributeServiceTest extends TestCase assertNotNull(fService.getAttribute("boolean")); assertEquals(42, (int)fService.getAttribute("short").getShortValue()); assertEquals("I sneeze.", fService.getAttribute("map/funky").getStringValue()); - assertEquals(10, fService.getKeys("").size()); + // This is 11 because of the AVMLockingService. + assertEquals(11, fService.getKeys("").size()); assertEquals(5, fService.getKeys("map").size()); List keys = fService.getKeys(""); for (String key : keys) @@ -276,4 +277,28 @@ public class AttributeServiceTest extends TestCase } } + /** + * Test ListAttributes + */ + public void testList() + { + try + { + ListAttribute list = new ListAttributeValue(); + list.add(new IntAttributeValue(0)); + list.add(new IntAttributeValue(1)); + list.add(new IntAttributeValue(2)); + list.add(new IntAttributeValue(3)); + list.add(new IntAttributeValue(4)); + fService.setAttribute("", "dummy", list); + Attribute found = fService.getAttribute("dummy"); + assertNotNull(found); + assertEquals(5, found.size()); + } + catch (Exception e) + { + e.printStackTrace(); + fail(); + } + } } diff --git a/source/java/org/alfresco/repo/attributes/AttributeValue.java b/source/java/org/alfresco/repo/attributes/AttributeValue.java index a7b4ffcc6c..6f14c217b2 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeValue.java +++ b/source/java/org/alfresco/repo/attributes/AttributeValue.java @@ -27,6 +27,7 @@ package org.alfresco.repo.attributes; import java.io.Serializable; import java.util.Collection; +import java.util.Iterator; import java.util.Set; import java.util.Map.Entry; @@ -286,4 +287,52 @@ public abstract class AttributeValue implements Attribute { fACL = acl; } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#add(org.alfresco.repo.attributes.Attribute) + */ + public void add(Attribute attr) + { + throw new AttributeMethodNotImplemented("Not a List."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#add(int, org.alfresco.repo.attributes.Attribute) + */ + public void add(int index, Attribute attr) + { + throw new AttributeMethodNotImplemented("Not a List."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#iterator() + */ + public Iterator iterator() + { + throw new AttributeMethodNotImplemented("Not a List."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#size() + */ + public int size() + { + throw new AttributeMethodNotImplemented("Not a List or Map."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#get(int) + */ + public Attribute get(int index) + { + throw new AttributeMethodNotImplemented("Not a List."); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#remove(int) + */ + public void remove(int index) + { + throw new AttributeMethodNotImplemented("Not a List."); + } } diff --git a/source/java/org/alfresco/repo/attributes/ListAttribute.java b/source/java/org/alfresco/repo/attributes/ListAttribute.java new file mode 100644 index 0000000000..b45b972ff6 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/ListAttribute.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +/** + * List Attribute dummy interface. + * @author britt + */ +public interface ListAttribute extends Attribute +{ +} diff --git a/source/java/org/alfresco/repo/attributes/ListAttributeImpl.java b/source/java/org/alfresco/repo/attributes/ListAttributeImpl.java new file mode 100644 index 0000000000..cd9beb46cb --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/ListAttributeImpl.java @@ -0,0 +1,251 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.service.cmr.avm.AVMBadArgumentException; + +/** + * Persistent implementation of a list attribute. + * @author britt + */ +public class ListAttributeImpl extends AttributeImpl implements ListAttribute +{ + private static final long serialVersionUID = -394553378173857035L; + + public ListAttributeImpl() + { + } + + public ListAttributeImpl(ListAttribute other) + { + int index = 0; + AVMDAOs.Instance().fAttributeDAO.save(this); + for (Attribute entry : other) + { + Attribute newEntry = null; + switch (entry.getType()) + { + case BOOLEAN : + { + newEntry = new BooleanAttributeImpl((BooleanAttribute)entry); + break; + } + case BYTE : + { + newEntry = new ByteAttributeImpl((ByteAttribute)entry); + break; + } + case SHORT : + { + newEntry = new ShortAttributeImpl((ShortAttribute)entry); + break; + } + case INT : + { + newEntry = new IntAttributeImpl((IntAttribute)entry); + break; + } + case LONG : + { + newEntry = new LongAttributeImpl((LongAttribute)entry); + break; + } + case FLOAT : + { + newEntry = new FloatAttributeImpl((FloatAttribute)entry); + break; + } + case DOUBLE : + { + newEntry = new DoubleAttributeImpl((DoubleAttribute)entry); + break; + } + case STRING : + { + newEntry = new StringAttributeImpl((StringAttribute)entry); + break; + } + case SERIALIZABLE : + { + newEntry = new SerializableAttributeImpl((SerializableAttribute)entry); + break; + } + case MAP : + { + newEntry = new MapAttributeImpl((MapAttribute)entry); + break; + } + case LIST : + { + newEntry = new ListAttributeImpl((ListAttribute)entry); + break; + } + default : + { + throw new AlfrescoRuntimeException("Unknown Attribute Type: " + entry.getType()); + } + } + ListEntry listEntry = new ListEntryImpl(this, index++, newEntry); + AVMDAOs.Instance().fListEntryDAO.save(listEntry); + } + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.LIST; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#add(org.alfresco.repo.attributes.Attribute) + */ + @Override + public void add(Attribute attr) + { + int size = AVMDAOs.Instance().fListEntryDAO.size(this); + ListEntry entry = new ListEntryImpl(this, size, attr); + AVMDAOs.Instance().fListEntryDAO.save(entry); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#add(int, org.alfresco.repo.attributes.Attribute) + */ + @Override + public void add(int index, Attribute attr) + { + ListEntryDAO dao = AVMDAOs.Instance().fListEntryDAO; + int size = dao.size(this); + if (index > size || index < 0) + { + throw new AVMBadArgumentException("Index out of bounds: " + index); + } + for (int i = size; i > index; i--) + { + ListEntry entry = dao.get(this, i - 1); + ListEntry newEntry = new ListEntryImpl(this, i, entry.getAttribute()); + dao.delete(entry); + dao.save(newEntry); + } + ListEntry newEntry = new ListEntryImpl(this, index, attr); + dao.save(newEntry); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#clear() + */ + @Override + public void clear() + { + AVMDAOs.Instance().fListEntryDAO.delete(this); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#get(int) + */ + @Override + public Attribute get(int index) + { + ListEntry entry = AVMDAOs.Instance().fListEntryDAO.get(this, index); + if (entry == null) + { + return null; + } + return entry.getAttribute(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#iterator() + */ + @Override + public Iterator iterator() + { + List entries = AVMDAOs.Instance().fListEntryDAO.get(this); + List attrList = new ArrayList(); + for (ListEntry entry : entries) + { + attrList.add(entry.getAttribute()); + } + return attrList.iterator(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#size() + */ + @Override + public int size() + { + return AVMDAOs.Instance().fListEntryDAO.size(this); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#remove(java.lang.String) + */ + @Override + public void remove(int index) + { + ListEntryDAO dao = AVMDAOs.Instance().fListEntryDAO; + ListEntry entry = dao.get(this, index); + if (entry == null) + { + throw new AVMBadArgumentException("Index out of bounds: " + index); + } + int size = dao.size(this); + dao.delete(entry); + AVMDAOs.Instance().fAttributeDAO.delete(entry.getAttribute()); + for (int i = index; i < size - 1; i++) + { + entry = dao.get(this, i + 1); + ListEntry newEntry = new ListEntryImpl(this, i, entry.getAttribute()); + dao.delete(entry); + dao.save(newEntry); + } + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append('['); + for (Attribute child : this) + { + builder.append(child.toString()); + builder.append(' '); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/source/java/org/alfresco/repo/attributes/ListAttributeValue.java b/source/java/org/alfresco/repo/attributes/ListAttributeValue.java new file mode 100644 index 0000000000..b2c368d931 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/ListAttributeValue.java @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.alfresco.error.AlfrescoRuntimeException; + +/** + * Value based implementation of a list attribute. + * @author britt + */ +public class ListAttributeValue extends AttributeValue implements ListAttribute +{ + private static final long serialVersionUID = 791121577967727000L; + + private List fData; + + public ListAttributeValue() + { + fData = new ArrayList(); + } + + public ListAttributeValue(ListAttribute attr) + { + this(); + for (Attribute child : attr) + { + Attribute newAttr = null; + switch (child.getType()) + { + case BOOLEAN : + { + newAttr = new BooleanAttributeValue((BooleanAttribute)child); + break; + } + case BYTE : + { + newAttr = new ByteAttributeValue((ByteAttribute)child); + break; + } + case SHORT : + { + newAttr = new ShortAttributeValue((ShortAttribute)child); + break; + } + case INT : + { + newAttr = new IntAttributeValue((IntAttribute)child); + break; + } + case LONG : + { + newAttr = new LongAttributeValue((LongAttribute)child); + break; + } + case FLOAT : + { + newAttr = new FloatAttributeValue((FloatAttribute)child); + break; + } + case DOUBLE : + { + newAttr = new DoubleAttributeValue((DoubleAttribute)child); + break; + } + case STRING : + { + newAttr = new StringAttributeValue((StringAttribute)child); + break; + } + case SERIALIZABLE : + { + newAttr = new SerializableAttributeValue((SerializableAttribute)child); + break; + } + case MAP : + { + newAttr = new MapAttributeValue((MapAttribute)child); + break; + } + case LIST : + { + newAttr = new ListAttributeValue((ListAttribute)child); + break; + } + default : + { + throw new AlfrescoRuntimeException("Unknown Attribute Type: " + child.getType()); + } + } + fData.add(newAttr); + } + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#get(int) + */ + public Attribute get(int index) + { + return fData.get(index); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#getType() + */ + public Type getType() + { + return Type.LIST; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#add(org.alfresco.repo.attributes.Attribute) + */ + @Override + public void add(Attribute attr) + { + fData.add(attr); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#add(int, org.alfresco.repo.attributes.Attribute) + */ + @Override + public void add(int index, Attribute attr) + { + fData.add(index, attr); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#iterator() + */ + @Override + public Iterator iterator() + { + return fData.iterator(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#size() + */ + @Override + public int size() + { + return fData.size(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#remove(int) + */ + @Override + public void remove(int index) + { + fData.remove(index); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append('['); + for (Attribute child : fData) + { + builder.append(child.toString()); + builder.append(' '); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/source/java/org/alfresco/repo/attributes/ListEntry.java b/source/java/org/alfresco/repo/attributes/ListEntry.java new file mode 100644 index 0000000000..6407363a13 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/ListEntry.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import java.io.Serializable; + +/** + * Interface for list entries. + * @author britt + */ +public interface ListEntry extends Serializable +{ + /** + * Get the List this is an entry for. + * @return The ListAttribute. + */ + public ListAttribute getList(); + + /** + * Get the index of this entry in the ListAttribute. + * @return The index. + */ + public int getIndex(); + + /** + * Get the Attribute for this entry. + * @return The Attribute + */ + public Attribute getAttribute(); +} diff --git a/source/java/org/alfresco/repo/attributes/ListEntryDAO.java b/source/java/org/alfresco/repo/attributes/ListEntryDAO.java new file mode 100644 index 0000000000..b8c56de36f --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/ListEntryDAO.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +import java.util.List; + +/** + * DAO interface for ListEntries. + * @author britt + */ +public interface ListEntryDAO +{ + /** + * Save a new Entry. + * @param entry + */ + public void save(ListEntry entry); + + /** + * Get the entry for the give list and index. + * @param list The ListAttribute. + * @param index The index. + * @return The ListEntry. + */ + public ListEntry get(ListAttribute list, int index); + + /** + * Get all entries for a given list. + * @param list The ListAttribute. + * @return The entries. + */ + public List get(ListAttribute list); + + /** + * Delete a list entry. + * @param entry + */ + public void delete(ListEntry entry); + + /** + * Delete all entries from a list. + * @param list + */ + public void delete(ListAttribute list); + + /** + * Get the size of the entries. + * @param list The list. + * @return The count of entries. + */ + public int size(ListAttribute list); +} diff --git a/source/java/org/alfresco/repo/attributes/ListEntryImpl.java b/source/java/org/alfresco/repo/attributes/ListEntryImpl.java new file mode 100644 index 0000000000..5d98fb04ed --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/ListEntryImpl.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes; + +/** + * Implementation of ListEntry + * @author britt + */ +public class ListEntryImpl implements ListEntry +{ + private static final long serialVersionUID = 1573391734169157835L; + + private long fID; + + private ListAttribute fList; + + private int fIndex; + + private Attribute fAttribute; + + /** + * Default constructor. + */ + public ListEntryImpl() + { + } + + public ListEntryImpl(ListAttribute list, int index, Attribute attr) + { + fList = list; + fIndex = index; + fAttribute = attr; + } + + public void setId(long id) + { + fID = id; + } + + public long getId() + { + return fID; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntry#getAttribute() + */ + public Attribute getAttribute() + { + return fAttribute; + } + + public void setAttribute(Attribute attr) + { + fAttribute = attr; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntry#getIndex() + */ + public int getIndex() + { + return fIndex; + } + + public void setIndex(int index) + { + fIndex = index; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntry#getList() + */ + public ListAttribute getList() + { + return fList; + } + + public void setList(ListAttribute list) + { + fList = list; + } +} diff --git a/source/java/org/alfresco/repo/attributes/MapAttributeImpl.java b/source/java/org/alfresco/repo/attributes/MapAttributeImpl.java index 02e52c0699..89a9e5bb1e 100644 --- a/source/java/org/alfresco/repo/attributes/MapAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/MapAttributeImpl.java @@ -110,6 +110,11 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute newAttr = new MapAttributeImpl((MapAttribute)value); break; } + case LIST : + { + newAttr = new ListAttributeImpl((ListAttribute)value); + break; + } default : { throw new AlfrescoRuntimeException("Unknown Attribute Type: " + value.getType()); @@ -248,4 +253,13 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute builder.append('}'); return builder.toString(); } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#size() + */ + @Override + public int size() + { + return AVMDAOs.Instance().fMapEntryDAO.size(this); + } } diff --git a/source/java/org/alfresco/repo/attributes/MapAttributeValue.java b/source/java/org/alfresco/repo/attributes/MapAttributeValue.java index 49267c0f91..655c335e65 100644 --- a/source/java/org/alfresco/repo/attributes/MapAttributeValue.java +++ b/source/java/org/alfresco/repo/attributes/MapAttributeValue.java @@ -108,6 +108,11 @@ public class MapAttributeValue extends AttributeValue implements MapAttribute newAttr = new MapAttributeValue((MapAttribute)value); break; } + case LIST : + { + newAttr = new ListAttributeValue((ListAttribute)value); + break; + } default : { throw new AlfrescoRuntimeException("Unknown Attribute Type: " + value.getType()); diff --git a/source/java/org/alfresco/repo/attributes/MapEntryDAO.java b/source/java/org/alfresco/repo/attributes/MapEntryDAO.java index 23e6d10636..1e4f5b16f0 100644 --- a/source/java/org/alfresco/repo/attributes/MapEntryDAO.java +++ b/source/java/org/alfresco/repo/attributes/MapEntryDAO.java @@ -40,4 +40,11 @@ public interface MapEntryDAO * @return A List of all entries in the given map. */ public List get(MapAttribute mapAttr); + + /** + * Get the number of entries in a MapAttribute. + * @param mapAttr The MapAttribute/ + * @return The number of entries. + */ + public int size(MapAttribute mapAttr); } diff --git a/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java b/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java index abd3fc7bb3..5dfab1abf9 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java +++ b/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java @@ -33,6 +33,8 @@ import java.util.Map; import org.alfresco.repo.attributes.AttrQueryHelperImpl; import org.alfresco.repo.attributes.Attribute; import org.alfresco.repo.attributes.AttributeDAO; +import org.alfresco.repo.attributes.ListAttribute; +import org.alfresco.repo.attributes.ListEntryDAO; import org.alfresco.repo.attributes.MapAttribute; import org.alfresco.repo.attributes.MapEntry; import org.alfresco.repo.attributes.MapEntryDAO; @@ -52,6 +54,8 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements { private MapEntryDAO fMapEntryDAO; + private ListEntryDAO fListEntryDAO; + public AttributeDAOHibernate() { } @@ -61,6 +65,11 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements fMapEntryDAO = dao; } + public void setListEntryDao(ListEntryDAO dao) + { + fListEntryDAO = dao; + } + /* (non-Javadoc) * @see org.alfresco.repo.attributes.AttributeDAO#delete(org.alfresco.repo.attributes.Attribute) */ @@ -76,6 +85,19 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements delete(subAttr); } } + if (attr.getType() == Type.LIST) + { + List children = new ArrayList(); + for (Attribute child : attr) + { + children.add(child); + } + fListEntryDAO.delete((ListAttribute)attr); + for (Attribute child : children) + { + delete(child); + } + } getSession().delete(attr); } diff --git a/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml b/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml index 185d4168ec..d6afb33cdf 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml +++ b/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml @@ -67,6 +67,10 @@ + + + @@ -83,5 +87,16 @@ - + + + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/attributes/hibernate/ListEntryDAOHibernate.java b/source/java/org/alfresco/repo/attributes/hibernate/ListEntryDAOHibernate.java new file mode 100644 index 0000000000..6d287f6395 --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/hibernate/ListEntryDAOHibernate.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.attributes.hibernate; + +import java.util.List; + +import org.alfresco.repo.attributes.ListAttribute; +import org.alfresco.repo.attributes.ListEntry; +import org.alfresco.repo.attributes.ListEntryDAO; +import org.hibernate.Query; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; + +/** + * @author britt + * + */ +public class ListEntryDAOHibernate extends HibernateDaoSupport implements + ListEntryDAO +{ + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntryDAO#delete(org.alfresco.repo.attributes.ListEntry) + */ + public void delete(ListEntry entry) + { + getSession().delete(entry); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntryDAO#delete(org.alfresco.repo.attributes.ListAttribute) + */ + public void delete(ListAttribute list) + { + Query query = getSession().createQuery("delete from ListEntryImpl le where le.list = :list"); + query.setEntity("list", list); + query.executeUpdate(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntryDAO#get(org.alfresco.repo.attributes.ListAttribute, int) + */ + public ListEntry get(ListAttribute list, int index) + { + Query query = getSession().createQuery("from ListEntryImpl le where le.list = :list and le.index = :index"); + query.setEntity("list", list); + query.setInteger("index", index); + return (ListEntry)query.uniqueResult(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntryDAO#get(org.alfresco.repo.attributes.ListAttribute) + */ + @SuppressWarnings("unchecked") + public List get(ListAttribute list) + { + Query query = getSession().createQuery("from ListEntryImpl le where le.list = :list"); + query.setEntity("list", list); + return (List)query.list(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntryDAO#save(org.alfresco.repo.attributes.ListEntry) + */ + public void save(ListEntry entry) + { + getSession().save(entry); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.ListEntryDAO#size(org.alfresco.repo.attributes.ListAttribute) + */ + public int size(ListAttribute list) + { + Query query = getSession().createQuery("select count() from ListEntryImpl le where le.list = :list"); + query.setEntity("list", list); + return (Integer)query.uniqueResult(); + } +} diff --git a/source/java/org/alfresco/repo/attributes/hibernate/MapEntryDAOHibernate.java b/source/java/org/alfresco/repo/attributes/hibernate/MapEntryDAOHibernate.java index 7a72568963..c3c0305888 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/MapEntryDAOHibernate.java +++ b/source/java/org/alfresco/repo/attributes/hibernate/MapEntryDAOHibernate.java @@ -87,4 +87,14 @@ public class MapEntryDAOHibernate extends HibernateDaoSupport implements { getSession().save(entry); } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.MapEntryDAO#size(org.alfresco.repo.attributes.MapAttribute) + */ + public int size(MapAttribute mapAttr) + { + Query query = getSession().createQuery("select count() from MapEntryImpl me where me.map = :map"); + query.setEntity("map", mapAttr); + return (Integer)query.uniqueResult(); + } } diff --git a/source/java/org/alfresco/repo/avm/AVMDAOs.java b/source/java/org/alfresco/repo/avm/AVMDAOs.java index ceb4cfd452..dedd25637f 100644 --- a/source/java/org/alfresco/repo/avm/AVMDAOs.java +++ b/source/java/org/alfresco/repo/avm/AVMDAOs.java @@ -5,6 +5,7 @@ package org.alfresco.repo.avm; import org.alfresco.repo.attributes.AttributeDAO; import org.alfresco.repo.attributes.GlobalAttributeEntryDAO; +import org.alfresco.repo.attributes.ListEntryDAO; import org.alfresco.repo.attributes.MapEntryDAO; /** @@ -89,6 +90,8 @@ public class AVMDAOs public GlobalAttributeEntryDAO fGlobalAttributeEntryDAO; + public ListEntryDAO fListEntryDAO; + /** * @param nodeDAO the fAVMNodeDAO to set */ @@ -174,4 +177,9 @@ public class AVMDAOs { fGlobalAttributeEntryDAO = dao; } + + public void setListEntryDAO(ListEntryDAO dao) + { + fListEntryDAO = dao; + } } diff --git a/source/java/org/alfresco/repo/avm/locking/AVMLockingBootstrap.java b/source/java/org/alfresco/repo/avm/locking/AVMLockingBootstrap.java new file mode 100644 index 0000000000..f2cde86fb5 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/locking/AVMLockingBootstrap.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.avm.locking; + +import org.alfresco.util.AbstractLifecycleBean; +import org.springframework.context.ApplicationEvent; + +/** + * Bootstrap for AVM Locking Service. + * @author britt + */ +public class AVMLockingBootstrap extends AbstractLifecycleBean +{ + private AVMLockingServiceImpl fLockingService; + + public void setAvmLockingService(AVMLockingServiceImpl service) + { + fLockingService = service; + } + + /* (non-Javadoc) + * @see org.alfresco.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.ApplicationEvent) + */ + @Override + protected void onBootstrap(ApplicationEvent event) + { + fLockingService.init(); + } + + /* (non-Javadoc) + * @see org.alfresco.util.AbstractLifecycleBean#onShutdown(org.springframework.context.ApplicationEvent) + */ + @Override + protected void onShutdown(ApplicationEvent event) + { + // Do nothing. + } +} diff --git a/source/java/org/alfresco/service/cmr/attributes/AttributeService.java b/source/java/org/alfresco/service/cmr/attributes/AttributeService.java index 5e9e9f949f..5203a8dae0 100644 --- a/source/java/org/alfresco/service/cmr/attributes/AttributeService.java +++ b/source/java/org/alfresco/service/cmr/attributes/AttributeService.java @@ -50,7 +50,6 @@ public interface AttributeService */ public Attribute getAttribute(List keys); - /** * Set an attribute. Overwrites if it exists. * @param name The name of the Attribute.