Skip to content

Commit

Permalink
#15 JPA adapter extensibility (#145)
Browse files Browse the repository at this point in the history
- DTO mapping support with JpaModule.addMappedEntityClass
- JpaMapper class to map entities to DTO and back
- JpaMapper makes use of Tuple API to support computed attributes
- virtual attributes renamed to computed attributes
- JpaRepositoryFilter to intercept most stages within the jpa repository to allow further customization
- JpaModule.addFilter(...) to register filters 
- test case showning use of computed attributes and dto mappers
- subquery comparable fix/workaround for computed attrs
- JpaModule constructors replaced by static create methods

pending:

- optimize reuse of computed attributes between select, filter and sort
  • Loading branch information
Remo authored Oct 6, 2016
1 parent 817a67a commit 27a7b0b
Show file tree
Hide file tree
Showing 66 changed files with 7,023 additions and 5,630 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,98 +1,98 @@
package io.katharsis.resource.mock.models;

import io.katharsis.resource.annotations.*;

import java.util.ArrayList;
import java.util.List;

@JsonApiResource(type = "projects")
public class Project {

@JsonApiId
private Long id;

private String name;

private String description;

private ProjectData data;

@JsonApiToMany
private List<Task> tasks = new ArrayList<>();

@JsonApiToOne
private Task task;

@JsonApiToOne
@JsonApiIncludeByDefault
private ProjectEager projectEager;

@JsonApiToMany
@JsonApiIncludeByDefault
private List<ProjectEager> projectEagerList = new ArrayList<>();

public Long getId() {
return id;
}

public Project setId(Long id) {
this.id = id;
return this;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(@SuppressWarnings("SameParameterValue") String description) {
this.description = description;
}

public ProjectData getData() {
return data;
}

public void setData(ProjectData data) {
this.data = data;
}

public List<Task> getTasks() {
return tasks;
}

public void setTasks(List<Task> tasks) {
this.tasks = tasks;
}

public Task getTask() {
return task;
}

public void setTask(Task task) {
this.task = task;
}

public ProjectEager getProjectEager() {
return projectEager;
}

public void setProjectEager(ProjectEager projectEager) {
this.projectEager = projectEager;
}

public List<ProjectEager> getProjectEagerList() {
return projectEagerList;
}

public void setProjectEagerList(List<ProjectEager> projectEagerList) {
this.projectEagerList = projectEagerList;
}
}
package io.katharsis.resource.mock.models;

import io.katharsis.resource.annotations.*;

import java.util.ArrayList;
import java.util.List;

@JsonApiResource(type = "projects")
public class Project {

@JsonApiId
private Long id;

private String name;

private String description;

private ProjectData data;

@JsonApiToMany
private List<Task> tasks = new ArrayList<>();

@JsonApiToOne
private Task task;

@JsonApiToOne
@JsonApiIncludeByDefault
private ProjectEager projectEager;

@JsonApiToMany
@JsonApiIncludeByDefault
private List<ProjectEager> projectEagerList = new ArrayList<>();

public Long getId() {
return id;
}

public Project setId(Long id) {
this.id = id;
return this;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(@SuppressWarnings("SameParameterValue") String description) {
this.description = description;
}

public ProjectData getData() {
return data;
}

public void setData(ProjectData data) {
this.data = data;
}

public List<Task> getTasks() {
return tasks;
}

public void setTasks(List<Task> tasks) {
this.tasks = tasks;
}

public Task getTask() {
return task;
}

public void setTask(Task task) {
this.task = task;
}

public ProjectEager getProjectEager() {
return projectEager;
}

public void setProjectEager(ProjectEager projectEager) {
this.projectEager = projectEager;
}

public List<ProjectEager> getProjectEagerList() {
return projectEagerList;
}

public void setProjectEagerList(List<ProjectEager> projectEagerList) {
this.projectEagerList = projectEagerList;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package io.katharsis.jpa;

import java.io.Serializable;

public class DefaultJpaRepositoryFactory implements JpaRepositoryFactory {

@Override
public <T, I extends Serializable> JpaEntityRepository<T, I> createEntityRepository(JpaModule module,
Class<T> entityClass) {
return new JpaEntityRepository<>(module, entityClass);
}

@Override
public <T, I extends Serializable, D, J extends Serializable> JpaRelationshipRepository<T, I, D, J> createRelationshipRepository(
JpaModule module, Class<T> entityClass, Class<D> relatedEntityClass) {
return new JpaRelationshipRepository<>(module, entityClass, relatedEntityClass);
}

}
package io.katharsis.jpa;

import java.io.Serializable;

import io.katharsis.jpa.mapping.JpaMapper;

public class DefaultJpaRepositoryFactory implements JpaRepositoryFactory {

@Override
public <T, I extends Serializable> JpaEntityRepository<T, I> createEntityRepository(JpaModule module, Class<T> entityClass) {
return new JpaEntityRepository<>(module, entityClass);
}

@Override
public <T, I extends Serializable, D, J extends Serializable> JpaRelationshipRepository<T, I, D, J> createRelationshipRepository(
JpaModule module, Class<T> entityClass, Class<D> relatedEntityClass) {
return new JpaRelationshipRepository<>(module, entityClass, relatedEntityClass);
}

@Override
public <E, D, I extends Serializable> JpaEntityRepository<D, I> createMappedEntityRepository(JpaModule module,
Class<E> entityClass, Class<D> dtoClass, JpaMapper<E, D> mapper) {
return new JpaEntityRepository<>(module, entityClass, dtoClass, mapper);
}

@Override
public <S, I extends Serializable, T, J extends Serializable, E, F> JpaRelationshipRepository<S, I, T, J> createMappedRelationshipRepository(
JpaModule module, Class<E> sourceEntityClass, Class<S> sourceResourceClass, Class<F> targetEntityClass,
Class<T> targetResourceClass, JpaMapper<E, S> sourceMapper, JpaMapper<F, T> targetMapper) {
return new JpaRelationshipRepository<>(module, sourceEntityClass, sourceResourceClass, targetEntityClass,
targetResourceClass, sourceMapper, targetMapper);
}

}
Loading

0 comments on commit 27a7b0b

Please sign in to comment.