Search in sources :

Example 1 with PropertyValueEntity

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

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

the class PropertyValueDAOImpl method findPropertyById.

// ================================
// 'alf_prop_root' accessors
// ================================
@Override
protected List<PropertyIdSearchRow> findPropertyById(Long id) {
    PropertyValueEntity entity = new PropertyValueEntity();
    entity.setId(id);
    List<PropertyIdSearchRow> results = template.selectList(SELECT_PROPERTY_BY_ID, entity);
    return results;
}
Also used : PropertyIdSearchRow(org.alfresco.repo.domain.propval.PropertyIdSearchRow) PropertyValueEntity(org.alfresco.repo.domain.propval.PropertyValueEntity)

Example 3 with PropertyValueEntity

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

the class PropertyValueDAOImpl method findPropertyValueById.

// ================================
// 'alf_prop_value' accessors
// ================================
@Override
protected PropertyValueEntity findPropertyValueById(Long id) {
    PropertyValueEntity entity = new PropertyValueEntity();
    entity.setId(id);
    List<PropertyValueEntity> results = template.selectList(SELECT_PROPERTY_VALUE_BY_ID, entity);
    // At most one of the results represents a real value
    int size = results.size();
    if (size == 0) {
        return null;
    } else if (size == 1) {
        return results.get(0);
    } else {
        logger.error("Found property value linked to multiple raw types: " + results);
        return results.get(0);
    }
}
Also used : PropertyValueEntity(org.alfresco.repo.domain.propval.PropertyValueEntity)

Example 4 with PropertyValueEntity

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

the class PropertyValueDAOImpl method createPropertyValueInternal.

private PropertyValueEntity createPropertyValueInternal(Serializable value) {
    // Get the actual type ID
    Class<?> clazz = (value == null ? Object.class : value.getClass());
    Pair<Long, Class<?>> clazzPair = getOrCreatePropertyClass(clazz);
    Long actualTypeId = clazzPair.getFirst();
    // Construct the insert entity
    PropertyValueEntity insertEntity = new PropertyValueEntity();
    insertEntity.setValue(value, converter);
    insertEntity.setActualTypeId(actualTypeId);
    // Persist the persisted value
    switch(insertEntity.getPersistedTypeEnum()) {
        case DOUBLE:
            Double doubleValue = insertEntity.getDoubleValue();
            Pair<Long, Double> insertDoublePair = getOrCreatePropertyDoubleValue(doubleValue);
            insertEntity.setLongValue(insertDoublePair.getFirst());
            break;
        case STRING:
        case CONSTRUCTABLE:
        case ENUM:
            String stringValue = insertEntity.getStringValue();
            Pair<Long, String> insertStringPair = getOrCreatePropertyStringValue(stringValue);
            insertEntity.setLongValue(insertStringPair.getFirst());
            break;
        case SERIALIZABLE:
            Pair<Long, Serializable> insertSerializablePair = createPropertySerializableValue(value);
            insertEntity.setLongValue(insertSerializablePair.getFirst());
            break;
        case NULL:
        case LONG:
            // Do nothing for these
            break;
        default:
            throw new IllegalStateException("Unknown PersistedType enum: " + insertEntity.getPersistedTypeEnum());
    }
    // Persist the entity
    template.insert(INSERT_PROPERTY_VALUE, insertEntity);
    // Done
    return insertEntity;
}
Also used : Serializable(java.io.Serializable) PropertyValueEntity(org.alfresco.repo.domain.propval.PropertyValueEntity)

Aggregations

PropertyValueEntity (org.alfresco.repo.domain.propval.PropertyValueEntity)4 Serializable (java.io.Serializable)1 PropertyIdSearchRow (org.alfresco.repo.domain.propval.PropertyIdSearchRow)1 PropertyStringQueryEntity (org.alfresco.repo.domain.propval.PropertyStringQueryEntity)1 PersistedType (org.alfresco.repo.domain.propval.PropertyValueEntity.PersistedType)1