mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
103438: Working towards a fix for ACE-3948: BM-0004: Factor out select on alf_content_url table during file creation - Complement the 'getOrCreate' EntityCache calls with 'createOrGet' - Cleanup of ContentDataDAOImpl code before further changes: tabs, @Override, unused code, etc git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@103622 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,12 +19,14 @@
|
||||
package org.alfresco.repo.cache.lookup;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Savepoint;
|
||||
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.domain.control.ControlDAO;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* A cache for two-way lookups of database entities. These are characterized by having a unique
|
||||
@@ -412,6 +414,48 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to create the entity and, failing that, look it up.<br/>
|
||||
* This method takes the opposite approach to {@link #getOrCreateByValue(Object)}, which assumes the entity's
|
||||
* existence: in this case the entity is assumed to NOT exist.
|
||||
* The {@link EntityLookupCallbackDAO#createValue(Object)} and {@link EntityLookupCallbackDAO#findByValue(Object)}
|
||||
* will be used if necessary.<br/>
|
||||
* <p/>
|
||||
* Use this method when the data involved is seldom reused.
|
||||
*
|
||||
* @param value The entity value (<tt>null</tt> is allowed)
|
||||
* @param controlDAO an essential DAO required in order to ensure a transactionally-safe attempt at data creation
|
||||
* @return Returns the key-value pair (new or existing and never <tt>null</tt>)
|
||||
*/
|
||||
public Pair<K, V> createOrGetByValue(V value, ControlDAO controlDAO)
|
||||
{
|
||||
if (controlDAO == null)
|
||||
{
|
||||
throw new IllegalArgumentException("The ControlDAO is required in order to perform a safe attempted insert.");
|
||||
}
|
||||
Savepoint savepoint = controlDAO.createSavepoint("EntityLookupCache.createOrGetByValue");
|
||||
try
|
||||
{
|
||||
Pair<K, V> entityPair = entityLookup.createValue(value);
|
||||
controlDAO.releaseSavepoint(savepoint);
|
||||
// Cache it
|
||||
if (cache != null)
|
||||
{
|
||||
cache.put(
|
||||
new CacheRegionKey(cacheRegion, entityPair.getFirst()),
|
||||
(entityPair.getSecond() == null ? VALUE_NULL : entityPair.getSecond()));
|
||||
}
|
||||
// It's been created and cached
|
||||
return entityPair;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
controlDAO.rollbackToSavepoint(savepoint);
|
||||
// Fall through to the usual way, which should find it if the failure cause was a duplicate key
|
||||
return getOrCreateByValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the entity associated with the given value and create it if it doesn't exist.
|
||||
* The {@link EntityLookupCallbackDAO#findByValue(Object)} and {@link EntityLookupCallbackDAO#createValue(Object)}
|
||||
|
@@ -82,6 +82,7 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
|
||||
this.template = sqlSessionTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<Long, String> createContentUrlOrphaned(String contentUrl, Date orphanTime)
|
||||
{
|
||||
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
|
||||
@@ -106,9 +107,7 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
|
||||
|
||||
if(contentUrlKeyEntity != null)
|
||||
{
|
||||
template.insert(INSERT_SYMMETRIC_KEY, contentUrlKeyEntity);
|
||||
|
||||
// contentUrlEntity.setContentUrlKey(contentUrlKeyEntity);
|
||||
template.insert(INSERT_SYMMETRIC_KEY, contentUrlKeyEntity);
|
||||
}
|
||||
|
||||
// Done
|
||||
@@ -139,6 +138,7 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
|
||||
return contentUrlEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getContentUrlsOrphaned(
|
||||
final ContentUrlHandler contentUrlHandler,
|
||||
final Long maxOrphanTimeExclusive,
|
||||
@@ -161,7 +161,7 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void getContentUrlsKeepOrphaned(
|
||||
final ContentUrlHandler contentUrlHandler,
|
||||
final int maxResults)
|
||||
@@ -178,6 +178,7 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateContentUrlOrphanTime(Long id, Long orphanTime, Long oldOrphanTime)
|
||||
{
|
||||
ContentUrlUpdateEntity contentUrlUpdateEntity = new ContentUrlUpdateEntity();
|
||||
@@ -190,6 +191,7 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int deleteContentUrls(List<Long> ids)
|
||||
{
|
||||
template.delete(DELETE_CONTENT_URL_KEYS, ids);
|
||||
@@ -289,6 +291,7 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
|
||||
return template.delete(DELETE_CONTENT_DATA, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContentDataForNode(Long nodeId, Set<Long> qnameIds)
|
||||
{
|
||||
if (qnameIds.size() == 0)
|
||||
@@ -317,62 +320,62 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int updateContentUrlEntity(ContentUrlEntity existing, ContentUrlEntity entity)
|
||||
{
|
||||
int ret = 0;
|
||||
@Override
|
||||
protected int updateContentUrlEntity(ContentUrlEntity existing, ContentUrlEntity entity)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ContentUrlKeyEntity existingContentUrlKey = existing.getContentUrlKey();
|
||||
ContentUrlKeyEntity contentUrlKey = entity.getContentUrlKey();
|
||||
contentUrlKey.setContentUrlId(existing.getId());
|
||||
if(existingContentUrlKey == null)
|
||||
{
|
||||
ret = template.insert(INSERT_SYMMETRIC_KEY, contentUrlKey);
|
||||
}
|
||||
else if (!EqualsHelper.nullSafeEquals(existingContentUrlKey, contentUrlKey))
|
||||
{
|
||||
ret = template.update(UPDATE_SYMMETRIC_KEY, contentUrlKey);
|
||||
}
|
||||
ContentUrlKeyEntity existingContentUrlKey = existing.getContentUrlKey();
|
||||
ContentUrlKeyEntity contentUrlKey = entity.getContentUrlKey();
|
||||
contentUrlKey.setContentUrlId(existing.getId());
|
||||
if(existingContentUrlKey == null)
|
||||
{
|
||||
ret = template.insert(INSERT_SYMMETRIC_KEY, contentUrlKey);
|
||||
}
|
||||
else if (!EqualsHelper.nullSafeEquals(existingContentUrlKey, contentUrlKey))
|
||||
{
|
||||
ret = template.update(UPDATE_SYMMETRIC_KEY, contentUrlKey);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int deleteContentUrlEntity(long id)
|
||||
{
|
||||
@Override
|
||||
protected int deleteContentUrlEntity(long id)
|
||||
{
|
||||
Map<String, Object> params = new HashMap<String, Object>(11);
|
||||
params.put("id", id);
|
||||
return template.delete(DELETE_SYMMETRIC_KEY, params);
|
||||
}
|
||||
return template.delete(DELETE_SYMMETRIC_KEY, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContentUrlKeyEntity> getSymmetricKeysByMasterKeyAlias(String masterKeyAlias, long fromId, int maxResults)
|
||||
{
|
||||
ContentUrlKeyEntity entity = new ContentUrlKeyEntity();
|
||||
entity.setMasterKeyAlias(masterKeyAlias);
|
||||
entity.setId(fromId);
|
||||
List<ContentUrlKeyEntity> results = template.selectList(SELECT_SYMMETRIC_KEYS_BY_MASTER_KEY,
|
||||
entity, new RowBounds(0, maxResults));
|
||||
return results;
|
||||
}
|
||||
@Override
|
||||
public List<ContentUrlKeyEntity> getSymmetricKeysByMasterKeyAlias(String masterKeyAlias, long fromId, int maxResults)
|
||||
{
|
||||
ContentUrlKeyEntity entity = new ContentUrlKeyEntity();
|
||||
entity.setMasterKeyAlias(masterKeyAlias);
|
||||
entity.setId(fromId);
|
||||
List<ContentUrlKeyEntity> results = template.selectList(SELECT_SYMMETRIC_KEYS_BY_MASTER_KEY,
|
||||
entity, new RowBounds(0, maxResults));
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> countSymmetricKeysForMasterKeys()
|
||||
{
|
||||
Map<String, Integer> counts = new HashMap<>();
|
||||
@Override
|
||||
public Map<String, Integer> countSymmetricKeysForMasterKeys()
|
||||
{
|
||||
Map<String, Integer> counts = new HashMap<>();
|
||||
|
||||
List<SymmetricKeyCount> res = template.selectList(COUNT_SYMMETRIC_KEYS_FOR_MASTER_KEYS);
|
||||
for(SymmetricKeyCount count : res)
|
||||
{
|
||||
counts.put(count.getMasterKeyAlias(), count.getCount());
|
||||
}
|
||||
List<SymmetricKeyCount> res = template.selectList(COUNT_SYMMETRIC_KEYS_FOR_MASTER_KEYS);
|
||||
for(SymmetricKeyCount count : res)
|
||||
{
|
||||
counts.put(count.getMasterKeyAlias(), count.getCount());
|
||||
}
|
||||
|
||||
return counts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countSymmetricKeysForMasterKeyAlias(String masterKeyAlias)
|
||||
{
|
||||
return (Integer)template.selectOne(COUNT_SYMMETRIC_KEYS_BY_MASTER_KEY, masterKeyAlias);
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countSymmetricKeysForMasterKeyAlias(String masterKeyAlias)
|
||||
{
|
||||
return (Integer)template.selectOne(COUNT_SYMMETRIC_KEYS_BY_MASTER_KEY, masterKeyAlias);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user