mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added DAOs. Attribute query objects seem to be able to generate hibernate predicates.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5467 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,162 +27,26 @@ package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
import org.alfresco.repo.attributes.AttributeUnsupportedQueryType;
|
||||
|
||||
/**
|
||||
* Abstract base class for Attribute Query nodes.
|
||||
* @author britt
|
||||
*/
|
||||
public abstract class AttrQuery implements Serializable
|
||||
{
|
||||
protected Attribute fValue;
|
||||
protected String fValue;
|
||||
|
||||
protected String fAttrName;
|
||||
protected AttrQuery()
|
||||
{
|
||||
}
|
||||
|
||||
protected String fEntityName;
|
||||
|
||||
protected AttrQuery(Attribute value)
|
||||
protected AttrQuery(String value)
|
||||
{
|
||||
fValue = value;
|
||||
switch (fValue.getType())
|
||||
{
|
||||
case BOOLEAN :
|
||||
{
|
||||
fAttrName = "booleanValue";
|
||||
fEntityName = "BooleanAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case BYTE :
|
||||
{
|
||||
fAttrName = "byteValue";
|
||||
fEntityName = "ByteAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case SHORT :
|
||||
{
|
||||
fAttrName = "shortValue";
|
||||
fEntityName = "ShortAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case INT :
|
||||
{
|
||||
fAttrName = "intValue";
|
||||
fEntityName = "IntAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case LONG :
|
||||
{
|
||||
fAttrName = "longValue";
|
||||
fEntityName = "LongAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case FLOAT :
|
||||
{
|
||||
fAttrName = "floatValue";
|
||||
fEntityName = "FloatAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case DOUBLE :
|
||||
{
|
||||
fAttrName = "doubleValue";
|
||||
fEntityName = "DoubleAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case STRING :
|
||||
{
|
||||
fAttrName = "stringValue";
|
||||
fEntityName = "StringAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case BLOB :
|
||||
{
|
||||
fAttrName = "blobValue";
|
||||
fEntityName = "BlobValueImpl";
|
||||
break;
|
||||
}
|
||||
case SERIALIZABLE :
|
||||
{
|
||||
fAttrName = "serializableValue";
|
||||
fEntityName = "SerializableValueImpl";
|
||||
break;
|
||||
}
|
||||
case MAP :
|
||||
{
|
||||
fAttrName = "mapValue"; // This doesn't need to make sense.
|
||||
fEntityName = "MapValueImpl"; // Nor does this.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the predicate that goes into a Hibernate query.
|
||||
* @return The predicate.
|
||||
*/
|
||||
public abstract String getPredicate();
|
||||
|
||||
/**
|
||||
* Get the entity that this predicate applies to.
|
||||
* @return The entity name.
|
||||
*/
|
||||
public String getEntity()
|
||||
{
|
||||
return fEntityName;
|
||||
}
|
||||
|
||||
protected String getValue()
|
||||
{
|
||||
switch (fValue.getType())
|
||||
{
|
||||
case BOOLEAN :
|
||||
{
|
||||
return fValue.getBooleanValue() ? "1" : "0";
|
||||
}
|
||||
case BYTE :
|
||||
{
|
||||
return Byte.toString(fValue.getByteValue());
|
||||
}
|
||||
case SHORT :
|
||||
{
|
||||
return Short.toString(fValue.getShortValue());
|
||||
}
|
||||
case INT :
|
||||
{
|
||||
return Integer.toString(fValue.getIntValue());
|
||||
}
|
||||
case LONG :
|
||||
{
|
||||
return Long.toString(fValue.getLongValue());
|
||||
}
|
||||
case FLOAT :
|
||||
{
|
||||
return Float.toString(fValue.getFloatValue());
|
||||
}
|
||||
case DOUBLE :
|
||||
{
|
||||
return Double.toString(fValue.getDoubleValue());
|
||||
}
|
||||
case STRING :
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char[] chars = fValue.getStringValue().toCharArray();
|
||||
builder.append('\'');
|
||||
for (char c : chars)
|
||||
{
|
||||
if (c == '\'')
|
||||
{
|
||||
builder.append("\\'");
|
||||
continue;
|
||||
}
|
||||
builder.append(c);
|
||||
}
|
||||
builder.append('\'');
|
||||
return builder.toString();
|
||||
}
|
||||
default :
|
||||
{
|
||||
throw new AttributeUnsupportedQueryType(fValue.getType().name());
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract String getPredicate(AttrQueryHelper helper);
|
||||
}
|
||||
|
Reference in New Issue
Block a user