AVM Nodes are (theoretically) mostly aspect ready. AVMNodeService is

now derived from AbstractNodeServiceImpl to make policy awareness easier.
Moved addDefaultPropertyValues from DbNodeServiceImpl to 
AbstractNodeServiceImpl so AVMNodeService can use it.  A fix for an
NPE that showed up in stress test.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3603 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-08-24 18:36:59 +00:00
parent d67b926589
commit 0606fa3ab6
15 changed files with 252 additions and 619 deletions

View File

@@ -1,301 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Datasource -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>${db.driver}</value>
</property>
<property name="jdbcUrl">
<value>${db.url}</value>
</property>
<property name="user">
<value>${db.username}</value>
</property>
<property name="password">
<value>${db.password}</value>
</property>
<property name="initialPoolSize">
<value>${db.pool.initial}</value>
</property>
<property name="maxPoolSize" >
<value>${db.pool.max}</value>
</property>
<property name="numHelperThreads">
<value>1</value>
</property>
<property name="idleConnectionTestPeriod">
<value>60</value>
</property>
</bean>
<!-- The SessionFactory for hibernate. -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop>
<prop key="hibernate.connection.isolation">${hibernate.connection.isolation}</prop>
<prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
<prop key="hibernate.jdbc.batch_versioned_data">${hibernate.jdbc.batch_versioned_data}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/alfresco/repo/avm/hibernate/AVM.hbm.xml</value>
</list>
</property>
</bean>
<bean id="nodeIssuer" class="org.alfresco.repo.avm.Issuer"
depends-on="retryingTransaction,avmContext" init-method="init">
<property name="name">
<value>node</value>
</property>
<property name="retryingTransaction">
<ref bean="retryingTransaction"/>
</property>
</bean>
<bean id="contentIssuer" class="org.alfresco.repo.avm.Issuer"
depends-on="retryingTransaction,avmContext" init-method="init">
<property name="name">
<value>content</value>
</property>
<property name="retryingTransaction">
<ref bean="retryingTransaction"/>
</property>
</bean>
<bean id="layerIssuer" class="org.alfresco.repo.avm.Issuer"
depends-on="retryingTransaction,avmContext" init-method="init">
<property name="name">
<value>layer</value>
</property>
<property name="retryingTransaction">
<ref bean="retryingTransaction"/>
</property>
</bean>
<bean id="issuerDAO" class="org.alfresco.repo.avm.IssuerDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="nodeDAO" class="org.alfresco.repo.avm.AVMNodeDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="avmStoreDAO" class="org.alfresco.repo.avm.AVMStoreDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="versionRootDAO" class="org.alfresco.repo.avm.VersionRootDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="childEntryDAO" class="org.alfresco.repo.avm.ChildEntryDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="historyLinkDAO" class="org.alfresco.repo.avm.HistoryLinkDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="mergeLinkDAO" class="org.alfresco.repo.avm.MergeLinkDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="deletedChildDAO" class="org.alfresco.repo.avm.DeletedChildDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="newInAVMStoreDAO" class="org.alfresco.repo.avm.NewInAVMStoreDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="avmNodePropertyDAO" class="org.alfresco.repo.avm.AVMNodePropertyDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="avmStorePropertyDAO" class="org.alfresco.repo.avm.AVMStorePropertyDAOHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="avmContext" class="org.alfresco.repo.avm.AVMContext">
<property name="issuerDAO">
<ref bean="issuerDAO"/>
</property>
<property name="nodeDAO">
<ref bean="nodeDAO"/>
</property>
<property name="avmStoreDAO">
<ref bean="avmStoreDAO"/>
</property>
<property name="versionRootDAO">
<ref bean="versionRootDAO"/>
</property>
<property name="fileContentDAO">
<ref bean="fileContentDAO"/>
</property>
<property name="childEntryDAO">
<ref bean="childEntryDAO"/>
</property>
<property name="historyLinkDAO">
<ref bean="historyLinkDAO"/>
</property>
<property name="mergeLinkDAO">
<ref bean="mergeLinkDAO"/>
</property>
<property name="deletedChildDAO">
<ref bean="deletedChildDAO"/>
</property>
<property name="newInAVMStoreDAO">
<ref bean="newInAVMStoreDAO"/>
</property>
<property name="avmNodePropertyDAO">
<ref bean="avmNodePropertyDAO"/>
</property>
<property name="avmStorePropertyDAO">
<ref bean="avmStorePropertyDAO"/>
</property>
<property name="contentService">
<ref bean="ContentService"/>
</property>
</bean>
<!-- The HibernateTransactionManager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- A read only DefaultTransactionDefinition -->
<bean id="readTransactionDefinition"
class="org.springframework.transaction.support.DefaultTransactionDefinition">
<property name="propagationBehaviorName">
<value>PROPAGATION_REQUIRED</value>
</property>
<property name="isolationLevelName">
<value>ISOLATION_READ_COMMITTED</value>
</property>
<property name="readOnly">
<value>true</value>
</property>
</bean>
<!-- A write DefaultTransactionDefinition -->
<bean id="writeTransactionDefinition"
class="org.springframework.transaction.support.DefaultTransactionDefinition">
<property name="propagationBehaviorName">
<value>PROPAGATION_REQUIRED</value>
</property>
<property name="isolationLevelName">
<value>ISOLATION_READ_COMMITTED</value>
</property>
<property name="readOnly">
<value>false</value>
</property>
</bean>
<!-- The Hibernate Transaction wrapper. -->
<bean id="retryingTransaction"
class="org.alfresco.repo.avm.HibernateRetryingTransactionHelper">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="readTransactionDefinition">
<ref bean="readTransactionDefinition"/>
</property>
<property name="writeTransactionDefinition">
<ref bean="writeTransactionDefinition"/>
</property>
</bean>
<bean id="orphanReaper" class="org.alfresco.repo.avm.OrphanReaper"
init-method="init" destroy-method="shutDown" depends-on="AVMService">
<property name="inactiveBaseSleep">
<value>4000</value>
</property>
<property name="activeBaseSleep">
<value>1000</value>
</property>
<property name="batchSize">
<value>50</value>
</property>
<property name="retryingTransaction">
<ref bean="retryingTransaction"/>
</property>
</bean>
<bean id="AVMService" class="org.alfresco.repo.avm.AVMServiceImpl"
init-method="init">
<property name="storage">
<value>${avm.storage}</value>
</property>
<property name="initialize">
<value>${avm.initialize}</value>
</property>
<property name="retryingTransaction">
<ref bean="retryingTransaction"/>
</property>
<property name="avmRepository">
<ref bean="avmRepository"/>
</property>
</bean>
<bean id="avmRepository" class="org.alfresco.repo.avm.AVMRepository"
init-method="init">
<property name="storage">
<value>${avm.storage}</value>
</property>
<property name="nodeIssuer">
<ref bean="nodeIssuer"/>
</property>
<property name="contentIssuer">
<ref bean="contentIssuer"/>
</property>
<property name="layerIssuer">
<ref bean="layerIssuer"/>
</property>
</bean>
</beans>

