package eu.eudat.data.dao.entities; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.criteria.OrganisationCriteria; import eu.eudat.data.dao.databaselayer.service.DatabaseService; import eu.eudat.data.entities.Organisation; import eu.eudat.queryable.QueryableList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.util.UUID; import java.util.concurrent.CompletableFuture; @Component("organisationDao") public class OrganisationDaoImpl extends DatabaseAccess implements OrganisationDao { @Autowired public OrganisationDaoImpl(DatabaseService databaseService) { super(databaseService); } @Override public QueryableList getWithCriteria(OrganisationCriteria criteria) { QueryableList query = this.getDatabaseService().getQueryable(Organisation.class); if (criteria.getLike() != null) query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike())); return query; } @Override public Organisation createOrUpdate(Organisation item) { return this.getDatabaseService().createOrUpdate(item, Organisation.class); } @Override public Organisation find(UUID id) { return this.getDatabaseService().getQueryable(Organisation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle(); } @Override public void delete(Organisation item) { this.getDatabaseService().delete(item); } @Override public QueryableList asQueryable() { return this.getDatabaseService().getQueryable(Organisation.class); } @Async @Override public CompletableFuture createOrUpdateAsync(Organisation item) { return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item)); } @Override public Organisation find(UUID id, String hint) { throw new UnsupportedOperationException(); } }