-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from oneteme/develop
Develop
- Loading branch information
Showing
157 changed files
with
6,381 additions
and
3,472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/main/java/org/usf/jquery/core/AggregationFunction.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.usf.jquery.core; | ||
|
||
import static org.usf.jquery.core.JDBCType.typeOf; | ||
import static org.usf.jquery.core.Validation.requireAtLeastNArgs; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* | ||
* @author u$f | ||
* | ||
*/ | ||
@FunctionalInterface | ||
interface ArgTypeRef extends Function<Object[], JDBCType> { | ||
|
||
static ArgTypeRef firstArgJdbcType() { | ||
return arr-> typeOf(requireAtLeastNArgs(1, arr, ArgTypeRef.class::getSimpleName)[0]) | ||
.orElse(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.usf.jquery.core; | ||
|
||
import static org.usf.jquery.core.Validation.requireNArgs; | ||
|
||
/** | ||
* | ||
* @author u$f | ||
* | ||
*/ | ||
@FunctionalInterface | ||
public interface ArithmeticOperator extends Operator { | ||
|
||
@Override | ||
default void sql(SqlStringBuilder sb, QueryContext ctx, Object[] args) { | ||
requireNArgs(2, args, ArithmeticException.class::getSimpleName); | ||
sb.parenthesis(()->{ | ||
ctx.appendLiteral(sb, args[0]); | ||
sb.append(id()); | ||
ctx.appendLiteral(sb, args[1]); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/org/usf/jquery/core/BadArgumentException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.usf.jquery.core; | ||
|
||
import static java.lang.String.format; | ||
import static org.usf.jquery.core.SqlStringBuilder.SCOMA; | ||
import static org.usf.jquery.core.Utils.joinAndDelemitArray; | ||
import static org.usf.jquery.core.Utils.joinArray; | ||
|
||
import org.usf.jquery.core.JavaType.Typed; | ||
|
||
/** | ||
* | ||
* @author u$f | ||
* | ||
*/ | ||
@SuppressWarnings("serial") | ||
public final class BadArgumentException extends JQueryException { | ||
|
||
public BadArgumentException(String message) { | ||
super(message); | ||
} | ||
|
||
public BadArgumentException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public static BadArgumentException badArgumentCountException(int count, int expect) { | ||
return new BadArgumentException(format("bad argument count: [%d], expected: %d", count, expect)); | ||
} | ||
|
||
public static BadArgumentException badArgumentTypeException(Object obj, JavaType[] types) { | ||
var type = obj instanceof Typed t ? t.getType() : JDBCType.typeOf(obj); | ||
return new BadArgumentException(format("bad argument type: %s[%s], expected: %s", obj, type, joinArray("|", types))); | ||
} | ||
|
||
public static BadArgumentException badArgumentsException(String type, String id, Object[] args, Exception e) { | ||
return new BadArgumentException(format("bad %s arguments: ", type) + badArgumentsFormat(id, args), e); | ||
} | ||
|
||
public static String badArgumentsFormat(String id, Object... args) { | ||
return id + joinAndDelemitArray(SCOMA, "([", "])", args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
package org.usf.jquery.core; | ||
|
||
import static java.util.stream.Collectors.joining; | ||
import static org.usf.jquery.core.QueryParameterBuilder.addWithValue; | ||
import static org.usf.jquery.core.SqlStringBuilder.SPACE; | ||
import static org.usf.jquery.core.Validation.requireAtLeastNArgs; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* | ||
* @author u$f | ||
* | ||
*/ | ||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) | ||
public final class CaseColumn implements DBColumn { | ||
|
||
private final Collection<WhenExpression> expressions = new LinkedList<>(); | ||
private final WhenCase[] whenCases; | ||
|
||
CaseColumn(WhenCase[] whenCases) { | ||
this.whenCases = requireAtLeastNArgs(1, whenCases, CaseColumn.class::getSimpleName); | ||
} | ||
|
||
@Override | ||
public String sql(QueryParameterBuilder builder) { | ||
builder.forceValue(true); //add filters as value | ||
try { | ||
return expressions.stream() | ||
.map(o-> o.sql(builder)) | ||
.collect(joining(SPACE, "CASE ", " END")); | ||
} | ||
finally { | ||
builder.forceValue(false); | ||
} | ||
public void sql(SqlStringBuilder sb, QueryContext ctx) { | ||
var sub = ctx.withValue(); //force literal parameter | ||
sb.runForeach(whenCases, SPACE, o-> o.sql(sb, sub), "CASE ", " END"); | ||
} | ||
|
||
public CaseColumn append(WhenExpression we) { | ||
expressions.add(we); | ||
return this; | ||
|
||
@Override | ||
public JDBCType getType() { | ||
return Stream.of(whenCases) | ||
.map(WhenCase::getType) | ||
.filter(Objects::nonNull) // should have same type | ||
.findAny().orElse(null); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return sql(addWithValue()); | ||
public int columns(QueryBuilder builder, Consumer<? super DBColumn> groupKeys) { | ||
return Nested.resolveColumn(this, builder, groupKeys, whenCases); | ||
} | ||
|
||
public static CaseColumn caseWhen(DBFilter filter, Object value){ | ||
return new CaseColumn() | ||
.append(new WhenExpression(filter, value)); | ||
|
||
@Override | ||
public void views(Consumer<DBView> cons) { | ||
Nested.resolveViews(cons, whenCases); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return DBObject.toSQL(this); | ||
} | ||
} |
Oops, something went wrong.