View File

@@ -14,5 +14,3 @@ hibernate.jdbc.batch_versioned_data=true
hibernate.cache.use_second_level_cache=true hibernate.cache.use_second_level_cache=true
hibernate.hbm2ddl.auto=update hibernate.hbm2ddl.auto=update
# AVM specific properties. # AVM specific properties.
avm.storage=build/test-results/storage
avm.initialize=false

View File

@@ -199,11 +199,7 @@
</property> </property>
</bean> </bean>
<bean id="avmRepository" class="org.alfresco.repo.avm.AVMRepository" <bean id="avmRepository" class="org.alfresco.repo.avm.AVMRepository">
init-method="init">
<property name="storage">
<value>${avm.storage}</value>
</property>
<property name="nodeIssuer"> <property name="nodeIssuer">
<ref bean="nodeIssuer"/> <ref bean="nodeIssuer"/>
</property> </property>

View File

@@ -1,18 +0,0 @@
# Database specifics.
db.driver=org.gjt.mm.mysql.Driver
db.url=jdbc:mysql://127.0.0.1/avm
db.username=root
db.password=
db.pool.initial=4
db.pool.max=32
# Hibernate properties
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.current_session_context_class=thread
hibernate.connection.isolation=4
hibernate.default_batch_fetch_size=16
hibernate.jdbc.batch_versioned_data=true
hibernate.cache.use_second_level_cache=true
hibernate.hbm2ddl.auto=update
# AVM specific properties.
avm.storage=build/test-results/storage
avm.initialize=true

View File

@@ -938,12 +938,6 @@
<!-- The AVMService --> <!-- The AVMService -->
<bean id="AVMService" class="org.alfresco.repo.avm.AVMServiceImpl" init-method="init"> <bean id="AVMService" class="org.alfresco.repo.avm.AVMServiceImpl" init-method="init">
<property name="storage">
<value>${avm.storage}</value>
</property>
<property name="initialize">
<value>${avm.initialize}</value>
</property>
<property name="retryingTransaction"> <property name="retryingTransaction">
<ref bean="retryingTransaction"/> <ref bean="retryingTransaction"/>
</property> </property>

