mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
More tests for property persistence and fixes to ensure that d:any always returns the same type as put in
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2247 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -145,66 +145,6 @@ public class PropertyValue implements Cloneable, Serializable
|
|||||||
},
|
},
|
||||||
SERIALIZABLE
|
SERIALIZABLE
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* As <code>Serializable</code> persistence is the last resort, being both
|
|
||||||
* more verbose as well as unusable in queries, the value is used to
|
|
||||||
* determine a more appropriate persistent type. This method defers to
|
|
||||||
* the other, more basic types' version of this method to fulfill the request.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected ValueType getPersistedType(Serializable value)
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Persisted type cannot be determined by null value");
|
|
||||||
}
|
|
||||||
// check the value to determine the most appropriate type to defer to
|
|
||||||
if (value instanceof Boolean)
|
|
||||||
{
|
|
||||||
return ValueType.BOOLEAN.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if ((value instanceof Integer) || (value instanceof Long))
|
|
||||||
{
|
|
||||||
return ValueType.LONG.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if (value instanceof Float)
|
|
||||||
{
|
|
||||||
return ValueType.FLOAT.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if (value instanceof Double)
|
|
||||||
{
|
|
||||||
return ValueType.DOUBLE.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if (value instanceof String)
|
|
||||||
{
|
|
||||||
return ValueType.STRING.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if (value instanceof Date)
|
|
||||||
{
|
|
||||||
return ValueType.DATE.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if (value instanceof ContentData)
|
|
||||||
{
|
|
||||||
return ValueType.CONTENT.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if (value instanceof NodeRef)
|
|
||||||
{
|
|
||||||
return ValueType.NODEREF.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if (value instanceof QName)
|
|
||||||
{
|
|
||||||
return ValueType.QNAME.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else if (value instanceof Path)
|
|
||||||
{
|
|
||||||
return ValueType.PATH.getPersistedType(value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Serializable convert(Serializable value)
|
Serializable convert(Serializable value)
|
||||||
{
|
{
|
||||||
@@ -269,7 +209,7 @@ public class PropertyValue implements Cloneable, Serializable
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override if the type gets persisted in a different format
|
* Override if the type gets persisted in a different format.
|
||||||
*
|
*
|
||||||
* @param value the actual value that is to be persisted. May not be null.
|
* @param value the actual value that is to be persisted. May not be null.
|
||||||
*/
|
*/
|
||||||
@@ -308,6 +248,65 @@ public class PropertyValue implements Cloneable, Serializable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the actual value type to aid in more concise persistence.
|
||||||
|
*
|
||||||
|
* @param value the value that is to be persisted
|
||||||
|
* @return Returns the value type equivalent of the
|
||||||
|
*/
|
||||||
|
private static ValueType getActualType(Serializable value)
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
return ValueType.NULL;
|
||||||
|
}
|
||||||
|
else if (value instanceof Boolean)
|
||||||
|
{
|
||||||
|
return ValueType.BOOLEAN;
|
||||||
|
}
|
||||||
|
else if ((value instanceof Integer) || (value instanceof Long))
|
||||||
|
{
|
||||||
|
return ValueType.LONG;
|
||||||
|
}
|
||||||
|
else if (value instanceof Float)
|
||||||
|
{
|
||||||
|
return ValueType.FLOAT;
|
||||||
|
}
|
||||||
|
else if (value instanceof Double)
|
||||||
|
{
|
||||||
|
return ValueType.DOUBLE;
|
||||||
|
}
|
||||||
|
else if (value instanceof String)
|
||||||
|
{
|
||||||
|
return ValueType.STRING;
|
||||||
|
}
|
||||||
|
else if (value instanceof Date)
|
||||||
|
{
|
||||||
|
return ValueType.DATE;
|
||||||
|
}
|
||||||
|
else if (value instanceof ContentData)
|
||||||
|
{
|
||||||
|
return ValueType.CONTENT;
|
||||||
|
}
|
||||||
|
else if (value instanceof NodeRef)
|
||||||
|
{
|
||||||
|
return ValueType.NODEREF;
|
||||||
|
}
|
||||||
|
else if (value instanceof QName)
|
||||||
|
{
|
||||||
|
return ValueType.QNAME;
|
||||||
|
}
|
||||||
|
else if (value instanceof Path)
|
||||||
|
{
|
||||||
|
return ValueType.PATH;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// type is not recognised as belonging to any particular slot
|
||||||
|
return ValueType.SERIALIZABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** a mapping from a property type <code>QName</code> to the corresponding value type */
|
/** a mapping from a property type <code>QName</code> to the corresponding value type */
|
||||||
private static Map<QName, ValueType> valueTypesByPropertyType;
|
private static Map<QName, ValueType> valueTypesByPropertyType;
|
||||||
static
|
static
|
||||||
@@ -362,7 +361,8 @@ public class PropertyValue implements Cloneable, Serializable
|
|||||||
*/
|
*/
|
||||||
public PropertyValue(QName typeQName, Serializable value)
|
public PropertyValue(QName typeQName, Serializable value)
|
||||||
{
|
{
|
||||||
this.actualType = makeValueType(typeQName);
|
this.actualType = PropertyValue.getActualType(value);
|
||||||
|
// this.actualType = makeValueType(typeQName);
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
{
|
||||||
setPersistedValue(ValueType.NULL, null);
|
setPersistedValue(ValueType.NULL, null);
|
||||||
@@ -382,8 +382,8 @@ public class PropertyValue implements Cloneable, Serializable
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// get the persisted type
|
// get the persisted type
|
||||||
ValueType valueType = makeValueType(typeQName);
|
// ValueType valueType = makeValueType(typeQName);
|
||||||
ValueType persistedValueType = valueType.getPersistedType(value);
|
ValueType persistedValueType = this.actualType.getPersistedType(value);
|
||||||
// convert to the persistent type
|
// convert to the persistent type
|
||||||
value = persistedValueType.convert(value);
|
value = persistedValueType.convert(value);
|
||||||
setPersistedValue(persistedValueType, value);
|
setPersistedValue(persistedValueType, value);
|
||||||
@@ -586,6 +586,11 @@ public class PropertyValue implements Cloneable, Serializable
|
|||||||
// first check for null
|
// first check for null
|
||||||
|
|
||||||
ValueType requiredType = makeValueType(typeQName);
|
ValueType requiredType = makeValueType(typeQName);
|
||||||
|
if (requiredType == ValueType.SERIALIZABLE)
|
||||||
|
{
|
||||||
|
// the required type must be the actual type
|
||||||
|
requiredType = this.actualType;
|
||||||
|
}
|
||||||
|
|
||||||
// we need to convert
|
// we need to convert
|
||||||
Serializable ret = null;
|
Serializable ret = null;
|
||||||
|
@@ -27,6 +27,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
@@ -893,6 +895,36 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that the type you get out of a <b>d:any</b> property is the type that you
|
||||||
|
* put in.
|
||||||
|
*/
|
||||||
|
public void testSerializableProperties() throws Exception
|
||||||
|
{
|
||||||
|
ContentData contentData = new ContentData(null, null, 0L, null);
|
||||||
|
QName qname = PROP_QNAME_CONTENT_VALUE;
|
||||||
|
|
||||||
|
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(17);
|
||||||
|
properties.put(PROP_QNAME_CONTENT_VALUE, contentData);
|
||||||
|
properties.put(PROP_QNAME_SERIALIZABLE_VALUE, qname);
|
||||||
|
// create node
|
||||||
|
NodeRef nodeRef = nodeService.createNode(
|
||||||
|
rootNodeRef,
|
||||||
|
ASSOC_TYPE_QNAME_TEST_CHILDREN,
|
||||||
|
QName.createQName("pathA"),
|
||||||
|
ContentModel.TYPE_CONTAINER,
|
||||||
|
properties).getChildRef();
|
||||||
|
// persist
|
||||||
|
flushAndClear();
|
||||||
|
|
||||||
|
// get the properties back
|
||||||
|
Map<QName, Serializable> checkProperties = nodeService.getProperties(nodeRef);
|
||||||
|
Serializable checkPropertyContentData = checkProperties.get(PROP_QNAME_CONTENT_VALUE);
|
||||||
|
Serializable checkPropertyQname = checkProperties.get(PROP_QNAME_SERIALIZABLE_VALUE);
|
||||||
|
assertTrue("Serialization/deserialization of ContentData failed", checkPropertyContentData instanceof ContentData);
|
||||||
|
assertTrue("Serialization/deserialization failed", checkPropertyQname instanceof QName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that properties go in and come out in the correct format
|
* Check that properties go in and come out in the correct format
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user