Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #627 from hohwille/feature-spring-data
Browse files Browse the repository at this point in the history
add advanced spring-data support and make it first class citizen but keep dao support for compatibility and non-spring/JEE contexts.
  • Loading branch information
hohwille authored Jul 31, 2018
2 parents c6855c9 + 3dfdb64 commit fe3a073
Show file tree
Hide file tree
Showing 87 changed files with 3,068 additions and 739 deletions.
6 changes: 3 additions & 3 deletions boms/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.2.4</version>
<version>3.2.5</version>
</dependency>
<!-- Support for dynamic and type-safe JPA queries -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>3.4.3</version>
<version>4.1.4</version>
</dependency>
<!-- DataBase Connection Pooling -->
<dependency>
Expand Down
20 changes: 20 additions & 0 deletions boms/minimal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@
<artifactId>oasp4j-jpa</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-jpa-basic</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-jpa-spring-data</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-jpa-dao</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.modules</groupId>
<artifactId>oasp4j-jpa-envers</artifactId>
Expand Down Expand Up @@ -151,6 +166,11 @@
<artifactId>oasp4j-starter-cxf-server-ws</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.oasp.java.starters</groupId>
<artifactId>oasp4j-starter-spring-data-jpa</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package io.oasp.module.basic.common.api.query;

