no message
This commit is contained in:
parent
bf10c0c31c
commit
39f124cd63
|
@ -4,7 +4,7 @@ import eu.eudat.dao.databaselayer.service.DatabaseService;
|
||||||
import eu.eudat.entities.DataEntity;
|
import eu.eudat.entities.DataEntity;
|
||||||
|
|
||||||
|
|
||||||
public class DatabaseAccess<T extends DataEntity<T>> {
|
public class DatabaseAccess<T extends DataEntity> {
|
||||||
private DatabaseService<T> databaseService;
|
private DatabaseService<T> databaseService;
|
||||||
|
|
||||||
public DatabaseService<T> getDatabaseService() {
|
public DatabaseService<T> getDatabaseService() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ package eu.eudat.dao;
|
||||||
import eu.eudat.entities.DataEntity;
|
import eu.eudat.entities.DataEntity;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
|
||||||
public interface DatabaseAccessLayer<T extends DataEntity<T>, I> {
|
public interface DatabaseAccessLayer<T extends DataEntity, I> {
|
||||||
T createOrUpdate(T item);
|
T createOrUpdate(T item);
|
||||||
|
|
||||||
T find(I id);
|
T find(I id);
|
||||||
|
|
|
@ -13,7 +13,7 @@ import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
|
||||||
@Repository("databaseCtx")
|
@Repository("databaseCtx")
|
||||||
public class DatabaseContext<T extends DataEntity<T>> {
|
public class DatabaseContext<T extends DataEntity> {
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
@ -30,8 +30,8 @@ public class DatabaseContext<T extends DataEntity<T>> {
|
||||||
@Transactional
|
@Transactional
|
||||||
public T createOrUpdate(T item, Class<T> type) {
|
public T createOrUpdate(T item, Class<T> type) {
|
||||||
EntityManager entityManager = this.entityManager;
|
EntityManager entityManager = this.entityManager;
|
||||||
if (item.getKeys()[0] != null) {
|
if (item.getKeys() != null) {
|
||||||
T oldItem = entityManager.find(type, item.getKeys()[0]);
|
T oldItem = entityManager.find(type, item.getKeys());
|
||||||
if (oldItem != null) {
|
if (oldItem != null) {
|
||||||
oldItem.update(item);
|
oldItem.update(item);
|
||||||
entityManager.merge(oldItem);
|
entityManager.merge(oldItem);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
@Service("databaseService")
|
@Service("databaseService")
|
||||||
public class DatabaseService<T extends DataEntity<T>> {
|
public class DatabaseService<T extends DataEntity> {
|
||||||
|
|
||||||
private DatabaseContext<T> databaseCtx;
|
private DatabaseContext<T> databaseCtx;
|
||||||
|
|
||||||
|
|
|
@ -17,5 +17,4 @@ public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
|
||||||
|
|
||||||
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UserInfo principal);
|
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UserInfo principal);
|
||||||
|
|
||||||
Long count();
|
|
||||||
}
|
}
|
|
@ -77,8 +77,4 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
||||||
return this.getDatabaseService().getQueryable(DMP.class);
|
return this.getDatabaseService().getQueryable(DMP.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long count() {
|
|
||||||
return this.getDatabaseService().count(DMP.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,5 +19,4 @@ public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> {
|
||||||
|
|
||||||
Dataset find(UUID id, String hint);
|
Dataset find(UUID id, String hint);
|
||||||
|
|
||||||
Long count();
|
|
||||||
}
|
}
|
|
@ -61,11 +61,6 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long count() {
|
|
||||||
return this.getDatabaseService().count(Dataset.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Dataset item) {
|
public void delete(Dataset item) {
|
||||||
this.getDatabaseService().delete(item);
|
this.getDatabaseService().delete(item);
|
||||||
|
|
|
@ -14,5 +14,4 @@ public interface ProjectDao extends DatabaseAccessLayer<Project, UUID> {
|
||||||
|
|
||||||
QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal);
|
QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal);
|
||||||
|
|
||||||
Long count();
|
|
||||||
}
|
}
|
|
@ -44,11 +44,6 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
|
||||||
return getDatabaseService().getQueryable(Project.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
|
return getDatabaseService().getQueryable(Project.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long count() {
|
|
||||||
return this.getDatabaseService().count(Project.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Project item) {
|
public void delete(Project item) {
|
||||||
this.getDatabaseService().delete(item);
|
this.getDatabaseService().delete(item);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Credential\"")
|
@Table(name = "\"Credential\"")
|
||||||
public class Credential implements DataEntity<Credential> {
|
public class Credential implements DataEntity<Credential,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
|
@ -119,7 +119,7 @@ public class Credential implements DataEntity<Credential> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.*;
|
||||||
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),
|
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),
|
||||||
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")})
|
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")})
|
||||||
})
|
})
|
||||||
public class DMP implements Serializable, DataEntity<DMP> {
|
public class DMP implements DataEntity<DMP,UUID> {
|
||||||
|
|
||||||
public enum DMPStatus {
|
public enum DMPStatus {
|
||||||
ACTIVE((short) 0), DELETED((short) 1);
|
ACTIVE((short) 0), DELETED((short) 1);
|
||||||
|
@ -286,8 +286,8 @@ public class DMP implements Serializable, DataEntity<DMP> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DMPOrganisation\"")
|
@Table(name = "\"DMPOrganisation\"")
|
||||||
public class DMPOrganisation implements Serializable {
|
public class DMPOrganisation {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.entities;
|
package eu.eudat.entities;
|
||||||
|
|
||||||
public interface DataEntity<T> {
|
public interface DataEntity<T,K> {
|
||||||
void update(T entity);
|
void update(T entity);
|
||||||
|
|
||||||
Object[] getKeys();
|
K getKeys();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DataRepository\"")
|
@Table(name = "\"DataRepository\"")
|
||||||
public class DataRepository implements Serializable, DataEntity<DataRepository> {
|
public class DataRepository implements Serializable, DataEntity<DataRepository,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -147,7 +147,7 @@ public class DataRepository implements Serializable, DataEntity<DataRepository>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.*;
|
||||||
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("dataRepositories"), @NamedAttributeNode("externalDatasets"), @NamedAttributeNode("registries"),
|
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("dataRepositories"), @NamedAttributeNode("externalDatasets"), @NamedAttributeNode("registries"),
|
||||||
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")})
|
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")})
|
||||||
})
|
})
|
||||||
public class Dataset implements DataEntity<Dataset> {
|
public class Dataset implements DataEntity<Dataset,UUID> {
|
||||||
|
|
||||||
public static Set<String> getHints() {
|
public static Set<String> getHints() {
|
||||||
return hints;
|
return hints;
|
||||||
|
@ -313,7 +313,7 @@ public class Dataset implements DataEntity<Dataset> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DatasetProfile\"")
|
@Table(name = "\"DatasetProfile\"")
|
||||||
public class DatasetProfile implements Serializable, DataEntity<DatasetProfile> {
|
public class DatasetProfile implements DataEntity<DatasetProfile,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -132,7 +132,7 @@ public class DatasetProfile implements Serializable, DataEntity<DatasetProfile>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DatasetProfileRuleset\"")
|
@Table(name = "\"DatasetProfileRuleset\"")
|
||||||
public class DatasetProfileRuleset implements Serializable {
|
public class DatasetProfileRuleset {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DatasetRegistry\"")
|
@Table(name = "\"DatasetRegistry\"")
|
||||||
public class DatasetRegistry implements Serializable {
|
public class DatasetRegistry {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"DatasetService\"")
|
@Table(name = "\"DatasetService\"")
|
||||||
public class DatasetService implements Serializable {
|
public class DatasetService {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"ExternalDataset\"")
|
@Table(name = "\"ExternalDataset\"")
|
||||||
public class ExternalDataset implements DataEntity<ExternalDataset> {
|
public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -104,7 +104,7 @@ public class ExternalDataset implements DataEntity<ExternalDataset> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Invitation\"")
|
@Table(name = "\"Invitation\"")
|
||||||
public class Invitation implements DataEntity<Invitation> {
|
public class Invitation implements DataEntity<Invitation,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -100,7 +100,7 @@ public class Invitation implements DataEntity<Invitation> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Organisation\"")
|
@Table(name = "\"Organisation\"")
|
||||||
public class Organisation implements Serializable, DataEntity<Organisation> {
|
public class Organisation implements Serializable, DataEntity<Organisation,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -151,7 +151,7 @@ public class Organisation implements Serializable, DataEntity<Organisation> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Project\"")
|
@Table(name = "\"Project\"")
|
||||||
public class Project implements DataEntity<Project> {
|
public class Project implements DataEntity<Project,UUID> {
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
|
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
|
||||||
|
@ -248,7 +248,7 @@ public class Project implements DataEntity<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Registry\"")
|
@Table(name = "\"Registry\"")
|
||||||
public class Registry implements DataEntity<Registry> {
|
public class Registry implements DataEntity<Registry,UUID> {
|
||||||
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -149,7 +149,7 @@ public class Registry implements DataEntity<Registry> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Researcher\"")
|
@Table(name = "\"Researcher\"")
|
||||||
public class Researcher implements DataEntity<Researcher> {
|
public class Researcher implements DataEntity<Researcher,UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -150,7 +150,7 @@ public class Researcher implements DataEntity<Researcher> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"Service\"")
|
@Table(name = "\"Service\"")
|
||||||
public class Service implements DataEntity<Service> {
|
public class Service implements DataEntity<Service, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -150,7 +150,7 @@ public class Service implements DataEntity<Service> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"UserDMP\"")
|
@Table(name = "\"UserDMP\"")
|
||||||
public class UserDMP implements DataEntity<UserDMP> {
|
public class UserDMP implements DataEntity<UserDMP, UUID> {
|
||||||
|
|
||||||
public enum UserDMPRoles {
|
public enum UserDMPRoles {
|
||||||
OWNER(0), USER(1);
|
OWNER(0), USER(1);
|
||||||
|
@ -90,7 +90,7 @@ public class UserDMP implements DataEntity<UserDMP> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import java.util.UUID;
|
||||||
name = "userInfo",
|
name = "userInfo",
|
||||||
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")})
|
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")})
|
||||||
})
|
})
|
||||||
public class UserInfo implements DataEntity<UserInfo> {
|
public class UserInfo implements DataEntity<UserInfo, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -173,7 +173,7 @@ public class UserInfo implements DataEntity<UserInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"UserRole\"")
|
@Table(name = "\"UserRole\"")
|
||||||
public class UserRole implements DataEntity<UserRole> {
|
public class UserRole implements DataEntity<UserRole, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -53,7 +53,7 @@ public class UserRole implements DataEntity<UserRole> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.id == null ? null : this.id};
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"UserToken\"")
|
@Table(name = "\"UserToken\"")
|
||||||
public class UserToken implements DataEntity<UserToken> {
|
public class UserToken implements DataEntity<UserToken, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
|
@ -62,7 +62,7 @@ public class UserToken implements DataEntity<UserToken> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getKeys() {
|
public UUID getKeys() {
|
||||||
return new UUID[]{this.token == null ? null : this.token};
|
return this.token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ public class DashBoardManager {
|
||||||
|
|
||||||
public DashBoardStatistics getStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository) {
|
public DashBoardStatistics getStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository) {
|
||||||
DashBoardStatistics statistics = new DashBoardStatistics();
|
DashBoardStatistics statistics = new DashBoardStatistics();
|
||||||
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.count());
|
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.asQueryable().count());
|
||||||
statistics.setTotalDataSetCount(datasetRepository.count());
|
statistics.setTotalDataSetCount(datasetRepository.asQueryable().count());
|
||||||
statistics.setTotalProjectCount(projectRepository.count());
|
statistics.setTotalProjectCount(projectRepository.asQueryable().count());
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,14 @@ import java.util.Collection;
|
||||||
|
|
||||||
public class PaginationManager {
|
public class PaginationManager {
|
||||||
|
|
||||||
public static <T extends DataEntity<T>> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
public static <T extends DataEntity> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
||||||
if (tableRequest.getOrderings() != null) applyOrder(items, tableRequest);
|
if (tableRequest.getOrderings() != null) applyOrder(items, tableRequest);
|
||||||
if (tableRequest.getLength() != null) items.take(tableRequest.getLength());
|
if (tableRequest.getLength() != null) items.take(tableRequest.getLength());
|
||||||
if (tableRequest.getOffset() != null) items.skip(tableRequest.getOffset());
|
if (tableRequest.getOffset() != null) items.skip(tableRequest.getOffset());
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends DataEntity<T>> void applyOrder(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
public static <T extends DataEntity> void applyOrder(QueryableList<T> items, TableRequest tableRequest) throws Exception {
|
||||||
ColumnOrderings columnOrderings = tableRequest.getOrderings();
|
ColumnOrderings columnOrderings = tableRequest.getOrderings();
|
||||||
for (Ordering ordering : columnOrderings.getFieldOrderings()) {
|
for (Ordering ordering : columnOrderings.getFieldOrderings()) {
|
||||||
if (ordering.getOrderByType() == Ordering.OrderByType.ASC)
|
if (ordering.getOrderByType() == Ordering.OrderByType.ASC)
|
||||||
|
@ -29,7 +29,7 @@ public class PaginationManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends DataEntity<T>> void applyAscOrder(QueryableList<T> items, Ordering ordering) {
|
private static <T extends DataEntity> void applyAscOrder(QueryableList<T> items, Ordering ordering) {
|
||||||
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
||||||
items.orderBy((builder, root) -> builder.asc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
items.orderBy((builder, root) -> builder.asc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
||||||
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
||||||
|
@ -40,7 +40,7 @@ public class PaginationManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends DataEntity<T>> void applyDescOrder(QueryableList<T> items, Ordering ordering) {
|
private static <T extends DataEntity> void applyDescOrder(QueryableList<T> items, Ordering ordering) {
|
||||||
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
|
||||||
items.orderBy((builder, root) -> builder.desc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
items.orderBy((builder, root) -> builder.desc(builder.size(root.<Collection>get(ordering.getFieldName()))));
|
||||||
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public interface QueryableList<T extends DataEntity<T>> {
|
public interface QueryableList<T extends DataEntity> {
|
||||||
QueryableList<T> where(SinglePredicate<T> predicate);
|
QueryableList<T> where(SinglePredicate<T> predicate);
|
||||||
|
|
||||||
<R> List<R> select(SelectPredicate<T, R> predicate);
|
<R> List<R> select(SelectPredicate<T, R> predicate);
|
||||||
|
|
|
@ -21,12 +21,12 @@ import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class QueryableHibernateList<T extends DataEntity<T>> implements QueryableList<T> {
|
public class QueryableHibernateList<T extends DataEntity> implements QueryableList<T> {
|
||||||
|
|
||||||
private EntityManager manager;
|
private EntityManager manager;
|
||||||
private CriteriaQuery<T> query;
|
private CriteriaQuery query;
|
||||||
private Class<T> tClass;
|
private Class<T> tClass;
|
||||||
private Root<T> root;
|
private Root root;
|
||||||
private Root<T> nestedQueryRoot;
|
private Root<T> nestedQueryRoot;
|
||||||
private Subquery<T> subquery;
|
private Subquery<T> subquery;
|
||||||
private List<SinglePredicate<T>> singlePredicates = new LinkedList<>();
|
private List<SinglePredicate<T>> singlePredicates = new LinkedList<>();
|
||||||
|
@ -61,7 +61,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
|
|
||||||
public QueryableHibernateList<T> setEntity(Class<T> type) {
|
public QueryableHibernateList<T> setEntity(Class<T> type) {
|
||||||
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
|
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
|
||||||
this.query = builder.createQuery(type);
|
this.query = builder.createTupleQuery();
|
||||||
this.root = this.query.from(this.tClass);
|
this.root = this.query.from(this.tClass);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||||
if (this.length != null) typedQuery.setMaxResults(this.length);
|
if (this.length != null) typedQuery.setMaxResults(this.length);
|
||||||
if (this.hint != null && this.hints.contains(hint)) {
|
if (this.hint != null && this.hints.contains(hint)) {
|
||||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()[0]).collect(Collectors.toList());
|
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
||||||
if (ids != null && !ids.isEmpty()) typedQuery = queryWithHint(ids);
|
if (ids != null && !ids.isEmpty()) typedQuery = queryWithHint(ids);
|
||||||
}
|
}
|
||||||
return typedQuery.getResultList();
|
return typedQuery.getResultList();
|
||||||
|
@ -184,7 +184,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
if (this.length != null) typedQuery.setMaxResults(this.length);
|
if (this.length != null) typedQuery.setMaxResults(this.length);
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
if (this.hint != null && this.hints.contains(hint)) {
|
if (this.hint != null && this.hints.contains(hint)) {
|
||||||
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()[0]).collect(Collectors.toList());
|
List ids = typedQuery.getResultList().stream().map(item -> item.getKeys()).collect(Collectors.toList());
|
||||||
if (ids != null && !ids.isEmpty()) return queryWithHint(ids).getResultList();
|
if (ids != null && !ids.isEmpty()) return queryWithHint(ids).getResultList();
|
||||||
}
|
}
|
||||||
return typedQuery.getResultList();
|
return typedQuery.getResultList();
|
||||||
|
@ -236,7 +236,6 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
||||||
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
||||||
CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(tClass);
|
CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(tClass);
|
||||||
Root<T> criteriaRoot = criteriaQuery.from(this.tClass);
|
Root<T> criteriaRoot = criteriaQuery.from(this.tClass);
|
||||||
|
|
||||||
criteriaQuery.where(criteriaRoot.get("id").in(ids));
|
criteriaQuery.where(criteriaRoot.get("id").in(ids));
|
||||||
if (!this.orderings.isEmpty())
|
if (!this.orderings.isEmpty())
|
||||||
criteriaQuery.orderBy(this.generateOrderPredicates(this.orderings, criteriaRoot));
|
criteriaQuery.orderBy(this.generateOrderPredicates(this.orderings, criteriaRoot));
|
||||||
|
|
Loading…
Reference in New Issue