diff --git a/config/alfresco/domain/hibernate-cfg.properties b/config/alfresco/domain/hibernate-cfg.properties index 275d4fedf4..d57e017b53 100644 --- a/config/alfresco/domain/hibernate-cfg.properties +++ b/config/alfresco/domain/hibernate-cfg.properties @@ -12,4 +12,5 @@ hibernate.cache.use_second_level_cache=true hibernate.default_batch_fetch_size=1 hibernate.jdbc.batch_size=32 hibernate.connection.release_mode=auto -hibernate.connection.isolation=2 \ No newline at end of file +hibernate.connection.isolation=2 +hibernate.jdbc.use_get_generated_keys=true diff --git a/config/alfresco/public-services-context.xml b/config/alfresco/public-services-context.xml index 241d4c67f6..fd6a7c9803 100644 --- a/config/alfresco/public-services-context.xml +++ b/config/alfresco/public-services-context.xml @@ -915,6 +915,7 @@ setAttribute removeAttribute + addAttribute diff --git a/source/java/org/alfresco/repo/attributes/Attribute.java b/source/java/org/alfresco/repo/attributes/Attribute.java index c1fbd5a334..47a96fcdb2 100644 --- a/source/java/org/alfresco/repo/attributes/Attribute.java +++ b/source/java/org/alfresco/repo/attributes/Attribute.java @@ -272,4 +272,11 @@ public interface Attribute extends Serializable, Iterable * @param index The entry to remove. */ public void remove(int index); + + /** + * Set an attribute in a list. + * @param index The index to set. + * @param value The attribute to set. + */ + public void set(int index, Attribute value); } diff --git a/source/java/org/alfresco/repo/attributes/AttributeImpl.java b/source/java/org/alfresco/repo/attributes/AttributeImpl.java index 48a3bae8aa..dfe53cfd5d 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/AttributeImpl.java @@ -395,4 +395,12 @@ public abstract class AttributeImpl implements Attribute { throw new AttributeMethodNotImplemented("Not a List."); } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#set(int, org.alfresco.repo.attributes.Attribute) + */ + public void set(int index, Attribute value) + { + throw new AttributeMethodNotImplemented("Not a List."); + } } diff --git a/source/java/org/alfresco/repo/attributes/AttributeServiceImpl.java b/source/java/org/alfresco/repo/attributes/AttributeServiceImpl.java index 487b3bc8fb..d8cc3ece9b 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeServiceImpl.java +++ b/source/java/org/alfresco/repo/attributes/AttributeServiceImpl.java @@ -186,25 +186,12 @@ public class AttributeServiceImpl implements AttributeService { throw new AVMBadArgumentException("Bad Attribute Path List."); } - GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0)); - if (entry == null) + Attribute found = getAttributeFromPath(keys); + if (found == null) { return null; } - Attribute current = entry.getAttribute(); - for (int i = 1; i < keys.size(); i++) - { - if (current.getType() != Type.MAP) - { - return null; - } - current = current.get(keys.get(i)); - if (current == null) - { - return null; - } - } - return fAttributeConverter.toValue(current); + return fAttributeConverter.toValue(found); } /* (non-Javadoc) @@ -220,29 +207,16 @@ public class AttributeServiceImpl implements AttributeService { return fGlobalAttributeEntryDAO.getKeys(); } - GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0)); - if (entry == null) + Attribute found = getAttributeFromPath(keys); + if (found == null) { - throw new AVMNotFoundException("Attribute Not Found: " + keys.get(0)); + throw new AVMNotFoundException("Attribute Not Found: " + keys); } - Attribute current = entry.getAttribute(); - if (current.getType() != Type.MAP) + if (found.getType() != Type.MAP) { - throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(0)); + throw new AVMWrongTypeException("Not a Map: " + keys.get(keys.size() - 1)); } - for (int i = 1; i < keys.size(); i++) - { - current = current.get(keys.get(i)); - if (current == null) - { - throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i)); - } - if (current.getType() != Type.MAP) - { - throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i)); - } - } - return new ArrayList(current.keySet()); + return new ArrayList(found.keySet()); } /* (non-Javadoc) @@ -254,9 +228,9 @@ public class AttributeServiceImpl implements AttributeService { throw new AVMBadArgumentException("Null argument."); } - Attribute toSave = fAttributeConverter.toPersistent(value); if (keys.size() == 0) { + Attribute toSave = fAttributeConverter.toPersistent(value); GlobalAttributeEntry found = fGlobalAttributeEntryDAO.get(name); if (found == null) { @@ -267,30 +241,16 @@ public class AttributeServiceImpl implements AttributeService found.setAttribute(toSave); return; } - GlobalAttributeEntry gEntry = fGlobalAttributeEntryDAO.get(keys.get(0)); - if (gEntry == null) + Attribute found = getAttributeFromPath(keys); + if (found == null) { - throw new AVMNotFoundException("Global Attribute Not Found: " + keys.get(0)); + throw new AVMNotFoundException("Attribute Not Found: " + keys); } - Attribute current = gEntry.getAttribute(); - if (current.getType() != Type.MAP) + if (found.getType() != Type.MAP) { - throw new AVMWrongTypeException("Global Attribute Not Map: " + keys.get(0)); + throw new AVMWrongTypeException("Not a Map: " + keys); } - for (int i = 1; i < keys.size(); i++) - { - Attribute child = current.get(keys.get(i)); - if (child == null) - { - throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i)); - } - if (child.getType() != Type.MAP) - { - throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i)); - } - current = child; - } - current.put(name, toSave); + found.put(name, fAttributeConverter.toPersistent(value)); } /* (non-Javadoc) @@ -306,30 +266,17 @@ public class AttributeServiceImpl implements AttributeService { throw new AVMBadArgumentException("Cannot query top level Attributes."); } - GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0)); - if (entry == null) + Attribute found = getAttributeFromPath(keys); + if (found == null) { - throw new AVMNotFoundException("Attribute Not Found: " + keys.get(0)); + throw new AVMNotFoundException("Attribute Not Found: " + keys); } - Attribute current = entry.getAttribute(); - if (current.getType() != Type.MAP) + if (found.getType() != Type.MAP) { - throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(0)); - } - for (int i = 1; i < keys.size(); i++) - { - current = current.get(keys.get(i)); - if (current == null) - { - throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i)); - } - if (current.getType() != Type.MAP) - { - throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i)); - } + throw new AVMWrongTypeException("Not a Map: " + keys); } List> rawResult = - fAttributeDAO.find((MapAttribute)current, query); + fAttributeDAO.find((MapAttribute)found, query); List> result = new ArrayList>(); for (Pair raw : rawResult) @@ -354,29 +301,160 @@ public class AttributeServiceImpl implements AttributeService fGlobalAttributeEntryDAO.delete(name); return; } + Attribute found = getAttributeFromPath(keys); + if (found == null) + { + throw new AVMNotFoundException("Attribute Not Found: " + keys); + } + if (found.getType() != Type.MAP) + { + throw new AVMWrongTypeException("Attribute Not Map: " + keys); + } + found.remove(name); + } + + private Attribute getAttributeFromPath(List keys) + { GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0)); if (entry == null) { - throw new AVMNotFoundException("Attribute Not Found: " + keys.get(0)); + return null; } Attribute current = entry.getAttribute(); - if (current.getType() != Type.MAP) - { - throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(0)); - } for (int i = 1; i < keys.size(); i++) { - current = current.get(keys.get(i)); + if (current.getType() == Type.MAP) + { + current = current.get(keys.get(i)); + } + else if (current.getType() == Type.LIST) + { + current = current.get(Integer.parseInt(keys.get(i))); + } + else + { + throw new AVMWrongTypeException("Not a Map or List: " + keys.get(i - 1)); + } if (current == null) { - throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i)); - } - if (current.getType() != Type.MAP) - { - throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i)); + return null; } } - current.remove(name); + return current; + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#addAttribute(java.util.List, org.alfresco.repo.attributes.Attribute) + */ + public void addAttribute(List keys, Attribute value) + { + if (keys == null || value == null) + { + throw new AVMBadArgumentException("Illegal Null Argument."); + } + if (keys.size() < 1) + { + throw new AVMBadArgumentException("Path too short: " + keys); + } + Attribute found = getAttributeFromPath(keys); + if (found == null) + { + throw new AVMNotFoundException("Attribute Not Found: " + keys); + } + if (found.getType() != Type.LIST) + { + throw new AVMWrongTypeException("Attribute Not List: " + keys); + } + found.add(fAttributeConverter.toPersistent(value)); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#addAttribute(java.lang.String, org.alfresco.repo.attributes.Attribute) + */ + public void addAttribute(String path, Attribute value) + { + if (path == null || value == null) + { + throw new AVMBadArgumentException("Illegal null arguments."); + } + List keys = parsePath(path); + addAttribute(keys, value); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#removeAttribute(java.util.List, int) + */ + public void removeAttribute(List keys, int index) + { + if (keys == null) + { + throw new AVMBadArgumentException("Illegal Null Keys."); + } + if (keys.size() < 1) + { + throw new AVMBadArgumentException("Keys too short: " + keys); + } + Attribute found = getAttributeFromPath(keys); + if (found == null) + { + throw new AVMNotFoundException("Attribute Not Found: " + keys); + } + if (found.getType() != Type.LIST) + { + throw new AVMWrongTypeException("Attribute Not List: " + keys); + } + found.remove(index); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#removeAttribute(java.lang.String, int) + */ + public void removeAttribute(String path, int index) + { + if (path == null) + { + throw new AVMBadArgumentException("Illegal null path."); + } + List keys = parsePath(path); + removeAttribute(keys, index); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.util.List, int, org.alfresco.repo.attributes.Attribute) + */ + public void setAttribute(List keys, int index, Attribute value) + { + if (keys == null || value == null) + { + throw new AVMBadArgumentException("Illegal Null Argument."); + } + if (keys.size() < 1) + { + throw new AVMBadArgumentException("Keys too short."); + } + Attribute found = getAttributeFromPath(keys); + if (found == null) + { + throw new AVMNotFoundException("Attribute Not Found: " + keys); + } + if (found.getType() != Type.LIST) + { + throw new AVMWrongTypeException("Attribute Not List: " + keys); + } + found.set(index, fAttributeConverter.toPersistent(value)); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.lang.String, int, org.alfresco.repo.attributes.Attribute) + */ + public void setAttribute(String path, int index, Attribute value) + { + if (path == null || value == null) + { + throw new AVMBadArgumentException("Illegal null argument."); + } + List keys = parsePath(path); + setAttribute(keys, index, value); } } diff --git a/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java b/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java index e536b9d373..d0eea55b82 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java +++ b/source/java/org/alfresco/repo/attributes/AttributeServiceTest.java @@ -111,6 +111,8 @@ public class AttributeServiceTest extends TestCase { System.out.println(key + " => " + fService.getAttribute(key)); } + fService.setAttribute("", "string", new StringAttributeValue("This is another string.")); + assertEquals("This is another string.", fService.getAttribute("string").getStringValue()); } catch (Exception e) { @@ -294,6 +296,16 @@ public class AttributeServiceTest extends TestCase Attribute found = fService.getAttribute("dummy"); assertNotNull(found); assertEquals(5, found.size()); + Attribute add = new IntAttributeValue(6); + fService.addAttribute("dummy", add); + assertEquals(6, fService.getAttribute("dummy").size()); + fService.removeAttribute("dummy", 2); + found = fService.getAttribute("dummy"); + assertEquals(5, found.size()); + assertEquals(3, found.get(2).getIntValue()); + Attribute replace = new StringAttributeValue("String"); + fService.setAttribute("dummy", 2, replace); + assertEquals("String", fService.getAttribute("dummy/2").getStringValue()); } catch (Exception e) { diff --git a/source/java/org/alfresco/repo/attributes/AttributeValue.java b/source/java/org/alfresco/repo/attributes/AttributeValue.java index 6f14c217b2..2311fa8efd 100644 --- a/source/java/org/alfresco/repo/attributes/AttributeValue.java +++ b/source/java/org/alfresco/repo/attributes/AttributeValue.java @@ -335,4 +335,12 @@ public abstract class AttributeValue implements Attribute { throw new AttributeMethodNotImplemented("Not a List."); } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.Attribute#set(int, org.alfresco.repo.attributes.Attribute) + */ + public void set(int index, Attribute value) + { + throw new AttributeMethodNotImplemented("Not a List."); + } } diff --git a/source/java/org/alfresco/repo/attributes/ListAttributeImpl.java b/source/java/org/alfresco/repo/attributes/ListAttributeImpl.java index cd9beb46cb..dbf2e6aabb 100644 --- a/source/java/org/alfresco/repo/attributes/ListAttributeImpl.java +++ b/source/java/org/alfresco/repo/attributes/ListAttributeImpl.java @@ -47,6 +47,7 @@ public class ListAttributeImpl extends AttributeImpl implements ListAttribute public ListAttributeImpl(ListAttribute other) { + super(other.getAcl()); int index = 0; AVMDAOs.Instance().fAttributeDAO.save(this); for (Attribute entry : other) @@ -114,7 +115,8 @@ public class ListAttributeImpl extends AttributeImpl implements ListAttribute throw new AlfrescoRuntimeException("Unknown Attribute Type: " + entry.getType()); } } - ListEntry listEntry = new ListEntryImpl(this, index++, newEntry); + ListEntryKey key = new ListEntryKey(this, index++); + ListEntry listEntry = new ListEntryImpl(key, newEntry); AVMDAOs.Instance().fListEntryDAO.save(listEntry); } } @@ -134,7 +136,8 @@ public class ListAttributeImpl extends AttributeImpl implements ListAttribute public void add(Attribute attr) { int size = AVMDAOs.Instance().fListEntryDAO.size(this); - ListEntry entry = new ListEntryImpl(this, size, attr); + ListEntryKey key = new ListEntryKey(this, size); + ListEntry entry = new ListEntryImpl(key, attr); AVMDAOs.Instance().fListEntryDAO.save(entry); } @@ -152,12 +155,15 @@ public class ListAttributeImpl extends AttributeImpl implements ListAttribute } for (int i = size; i > index; i--) { - ListEntry entry = dao.get(this, i - 1); - ListEntry newEntry = new ListEntryImpl(this, i, entry.getAttribute()); + ListEntryKey key = new ListEntryKey(this, i - 1); + ListEntry entry = dao.get(key); + key = new ListEntryKey(this, i); + ListEntry newEntry = new ListEntryImpl(key, entry.getAttribute()); dao.delete(entry); dao.save(newEntry); } - ListEntry newEntry = new ListEntryImpl(this, index, attr); + ListEntryKey key = new ListEntryKey(this, index); + ListEntry newEntry = new ListEntryImpl(key, attr); dao.save(newEntry); } @@ -176,7 +182,8 @@ public class ListAttributeImpl extends AttributeImpl implements ListAttribute @Override public Attribute get(int index) { - ListEntry entry = AVMDAOs.Instance().fListEntryDAO.get(this, index); + ListEntryKey key = new ListEntryKey(this, index); + ListEntry entry = AVMDAOs.Instance().fListEntryDAO.get(key); if (entry == null) { return null; @@ -215,7 +222,8 @@ public class ListAttributeImpl extends AttributeImpl implements ListAttribute public void remove(int index) { ListEntryDAO dao = AVMDAOs.Instance().fListEntryDAO; - ListEntry entry = dao.get(this, index); + ListEntryKey key = new ListEntryKey(this, index); + ListEntry entry = dao.get(key); if (entry == null) { throw new AVMBadArgumentException("Index out of bounds: " + index); @@ -225,8 +233,10 @@ public class ListAttributeImpl extends AttributeImpl implements ListAttribute 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()); + key = new ListEntryKey(this, i + 1); + entry = dao.get(key); + key = new ListEntryKey(this, i); + ListEntry newEntry = new ListEntryImpl(key, entry.getAttribute()); dao.delete(entry); dao.save(newEntry); } @@ -248,4 +258,21 @@ public class ListAttributeImpl extends AttributeImpl implements ListAttribute builder.append(']'); return builder.toString(); } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeImpl#set(int, org.alfresco.repo.attributes.Attribute) + */ + @Override + public void set(int index, Attribute value) + { + ListEntryKey key = new ListEntryKey(this, index); + ListEntry entry = AVMDAOs.Instance().fListEntryDAO.get(key); + if (entry == null) + { + throw new AVMBadArgumentException("Index out of bounds: " + index); + } + Attribute oldAttr = entry.getAttribute(); + entry.setAttribute(value); + AVMDAOs.Instance().fAttributeDAO.delete(oldAttr); + } } diff --git a/source/java/org/alfresco/repo/attributes/ListAttributeValue.java b/source/java/org/alfresco/repo/attributes/ListAttributeValue.java index b2c368d931..8969dee739 100644 --- a/source/java/org/alfresco/repo/attributes/ListAttributeValue.java +++ b/source/java/org/alfresco/repo/attributes/ListAttributeValue.java @@ -195,4 +195,13 @@ public class ListAttributeValue extends AttributeValue implements ListAttribute builder.append(']'); return builder.toString(); } + + /* (non-Javadoc) + * @see org.alfresco.repo.attributes.AttributeValue#set(int, org.alfresco.repo.attributes.Attribute) + */ + @Override + public void set(int index, Attribute value) + { + fData.set(index, value); + } } diff --git a/source/java/org/alfresco/repo/attributes/ListEntry.java b/source/java/org/alfresco/repo/attributes/ListEntry.java index 6407363a13..1760cb8873 100644 --- a/source/java/org/alfresco/repo/attributes/ListEntry.java +++ b/source/java/org/alfresco/repo/attributes/ListEntry.java @@ -34,20 +34,20 @@ import java.io.Serializable; public interface ListEntry extends Serializable { /** - * Get the List this is an entry for. - * @return The ListAttribute. + * Get the key. + * @return The key. */ - public ListAttribute getList(); - - /** - * Get the index of this entry in the ListAttribute. - * @return The index. - */ - public int getIndex(); + public ListEntryKey getKey(); /** * Get the Attribute for this entry. * @return The Attribute */ public Attribute getAttribute(); + + /** + * Set the Attribute. + * @param attr The attribute to set. + */ + public void setAttribute(Attribute attr); } diff --git a/source/java/org/alfresco/repo/attributes/ListEntryDAO.java b/source/java/org/alfresco/repo/attributes/ListEntryDAO.java index b8c56de36f..fc52814d8e 100644 --- a/source/java/org/alfresco/repo/attributes/ListEntryDAO.java +++ b/source/java/org/alfresco/repo/attributes/ListEntryDAO.java @@ -45,7 +45,7 @@ public interface ListEntryDAO * @param index The index. * @return The ListEntry. */ - public ListEntry get(ListAttribute list, int index); + public ListEntry get(ListEntryKey key); /** * Get all entries for a given list. diff --git a/source/java/org/alfresco/repo/attributes/ListEntryImpl.java b/source/java/org/alfresco/repo/attributes/ListEntryImpl.java index 5d98fb04ed..2e54b51690 100644 --- a/source/java/org/alfresco/repo/attributes/ListEntryImpl.java +++ b/source/java/org/alfresco/repo/attributes/ListEntryImpl.java @@ -33,11 +33,7 @@ public class ListEntryImpl implements ListEntry { private static final long serialVersionUID = 1573391734169157835L; - private long fID; - - private ListAttribute fList; - - private int fIndex; + private ListEntryKey fKey; private Attribute fAttribute; @@ -48,21 +44,20 @@ public class ListEntryImpl implements ListEntry { } - public ListEntryImpl(ListAttribute list, int index, Attribute attr) + public ListEntryImpl(ListEntryKey key, Attribute attr) { - fList = list; - fIndex = index; + fKey = key; fAttribute = attr; } - public void setId(long id) + public void setKey(ListEntryKey key) { - fID = id; + fKey = key; } - public long getId() + public ListEntryKey getKey() { - return fID; + return fKey; } /* (non-Javadoc) @@ -77,30 +72,4 @@ public class ListEntryImpl implements ListEntry { 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/ListEntryKey.java b/source/java/org/alfresco/repo/attributes/ListEntryKey.java new file mode 100644 index 0000000000..63d51eb2fd --- /dev/null +++ b/source/java/org/alfresco/repo/attributes/ListEntryKey.java @@ -0,0 +1,81 @@ +/* + * 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; + +/** + * Key class for the ListEntry entity. + * @author britt + */ +public class ListEntryKey implements Serializable +{ + private ListAttribute fList; + + private int fIndex; + + public ListEntryKey() + { + } + + public ListEntryKey(ListAttribute list, int index) + { + fList = list; + fIndex = index; + } + + /** + * @return the Index + */ + public int getIndex() + { + return fIndex; + } + + /** + * @param index the fIndex to set + */ + public void setIndex(int index) + { + fIndex = index; + } + + /** + * @return the fList + */ + public ListAttribute getList() + { + return fList; + } + + /** + * @param list the fList to set + */ + public void setList(ListAttribute list) + { + fList = list; + } +} 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 d6afb33cdf..7e6a1f3b5d 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml +++ b/source/java/org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml @@ -90,13 +90,10 @@ - - - - - - - + + + + diff --git a/source/java/org/alfresco/repo/attributes/hibernate/ListEntryDAOHibernate.java b/source/java/org/alfresco/repo/attributes/hibernate/ListEntryDAOHibernate.java index 6d287f6395..e35f226e5f 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/ListEntryDAOHibernate.java +++ b/source/java/org/alfresco/repo/attributes/hibernate/ListEntryDAOHibernate.java @@ -30,6 +30,8 @@ import java.util.List; import org.alfresco.repo.attributes.ListAttribute; import org.alfresco.repo.attributes.ListEntry; import org.alfresco.repo.attributes.ListEntryDAO; +import org.alfresco.repo.attributes.ListEntryImpl; +import org.alfresco.repo.attributes.ListEntryKey; import org.hibernate.Query; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; @@ -53,7 +55,7 @@ public class ListEntryDAOHibernate extends HibernateDaoSupport implements */ public void delete(ListAttribute list) { - Query query = getSession().createQuery("delete from ListEntryImpl le where le.list = :list"); + Query query = getSession().createQuery("delete from ListEntryImpl le where le.key.list = :list"); query.setEntity("list", list); query.executeUpdate(); } @@ -61,12 +63,9 @@ public class ListEntryDAOHibernate extends HibernateDaoSupport implements /* (non-Javadoc) * @see org.alfresco.repo.attributes.ListEntryDAO#get(org.alfresco.repo.attributes.ListAttribute, int) */ - public ListEntry get(ListAttribute list, int index) + public ListEntry get(ListEntryKey key) { - 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(); + return (ListEntry)getSession().get(ListEntryImpl.class, key); } /* (non-Javadoc) @@ -75,7 +74,7 @@ public class ListEntryDAOHibernate extends HibernateDaoSupport implements @SuppressWarnings("unchecked") public List get(ListAttribute list) { - Query query = getSession().createQuery("from ListEntryImpl le where le.list = :list"); + Query query = getSession().createQuery("from ListEntryImpl le where le.key.list = :list"); query.setEntity("list", list); return (List)query.list(); } @@ -93,8 +92,8 @@ public class ListEntryDAOHibernate extends HibernateDaoSupport implements */ public int size(ListAttribute list) { - Query query = getSession().createQuery("select count() from ListEntryImpl le where le.list = :list"); + Query query = getSession().createQuery("select count(*) from ListEntryImpl le where le.key.list = :list"); query.setEntity("list", list); - return (Integer)query.uniqueResult(); + return ((Long)query.uniqueResult()).intValue(); } } diff --git a/source/java/org/alfresco/repo/attributes/hibernate/MapEntryDAOHibernate.java b/source/java/org/alfresco/repo/attributes/hibernate/MapEntryDAOHibernate.java index c3c0305888..8a55dd9462 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/MapEntryDAOHibernate.java +++ b/source/java/org/alfresco/repo/attributes/hibernate/MapEntryDAOHibernate.java @@ -93,8 +93,8 @@ public class MapEntryDAOHibernate extends HibernateDaoSupport implements */ public int size(MapAttribute mapAttr) { - Query query = getSession().createQuery("select count() from MapEntryImpl me where me.map = :map"); + Query query = getSession().createQuery("select count(me) from MapEntryImpl me where me.map = :map"); query.setEntity("map", mapAttr); - return (Integer)query.uniqueResult(); + return ((Long)query.uniqueResult()).intValue(); } } diff --git a/source/java/org/alfresco/service/cmr/attributes/AttributeService.java b/source/java/org/alfresco/service/cmr/attributes/AttributeService.java index 5203a8dae0..68447dcd5e 100644 --- a/source/java/org/alfresco/service/cmr/attributes/AttributeService.java +++ b/source/java/org/alfresco/service/cmr/attributes/AttributeService.java @@ -65,6 +65,36 @@ public interface AttributeService */ public void setAttribute(List keys, String name, Attribute value); + /** + * Set an attribute in a list. + * @param path The path to the list. + * @param index The list index. + * @param value The Attribute to set. + */ + public void setAttribute(String path, int index, Attribute value); + + /** + * Set an attribute in a list. + * @param keys The path components to the list. + * @param index The list index. + * @param value The Attribute to set. + */ + public void setAttribute(List keys, int index, Attribute value); + + /** + * Add an attribute to a List Attribute + * @param path The path to the list. + * @param value The Attribute to add. + */ + public void addAttribute(String path, Attribute value); + + /** + * Add an attribute to a List Attribute. + * @param keys The path components to the list. + * @param value The Attribute to add. + */ + public void addAttribute(List keys, Attribute value); + /** * Remove an Attribute. * @param name The name of the Attribute. @@ -77,7 +107,21 @@ public interface AttributeService * @param name The name of the attribute to remove. */ public void removeAttribute(List keys, String name); + + /** + * Remove an attribute from a list. + * @param path The path to the list. + * @param index The index to remove. + */ + public void removeAttribute(String path, int index); + /** + * Remove an attribute from a list. + * @param keys The components of the path to the list. + * @param index The index to remove. + */ + public void removeAttribute(List keys, int index); + /** * Query for a list of attributes which are contained in the map * defined by the given path and meet the query criteria. diff --git a/source/java/org/alfresco/service/cmr/avm/AVMService.java b/source/java/org/alfresco/service/cmr/avm/AVMService.java index fc214d8462..836ad1f13e 100644 --- a/source/java/org/alfresco/service/cmr/avm/AVMService.java +++ b/source/java/org/alfresco/service/cmr/avm/AVMService.java @@ -1170,7 +1170,6 @@ public interface AVMService * @throws AVMNotFoundException */ public AVMNodeDescriptor forceCopy(String path); - /** * Perform a non-virtual (heavy-weight), and potentially recursive