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

@@ -800,12 +800,31 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
* @see #createPropertyImpl(Serializable, int, int) * @see #createPropertyImpl(Serializable, int, int)
*/ */
public Long createProperty(Serializable value) public Long createProperty(Serializable value)
{
Pair<Long, Serializable> entityPair = propertyCache.getOrCreateByValue(value);
return entityPair.getFirst();
}
public void updateProperty(Long rootPropId, Serializable value)
{
propertyCache.updateValue(rootPropId, value);
}
public void deleteProperty(Long id)
{
propertyCache.deleteByKey(id);
}
/**
* Callback for <b>alf_prop_root</b> DAO.
*/
private class PropertyCallbackDAO extends EntityLookupCallbackDAOAdaptor<Long, Serializable, Serializable>
{
public Pair<Long, Serializable> createValue(Serializable value)
{ {
// We will need a new root // We will need a new root
Long rootPropId = createPropertyRoot(); Long rootPropId = createPropertyRoot();
createPropertyImpl(rootPropId, 0L, 0L, null, value); createPropertyImpl(rootPropId, 0L, 0L, null, value);
// Push this value into the cache
propertyCache.updateValue(rootPropId, value);
// Done // Done
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -814,22 +833,38 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
" ID: " + rootPropId + "\n" + " ID: " + rootPropId + "\n" +
" Value: " + value); " Value: " + value);
} }
return rootPropId; return new Pair<Long, Serializable>(rootPropId, value);
} }
public void updateProperty(Long rootPropId, Serializable 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 // Remove all entries for the root
PropertyRootEntity entity = getPropertyRoot(rootPropId); PropertyRootEntity entity = getPropertyRoot(key);
if (entity == null) if (entity == null)
{ {
throw new DataIntegrityViolationException("No property root exists for ID " + rootPropId); throw new DataIntegrityViolationException("No property root exists for ID " + key);
} }
// Remove all links using the root // Remove all links using the root
deletePropertyLinks(rootPropId); deletePropertyLinks(key);
// Create the new properties and update the cache // Create the new properties and update the cache
createPropertyImpl(rootPropId, 0L, 0L, null, value); createPropertyImpl(key, 0L, 0L, null, value);
propertyCache.updateValue(rootPropId, value);
// Update the property root to detect concurrent modification // Update the property root to detect concurrent modification
updatePropertyRoot(entity); updatePropertyRoot(entity);
// Done // Done
@@ -837,20 +872,24 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
{ {
logger.debug( logger.debug(
"Updated property: \n" + "Updated property: \n" +
" ID: " + rootPropId + "\n" + " ID: " + key + "\n" +
" Value: " + value); " Value: " + value);
} }
return 1;
} }
public void deleteProperty(Long id) @Override
public int deleteByKey(Long key)
{ {
deletePropertyRoot(id); deletePropertyRoot(key);
// Done // Done
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug( logger.debug(
"Deleted property: \n" + "Deleted property: \n" +
" ID: " + id); " 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);
/** /**