use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class DataAccessServiceImpl method find.
@Override
@Transactional(readOnly = true)
@Monitorable
public SearchResult find(final SearchQuery searchQuery) {
checkArgument(searchQuery != null, "SearchCriteria must be given");
Query query = searchQuery.createQuery(hibernateService.getCurrentSession());
searchQuery.addParameters(query);
searchQuery.addCacheable(query);
int totalNumberOfEntities = -1;
if (searchQuery.hasFirstAndMaxResults()) {
totalNumberOfEntities = hibernateService.list(query).size();
searchQuery.addFirstAndMaxResults(query);
}
if (totalNumberOfEntities == 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("There is no entity matching criteria " + searchQuery);
}
return getResultSet(null, totalNumberOfEntities, Collections.emptyList());
}
List<?> results = hibernateService.list(query);
if (totalNumberOfEntities == -1) {
totalNumberOfEntities = results.size();
if (totalNumberOfEntities == 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("There is no entity matching criteria " + searchQuery);
}
return getResultSet(null, totalNumberOfEntities, Collections.emptyList());
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("There are " + totalNumberOfEntities + " entities matching criteria " + searchQuery);
}
InternalDataDefinition searchQueryDataDefinition = (InternalDataDefinition) searchQuery.getDataDefinition();
if (searchQueryDataDefinition == null) {
searchQueryDataDefinition = hibernateService.resolveDataDefinition(query);
}
return getResultSet(searchQueryDataDefinition, totalNumberOfEntities, results);
}
use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class DataAccessServiceImpl method copy.
public Entity copy(final InternalDataDefinition dataDefinition, final Entity sourceEntity) {
InternalDataDefinition dataDefinitionToCopy = getDataDefinitionByMasterModel(dataDefinition);
Entity targetEntity = dataDefinitionToCopy.create();
for (Entry<String, FieldDefinition> fieldEntry : dataDefinitionToCopy.getFields().entrySet()) {
FieldDefinition fieldDefinition = fieldEntry.getValue();
String fieldName = fieldEntry.getKey();
boolean copy = fieldDefinition.getType().isCopyable();
if (copy) {
targetEntity.setField(fieldName, getCopyValueOfSimpleField(sourceEntity, dataDefinitionToCopy, fieldName));
}
}
if (!dataDefinitionToCopy.callCopyHook(targetEntity)) {
return null;
}
for (String fieldName : dataDefinitionToCopy.getFields().keySet()) {
copyHasManyField(sourceEntity, targetEntity, dataDefinitionToCopy, fieldName);
}
for (String fieldName : dataDefinitionToCopy.getFields().keySet()) {
copyTreeField(sourceEntity, targetEntity, dataDefinitionToCopy, fieldName);
}
for (String fieldName : dataDefinitionToCopy.getFields().keySet()) {
copyManyToManyField(sourceEntity, targetEntity, dataDefinitionToCopy, fieldName);
}
return targetEntity;
}
use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class DataAccessServiceImpl method delete.
@Override
@Transactional
@Monitorable
public EntityOpResult delete(final InternalDataDefinition dataDefinition, final Long... entityIds) {
InternalDataDefinition dataDefinitionToDelete = getDataDefinitionByMasterModel(dataDefinition);
checkState(dataDefinitionToDelete.isDeletable(), "Entity must be deletable");
checkState(dataDefinitionToDelete.isEnabled(), L_DATA_DEFINITION_BELONGS_TO_DISABLED_PLUGIN);
checkState(entityIds.length > 0, "EntityIds must be given");
for (Long entityId : entityIds) {
EntityOpResult result = deleteEntity(dataDefinitionToDelete, entityId);
if (!result.isSuccessfull()) {
return result;
}
}
return EntityOpResult.successfull();
}
use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class DataAccessServiceImpl method getDataDefinitionByMasterModel.
private InternalDataDefinition getDataDefinitionByMasterModel(InternalDataDefinition dataDefinition) {
InternalDataDefinition masterDataDefinition;
if (dataDefinition.getMasterModel() == null) {
masterDataDefinition = dataDefinition;
} else {
masterDataDefinition = (InternalDataDefinition) dataDefinitionService.get(dataDefinition.getMasterModel().getPluginIdentifier(), dataDefinition.getMasterModel().getName());
}
checkNotNull(masterDataDefinition, L_DATA_DEFINITION_MUST_BE_GIVEN);
return masterDataDefinition;
}
use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class DataAccessServiceImpl method performCascadeStrategy.
private EntityOpResult performCascadeStrategy(final Entity entity, final FieldType fieldType, final Collection<Entity> children, final Set<EntitySignature> traversedEntities) {
if (children == null || children.isEmpty()) {
return EntityOpResult.successfull();
}
boolean isManyToManyType = fieldType instanceof ManyToManyType;
InternalDataDefinition childDataDefinition = (InternalDataDefinition) ((DataDefinitionHolder) fieldType).getDataDefinition();
Cascadeable.Cascade cascade = ((Cascadeable) fieldType).getCascade();
if (Cascadeable.Cascade.NULLIFY.equals(cascade)) {
if (!isManyToManyType) {
return performCascadeNullification(childDataDefinition, children, entity, fieldType);
}
return EntityOpResult.successfull();
} else if (Cascadeable.Cascade.DELETE.equals(cascade)) {
return performCascadeDelete(childDataDefinition, children, isManyToManyType, traversedEntities);
} else {
throw new IllegalArgumentException(String.format("Unsupported cascade value '%s'", cascade));
}
}
Aggregations