View File

@@ -109,8 +109,6 @@ system.people_container.childname=sys:people
user.name.caseSensitive=false user.name.caseSensitive=false
# AVM Specific properties. # AVM Specific properties.
avm.storage=build/test-results/storage
avm.initialize=true
avm.remote.idlestream.timeout=30000 avm.remote.idlestream.timeout=30000
avm.remote.port=1313 avm.remote.port=1313

View File

@@ -29,8 +29,10 @@ import java.util.SortedMap;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.node.AbstractNodeServiceImpl;
import org.alfresco.service.Auditable; import org.alfresco.service.Auditable;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.InvalidAspectException; import org.alfresco.service.cmr.dictionary.InvalidAspectException;
import org.alfresco.service.cmr.dictionary.InvalidTypeException; import org.alfresco.service.cmr.dictionary.InvalidTypeException;
import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.dictionary.PropertyDefinition;
@@ -56,7 +58,7 @@ import org.apache.log4j.Logger;
* NodeService implementing facade over AVMService. * NodeService implementing facade over AVMService.
* @author britt * @author britt
*/ */
public class AVMNodeService implements NodeService public class AVMNodeService extends AbstractNodeServiceImpl implements NodeService
{ {
private static Logger fgLogger = Logger.getLogger(AVMNodeService.class); private static Logger fgLogger = Logger.getLogger(AVMNodeService.class);
@@ -65,11 +67,6 @@ public class AVMNodeService implements NodeService
*/ */
private AVMService fAVMService; private AVMService fAVMService;
/**
* Reference to DictionaryService.
*/
private DictionaryService fDictionaryService;
/** /**
* Set the AVMService. For Spring. * Set the AVMService. For Spring.
* @param service The AVMService instance. * @param service The AVMService instance.
@@ -79,15 +76,6 @@ public class AVMNodeService implements NodeService
fAVMService = service; fAVMService = service;
} }
/**
* Set the DictionaryService. For Spring.
* @param dictionaryService The DictionaryService instance.
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
fDictionaryService = dictionaryService;
}
/** /**
* Default constructor. * Default constructor.
*/ */
@@ -484,7 +472,68 @@ public class AVMNodeService implements NodeService
Map<QName, Serializable> aspectProperties) Map<QName, Serializable> aspectProperties)
throws InvalidNodeRefException, InvalidAspectException throws InvalidNodeRefException, InvalidAspectException
{ {
throw new UnsupportedOperationException("AVM Nodes cannot be advised yet."); // Check that the aspect exists.
AspectDefinition aspectDef = this.dictionaryService.getAspect(aspectTypeQName);
if (aspectDef == null)
{
throw new InvalidAspectException("The aspect is invalid: " + aspectTypeQName,
aspectTypeQName);
}
// Crack the nodeRef.
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = (Integer)avmVersionPath[0];
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only node.", nodeRef);
}
String avmPath = (String)avmVersionPath[1];
// Get the current node properties.
Map<QName, Serializable> properties = getProperties(nodeRef);
// Add the supplied properties.
if (aspectProperties != null)
{
properties.putAll(aspectProperties);
}
// Now set any unspecified default properties for the aspect.
addDefaultPropertyValues(aspectDef, properties);
// Now add any cascading aspects.
addDefaultAspects(aspectDef, avmPath, properties);
// Set the property values on the AVM Node.
setProperties(nodeRef, properties);
if (isBuiltinAspect(aspectTypeQName))
{
// No more work to do in this case.
return;
}
try
{
fAVMService.addAspect(avmPath, aspectTypeQName);
}
catch (AVMNotFoundException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
/**
* Add any aspects that are mandatory for the ClassDefinition.
* @param classDef The ClassDefinition.
* @param path The path to the AVMNode.
* @param properties The in/out map of accumulated properties.
*/
private void addDefaultAspects(ClassDefinition classDef, String path,
Map<QName, Serializable> properties)
{
// Get mandatory aspects.
List<AspectDefinition> defaultAspectDefs = classDef.getDefaultAspects();
// add all the aspects (and there dependent aspects recursively).
for (AspectDefinition def : defaultAspectDefs)
{
fAVMService.addAspect(path, def.getName());
addDefaultPropertyValues(def, properties);
// recurse
addDefaultAspects(def, path, properties);
}
} }
/** /**
@@ -499,7 +548,39 @@ public class AVMNodeService implements NodeService
public void removeAspect(NodeRef nodeRef, QName aspectTypeQName) public void removeAspect(NodeRef nodeRef, QName aspectTypeQName)
throws InvalidNodeRefException, InvalidAspectException throws InvalidNodeRefException, InvalidAspectException
{ {
throw new UnsupportedOperationException("AVM Nodes do not yet have aspects."); AspectDefinition def = dictionaryService.getAspect(aspectTypeQName);
if (def == null)
{
throw new InvalidAspectException(aspectTypeQName);
}
if (isBuiltinAspect(aspectTypeQName))
{
// TODO shouldn't we be throwing some kind of exception here.
return;
}
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = (Integer)avmVersionPath[0];
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", nodeRef);
}
String path = (String)avmVersionPath[1];
try
{
if (fAVMService.hasAspect(-1, path, aspectTypeQName))
{
fAVMService.removeAspect(path, aspectTypeQName);
Map<QName, PropertyDefinition> propDefs = def.getProperties();
for (QName propertyName : propDefs.keySet())
{
fAVMService.deleteNodeProperty(path, propertyName);
}
}
}
catch (AVMNotFoundException e)
{
throw new InvalidNodeRefException(nodeRef);
}
} }
/** /**
@@ -516,6 +597,35 @@ public class AVMNodeService implements NodeService
public boolean hasAspect(NodeRef nodeRef, QName aspectTypeQName) public boolean hasAspect(NodeRef nodeRef, QName aspectTypeQName)
throws InvalidNodeRefException, InvalidAspectException throws InvalidNodeRefException, InvalidAspectException
{ {
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = (Integer)avmVersionPath[0];
String path = (String)avmVersionPath[1];
if (isBuiltinAspect(aspectTypeQName))
{
return true;
}
try
{
return fAVMService.hasAspect(version, path, aspectTypeQName);
}
catch (AVMNotFoundException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
private static QName [] fgBuiltinAspects = new QName[] { ContentModel.ASPECT_AUDITABLE,
ContentModel.ASPECT_REFERENCEABLE };
private boolean isBuiltinAspect(QName aspectQName)
{
for (QName builtin : fgBuiltinAspects)
{
if (builtin.equals(aspectQName))
{
return true;
}
}
return false; return false;
} }
@@ -527,8 +637,28 @@ public class AVMNodeService implements NodeService
*/ */
public Set<QName> getAspects(NodeRef nodeRef) throws InvalidNodeRefException public Set<QName> getAspects(NodeRef nodeRef) throws InvalidNodeRefException
{ {
// TODO This is almost certainly not the right thing to do. Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
return new HashSet<QName>(); int version = (Integer)avmVersionPath[0];
String path = (String)avmVersionPath[1];
Set<QName> result = new HashSet<QName>();
// Add the builtin ones.
for (QName name : fgBuiltinAspects)
{
result.add(name);
}
try
{
List<QName> aspects = fAVMService.getAspects(version, path);
for (QName name : aspects)
{
result.add(name);
}
return result;
}
catch (AVMNotFoundException e)
{
throw new InvalidNodeRefException(nodeRef);
}
} }
/** /**
@@ -648,7 +778,7 @@ public class AVMNodeService implements NodeService
for (QName qName : props.keySet()) for (QName qName : props.keySet())
{ {
PropertyValue value = props.get(qName); PropertyValue value = props.get(qName);
PropertyDefinition def = fDictionaryService.getProperty(qName); PropertyDefinition def = this.dictionaryService.getProperty(qName);
result.put(qName, value.getValue(def.getDataType().getName())); result.put(qName, value.getValue(def.getDataType().getName()));
} }
// Now spoof properties that are built in. // Now spoof properties that are built in.
@@ -695,7 +825,7 @@ public class AVMNodeService implements NodeService
{ {
return null; return null;
} }
PropertyDefinition def = fDictionaryService.getProperty(qname); PropertyDefinition def = this.dictionaryService.getProperty(qname);
return value.getValue(def.getDataType().getName()); return value.getValue(def.getDataType().getName());
} }
catch (AVMNotFoundException e) catch (AVMNotFoundException e)
@@ -726,7 +856,8 @@ public class AVMNodeService implements NodeService
} }
catch (AVMException e) catch (AVMException e)
{ {
// TODO For now, ignore. // TODO This seems very wrong. Do something better
// sooner rather than later.
return null; return null;
} }
} }
@@ -807,6 +938,16 @@ public class AVMNodeService implements NodeService
} }
} }
static QName [] fgBuiltinProperties = new QName []
{
ContentModel.PROP_CREATED,
ContentModel.PROP_CREATOR,
ContentModel.PROP_MODIFIED,
ContentModel.PROP_MODIFIER,
ContentModel.PROP_OWNER,
ContentModel.PROP_CONTENT
};
/** /**
* Helper to distinguish built-in from generic properties. * Helper to distinguish built-in from generic properties.
* @param qName The name of the property to check. * @param qName The name of the property to check.
@@ -814,12 +955,14 @@ public class AVMNodeService implements NodeService
*/ */
private boolean isBuiltInProperty(QName qName) private boolean isBuiltInProperty(QName qName)
{ {
return qName.equals(ContentModel.PROP_CREATED) || for (QName name : fgBuiltinProperties)
qName.equals(ContentModel.PROP_CREATOR) || {
qName.equals(ContentModel.PROP_MODIFIED) || if (name.equals(qName))
qName.equals(ContentModel.PROP_MODIFIER) || {
qName.equals(ContentModel.PROP_OWNER) || return true;
qName.equals(ContentModel.PROP_CONTENT); }
}
return false;
} }
/** /**
@@ -875,9 +1018,6 @@ public class AVMNodeService implements NodeService
String path = (String)avmVersionPath[1]; String path = (String)avmVersionPath[1];
List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>(); List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>();
String [] splitPath = AVMNodeConverter.SplitBase(path); String [] splitPath = AVMNodeConverter.SplitBase(path);
// TODO Remove when you figure this out.
fgLogger.error(splitPath[0]);
fgLogger.error(splitPath[1]);
if (splitPath[0] == null) if (splitPath[0] == null)
{ {
return result; return result;

View File

@@ -28,8 +28,6 @@ import java.util.SortedMap;
import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
/** /**
@@ -59,11 +57,6 @@ public class AVMRepository
*/ */
private Issuer fLayerIssuer; private Issuer fLayerIssuer;
/**
* The file storage directory.
*/
private String fStorage;
/** /**
* Create a new one. * Create a new one.
*/ */
@@ -73,15 +66,6 @@ public class AVMRepository
fgInstance = this; fgInstance = this;
} }
/**
* Set the storage directory.
* @param storage The absolute path to content storage directory.
*/
public void setStorage(String storage)
{
fStorage = storage;
}
/** /**
* Set the node issuer. For Spring. * Set the node issuer. For Spring.
* @param nodeIssuer The issuer. * @param nodeIssuer The issuer.
@@ -100,12 +84,6 @@ public class AVMRepository
fLayerIssuer = layerIssuer; fLayerIssuer = layerIssuer;
} }
public void init()
{
File storageDir = new File(fStorage);
storageDir.mkdirs();
}
/** /**
* Create a file. * Create a file.
* @param path The path to the containing directory. * @param path The path to the containing directory.
@@ -496,33 +474,6 @@ public class AVMRepository
return store.getInputStream(version, pathParts[1]); return store.getInputStream(version, pathParts[1]);
} }
/**
* Get a ContentReader from a file.
* @param version The version to look under.
* @param path The path to the file.
* @return A ContentReader
*/
public ContentReader getReader(int version, String path)
{
fLookupCount.set(1);
String [] pathParts = SplitPath(path);
AVMStore store = getAVMStoreByName(pathParts[0]);
return store.getReader(version, pathParts[1]);
}
/**
* Get a ContentWriter to a file.
* @param path The path to the file.
* @return A ContentWriter.
*/
public ContentWriter getWriter(String path)
{
fLookupCount.set(1);
String [] pathParts = SplitPath(path);
AVMStore store = getAVMStoreByName(pathParts[0]);
return store.getWriter(pathParts[1]);
}
/** /**
* Get a listing of a directory. * Get a listing of a directory.
* @param version The version to look under. * @param version The version to look under.
@@ -819,15 +770,6 @@ public class AVMRepository
return pathParts; return pathParts;
} }
/**
* Get the path to file storage.
* @return The root path of file storage.
*/
public String getStorageRoot()
{
return fStorage;
}
/** /**
* Make a directory into a primary indirection. * Make a directory into a primary indirection.
* @param path The full path. * @param path The full path.

View File

@@ -26,8 +26,6 @@ import java.util.SortedMap;
import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
/** /**
@@ -60,25 +58,6 @@ public interface AVMService
*/ */
public OutputStream getFileOutputStream(String path); public OutputStream getFileOutputStream(String path);
/**
* Get a ContentReader for the given file.
* @param version The version to look under.
* @param path The path to the file.
* @return A ContentReader.
* @throws AVMNotFoundException If <code>path</code> does not exist.
* @throws AVMWrongTypeException if <code>path</code> is not a file.
*/
public ContentReader getReader(int version, String path);
/**
* Get a ContentWriter to a file.
* @param path The path to the file.
* @return A ContentWriter.
* @throws AVMNotFoundException If <code>path</code> does not exist.
* @throws AVMWrongTypeException if <code>path</code> is not a file.
*/
public ContentWriter getWriter(String path);
/** /**
* Get a listing of a Folder by name. * Get a listing of a Folder by name.
* @param version The version id to look in. * @param version The version id to look in.

View File

@@ -30,13 +30,12 @@ import java.util.SortedMap;
import org.alfresco.repo.avm.AVMRepository; import org.alfresco.repo.avm.AVMRepository;
import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.TempFileProvider;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* Implements the AVMService. Stub. * Implements the AVMService.
* @author britt * @author britt
*/ */
public class AVMServiceImpl implements AVMService public class AVMServiceImpl implements AVMService
@@ -53,16 +52,6 @@ public class AVMServiceImpl implements AVMService
*/ */
private AVMRepository fAVMRepository; private AVMRepository fAVMRepository;
/**
* The storage directory.
*/
private String fStorage;
/**
* Whether the tables should be dropped and created.
*/
private boolean fInitialize;
/** /**
* Basic constructor for the service. * Basic constructor for the service.
*/ */
@@ -70,22 +59,11 @@ public class AVMServiceImpl implements AVMService
{ {
} }
/**
* Set the storage directory.
* @param storage The full path to the storage directory.
*/
public void setStorage(String storage)
{
fStorage = storage;
}
/** /**
* Final initialization of the service. Must be called only on a * Final initialization of the service. Must be called only on a
* fully initialized instance. * fully initialized instance.
*/ */
public void init() public void init()
{
if (fInitialize)
{ {
try try
{ {
@@ -97,7 +75,6 @@ public class AVMServiceImpl implements AVMService
fgLogger.info("AVMStore main already exists"); fgLogger.info("AVMStore main already exists");
} }
} }
}
/** /**
* Set the Retrying Transaction wrapper. * Set the Retrying Transaction wrapper.
@@ -108,15 +85,6 @@ public class AVMServiceImpl implements AVMService
fTransaction = txn; fTransaction = txn;
} }
/**
* Set whether we should create an initial AVMStore.
* @param initialize
*/
public void setInitialize(boolean initialize)
{
fInitialize = initialize;
}
/** /**
* Set the repository reference. For Spring. * Set the repository reference. For Spring.
* @param avmRepository The repository reference. * @param avmRepository The repository reference.
@@ -153,58 +121,6 @@ public class AVMServiceImpl implements AVMService
return doit.in; return doit.in;
} }
/**
* Get a ContentReader for the given file.
* @param version The version to look under.
* @param path The path to the file.
* @return A ContentReader.
*/
public ContentReader getReader(final int version, final String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Null path.");
}
class TxnCallback implements RetryingTransactionCallback
{
public ContentReader reader;
public void perform()
{
reader = fAVMRepository.getReader(version, path);
}
}
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, false);
return doit.reader;
}
/**
* Get a ContentWriter to a file.
* @param path The path to the file.
* @return A ContentWriter.
* @throws AVMNotFoundException If <code>path</code> does not exist.
* @throws AVMWrongTypeException if <code>path</code> is not a file.
*/
public ContentWriter getWriter(final String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Null path.");
}
class TxnCallback implements RetryingTransactionCallback
{
public ContentWriter writer;
public void perform()
{
writer = fAVMRepository.getWriter(path);
}
}
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
return doit.writer;
}
/** /**
* Get an output stream to a file. Triggers versioning. * Get an output stream to a file. Triggers versioning.
*/ */
@@ -365,6 +281,7 @@ public class AVMServiceImpl implements AVMService
return doit.out; return doit.out;
} }
// TODO Eliminate this.
/** /**
* Create a file with content specified by the InputStream. * Create a file with content specified by the InputStream.
* Guaranteed to be created atomically. * Guaranteed to be created atomically.
@@ -379,11 +296,10 @@ public class AVMServiceImpl implements AVMService
throw new AVMBadArgumentException("Illegal null argument."); throw new AVMBadArgumentException("Illegal null argument.");
} }
// Save the contents to temp space. // Save the contents to temp space.
File dir = new File(fStorage);
final File temp; final File temp;
try try
{ {
temp = File.createTempFile("alf", "tmp", dir); temp = TempFileProvider.createTempFile("alf", "tmp");
OutputStream out = new FileOutputStream(temp); OutputStream out = new FileOutputStream(temp);
byte [] buff = new byte[8192]; byte [] buff = new byte[8192];
int read; int read;

View File

@@ -26,8 +26,6 @@ import java.util.SortedMap;
import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
/** /**
@@ -105,21 +103,6 @@ interface AVMStore
*/ */
public InputStream getInputStream(int version, String path); public InputStream getInputStream(int version, String path);
/**
* Get a ContentReader from a file.
* @param version The version to look under.
* @param path The path to the file.
* @return A ContentReader.
*/
public ContentReader getReader(int version, String path);
/**
* Get a ContentWriter to a file.
* @param path The path to the file.
* @return A ContentWriter.
*/
public ContentWriter getWriter(String path);
/** /**
* Get a listing of the designated directory. * Get a listing of the designated directory.
* @param version The version to look under. * @param version The version to look under.

View File

@@ -268,7 +268,6 @@ class AVMStoreImpl implements AVMStore, Serializable
"UTF-8")); "UTF-8"));
ContentWriter writer = getWriter(AVMNodeConverter.ExtendAVMPath(path, name)); ContentWriter writer = getWriter(AVMNodeConverter.ExtendAVMPath(path, name));
writer.putContent(data); writer.putContent(data);
file.setContentData(writer.getContentData());
} }
/** /**
@@ -302,6 +301,12 @@ class AVMStoreImpl implements AVMStore, Serializable
public InputStream getInputStream(int version, String path) public InputStream getInputStream(int version, String path)
{ {
ContentReader reader = getReader(version, path); ContentReader reader = getReader(version, path);
if (reader == null)
{
// TODO This is wrong, wrong, wrong. Do something about it
// sooner rather than later.
throw new AVMNotFoundException(path + " has no content.");
}
return reader.getContentInputStream(); return reader.getContentInputStream();
/* /*
Lookup lPath = lookup(version, path, false); Lookup lPath = lookup(version, path, false);
@@ -323,7 +328,7 @@ class AVMStoreImpl implements AVMStore, Serializable
* @param path The path to the file. * @param path The path to the file.
* @return A ContentReader. * @return A ContentReader.
*/ */
public ContentReader getReader(int version, String path) private ContentReader getReader(int version, String path)
{ {
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, fName + ":" + path); NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, fName + ":" + path);
return AVMContext.fgInstance.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT); return AVMContext.fgInstance.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT);
@@ -334,11 +339,12 @@ class AVMStoreImpl implements AVMStore, Serializable
* @param path The path to the file. * @param path The path to the file.
* @return A ContentWriter. * @return A ContentWriter.
*/ */
public ContentWriter getWriter(String path) private ContentWriter getWriter(String path)
{ {
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, fName + ":" + path); NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, fName + ":" + path);
ContentWriter writer = ContentWriter writer =
AVMContext.fgInstance.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true); AVMContext.fgInstance.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
// TODO This can't perform very well.
setContentData(path, writer.getContentData()); setContentData(path, writer.getContentData());
return writer; return writer;
} }

