mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
JSON simple implementation for MSSQL (#1057)
- Use JSON_VALUE - Use NVARCHAR type Signed-off-by: Thibault Meyer <meyer.thibault@gmail.com>
This commit is contained in:
committed by
Rob Bygrave
parent
2001539755
commit
35b467c04f
@@ -2,11 +2,7 @@ package io.ebean.config.dbplatform.sqlserver;
|
||||
|
||||
import io.ebean.PersistBatch;
|
||||
import io.ebean.Platform;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.config.dbplatform.DbPlatformType;
|
||||
import io.ebean.config.dbplatform.DbType;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.config.dbplatform.SqlErrorCodes;
|
||||
import io.ebean.config.dbplatform.*;
|
||||
import io.ebean.dbmigration.ddlgeneration.platform.SqlServerDdl;
|
||||
|
||||
import java.sql.Types;
|
||||
@@ -35,13 +31,13 @@ public class SqlServerPlatform extends DatabasePlatform {
|
||||
this.exceptionTranslator =
|
||||
new SqlErrorCodes()
|
||||
.addAcquireLock("1222")
|
||||
.addDuplicateKey("2601","2627")
|
||||
.addDataIntegrity("544","8114","8115")
|
||||
.addDuplicateKey("2601", "2627")
|
||||
.addDataIntegrity("544", "8114", "8115")
|
||||
.build();
|
||||
|
||||
this.openQuote = "[";
|
||||
this.closeQuote = "]";
|
||||
this.specialLikeCharacters = new char[] { '%', '_', '[' };
|
||||
this.specialLikeCharacters = new char[]{'%', '_', '['};
|
||||
this.likeClause = "like ? COLLATE Latin1_General_BIN";
|
||||
|
||||
booleanDbType = Types.INTEGER;
|
||||
@@ -63,11 +59,13 @@ public class SqlServerPlatform extends DatabasePlatform {
|
||||
dbTypeMap.put(DbType.TIME, new DbPlatformType("time"));
|
||||
dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime2"));
|
||||
|
||||
dbTypeMap.put(DbType.JSON, new DbPlatformType("nvarchar(max)"));
|
||||
dbTypeMap.put(DbType.JSONB, new DbPlatformType("nvarchar(max)"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void escapeLikeCharacter(char ch, StringBuilder sb) {
|
||||
sb.append('[').append(ch).append(']');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -248,19 +248,20 @@ public class InternalConfiguration {
|
||||
* Return the JSON expression handler for the given database platform.
|
||||
*/
|
||||
private DbExpressionHandler getDbExpressionHandler(DatabasePlatform databasePlatform) {
|
||||
|
||||
Platform platform = databasePlatform.getPlatform();
|
||||
if (platform == Platform.POSTGRES) {
|
||||
return new PostgresJsonExpression();
|
||||
final Platform platform = databasePlatform.getPlatform();
|
||||
switch (platform) {
|
||||
case POSTGRES:
|
||||
return new PostgresJsonExpression();
|
||||
case ORACLE:
|
||||
return new OracleDbExpression();
|
||||
case SQLSERVER:
|
||||
return new SqlServerJsonExpression();
|
||||
default:
|
||||
return new NotSupportedDbExpression();
|
||||
}
|
||||
if (platform == Platform.ORACLE) {
|
||||
return new OracleDbExpression();
|
||||
}
|
||||
return new NotSupportedDbExpression();
|
||||
}
|
||||
|
||||
public JsonContext createJsonContext(SpiEbeanServer server) {
|
||||
|
||||
return new DJsonContext(server, jsonFactory, typeManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.ebeaninternal.server.core;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
/**
|
||||
* Microsoft SQL Server JSON. ARRAY expressions not supported.
|
||||
*/
|
||||
public class SqlServerJsonExpression implements DbExpressionHandler {
|
||||
|
||||
@Override
|
||||
public void json(final SpiExpressionRequest request, final String propName,
|
||||
final String path, final Op operator, final Object value) {
|
||||
request.append("json_value(").append(propName).append(", '$.").append(path).append("')");
|
||||
request.append(operator.bind());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayContains(final SpiExpressionRequest request, final String propName,
|
||||
final boolean contains, final Object... values) {
|
||||
throw new RuntimeException("ARRAY expressions not supported on Microsoft SQL Server");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayIsEmpty(final SpiExpressionRequest request, final String propName, final boolean empty) {
|
||||
throw new RuntimeException("ARRAY expressions not supported on Microsoft SQL Server");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user