Merged V2.1 to HEAD

6944: More hibernate session cache taming.
   6945: Times for commits are close to linear in the number of items submitted.
   6946: Missing break statement. (Courtesy of Jan).
   6948: Fixed session cache eviction problem triggered by resetLayer().
   6956: Wrapped AVMService and AttributeService in TransactionResourceInterceptor.
   Reverted log4j.properties


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7368 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-11-12 23:18:09 +00:00
parent e3d5cececb
commit 209dd85a0d
23 changed files with 416 additions and 306 deletions

View File

@@ -15,17 +15,20 @@
* 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:
* 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.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.avm.AVMDAOs;
/**
* Handles conversions between persistent and value based Attributes.
@@ -34,7 +37,7 @@ import org.alfresco.error.AlfrescoRuntimeException;
public class AttributeConverter
{
/**
* Convert an Attribute (recursively) to a persistent attribute. This persists
* Convert an Attribute (recursively) to a persistent attribute. This persists
* the newly created Attribute immediately.
* @param from The Attribute to clone.
* @return The cloned persistent Attribute.
@@ -96,56 +99,78 @@ public class AttributeConverter
public Attribute toValue(Attribute from)
{
Attribute ret = null;
switch (from.getType())
{
case BOOLEAN :
{
return new BooleanAttributeValue((BooleanAttribute)from);
ret = new BooleanAttributeValue((BooleanAttribute)from);
break;
}
case BYTE :
{
return new ByteAttributeValue((ByteAttribute)from);
ret = new ByteAttributeValue((ByteAttribute)from);
break;
}
case SHORT :
{
return new ShortAttributeValue((ShortAttribute)from);
ret = new ShortAttributeValue((ShortAttribute)from);
break;
}
case INT :
{
return new IntAttributeValue((IntAttribute)from);
ret = new IntAttributeValue((IntAttribute)from);
break;
}
case LONG :
{
return new LongAttributeValue((LongAttribute)from);
ret = new LongAttributeValue((LongAttribute)from);
break;
}
case FLOAT :
{
return new FloatAttributeValue((FloatAttribute)from);
ret = new FloatAttributeValue((FloatAttribute)from);
break;
}
case DOUBLE :
{
return new DoubleAttributeValue((DoubleAttribute)from);
ret = new DoubleAttributeValue((DoubleAttribute)from);
break;
}
case STRING :
{
return new StringAttributeValue((StringAttribute)from);
ret = new StringAttributeValue((StringAttribute)from);
break;
}
case SERIALIZABLE :
{
return new SerializableAttributeValue((SerializableAttribute)from);
ret = new SerializableAttributeValue((SerializableAttribute)from);
break;
}
case MAP :
{
return new MapAttributeValue((MapAttribute)from);
ret = new MapAttributeValue();
for (Map.Entry<String, Attribute> entry : from.entrySet())
{
ret.put(entry.getKey(), toValue(entry.getValue()));
}
break;
}
case LIST :
{
return new ListAttributeValue((ListAttribute)from);
ret = new ListAttributeValue();
for (Attribute child : from)
{
ret.add(toValue(child));
}
break;
}
default :
{
throw new AlfrescoRuntimeException("Invalid Attribute Type: " + from.getType());
}
}
AVMDAOs.Instance().fAttributeDAO.evictFlat(from);
return ret;
}
}

View File

@@ -68,4 +68,15 @@ public interface AttributeDAO
* @param attr
*/
public void evict(Attribute attr);
/**
* Evict an Attribute non-recursively.
* @param attr
*/
public void evictFlat(Attribute attr);
/**
* Force a flush.
*/
public void flush();
}

View File