View File

@@ -102,9 +102,9 @@ public class HibernateRetryingTransactionHelper extends HibernateTemplate implem
} }
if (!newTxn) if (!newTxn)
{ {
if (t instanceof AVMException) if (t instanceof RuntimeException)
{ {
throw (AVMException)t; throw (RuntimeException)t;
} }
throw new AVMException("Unrecoverable error.", t); throw new AVMException("Unrecoverable error.", t);
} }

View File

@@ -49,8 +49,10 @@ import org.alfresco.repo.policy.AssociationPolicyDelegate;
import org.alfresco.repo.policy.ClassPolicyDelegate; import org.alfresco.repo.policy.ClassPolicyDelegate;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.search.Indexer; import org.alfresco.repo.search.Indexer;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryException; import org.alfresco.service.cmr.dictionary.DictionaryException;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -88,6 +90,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
private String uuid; private String uuid;
/** controls policy delegates */ /** controls policy delegates */
private PolicyComponent policyComponent; private PolicyComponent policyComponent;
protected DictionaryService dictionaryService;
/* /*
* Policy delegates * Policy delegates
@@ -125,6 +128,11 @@ public abstract class AbstractNodeServiceImpl implements NodeService
this.policyComponent = policyComponent; this.policyComponent = policyComponent;
} }
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/** /**
* Checks equality by type and uuid * Checks equality by type and uuid
*/ */
@@ -564,7 +572,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
* @see RegexQNamePattern#MATCH_ALL * @see RegexQNamePattern#MATCH_ALL
* @see NodeService#getChildAssocs(NodeRef, QNamePattern, QNamePattern) * @see NodeService#getChildAssocs(NodeRef, QNamePattern, QNamePattern)
*/ */
public final List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef) throws InvalidNodeRefException public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef) throws InvalidNodeRefException
{ {
return getChildAssocs(nodeRef, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL); return getChildAssocs(nodeRef, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL);
} }
@@ -677,4 +685,51 @@ public abstract class AbstractNodeServiceImpl implements NodeService
e); e);
} }
} }
/**
* Sets the default property values
*
* @param classDefinition
* @param properties
*/
protected void addDefaultPropertyValues(ClassDefinition classDefinition, Map<QName, Serializable> properties)
{
for (Map.Entry<QName, Serializable> entry : classDefinition.getDefaultValues().entrySet())
{
if (properties.containsKey(entry.getKey()))
{
// property is present
continue;
}
Serializable value = entry.getValue();
// Check the type of the default property
PropertyDefinition prop = this.dictionaryService.getProperty(entry.getKey());
if (prop == null)
{
// dictionary doesn't have a default value present
continue;
}
// TODO: what other conversions are necessary here for other types of default values ?
// ensure that we deliver the property in the correct form
if (DataTypeDefinition.BOOLEAN.equals(prop.getDataType().getName()) == true)
{
if (value instanceof String)
{
if (((String)value).toUpperCase().equals("TRUE") == true)
{
value = Boolean.TRUE;
}
else if (((String)value).toUpperCase().equals("FALSE") == true)
{
value = Boolean.FALSE;
}
}
}
// Set the default value of the property
properties.put(entry.getKey(), value);
}
}
} }

