Search in sources :

Example 1 with PropertyStringQueryEntity

use of org.alfresco.repo.domain.propval.PropertyStringQueryEntity in project alfresco-repository by Alfresco.

the class PropertyValueDAOImpl method findPropertyValueByValue.

@Override
protected PropertyValueEntity findPropertyValueByValue(Serializable value) {
    // Get the actual type ID
    Class<?> clazz = (value == null ? Object.class : value.getClass());
    Pair<Long, Class<?>> clazzPair = getPropertyClass(clazz);
    if (clazzPair == null) {
        // Shortcut: There are no properties of this type
        return null;
    }
    Long actualTypeId = clazzPair.getFirst();
    // Construct the search parameters
    PropertyValueEntity queryEntity = new PropertyValueEntity();
    queryEntity.setValue(value, converter);
    queryEntity.setActualTypeId(actualTypeId);
    // How would it be persisted?
    PersistedType persistedType = queryEntity.getPersistedTypeEnum();
    Short persistedTypeId = queryEntity.getPersistedType();
    // Query based on the the persistable value type
    String query = null;
    Object queryObject = queryEntity;
    switch(persistedType) {
        case NULL:
        case LONG:
            query = SELECT_PROPERTY_VALUE_BY_LOCAL_VALUE;
            break;
        case DOUBLE:
            query = SELECT_PROPERTY_VALUE_BY_DOUBLE_VALUE;
            break;
        case CONSTRUCTABLE:
        // The string value is the name of the class (e.g. 'java.util.HashMap')
        case ENUM:
        // The string-equivalent representation
        case STRING:
            // It's best to query using the CRC and short end-value
            query = SELECT_PROPERTY_VALUE_BY_STRING_VALUE;
            queryObject = new PropertyStringQueryEntity(persistedTypeId, actualTypeId, queryEntity.getStringValue());
            break;
        case SERIALIZABLE:
            // No query
            break;
        default:
            throw new IllegalStateException("Unhandled PersistedType value: " + persistedType);
    }
    // Now query
    PropertyValueEntity result = null;
    if (query != null) {
        // Uniqueness is guaranteed by the tables, so we get one value only
        result = template.selectOne(query, queryObject);
    }
    // Done
    return result;
}
Also used : PropertyStringQueryEntity(org.alfresco.repo.domain.propval.PropertyStringQueryEntity) PersistedType(org.alfresco.repo.domain.propval.PropertyValueEntity.PersistedType) PropertyValueEntity(org.alfresco.repo.domain.propval.PropertyValueEntity)

Aggregations

PropertyStringQueryEntity (org.alfresco.repo.domain.propval.PropertyStringQueryEntity)1 PropertyValueEntity (org.alfresco.repo.domain.propval.PropertyValueEntity)1 PersistedType (org.alfresco.repo.domain.propval.PropertyValueEntity.PersistedType)1