Updates of root (unshared) properties are done via EntityLookupCache

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16269 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2009-09-15 10:03:18 +00:00
parent 9d6d25b60a
commit b0aac65e9a
2 changed files with 81 additions and 76 deletions

View File

@@ -801,56 +801,95 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
*/ */
public Long createProperty(Serializable value) public Long createProperty(Serializable value)
{ {
// We will need a new root Pair<Long, Serializable> entityPair = propertyCache.getOrCreateByValue(value);
Long rootPropId = createPropertyRoot(); return entityPair.getFirst();
createPropertyImpl(rootPropId, 0L, 0L, null, value);
// Push this value into the cache
propertyCache.updateValue(rootPropId, value);
// Done
if (logger.isDebugEnabled())
{
logger.debug(
"Created property: \n" +
" ID: " + rootPropId + "\n" +
" Value: " + value);
}
return rootPropId;
} }
public void updateProperty(Long rootPropId, Serializable value) public void updateProperty(Long rootPropId, Serializable value)
{ {
// Remove all entries for the root
PropertyRootEntity entity = getPropertyRoot(rootPropId);
if (entity == null)
{
throw new DataIntegrityViolationException("No property root exists for ID " + rootPropId);
}
// Remove all links using the root
deletePropertyLinks(rootPropId);
// Create the new properties and update the cache
createPropertyImpl(rootPropId, 0L, 0L, null, value);
propertyCache.updateValue(rootPropId, value); propertyCache.updateValue(rootPropId, value);
// Update the property root to detect concurrent modification
updatePropertyRoot(entity);
// Done
if (logger.isDebugEnabled())
{
logger.debug(
"Updated property: \n" +
" ID: " + rootPropId + "\n" +
" Value: " + value);
}
} }
public void deleteProperty(Long id) public void deleteProperty(Long id)
{ {
deletePropertyRoot(id); propertyCache.deleteByKey(id);
// Done }
if (logger.isDebugEnabled())
/**
* Callback for <b>alf_prop_root</b> DAO.
*/
private class PropertyCallbackDAO extends EntityLookupCallbackDAOAdaptor<Long, Serializable, Serializable>
{
public Pair<Long, Serializable> createValue(Serializable value)
{ {
logger.debug( // We will need a new root
"Deleted property: \n" + Long rootPropId = createPropertyRoot();
" ID: " + id); createPropertyImpl(rootPropId, 0L, 0L, null, value);
// Done
if (logger.isDebugEnabled())
{
logger.debug(
"Created property: \n" +
" ID: " + rootPropId + "\n" +
" Value: " + value);
}
return new Pair<Long, Serializable>(rootPropId, value);
}
public Pair<Long, Serializable> findByKey(Long key)
{
List<PropertyIdSearchRow> rows = findPropertyById(key);
if (rows.size() == 0)
{
// No results
return null;
}
Serializable value = convertPropertyIdSearchRows(rows);
return new Pair<Long, Serializable>(key, value);
}
/**
* No-op. This is implemented as we just want to update the cache.
* @return Returns 0 always
*/
@Override
public int updateValue(Long key, Serializable value)
{
// Remove all entries for the root
PropertyRootEntity entity = getPropertyRoot(key);
if (entity == null)
{
throw new DataIntegrityViolationException("No property root exists for ID " + key);
}
// Remove all links using the root
deletePropertyLinks(key);
// Create the new properties and update the cache
createPropertyImpl(key, 0L, 0L, null, value);
// Update the property root to detect concurrent modification
updatePropertyRoot(entity);
// Done
if (logger.isDebugEnabled())
{
logger.debug(
"Updated property: \n" +
" ID: " + key + "\n" +
" Value: " + value);
}
return 1;
}
@Override
public int deleteByKey(Long key)
{
deletePropertyRoot(key);
// Done
if (logger.isDebugEnabled())
{
logger.debug(
"Deleted property: \n" +
" ID: " + key);
}
return 1;
} }
} }
@@ -991,42 +1030,6 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
} }
} }
/**
* Callback for <b>alf_prop_root</b> DAO.
*/
private class PropertyCallbackDAO extends EntityLookupCallbackDAOAdaptor<Long, Serializable, Serializable>
{
public Pair<Long, Serializable> createValue(Serializable value)
{
PropertyValueEntity entity = createPropertyValue(value);
// Done
return new Pair<Long, Serializable>(entity.getId(), value);
}
public Pair<Long, Serializable> findByKey(Long key)
{
List<PropertyIdSearchRow> rows = findPropertyById(key);
if (rows.size() == 0)
{
// No results
return null;
}
Serializable value = convertPropertyIdSearchRows(rows);
return new Pair<Long, Serializable>(key, value);
}
/**
* No-op. This is implemented as we just want to update the cache.
* @return Returns 0 always
*/
@Override
public int updateValue(Long key, Serializable value)
{
return 0;
}
}
protected abstract List<PropertyIdSearchRow> findPropertyById(Long id); protected abstract List<PropertyIdSearchRow> findPropertyById(Long id);
protected abstract Long createPropertyRoot(); protected abstract Long createPropertyRoot();
protected abstract PropertyRootEntity getPropertyRoot(Long id); protected abstract PropertyRootEntity getPropertyRoot(Long id);

View File

@@ -30,6 +30,7 @@ import java.util.List;
import org.alfresco.repo.domain.CrcHelper; import org.alfresco.repo.domain.CrcHelper;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.springframework.dao.DataIntegrityViolationException;
/** /**
* DAO services for <b>alf_prop_XXX</b> tables. * DAO services for <b>alf_prop_XXX</b> tables.
@@ -184,6 +185,7 @@ public interface PropertyValueDAO
* *
* @param id the ID (may not be <tt>null</tt>) * @param id the ID (may not be <tt>null</tt>)
* @return Returns the value of the property (never <tt>null</tt>) * @return Returns the value of the property (never <tt>null</tt>)
* @throws DataIntegrityViolationException if the ID is invalid
*/ */
Serializable getPropertyById(Long id); Serializable getPropertyById(Long id);
/** /**