Search in sources :

Example 1 with PersistedType

use of org.alfresco.repo.domain.propval.PropertyValueEntity.PersistedType 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)

Example 2 with PersistedType

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

the class DefaultPropertyTypeConverter method getPersistentType.

/**
 * {@inheritDoc}
 */
public PersistedType getPersistentType(Serializable value) {
    ParameterCheck.mandatory("value", value);
    Class<?> clazz = value.getClass();
    PersistedType type = persistenceMapping.get(clazz);
    if (type != null) {
        // MNT-17523: Loss of information, field values truncated
        if (value instanceof String) {
            if (((String) value).length() > SchemaBootstrap.getMaxStringLength()) {
                return PropertyValueEntity.PersistedType.SERIALIZABLE;
            }
        }
        return type;
    }
    // Before we give up, check if it is constructable
    if (isConstructable(value)) {
        // It'll just be given back as a class name i.e. a CONSTRUCTABLE
        return PersistedType.CONSTRUCTABLE;
    } else if (value instanceof Enum<?>) {
        return PersistedType.ENUM;
    } else {
        // Check if there are converters to and from well-known types, just in case
        if (DefaultTypeConverter.INSTANCE.getConverter(clazz, Long.class) != null && DefaultTypeConverter.INSTANCE.getConverter(Long.class, clazz) != null) {
            return PersistedType.LONG;
        } else if (DefaultTypeConverter.INSTANCE.getConverter(clazz, String.class) != null && DefaultTypeConverter.INSTANCE.getConverter(String.class, clazz) != null) {
            return PersistedType.STRING;
        }
        // No hope of doing anything useful other than storing it
        return PersistedType.SERIALIZABLE;
    }
}
Also used : PersistedType(org.alfresco.repo.domain.propval.PropertyValueEntity.PersistedType)

Aggregations

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