@@ -193,7 +193,6 @@ public class AttributeServiceImpl implements AttributeService
return null;
}
Attribute converted = fAttributeConverter.toValue(found);
fAttributeDAO.evict(found);
return converted;
}
@@ -255,7 +254,6 @@ public class AttributeServiceImpl implements AttributeService
}
Attribute converted = fAttributeConverter.toPersistent(value);
found.put(name, converted);
fAttributeDAO.evict(converted);
}
/* (non-Javadoc)
@@ -316,6 +314,8 @@ public class AttributeServiceImpl implements AttributeService
throw new AVMWrongTypeException("Attribute Not Map: " + keys);
}
found.remove(name);
fAttributeDAO.flush();
fAttributeDAO.evictFlat(found);
}
private Attribute getAttributeFromPath(List<String> keys)
@@ -330,11 +330,15 @@ public class AttributeServiceImpl implements AttributeService
{
if (current.getType() == Type.MAP)
{
current = current.get(keys.get(i));
Attribute newCurrent = current.get(keys.get(i));
fAttributeDAO.evictFlat(current);
current = newCurrent;
}
else if (current.getType() == Type.LIST)
{
current = current.get(Integer.parseInt(keys.get(i)));
Attribute newCurrent = current.get(Integer.parseInt(keys.get(i)));
fAttributeDAO.evictFlat(current);
current = newCurrent;
}
else
{
@@ -486,7 +490,6 @@ public class AttributeServiceImpl implements AttributeService
}
Attribute converted = fAttributeConverter.toPersistent(value);
found.set(index, fAttributeConverter.toPersistent(value));
fAttributeDAO.evict(converted);
}
/* (non-Javadoc)
@@ -515,7 +518,13 @@ public class AttributeServiceImpl implements AttributeService
{
throw new AVMBadArgumentException("Illegal zero length keys list.");
}
return getAttributeFromPath(keys) != null;
Attribute attr = getAttributeFromPath(keys);
if (attr != null)
{
fAttributeDAO.evictFlat(attr);
return true;
}
return false;
}
/* (non-Javadoc)

View File

@@ -15,11 +15,11 @@
* 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:
* 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
*/
@@ -49,7 +49,7 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute
public MapAttributeImpl()
{
}
public MapAttributeImpl(MapAttribute attr)
{
super(attr.getAcl());
@@ -125,7 +125,7 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute
AVMDAOs.Instance().fMapEntryDAO.save(mapEntry);
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.attributes.Attribute#getType()
*/
@@ -170,7 +170,8 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute
{
return null;
}
return entry.getAttribute();
Attribute attr = entry.getAttribute();
return attr;
}
/* (non-Javadoc)

View File

@@ -3,7 +3,7 @@ package org.alfresco.repo.attributes;
import java.util.List;
/**
* Interface for MapEntry persistence.
* Interface for MapEntry persistence.
* @author britt
*/
public interface MapEntryDAO
@@ -13,37 +13,43 @@ public interface MapEntryDAO
* @param entry To save.
*/
public void save(MapEntry entry);
/**
* Delete a MapEntry.
* @param entry
*/
public void delete(MapEntry entry);
/**
* Delete all entries for a map.
* @param mapAttr The map to purge.
*/
public void delete(MapAttribute mapAttr);
/**
* Get an entry by name.
* @param key The key of the entry.
* @return A MapEntry or null.
*/
public MapEntry get(MapEntryKey key);
/**
* Retrieve all the entries in a map.
* @param mapAttr
* @return A List of all entries in the given map.
*/
public List<MapEntry> 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);
/**
* Evict an entry.
* @param entry
*/
public void evict(MapEntry entry);
}

View File

@@ -27,8 +27,10 @@ package org.alfresco.repo.attributes.hibernate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.attributes.AttrQueryHelperImpl;
import org.alfresco.repo.attributes.Attribute;
@@ -40,12 +42,14 @@ import org.alfresco.repo.attributes.MapAttribute;
import org.alfresco.repo.attributes.MapEntry;
import org.alfresco.repo.attributes.MapEntryDAO;
import org.alfresco.repo.attributes.Attribute.Type;
import org.alfresco.repo.avm.hibernate.SessionCacheChecker;
import org.alfresco.service.cmr.attributes.AttrQuery;
import org.alfresco.service.cmr.attributes.AttrQueryHelper;
import org.alfresco.util.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.engine.EntityKey;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
@@ -87,7 +91,6 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements
for (MapEntry entry : mapEntries)
{
Attribute subAttr = entry.getAttribute();
getSession().evict(entry);
fMapEntryDAO.delete(entry);
delete(subAttr);
}
@@ -99,7 +102,6 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements
for (ListEntry entry : listEntries)
{
Attribute subAttr = entry.getAttribute();
getSession().evict(entry);
fListEntryDAO.delete(entry);
delete(subAttr);
}
@@ -108,7 +110,6 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements
{
fgLogger.debug("Entities: " + getSession().getStatistics().getEntityCount());
}
getSession().evict(attr);
getSession().delete(attr);
}
@@ -161,20 +162,20 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements
*/
public void evict(Attribute attr)
{
if (attr.getType() == Attribute.Type.MAP)
{
for (Attribute child : attr.values())
{
evict(child);
}
}
if (attr.getType() == Attribute.Type.LIST)
{
for (Attribute child : attr)
{
evict(child);
}
}
getSession().evict(attr);
}
/* (non-Javadoc)
* @see org.alfresco.repo.attributes.AttributeDAO#flush()
*/
public void flush()
{
getSession().flush();
}
/* (non-Javadoc)
* @see org.alfresco.repo.attributes.AttributeDAO#evictFlat(org.alfresco.repo.attributes.Attribute)
*/
public void evictFlat(Attribute attr)
{
}
}

View File

@@ -15,11 +15,11 @@
* 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:
* 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
*/
@@ -96,4 +96,11 @@ public class MapEntryDAOHibernate extends HibernateDaoSupport implements
query.setEntity("map", mapAttr);
return ((Long)query.uniqueResult()).intValue();
}
/* (non-Javadoc)
* @see org.alfresco.repo.attributes.MapEntryDAO#evict(org.alfresco.repo.attributes.MapEntry)
*/
public void evict(MapEntry entry)
{
}
}