View File

@@ -42,8 +42,6 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition; import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.InvalidAspectException; import org.alfresco.service.cmr.dictionary.InvalidAspectException;
import org.alfresco.service.cmr.dictionary.InvalidTypeException; import org.alfresco.service.cmr.dictionary.InvalidTypeException;
import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.dictionary.PropertyDefinition;
@@ -77,7 +75,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{ {
private static Log logger = LogFactory.getLog(DbNodeServiceImpl.class); private static Log logger = LogFactory.getLog(DbNodeServiceImpl.class);
private DictionaryService dictionaryService;
private NodeDaoService nodeDaoService; private NodeDaoService nodeDaoService;
private StoreArchiveMap storeArchiveMap; private StoreArchiveMap storeArchiveMap;
private NodeService avmNodeService; private NodeService avmNodeService;
@@ -87,11 +84,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
storeArchiveMap = new StoreArchiveMap(); // in case it is not set storeArchiveMap = new StoreArchiveMap(); // in case it is not set
} }
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
public void setNodeDaoService(NodeDaoService nodeDaoService) public void setNodeDaoService(NodeDaoService nodeDaoService)
{ {
this.nodeDaoService = nodeDaoService; this.nodeDaoService = nodeDaoService;
@@ -347,53 +339,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
} }
} }
/**
* Sets the default property values
*
* @param classDefinition
* @param properties
*/
private void addDefaultPropertyValues(ClassDefinition classDefinition, Map<QName, Serializable> properties)
{
for (Map.Entry<QName, Serializable> entry : classDefinition.getDefaultValues().entrySet())
{
if (properties.containsKey(entry.getKey()))
{
// property is present
continue;
}
Serializable value = entry.getValue();
// Check the type of the default property
PropertyDefinition prop = this.dictionaryService.getProperty(entry.getKey());
if (prop == null)
{
// dictionary doesn't have a default value present
continue;
}
// TODO: what other conversions are necessary here for other types of default values ?
// ensure that we deliver the property in the correct form
if (DataTypeDefinition.BOOLEAN.equals(prop.getDataType().getName()) == true)
{
if (value instanceof String)
{
if (((String)value).toUpperCase().equals("TRUE") == true)
{
value = Boolean.TRUE;
}
else if (((String)value).toUpperCase().equals("FALSE") == true)
{
value = Boolean.FALSE;
}
}
}
// Set the default value of the property
properties.put(entry.getKey(), value);
}
}
/** /**
* Drops the old primary association and creates a new one * Drops the old primary association and creates a new one