Another pair of convenience methods for AttributeService:

removeEntries, which removes map entries by query.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5806 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2007-05-29 19:17:04 +00:00
parent aa046ff09b
commit 0ea69ac954
9 changed files with 127 additions and 2 deletions

View File

@@ -54,5 +54,12 @@ public interface AttributeDAO
* @param query The AttrQuery.
* @return A List of key, attribute value pairs.
*/
List<Pair<String,Attribute>> find(MapAttribute map, AttrQuery query);
public List<Pair<String,Attribute>> find(MapAttribute map, AttrQuery query);
/**
* Delete entries from a map that match the given query.
* @param map
* @param query
*/
public void delete(MapAttribute map, AttrQuery query);
}

View File

@@ -420,6 +420,44 @@ public class AttributeServiceImpl implements AttributeService
removeAttribute(keys, index);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#removeEntries(java.util.List, org.alfresco.service.cmr.attributes.AttrQuery)
*/
public void removeEntries(List<String> keys, AttrQuery query)
{
if (keys == null || query == null)
{
throw new AVMBadArgumentException("Illegal null argument.");
}
if (keys.size() == 0)
{
throw new AVMBadArgumentException("Illegal zero length key path.");
}
Attribute map = getAttributeFromPath(keys);
if (map == null)
{
throw new AVMNotFoundException("Could not find attribute: " + keys);
}
if (map.getType() != Attribute.Type.MAP)
{
throw new AVMWrongTypeException("Not a map: " + keys);
}
fAttributeDAO.delete((MapAttribute)map, query);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#removeEntries(java.lang.String, org.alfresco.service.cmr.attributes.AttrQuery)
*/
public void removeEntries(String path, AttrQuery query)
{
if (path == null || query == null)
{
throw new AVMBadArgumentException("Illegal null argument.");
}
List<String> keys = parsePath(path);
removeEntries(keys, query);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#setAttribute(java.util.List, int, org.alfresco.repo.attributes.Attribute)
*/

View File

@@ -282,6 +282,9 @@ public class AttributeServiceTest extends TestCase
assertEquals(25, fService.getKeys("map/submap/subsubmap").size());
fService.removeAttribute("map/submap", "subsubmap");
assertEquals(26, fService.getKeys("map/submap").size());
fService.removeEntries("map/submap", new AttrAndQuery(new AttrQueryGTE("a"),
new AttrQueryLTE("d")));
assertEquals(22, fService.getCount("map/submap"));
}
catch (Exception e)
{

View File

@@ -280,4 +280,22 @@ public class AttributeServiceTransportService implements
fAuthService.validate(ticket);
fService.setAttributes(path, entries);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#removeEntries(java.lang.String, java.util.List, org.alfresco.service.cmr.attributes.AttrQuery)
*/
public void removeEntries(String ticket, List<String> keys, AttrQuery query)
{
fAuthService.validate(ticket);
fService.removeEntries(keys, query);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.remote.AttributeServiceTransport#removeEntries(java.lang.String, java.lang.String, org.alfresco.service.cmr.attributes.AttrQuery)
*/
public void removeEntries(String ticket, String path, AttrQuery query)
{
fAuthService.validate(ticket);
fService.removeEntries(path, query);
}
}

View File

@@ -125,6 +125,18 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements
return result;
}
/* (non-Javadoc)
* @see org.alfresco.repo.attributes.AttributeDAO#delete(org.alfresco.repo.attributes.MapAttribute, org.alfresco.service.cmr.attributes.AttrQuery)
*/
public void delete(MapAttribute map, AttrQuery query)
{
List<Pair<String, Attribute>> result = find(map, query);
for (Pair<String, Attribute> entry : result)
{
map.remove(entry.getFirst());
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.attributes.AttributeDAO#save(org.alfresco.repo.attributes.Attribute)
*/

View File

@@ -250,4 +250,20 @@ public class AttributeServiceRemote implements AttributeService
{
fTransport.setAttributes(fTicketHolder.getTicket(), path, entries);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#removeEntries(java.util.List, org.alfresco.service.cmr.attributes.AttrQuery)
*/
public void removeEntries(List<String> keys, AttrQuery query)
{
fTransport.removeEntries(fTicketHolder.getTicket(), keys, query);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#removeEntries(java.lang.String, org.alfresco.service.cmr.attributes.AttrQuery)
*/
public void removeEntries(String path, AttrQuery query)
{
fTransport.removeEntries(fTicketHolder.getTicket(), path, query);
}
}

View File

@@ -191,6 +191,20 @@ public interface AttributeService
*/
public void removeAttribute(List<String> keys, int index);
/**
* Remove entries from the designated map which match the given query.
* @param keys The list of attribute path entries.
* @param query The attribute query.
*/
public void removeEntries(List<String> keys, AttrQuery query);
/**
* Remove entries from the designated map which match the given query.
* @param path The path to the map.
* @param query The attribute query.
*/
public void removeEntries(String path, AttrQuery query);
/**
* Query for the list of attributes that is contained in the map
* defined by the given path and meet the query criteria.

View File

@@ -231,4 +231,20 @@ public interface AttributeServiceTransport
* @param entries
*/
public void setAttributes(String ticket, String path, Map<String, Attribute> entries);
/**
* Remove entries from a map that match a query.
* @param ticket
* @param keys
* @param query
*/
public void removeEntries(String ticket, List<String> keys, AttrQuery query);
/**
* Remove entries from a map that match a query.
* @param ticket
* @param path
* @param query
*/
public void removeEntries(String ticket, String path, AttrQuery query);
}