no message

This commit is contained in:
Ioannis Kalyvas 2018-01-30 14:23:47 +02:00
parent fec219c3ee
commit 4d191f50ca
5 changed files with 35 additions and 2 deletions

View File

@ -26,7 +26,7 @@ public class UserTokenDaoImpl extends DatabaseAccess<UserToken> implements UserT
@Override
public UserToken find(UUID id) {
return this.getDatabaseService().getQueryable(UserToken.class).where((builder, root) -> builder.equal(root.get("token"),id)).getSingle();
return this.getDatabaseService().getQueryable(UserToken.class).where((builder, root) -> builder.equal(root.get("token"),id)).getSingleOrDefault();
}
@Override

View File

@ -19,6 +19,8 @@ public interface QueryableList<T extends DataEntity<T>> {
T getSingle();
T getSingleOrDefault();
QueryableList<T> skip(Integer offset);
QueryableList<T> take(Integer length);

View File

@ -0,0 +1,19 @@
package eu.eudat.queryable.exceptions;
/**
* Created by ikalyvas on 1/30/2018.
*/
public class NotSingleResultException extends RuntimeException{
public NotSingleResultException() {
super();
}
public NotSingleResultException(String message, Throwable cause) {
super(message, cause);
}
public NotSingleResultException(String message) {
super(message);
}
public NotSingleResultException(Throwable cause) {
super(cause);
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.queryable.hibernatequeryablelist;
import eu.eudat.entities.DataEntity;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.exceptions.NotSingleResultException;
import eu.eudat.queryable.predicates.OrderByPredicate;
import eu.eudat.queryable.predicates.SelectPredicate;
import eu.eudat.queryable.predicates.SinglePredicate;
@ -133,6 +134,18 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
return typedQuery.getSingleResult();
}
public T getSingleOrDefault() {
Predicate[] array = new Predicate[this.predicates.size()];
this.predicates.toArray(array);
this.query.where(array);
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
List<T> results = typedQuery.getResultList();
if (results.size() == 0) return null;
if (results.size() == 1) return results.get(0);
else throw new NotSingleResultException("Query returned more than one items");
}
private TypedQuery<T> queryWithHint(List ids) {
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(tClass);

View File

@ -26,7 +26,6 @@ export class DatasetWizardModel implements Serializable<DatasetWizardModel> {
public externalDatasets: ExternalDatasetModel[] = [];
public dmp: DataManagementPlanModel = new DataManagementPlanModel();
public datasetProfileDefinition;
public properties: any;
public errorModel: BaseErrorModel = new BaseErrorModel();
fromJSONObject(item: any): DatasetWizardModel {