/**
* Enum defining available syntaxes for a match pattern in a LIKE-clause. While databases typically require {@link #SQL}
* syntax, human user expect {@link #GLOB} syntax in search forms. Therefore this enum also supports
* {@link #convert(String, LikePatternSyntax, boolean) conversion} from one syntax to another.
*
* @since 3.0.0
*/
public enum LikePatternSyntax {

/**
* Glob syntax that is typically expected by end-users and supported by typical search forms. It uses asterisk ('*')
* for {@link #getAny() any wildcard} and question-mark ('?') for {@link #getSingle() single wildcard}.
*/
GLOB('*', '?'),

/**
* SQL syntax that is typically required by databases. It uses percent ('%') for {@link #getAny() any wildcard} and
* underscore ('_') for {@link #getSingle() single wildcard}.
*/
SQL('%', '_');

/** The escape character. */
public static final char ESCAPE = '\\';

private final char any;

private final char single;

private LikePatternSyntax(char any, char single) {

this.any = any;
this.single = single;
}

/**
* @return the wildcard character that matches any string including the {@link String#isEmpty() empty} string.
*/
public char getAny() {

return this.any;
}

/**
* @return the wildcard character that matches exactly one single character.
*/
public char getSingle() {

return this.single;
}

/**
* @param pattern the LIKE pattern in the given {@link LikePatternSyntax}.
* @param syntax the {@link LikePatternSyntax} of the given {@code pattern}.
* @return the given {@code pattern} converted to this {@link LikePatternSyntax}.
*/
public String convert(String pattern, LikePatternSyntax syntax) {

return convert(pattern, syntax, false);
}

/**
* @param pattern the LIKE pattern in the given {@link LikePatternSyntax}.
* @param syntax the {@link LikePatternSyntax} of the given {@code pattern}.
* @param matchSubstring - {@code true} if the given {@code pattern} shall also match substrings, {@code false}
* otherwise.
* @return the given {@code pattern} converted to this {@link LikePatternSyntax}.
*/
public String convert(String pattern, LikePatternSyntax syntax, boolean matchSubstring) {

if ((pattern == null) || pattern.isEmpty()) {
if (matchSubstring) {
return Character.toString(this.any);
} else {
return pattern;
}
}
if (this == syntax) {
String result = pattern;
if (matchSubstring) {
if (pattern.charAt(0) != this.any) {
result = this.any + result;
}
int lastIndex = pattern.length() - 1;
if ((pattern.charAt(lastIndex) != this.any) || ((lastIndex > 0) && (pattern.charAt(lastIndex - 1) == ESCAPE))) {
result = result + this.any;
}
}
return result;
}
int length = pattern.length();
StringBuilder sb = new StringBuilder(length + 8);
boolean lastWildcardAny = false;
for (int i = 0; i < length; i++) {
lastWildcardAny = false;
char c = pattern.charAt(i);
if (c == syntax.any) {
c = this.any;
lastWildcardAny = true;
} else if (c == syntax.single) {
c = this.single;
} else if ((c == this.any) || (c == this.single) || (c == ESCAPE)) {
if ((i == 0) && matchSubstring) {
sb.append(this.any);
}
sb.append(ESCAPE);
}
if (matchSubstring && (i == 0) && !lastWildcardAny) {
sb.append(this.any);
}
sb.append(c);
}
if (matchSubstring && !lastWildcardAny) {
sb.append(this.any);
}
return sb.toString();
}

/**
* @param pattern the string value that may be a pattern.
* @return the {@link LikePatternSyntax} for the given {@code pattern} or {@code null} if the given {@code pattern}
* does not contain any wildcards.
*/
public static LikePatternSyntax autoDetect(String pattern) {

if ((pattern == null) || pattern.isEmpty()) {
return null;
}
for (LikePatternSyntax syntax : values()) {
if (pattern.indexOf(syntax.any) > 0) {
return syntax;
} else if (pattern.indexOf(syntax.single) > 0) {
return syntax;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package io.oasp.module.basic.common.api.query;

import io.oasp.module.basic.common.api.to.AbstractTo;

/**
* {@link AbstractTo TO} for the options to search for a string value.
*
* @since 3.0.0
*/
public class StringSearchConfigTo extends AbstractTo {

private static final long serialVersionUID = 1L;

private boolean ignoreCase;

private boolean matchSubstring;

private LikePatternSyntax likeSyntax;

private StringSearchOperator operator;

/**
* @return {@code true} to ignore the case, {@code false} otherwise (to search case-sensitive).
*/
public boolean isIgnoreCase() {

return this.ignoreCase;
}

/**
* @param ignoreCase new value of {@link #isIgnoreCase()}.
*/
public void setIgnoreCase(boolean ignoreCase) {

this.ignoreCase = ignoreCase;
}

/**
* @return matchSubstring {@code true} if search string shall also match substrings of the string values to search on.
*/
public boolean isMatchSubstring() {

return this.matchSubstring;
}

/**
* @param matchSubstring new value of {@link #isMatchSubstring()}.
*/
public void setMatchSubstring(boolean matchSubstring) {

this.matchSubstring = matchSubstring;
}

/**
* @return the {@link LikePatternSyntax} of the search string used to do a LIKE-search, {@code null} for no
* LIKE-search. Shall be {@code null} if {@link #getOperator() operator} is neither {@code null} nor
* {@link StringSearchOperator#LIKE}.
*/
public LikePatternSyntax getLikeSyntax() {

return this.likeSyntax;
}

/**
* @param likeSyntax new value of {@link #getLikeSyntax()}.
*/
public void setLikeSyntax(LikePatternSyntax likeSyntax) {

this.likeSyntax = likeSyntax;
}

/**
* @return operator the {@link StringSearchOperator} used to search. If {@code null} a "magic auto mode" is used where
* {@link StringSearchOperator#LIKE} is used in case the search string contains wildcards and
* {@link StringSearchOperator#EQ} is used otherwise.
*/
public StringSearchOperator getOperator() {

return this.operator;
}

/**
* @param operator new value of {@link #getOperator()}.
*/
public void setOperator(StringSearchOperator operator) {

this.operator = operator;
}

/**
* @param operator the {@link StringSearchOperator}.
* @return a new {@link StringSearchConfigTo} with the given config.
*/
public static StringSearchConfigTo of(StringSearchOperator operator) {

StringSearchConfigTo result = new StringSearchConfigTo();
result.setOperator(operator);
return result;
}

/**
* @param syntax the {@link LikePatternSyntax}.
* @return a new {@link StringSearchConfigTo} with the given config.
*/
public static StringSearchConfigTo of(LikePatternSyntax syntax) {

StringSearchConfigTo result = new StringSearchConfigTo();
result.setOperator(StringSearchOperator.LIKE);
result.setLikeSyntax(syntax);
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.oasp.module.basic.common.api.query;

/**
* Enum defining available operators for a string search or string comparison.
*
* @since 3.0.0
*/
public enum StringSearchOperator {

/** Matches if strings are {@link String#equals(Object) equal}. */
EQ("=="),

/** Matches if strings are NOT {@link String#equals(Object) equal}. */
NE("!="),

/** Matches if search value is less than search hit(s) in {@link String#compareTo(String) lexicographical order}. */
LT("<"),

/**
* Matches if search value is less or equal to search hit(s) in {@link String#compareTo(String) lexicographical
* order}.
*/
LE("<="),

/**
* Matches if search value is greater than search hit(s) in {@link String#compareTo(String) lexicographical order}.
*/
GT(">"),

/**
* Matches if search value is greater or equal to search hit(s) in {@link String#compareTo(String) lexicographical
* order}.
*/
GE(">="),

/**
* Matches if search value as pattern matches search hit(s) in <em>LIKE</em> search.
*
* @see LikePatternSyntax
*/
LIKE("LIKE"),

/**
* Matches if search value as pattern does not match search hit(s) in <em>LIKE</em> search.
*
* @see LikePatternSyntax
*/
NOT_LIKE("NOT LIKE");

private final String operator;

private StringSearchOperator(String operator) {

this.operator = operator;
}

@Override
public String toString() {

return this.operator;
}

}
Loading

0 comments on commit fe3a073

Please sign in to comment.