Skip to content

Commit

Permalink
geoserver#128: jdk11: first set of fixes in services - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
etj committed Dec 20, 2019
1 parent c095287 commit 7e5bd25
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface RestrictedGenericDAO<ENTITY> /* extends GenericDAO<ENTITY, Long
public ENTITY find(Long id);
public void persist(ENTITY... entities);
public ENTITY merge(ENTITY entity);
public void remove(ENTITY entity);
public boolean remove(ENTITY entity);
public boolean removeById(Long id);
public List<ENTITY> search(Search search);
public long count(Search search);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public AdminRule merge(AdminRule entity) {
}

@Override
public void remove(AdminRule entity) {
super.remove(entity);
public boolean remove(AdminRule entity) {
return super.remove(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public void merge(E... entities) {
}
}

public void remove(E entity) {
removeById(entity.getId());
public boolean remove(E entity) {
return removeById(entity.getId());
}

public boolean removeById(Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public GFUser merge(GFUser entity)
}

@Override
public void remove(GFUser entity)
public boolean remove(GFUser entity)
{
super.remove(entity);
return super.remove(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public GSInstance merge(GSInstance entity)
}

@Override
public void remove(GSInstance entity)
public boolean remove(GSInstance entity)
{
super.remove(entity);
return super.remove(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public GSUser merge(GSUser entity)
}

@Override
public void remove(GSUser entity)
public boolean remove(GSUser entity)
{
super.remove(entity);
return super.remove(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public LayerDetails merge(LayerDetails entity) {
}

@Override
public void remove(LayerDetails entity) {
super.remove(entity);
public boolean remove(LayerDetails entity) {
return super.remove(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public Rule merge(Rule entity) {
}

@Override
public void remove(Rule entity) {
super.remove(entity);
public boolean remove(Rule entity) {
return super.remove(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public RuleLimits merge(RuleLimits entity)
}

@Override
public void remove(RuleLimits entity)
public boolean remove(RuleLimits entity)
{
super.remove(entity);
return super.remove(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public UserGroup merge(UserGroup entity)
}

@Override
public void remove(UserGroup entity)
public boolean remove(UserGroup entity)
{
super.remove(entity);
return super.remove(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Search<O, R> {

Integer firstResult = null;
Integer maxResults = null;
Integer page = null;

protected Search(EntityManager em, Class<O> resultType, Class<R> rootClass) {
this.em = em;
Expand Down Expand Up @@ -72,8 +73,9 @@ public void setMaxResults(int i) {
maxResults = i;
}

// public void setPage(Integer page) {
// }
public void setPage(int page) {
this.page = page;
}

public void addSortAsc(String field) {
orderBy.add(cb.asc(root.get(field)));
Expand Down Expand Up @@ -188,14 +190,24 @@ public TypedQuery<O> getQuery() {

TypedQuery<O> query = em.createQuery(q);

applyPagination(query);

return query;
}

private void applyPagination(TypedQuery<O> query) throws IllegalStateException {
if(firstResult != null) {
query.setFirstResult(firstResult);
}
if(maxResults != null) {
query.setMaxResults(maxResults);
}

return query;
if(page != null) {
if(maxResults == null) {
throw new IllegalStateException("Page set without maxresults");
}
query.setFirstResult((page-1) * maxResults);
}
}

// public TypedQuery<Long> _getCountQuery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void deleteRulesByUser(String username) throws NotFoundServiceEx {
@Override
public void deleteRulesByRole(String rolename) throws NotFoundServiceEx {
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilter(Filter.equal("rolename", rolename));
searchCriteria.addFilterEqual("rolename", rolename);

List<AdminRule> list = ruleDAO.search(searchCriteria);
for (AdminRule rule : list) {
Expand All @@ -139,7 +139,7 @@ public void deleteRulesByRole(String rolename) throws NotFoundServiceEx {
@Override
public void deleteRulesByInstance(long instanceId) throws NotFoundServiceEx {
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilter(Filter.equal("instance.id", instanceId));
searchCriteria.addFilterEqual("instance.id", instanceId);

List<AdminRule> list = ruleDAO.search(searchCriteria);
for (AdminRule rule : list) {
Expand Down Expand Up @@ -181,7 +181,7 @@ public ShortAdminRule getRule(RuleFilter filter) throws BadRequestServiceEx {
@Override
public List<ShortAdminRule> getRulesByPriority(long priority, Integer page, Integer entries) {
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilter(Filter.greaterOrEqual("priority", priority));
searchCriteria.addFilterGreaterOrEqual("priority", priority);
searchCriteria.addSortAsc("priority");
addPagingConstraints(searchCriteria, page, entries);
List<AdminRule> found = ruleDAO.search(searchCriteria);
Expand All @@ -191,7 +191,7 @@ public List<ShortAdminRule> getRulesByPriority(long priority, Integer page, Inte
@Override
public ShortAdminRule getRuleByPriority(long priority) throws BadRequestServiceEx {
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilter(Filter.equal("priority", priority));
searchCriteria.addFilterEqual("priority", priority);
List<AdminRule> found = ruleDAO.search(searchCriteria);
if(found.isEmpty())
return null;
Expand All @@ -211,7 +211,8 @@ public List<AdminRule> getListFull(RuleFilter filter, Integer page, Integer entr
}

protected Search buildSearch(Integer page, Integer entries, RuleFilter filter) throws BadRequestServiceEx {
Search searchCriteria = buildRuleSearch(filter);
Search searchCriteria = ruleDAO.createSearch();
searchCriteria = buildRuleSearch(searchCriteria, filter);
addPagingConstraints(searchCriteria, page, entries);
searchCriteria.addSortAsc("priority");
return searchCriteria;
Expand All @@ -226,8 +227,8 @@ public long getCountAll() {
public long count(RuleFilter filter) {
// if(LOGGER.isDebugEnabled())
// LOGGER.debug("Counting rules: " + filter);

Search searchCriteria = buildRuleSearch(filter);
Search searchCriteria = ruleDAO.createCountSearch();
searchCriteria = buildRuleSearch(searchCriteria, filter);
// if(LOGGER.isDebugEnabled())
// LOGGER.debug("Counting rules: " + searchCriteria);
return ruleDAO.count(searchCriteria);
Expand All @@ -236,8 +237,8 @@ public long count(RuleFilter filter) {
// =========================================================================
// Search stuff

private Search buildRuleSearch(RuleFilter filter) {
Search searchCriteria = new Search(AdminRule.class);
private Search buildRuleSearch(Search searchCriteria, RuleFilter filter) {


if(filter != null) {
addStringCriteria(searchCriteria, "username", filter.getUser());
Expand All @@ -255,7 +256,7 @@ private Search buildRuleSearch(RuleFilter filter) {
//=========================================================================

private Search buildFixedRuleSearch(RuleFilter filter) {
Search searchCriteria = new Search(AdminRule.class);
Search searchCriteria = ruleDAO.createSearch();

if(filter != null) {
addFixedStringCriteria(searchCriteria, "username", filter.getUser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AuthUser authorize(String username, String password) {
}

private GSUser getUserByName(String userName) {
Search search = new Search(GSUser.class);
Search search = userDAO.createSearch();
search.addFilterEqual("name", userName);
List<GSUser> users = userDAO.search(search);
if(users.size() > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public GFUser get(long id) throws NotFoundServiceEx {

@Override
public GFUser get(String name) {
Search search = new Search(GFUser.class);
Search search = gfUserDAO.createSearch();
search.addFilterEqual("name", name);
List<GFUser> users = gfUserDAO.search(search);

Expand All @@ -86,7 +86,7 @@ public List<GFUser> getFullList(String nameLike, Integer page, Integer entries)
throw new BadRequestServiceEx("Page and entries params should be declared together.");
}

Search searchCriteria = new Search(GFUser.class);
Search searchCriteria = gfUserDAO.createSearch();

if(page != null) {
searchCriteria.setMaxResults(entries);
Expand All @@ -110,7 +110,7 @@ public List<ShortUser> getList(String nameLike, Integer page, Integer entries) {

@Override
public long getCount(String nameLike) {
Search searchCriteria = new Search(GFUser.class);
Search searchCriteria = gfUserDAO.createCountSearch();

if (nameLike != null) {
searchCriteria.addFilterILike("name", nameLike);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public GSInstance get(long id) throws NotFoundServiceEx {

@Override
public GSInstance get(String name) {
Search search = new Search(GSInstance.class);
Search search = instanceDAO.createSearch();
search.addFilterEqual("name", name);
List<GSInstance> groups = instanceDAO.search(search);

Expand Down Expand Up @@ -97,7 +97,7 @@ public List<GSInstance> getFullList(String nameLike, Integer page, Integer entri
throw new BadRequestServiceEx("Page and entries params should be declared together.");
}

Search searchCriteria = new Search(GSInstance.class);
Search searchCriteria = instanceDAO.createSearch();

if(page != null) {
searchCriteria.setMaxResults(entries);
Expand Down Expand Up @@ -128,7 +128,7 @@ private List<ShortInstance> convertToShortList(List<GSInstance> list) {

@Override
public long getCount(String nameLike) {
Search searchCriteria = new Search(GSInstance.class);
Search searchCriteria = instanceDAO.createCountSearch();

if (nameLike != null) {
searchCriteria.addFilterILike("name", nameLike);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public boolean delete(long id) throws NotFoundServiceEx {

@Override
public void deleteRulesByUser(String username) throws NotFoundServiceEx {
Search searchCriteria = new Search(Rule.class);
searchCriteria.addFilter(Filter.equal("username", username));
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilterEqual("username", username);

List<Rule> list = ruleDAO.search(searchCriteria);
if(LOGGER.isInfoEnabled())
Expand All @@ -159,8 +159,8 @@ public void deleteRulesByUser(String username) throws NotFoundServiceEx {

@Override
public void deleteRulesByRole(String rolename) throws NotFoundServiceEx {
Search searchCriteria = new Search(Rule.class);
searchCriteria.addFilter(Filter.equal("rolename", rolename));
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilterEqual("rolename", rolename);

List<Rule> list = ruleDAO.search(searchCriteria);
for (Rule rule : list) {
Expand All @@ -172,8 +172,8 @@ public void deleteRulesByRole(String rolename) throws NotFoundServiceEx {

@Override
public void deleteRulesByInstance(long instanceId) throws NotFoundServiceEx {
Search searchCriteria = new Search(Rule.class);
searchCriteria.addFilter(Filter.equal("instance.id", instanceId));
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilterEqual("instance.id", instanceId);

List<Rule> list = ruleDAO.search(searchCriteria);
for (Rule rule : list) {
Expand Down Expand Up @@ -256,8 +256,8 @@ public ShortRule getRule(RuleFilter filter) throws BadRequestServiceEx {

@Override
public List<ShortRule> getRulesByPriority(long priority, Integer page, Integer entries) {
Search searchCriteria = new Search(Rule.class);
searchCriteria.addFilter(Filter.greaterOrEqual("priority", priority));
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilterGreaterOrEqual("priority", priority);
searchCriteria.addSortAsc("priority");
addPagingConstraints(searchCriteria, page, entries);
List<Rule> found = ruleDAO.search(searchCriteria);
Expand All @@ -266,8 +266,8 @@ public List<ShortRule> getRulesByPriority(long priority, Integer page, Integer e

@Override
public ShortRule getRuleByPriority(long priority) throws BadRequestServiceEx {
Search searchCriteria = new Search(Rule.class);
searchCriteria.addFilter(Filter.equal("priority", priority));
Search searchCriteria = ruleDAO.createSearch();
searchCriteria.addFilterEqual("priority", priority);
List<Rule> found = ruleDAO.search(searchCriteria);
if(found.isEmpty())
return null;
Expand Down Expand Up @@ -314,7 +314,7 @@ public long count(RuleFilter filter) {
// Search stuff

private Search buildRuleSearch(RuleFilter filter) {
Search searchCriteria = new Search(Rule.class);
Search searchCriteria = ruleDAO.createSearch();

if(filter != null) {
addStringCriteria(searchCriteria, "username", filter.getUser());
Expand All @@ -333,7 +333,7 @@ private Search buildRuleSearch(RuleFilter filter) {
//=========================================================================

private Search buildFixedRuleSearch(RuleFilter filter) {
Search searchCriteria = new Search(Rule.class);
Search searchCriteria = ruleDAO.createSearch();

if(filter != null) {
addFixedStringCriteria(searchCriteria, "username", filter.getUser());
Expand Down
Loading

0 comments on commit 7e5bd25

Please sign in to comment.