Skip to content

Commit

Permalink
parameterized EntityRepresentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jyrimatti committed Mar 5, 2015
1 parent 290052e commit 7c72959
Show file tree
Hide file tree
Showing 27 changed files with 224 additions and 173 deletions.
46 changes: 23 additions & 23 deletions src/main/java/fi/solita/utils/query/Dao.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,75 +44,75 @@ public Dao(JpaBasicQueries jpaBasicQueries, JpaCriteriaQueries jpaCriteriaQuerie
this.qlQueries = qlQueries;
}

public <E extends IEntity & Identifiable<? extends Id<? super E>>> Id<E> persist(E entity) {
public <E extends IEntity<?> & Identifiable<? extends Id<? super E>>> Id<E> persist(E entity) {
return jpaBasicQueries.persist(entity);
}

public boolean isManaged(IEntity entity) {
public boolean isManaged(IEntity<?> entity) {
return jpaBasicQueries.isManaged(entity);
}

/**
* Removes the entity corresponding to <i>id</i> from the database. Fails if not found.
*/
public <E extends IEntity & Removable> void remove(Id<E> id) {
public <E extends IEntity<?> & Removable> void remove(Id<E> id) {
jpaBasicQueries.remove(id);
}

public <E extends IEntity & Identifiable<? extends Id<E>> & Removable> void removeAll(CriteriaQuery<E> query) {
public <E extends IEntity<?> & Identifiable<? extends Id<E>> & Removable> void removeAll(CriteriaQuery<E> query) {
jpaBasicQueries.removeAll(query);
}

/**
* Get the entity corresponding to <i>id</i>. Fails if not found.
*/
public <E extends IEntity> E get(Id<E> id) {
public <E extends IEntity<?>> E get(Id<E> id) {
return jpaBasicQueries.get(id);
}

/**
* Convert <i>id</i> to a proxy instance without hitting the database
*/
public <E extends IEntity> E toProxy(Id<E> id) {
public <E extends IEntity<?>> E toProxy(Id<E> id) {
return jpaBasicQueries.toProxy(id);
}

/**
* Convert <i>ids</i> to a proxy instances without hitting the database
*/
public <E extends IEntity> Iterable<E> toProxies(Iterable<? extends Id<E>> ids) {
public <E extends IEntity<?>> Iterable<E> toProxies(Iterable<? extends Id<E>> ids) {
return jpaBasicQueries.toProxies(ids);
}

public <E extends IEntity> Option<E> find(Id<E> id) {
public <E extends IEntity<?>> Option<E> find(Id<E> id) {
return jpaBasicQueries.find(id);
}

/**
* Get a proxy of <i>relation</i> from <i>entity</i> without hitting the database
*/
public <E extends IEntity & Identifiable<? extends Id<? super E>>, T> T toProxy(E entity, SingularAttribute<? super E, T> relation) {
public <E extends IEntity<?> & Identifiable<? extends Id<? super E>>, T> T toProxy(E entity, SingularAttribute<? super E, T> relation) {
return jpaBasicQueries.toProxy(entity, relation);
}

/**
* Get proxies of <i>relation</i> from <i>entity</i>. THIS HITS THE DATABASE.
*/
public <E extends IEntity & Identifiable<? extends Id<? super E>>, T extends IEntity> Collection<T> getProxies(E entity, CollectionAttribute<? super E, T> relation) {
public <E extends IEntity<?> & Identifiable<? extends Id<? super E>>, T extends IEntity<?>> Collection<T> getProxies(E entity, CollectionAttribute<? super E, T> relation) {
return jpaBasicQueries.getProxies(entity, relation);
}

/**
* Get proxies of <i>relation</i> from <i>entity</i>. THIS HITS THE DATABASE.
*/
public <E extends IEntity & Identifiable<? extends Id<? super E>>, T extends IEntity> Set<T> getProxies(E entity, SetAttribute<? super E, T> relation) {
public <E extends IEntity<?> & Identifiable<? extends Id<? super E>>, T extends IEntity<?>> Set<T> getProxies(E entity, SetAttribute<? super E, T> relation) {
return jpaBasicQueries.getProxies(entity, relation);
}

/**
* Get proxies of <i>relation</i> from <i>entity</i>. THIS HITS THE DATABASE.
*/
public <E extends IEntity & Identifiable<? extends Id<? super E>>, T extends IEntity> List<T> getProxies(E entity, ListAttribute<? super E, T> relation) {
public <E extends IEntity<?> & Identifiable<? extends Id<? super E>>, T extends IEntity<?>> List<T> getProxies(E entity, ListAttribute<? super E, T> relation) {
return jpaBasicQueries.getProxies(entity, relation);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ public <T> Option<T> findFirst(CriteriaQuery<T> query) throws NoOrderingSpecifie
/**
* Get the first row of <i>query</i>, if any
*/
public <E extends IEntity> Option<E> findFirst(CriteriaQuery<E> query, Iterable<? extends Order<? super E,?>> ordering) {
public <E> Option<E> findFirst(CriteriaQuery<E> query, Iterable<? extends Order<? super E,?>> ordering) {
return jpaCriteriaQueries.findFirst(query, ordering);
}

Expand All @@ -165,14 +165,14 @@ public <T> List<T> getMany(CriteriaQuery<T> query, Page page) throws NoOrderingS
return jpaCriteriaQueries.getMany(query, page);
}

public <E extends IEntity> List<E> getMany(CriteriaQuery<E> query, Iterable<? extends Order<? super E, ?>> ordering) {
public <E> List<E> getMany(CriteriaQuery<E> query, Iterable<? extends Order<? super E, ?>> ordering) {
return jpaCriteriaQueries.getMany(query, ordering);
}

/**
* Get rows of <i>query</i> considering <i>page</i>
*/
public <E extends IEntity> List<E> getMany(CriteriaQuery<E> query, Page page, Iterable<? extends Order<? super E, ?>> ordering) {
public <E> List<E> getMany(CriteriaQuery<E> query, Page page, Iterable<? extends Order<? super E, ?>> ordering) {
return jpaCriteriaQueries.getMany(query, page, ordering);
}

Expand All @@ -181,56 +181,56 @@ public <E extends IEntity> List<E> getMany(CriteriaQuery<E> query, Page page, It
/**
* Get the single row of <i>query</i>, projecting the result. Fails if multiple or no rows found.
*/
public <E extends IEntity, R> R get(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection) throws NoResultException, NonUniqueResultException {
public <E, R> R get(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection) throws NoResultException, NonUniqueResultException {
return jpaProjectionQueries.get(query, projection);
}

/**
* Get the only row of <i>query</i>, if any, projecting the result. Fails if multiple or no rows found.
*/
public <E extends IEntity, R> Option<R> find(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection) throws NonUniqueResultException {
public <E, R> Option<R> find(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection) throws NonUniqueResultException {
return jpaProjectionQueries.find(query, projection);
}

/**
* Get the first row of <i>query</i>, if any, projecting the result. Requires <i>query</i> to have ordering.
*/
public <E extends IEntity,R> Option<R> findFirst(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection) {
public <E,R> Option<R> findFirst(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection) {
return jpaProjectionQueries.findFirst(query, projection);
}

/**
* Get the first row of <i>query</i>, if any, projecting the result
*/
public <E extends IEntity,R> Option<R> findFirst(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection, Iterable<? extends Order<? super E,?>> ordering) {
public <E,R> Option<R> findFirst(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection, Iterable<? extends Order<? super E,?>> ordering) {
return jpaProjectionQueries.findFirst(query, projection, ordering);
}

/**
* Get all rows of <i>query</i>, projecting the results
*/
public <E extends IEntity,R> Collection<R> getMany(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection) {
public <E,R> Collection<R> getMany(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection) {
return jpaProjectionQueries.getMany(query, projection);
}

/**
* Get rows of <i>query</i> considering <i>page</i>, projecting the results. Requires <i>query</i> to have ordering.
*/
public <E extends IEntity,R> List<R> getMany(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection, Page page) throws NoOrderingSpecifiedException {
public <E,R> List<R> getMany(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection, Page page) throws NoOrderingSpecifiedException {
return jpaProjectionQueries.getMany(query, projection, page);
}

/**
* Get all rows of <i>query</i>, projecting the results
*/
public <E extends IEntity,R> List<R> getMany(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection, Iterable<? extends Order<? super E,?>> ordering) {
public <E,R> List<R> getMany(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection, Iterable<? extends Order<? super E,?>> ordering) {
return jpaProjectionQueries.getMany(query, projection, ordering);
}

/**
* Get rows of <i>query</i> considering <i>page</i>, projecting the results
*/
public <E extends IEntity,R> List<R> getMany(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection, Page page, Iterable<? extends Order<? super E,?>> ordering) {
public <E,R> List<R> getMany(CriteriaQuery<E> query, MetaJpaConstructor<? super E,R, ?> projection, Page page, Iterable<? extends Order<? super E,?>> ordering) {
return jpaProjectionQueries.getMany(query, projection, page, ordering);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/solita/utils/query/IEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package fi.solita.utils.query;


public interface IEntity extends EntityRepresentation {
public interface IEntity<T> extends EntityRepresentation<T> {
}
2 changes: 1 addition & 1 deletion src/main/java/fi/solita/utils/query/Id.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import java.io.Serializable;

public interface Id<T> extends EntityRepresentation, Serializable {
public interface Id<T> extends EntityRepresentation<T>, Serializable {
Class<T> getOwningClass();
}
6 changes: 3 additions & 3 deletions src/main/java/fi/solita/utils/query/QueryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import static fi.solita.utils.functional.Collections.newList;
import static fi.solita.utils.functional.Collections.newListOfSize;
import static fi.solita.utils.functional.Functional.cons;
import static fi.solita.utils.functional.Functional.head;
import static fi.solita.utils.functional.Functional.isEmpty;
import static fi.solita.utils.functional.Functional.flatMap;
import static fi.solita.utils.functional.Functional.forall;
import static fi.solita.utils.functional.Functional.grouped;
import static fi.solita.utils.functional.Functional.head;
import static fi.solita.utils.functional.Functional.isEmpty;
import static fi.solita.utils.functional.Functional.map;
import static fi.solita.utils.query.attributes.AttributeProxy.unwrap;

Expand Down Expand Up @@ -155,7 +155,7 @@ public static <T> void checkOrdering(CriteriaQuery<T> query, Page page) throws N
}
}

public static final <E extends IEntity> CriteriaQuery<E> applyOrder(CriteriaQuery<E> query, final Path<E> selection, Iterable<? extends fi.solita.utils.query.Order<? super E, ?>> orderings, final CriteriaBuilder cb) {
public static final <E> CriteriaQuery<E> applyOrder(CriteriaQuery<E> query, final Path<E> selection, Iterable<? extends fi.solita.utils.query.Order<? super E, ?>> orderings, final CriteriaBuilder cb) {
if (!isEmpty(orderings)) {
query.orderBy(newList(map(QueryUtils_.<E>order2jpaOrder().ap(cb, selection), orderings)));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
import fi.solita.utils.query.meta.MetaJpaConstructor;

class RelationCollectionAttribute<E, R, A extends Attribute<E, Collection<R>> & Bindable<R>> extends PluralAttributeProxy<E, Collection<R>, R, A> implements CollectionAttribute<E,R>, AdditionalQueryPerformingAttribute {
private final MetaJpaConstructor<? extends IEntity, R, ?> constructor;
private final MetaJpaConstructor<? extends IEntity<?>, R, ?> constructor;

@SuppressWarnings("unchecked")
public <E2 extends IEntity> RelationCollectionAttribute(CollectionAttribute<? super E, ? super E2> attribute, MetaJpaConstructor<? super E2, R, ?> constructor) {
public <E2 extends IEntity<?>> RelationCollectionAttribute(CollectionAttribute<? super E, ? super E2> attribute, MetaJpaConstructor<? super E2, R, ?> constructor) {
super((A)(Object)attribute, CollectionType.COLLECTION, (Type<R>)attribute.getElementType());
this.constructor = (MetaJpaConstructor<? extends IEntity, R, ?>) constructor;
this.constructor = (MetaJpaConstructor<? extends IEntity<?>, R, ?>) constructor;
}

@Override
public MetaJpaConstructor<? extends IEntity, R, ?> getConstructor() {
public MetaJpaConstructor<? extends IEntity<?>, R, ?> getConstructor() {
return constructor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
import fi.solita.utils.query.meta.MetaJpaConstructor;

class RelationListAttribute<E, R, A extends Attribute<E, List<R>> & Bindable<R>> extends PluralAttributeProxy<E, List<R>, R, A> implements ListAttribute<E,R>, AdditionalQueryPerformingAttribute {
private final MetaJpaConstructor<? extends IEntity, R, ?> constructor;
private final MetaJpaConstructor<? extends IEntity<?>, R, ?> constructor;

@SuppressWarnings("unchecked")
public <E2 extends IEntity> RelationListAttribute(ListAttribute<? super E, ? super E2> attribute, MetaJpaConstructor<? super E2, R, ?> constructor) {
public <E2 extends IEntity<?>> RelationListAttribute(ListAttribute<? super E, ? super E2> attribute, MetaJpaConstructor<? super E2, R, ?> constructor) {
super((A)(Object)attribute, CollectionType.LIST, (Type<R>)attribute.getElementType());
this.constructor = (MetaJpaConstructor<? extends IEntity, R, ?>) constructor;
this.constructor = (MetaJpaConstructor<? extends IEntity<?>, R, ?>) constructor;
}

@Override
public MetaJpaConstructor<? extends IEntity, R, ?> getConstructor() {
public MetaJpaConstructor<? extends IEntity<?>, R, ?> getConstructor() {
return constructor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
import fi.solita.utils.query.meta.MetaJpaConstructor;

class RelationSetAttribute<E, R, A extends Attribute<E, Set<R>> & Bindable<R>> extends PluralAttributeProxy<E, Set<R>, R, A> implements SetAttribute<E,R>, AdditionalQueryPerformingAttribute {
private final MetaJpaConstructor<? extends IEntity, R, ?> constructor;
private final MetaJpaConstructor<? extends IEntity<?>, R, ?> constructor;

@SuppressWarnings("unchecked")
public <E2 extends IEntity> RelationSetAttribute(SetAttribute<? super E, ? super E2> attribute, MetaJpaConstructor<? super E2, R, ?> constructor) {
public <E2 extends IEntity<?>> RelationSetAttribute(SetAttribute<? super E, ? super E2> attribute, MetaJpaConstructor<? super E2, R, ?> constructor) {
super((A)(Object)attribute, CollectionType.SET, (Type<R>)attribute.getElementType());
this.constructor = (MetaJpaConstructor<? extends IEntity, R, ?>) constructor;
this.constructor = (MetaJpaConstructor<? extends IEntity<?>, R, ?>) constructor;
}

@Override
public MetaJpaConstructor<? extends IEntity, R, ?> getConstructor() {
public MetaJpaConstructor<? extends IEntity<?>, R, ?> getConstructor() {
return constructor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import fi.solita.utils.query.meta.MetaJpaConstructor;

class RelationSingularAttribute<E, R> extends SingularAttributeProxy<E, R> implements AdditionalQueryPerformingAttribute {
private final MetaJpaConstructor<? extends IEntity, R, ?> constructor;
private final MetaJpaConstructor<? extends IEntity<?>, R, ?> constructor;

@SuppressWarnings("unchecked")
public <E2 extends IEntity> RelationSingularAttribute(SingularAttribute<? super E, ? super E2> attribute, MetaJpaConstructor<? super E2, R, ?> constructor) {
public <E2 extends IEntity<?>> RelationSingularAttribute(SingularAttribute<? super E, ? super E2> attribute, MetaJpaConstructor<? super E2, R, ?> constructor) {
super((SingularAttribute<E, R>) attribute);
this.constructor = (MetaJpaConstructor<? extends IEntity, R, ?>) constructor;
this.constructor = (MetaJpaConstructor<? extends IEntity<?>, R, ?>) constructor;
}

@Override
public MetaJpaConstructor<? extends IEntity, R, ?> getConstructor() {
public MetaJpaConstructor<? extends IEntity<?>, R, ?> getConstructor() {
return constructor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public interface TypeProvider {
<ID extends Serializable, T extends Identifiable<ID>> Type<ID> idType(Class<T> entityType);
<T> Type<T> type(Class<T> clazz);

Class<?> getEntityClass(IEntity entity);
Class<?> getEntityClass(IEntity<?> entity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public <T> Type<T> type(final Class<T> clazz) {
}

@Override
public Class<?> getEntityClass(IEntity entity) {
public Class<?> getEntityClass(IEntity<?> entity) {
return HibernateProxyHelper.getClassWithoutInitializingProxy(entity);
}
}
Loading

0 comments on commit 7c72959

Please sign in to comment.