mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
removed the concat-operator "||" and replaced with "concat()" (#1489)
* removed the concat-operator "||" and replaced with "concat()" * using || in postgres * FIX: Assert-statement
This commit is contained in:
committed by
Rob Bygrave
parent
efa86043bf
commit
a020bb15a1
@@ -64,8 +64,6 @@ public class DatabasePlatform {
|
||||
*/
|
||||
protected String closeQuote = "\"";
|
||||
|
||||
protected String concatOperator = "||";
|
||||
|
||||
/**
|
||||
* When set to true all db column names and table names use quoted identifiers.
|
||||
*/
|
||||
@@ -455,13 +453,6 @@ public class DatabasePlatform {
|
||||
return openQuote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB concat operator.
|
||||
*/
|
||||
public String getConcatOperator() {
|
||||
return concatOperator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JDBC type used to store booleans.
|
||||
*/
|
||||
|
||||
@@ -92,14 +92,12 @@ class InPairsExpression extends AbstractExpression {
|
||||
return;
|
||||
}
|
||||
|
||||
String concat = request.getDbPlatformHandler().getConcatOperator();
|
||||
|
||||
String concatFormula = "(" + property0 + concat + "'" + separator + "'" + concat + property1;
|
||||
if (suffix != null && !suffix.isEmpty()) {
|
||||
concatFormula += concat + "'" + suffix + "'";
|
||||
}
|
||||
concatFormula += ")";
|
||||
request.append(concatFormula);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
request.getDbPlatformHandler().concat(property0, separator, property1, suffix);
|
||||
|
||||
request.append(request.getDbPlatformHandler().concat(property0, separator, property1, suffix));
|
||||
request.appendInExpression(not, concatBindValues);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,17 +8,6 @@ import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
*/
|
||||
abstract class BaseDbExpression implements DbExpressionHandler {
|
||||
|
||||
private final String concatOperator;
|
||||
|
||||
BaseDbExpression(String concatOperator) {
|
||||
this.concatOperator = concatOperator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConcatOperator() {
|
||||
return concatOperator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
|
||||
@@ -57,4 +46,15 @@ abstract class BaseDbExpression implements DbExpressionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String concat(String property0, String separator, String property1, String suffix) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("CONCAT(").append(property0).append(",'").append(separator).append("',").append(property1);
|
||||
|
||||
if (suffix != null && !suffix.isEmpty()) {
|
||||
sb.append(",'").append(suffix).append('\'');
|
||||
}
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@ import io.ebeaninternal.server.expression.Op;
|
||||
*/
|
||||
public class BasicDbExpression extends BaseDbExpression {
|
||||
|
||||
BasicDbExpression(String concatOperator) {
|
||||
super(concatOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
throw new RuntimeException("JSON expressions only supported on Postgres and Oracle");
|
||||
|
||||
@@ -9,11 +9,6 @@ import io.ebeaninternal.server.expression.Op;
|
||||
*/
|
||||
public interface DbExpressionHandler {
|
||||
|
||||
/**
|
||||
* Return the DB concat operator (Usually SQL standard "||").
|
||||
*/
|
||||
String getConcatOperator();
|
||||
|
||||
/**
|
||||
* Write the db platform specific json expression.
|
||||
*/
|
||||
@@ -33,4 +28,9 @@ public interface DbExpressionHandler {
|
||||
* Add the bitwise expression.
|
||||
*/
|
||||
void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match);
|
||||
|
||||
/**
|
||||
* Performs a "CONCAT" operation for that platform.
|
||||
*/
|
||||
String concat(String property0, String separator, String property1, String suffix);
|
||||
}
|
||||
|
||||
+8
-7
@@ -12,20 +12,21 @@ public class DbExpressionHandlerFactory {
|
||||
public static DbExpressionHandler from(DatabasePlatform databasePlatform) {
|
||||
|
||||
Platform platform = databasePlatform.getPlatform();
|
||||
String concatOperator = databasePlatform.getConcatOperator();
|
||||
switch (platform) {
|
||||
case H2:
|
||||
return new H2DbExpression(concatOperator);
|
||||
return new H2DbExpression();
|
||||
case POSTGRES:
|
||||
return new PostgresDbExpression(concatOperator);
|
||||
return new PostgresDbExpression();
|
||||
case MYSQL:
|
||||
return new MySqlDbExpression(concatOperator);
|
||||
return new MySqlDbExpression();
|
||||
case ORACLE:
|
||||
return new OracleDbExpression(concatOperator);
|
||||
return new OracleDbExpression();
|
||||
case SQLSERVER16:
|
||||
case SQLSERVER17:
|
||||
case SQLSERVER:
|
||||
return new SqlServerDbExpression(concatOperator);
|
||||
return new SqlServerDbExpression();
|
||||
default:
|
||||
return new BasicDbExpression(concatOperator);
|
||||
return new BasicDbExpression();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@ import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
*/
|
||||
class H2DbExpression extends BasicDbExpression {
|
||||
|
||||
H2DbExpression(String concatOperator) {
|
||||
super(concatOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
|
||||
|
||||
@@ -5,8 +5,4 @@ package io.ebeaninternal.server.expression.platform;
|
||||
*/
|
||||
class MySqlDbExpression extends BasicDbExpression {
|
||||
|
||||
MySqlDbExpression(String concatOperator) {
|
||||
super(concatOperator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,6 @@ import io.ebeaninternal.server.expression.Op;
|
||||
*/
|
||||
public class OracleDbExpression extends BaseDbExpression {
|
||||
|
||||
OracleDbExpression(String concatOperator) {
|
||||
super(concatOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
|
||||
|
||||
+12
-4
@@ -8,10 +8,6 @@ import io.ebeaninternal.server.expression.Op;
|
||||
*/
|
||||
public class PostgresDbExpression extends BaseDbExpression {
|
||||
|
||||
PostgresDbExpression(String concatOperator) {
|
||||
super(concatOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
|
||||
@@ -65,4 +61,16 @@ public class PostgresDbExpression extends BaseDbExpression {
|
||||
request.append(" <> 0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String concat(String property0, String separator, String property1, String suffix) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(").append(property0).append("||'").append(separator).append("'||").append(property1);
|
||||
|
||||
if (suffix != null && !suffix.isEmpty()) {
|
||||
sb.append("||'").append(suffix).append('\'');
|
||||
}
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@ import io.ebeaninternal.server.expression.Op;
|
||||
*/
|
||||
public class SqlServerDbExpression extends BaseDbExpression {
|
||||
|
||||
SqlServerDbExpression(String concatOperator) {
|
||||
super(concatOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void json(final SpiExpressionRequest request, final String propName,
|
||||
final String path, final Op operator, final Object value) {
|
||||
|
||||
Reference in New Issue
Block a user