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;
}
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;
}
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);
}
}
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;
}
Aggregations