mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added API methods to query AVM store properties by key pattern.
Cleaned up some warnings in AVMInterpreter. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3765 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,24 +24,16 @@ import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.avm.util.BulkLoader;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
|
||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
|
||||
|
@@ -393,6 +393,21 @@ public interface AVMRemote
|
||||
*/
|
||||
public PropertyValue getStoreProperty(String store, QName name);
|
||||
|
||||
/**
|
||||
* Query a store for keys that match a pattern.
|
||||
* @param store The store name.
|
||||
* @param keyPattern The sql 'like' pattern.
|
||||
* @return A Map of keys to values.
|
||||
*/
|
||||
public Map<QName, PropertyValue> queryStorePropertyKey(String store, QName keyPattern);
|
||||
|
||||
/**
|
||||
* Query all stores for keys that match a pattern.
|
||||
* @param keyPattern The sql 'like' pattern.
|
||||
* @return A Map of store names to Maps of matching keys to values.
|
||||
*/
|
||||
public Map<String, Map<QName, PropertyValue>> queryStoresPropertyKey(QName keyPattern);
|
||||
|
||||
/**
|
||||
* Get all the properties on a store.
|
||||
* @param store The name of the store.
|
||||
|
@@ -847,6 +847,27 @@ public class AVMRemoteImpl implements AVMRemote, Runnable
|
||||
return fAVMService.getStoreProperty(store, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query a store for keys that match a pattern.
|
||||
* @param store The store name.
|
||||
* @param keyPattern The sql 'like' pattern.
|
||||
* @return A Map of keys to values.
|
||||
*/
|
||||
public Map<QName, PropertyValue> queryStorePropertyKey(String store, QName keyPattern)
|
||||
{
|
||||
return fAVMService.queryStorePropertyKey(store, keyPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query all stores for keys that match a pattern.
|
||||
* @param keyPattern The sql 'like' pattern.
|
||||
* @return A Map of store names to Maps of matching keys to values.
|
||||
*/
|
||||
public Map<String, Map<QName, PropertyValue>> queryStoresPropertyKey(QName keyPattern)
|
||||
{
|
||||
return fAVMService.queryStoresPropertyKeys(keyPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the properties on a store.
|
||||
* @param store The name of the store.
|
||||
|
@@ -22,6 +22,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
@@ -965,6 +966,51 @@ public class AVMRepository
|
||||
return getAVMStoreByName(store).getProperty(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries a given store for properties with keys that match a given pattern.
|
||||
* @param store The name of the store.
|
||||
* @param keyPattern The sql 'like' pattern, inserted into a QName.
|
||||
* @return A Map of the matching key value pairs.
|
||||
*/
|
||||
public Map<QName, PropertyValue> queryStorePropertyKey(String store, QName keyPattern)
|
||||
{
|
||||
List<AVMStoreProperty> matches =
|
||||
AVMContext.fgInstance.fAVMStorePropertyDAO.queryByKeyPattern(getAVMStoreByName(store),
|
||||
keyPattern);
|
||||
Map<QName, PropertyValue> results = new HashMap<QName, PropertyValue>();
|
||||
for (AVMStoreProperty prop : matches)
|
||||
{
|
||||
results.put(prop.getName(), prop.getValue());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries all AVM stores for properties with keys that matcha given pattern.
|
||||
* @param keyPattern The sql 'like' pattern, inserted into a QName.
|
||||
* @return A List of Pairs of Store name, Map.Entry.
|
||||
*/
|
||||
public Map<String, Map<QName, PropertyValue>>
|
||||
queryStoresPropertyKeys(QName keyPattern)
|
||||
{
|
||||
List<AVMStoreProperty> matches =
|
||||
AVMContext.fgInstance.fAVMStorePropertyDAO.queryByKeyPattern(keyPattern);
|
||||
Map<String, Map<QName, PropertyValue>> results =
|
||||
new HashMap<String, Map<QName, PropertyValue>>();
|
||||
for (AVMStoreProperty prop : matches)
|
||||
{
|
||||
String storeName = prop.getStore().getName();
|
||||
Map<QName, PropertyValue> pairs = null;
|
||||
if ((pairs = results.get(storeName)) == null)
|
||||
{
|
||||
pairs = new HashMap<QName, PropertyValue>();
|
||||
results.put(storeName, pairs);
|
||||
}
|
||||
pairs.put(prop.getName(), prop.getValue());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the properties for a store.
|
||||
* @param store The name of the Store.
|
||||
|
@@ -840,6 +840,36 @@ public class AVMServiceImpl implements AVMService
|
||||
return fAVMRepository.getStoreProperty(store, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries a given store for properties with keys that match a given pattern.
|
||||
* @param store The name of the store.
|
||||
* @param keyPattern The sql 'like' pattern, inserted into a QName.
|
||||
* @return A Map of the matching key value pairs.
|
||||
*/
|
||||
public Map<QName, PropertyValue> queryStorePropertyKey(String store, QName keyPattern)
|
||||
{
|
||||
if (store == null || keyPattern == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Illegal null argument.");
|
||||
}
|
||||
return fAVMRepository.queryStorePropertyKey(store, keyPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries all AVM stores for properties with keys that matcha given pattern.
|
||||
* @param keyPattern The sql 'like' pattern, inserted into a QName.
|
||||
* @return A List of Pairs of Store name, Map.Entry.
|
||||
*/
|
||||
public Map<String, Map<QName, PropertyValue>>
|
||||
queryStoresPropertyKeys(QName keyPattern)
|
||||
{
|
||||
if (keyPattern == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Illegal null argument.");
|
||||
}
|
||||
return fAVMRepository.queryStoresPropertyKeys(keyPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the properties associated with a store.
|
||||
* @param store The name of the store.
|
||||
|
@@ -2477,4 +2477,38 @@ public class AVMServiceTest extends AVMServiceTestBase
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Store property querying.
|
||||
*/
|
||||
public void testStorePropertyQuerying()
|
||||
{
|
||||
try
|
||||
{
|
||||
fService.setStoreProperty("main", QName.createQName(null, ".dns.alice--preview"),
|
||||
new PropertyValue(null, "alice-preview"));
|
||||
fService.setStoreProperty("main", QName.createQName("", ".other.property"),
|
||||
new PropertyValue(null, "other value"));
|
||||
Map<QName, PropertyValue> result =
|
||||
fService.queryStorePropertyKey("main", QName.createQName("", ".dns.%"));
|
||||
assertEquals(1, result.size());
|
||||
fService.createAVMStore("second");
|
||||
fService.setStoreProperty("second", QName.createQName("", ".dns.alice"),
|
||||
new PropertyValue(null, "alice-space"));
|
||||
Map<String, Map<QName, PropertyValue>> matches =
|
||||
fService.queryStoresPropertyKeys(QName.createQName("", ".dns.%"));
|
||||
assertEquals(2, matches.size());
|
||||
assertEquals(1, matches.get("main").size());
|
||||
assertEquals(1, matches.get("second").size());
|
||||
assertEquals("alice-preview", matches.get("main").get(QName.createQName(null,
|
||||
".dns.alice--preview")).getStringValue());
|
||||
assertEquals("alice-space", matches.get("second").get(QName.createQName(null, ".dns.alice")).
|
||||
getStringValue());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,21 @@ public interface AVMStorePropertyDAO
|
||||
* @return A List of properties associated with the store.
|
||||
*/
|
||||
public List<AVMStoreProperty> get(AVMStore store);
|
||||
|
||||
/**
|
||||
* Query store properties by key pattern.
|
||||
* @param store The store.
|
||||
* @param keyPattern An sql 'like' pattern wrapped up in a QName
|
||||
* @return A List of matching AVMStoreProperties.
|
||||
*/
|
||||
public List<AVMStoreProperty> queryByKeyPattern(AVMStore store, QName keyPattern);
|
||||
|
||||
/**
|
||||
* Query all stores' properties by key pattern.
|
||||
* @param keyPattern The sql 'like' pattern wrapped up in a QName
|
||||
* @return A List of match AVMStoreProperties.
|
||||
*/
|
||||
public List<AVMStoreProperty> queryByKeyPattern(QName keyPattern);
|
||||
|
||||
/**
|
||||
* Update a modified property.
|
||||
|
@@ -69,7 +69,41 @@ class AVMStorePropertyDAOHibernate extends HibernateDaoSupport implements AVMSto
|
||||
query.setEntity("store", store);
|
||||
return (List<AVMStoreProperty>)query.list();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query store properties by key pattern.
|
||||
* @param store The store.
|
||||
* @param keyPattern An sql 'like' pattern wrapped up in a QName
|
||||
* @return A List of matching AVMStoreProperties.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AVMStoreProperty> queryByKeyPattern(AVMStore store, QName keyPattern)
|
||||
{
|
||||
Query query =
|
||||
getSession().createQuery(
|
||||
"from AVMStorePropertyImpl asp " +
|
||||
"where asp.store = :store and asp.name like :name");
|
||||
query.setEntity("store", store);
|
||||
query.setParameter("name", keyPattern);
|
||||
return (List<AVMStoreProperty>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Query all stores' properties by key pattern.
|
||||
* @param keyPattern The sql 'like' pattern wrapped up in a QName
|
||||
* @return A List of match AVMStoreProperties.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AVMStoreProperty> queryByKeyPattern(QName keyPattern)
|
||||
{
|
||||
Query query =
|
||||
getSession().createQuery(
|
||||
"from AVMStorePropertyImpl asp " +
|
||||
"where asp.name like :name");
|
||||
query.setParameter("name", keyPattern);
|
||||
return (List<AVMStoreProperty>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a modified property.
|
||||
* @param prop The AVMStoreProperty to update.
|
||||
|
@@ -584,6 +584,23 @@ public interface AVMService
|
||||
* does not exist.
|
||||
*/
|
||||
public Map<QName, PropertyValue> getStoreProperties(String store);
|
||||
|
||||
/**
|
||||
* Queries a given store for properties with keys that match a given pattern.
|
||||
* @param store The name of the store.
|
||||
* @param keyPattern The sql 'like' pattern, inserted into a QName.
|
||||
* @return A Map of the matching key value pairs.
|
||||
*/
|
||||
public Map<QName, PropertyValue> queryStorePropertyKey(String store, QName keyPattern);
|
||||
|
||||
/**
|
||||
* Queries all AVM stores for properties with keys that matcha given pattern.
|
||||
* @param keyPattern The sql 'like' pattern, inserted into a QName.
|
||||
* @return A Map of store names to Maps of property key value pairs that match
|
||||
* the pattern.
|
||||
*/
|
||||
public Map<String, Map<QName, PropertyValue>>
|
||||
queryStoresPropertyKeys(QName keyPattern);
|
||||
|
||||
/**
|
||||
* Delete a property on a store by name.
|
||||
|
Reference in New Issue
Block a user