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:
Thibault Meyer authored and Rob Bygrave committed 2017-07-03 20:45:48 +12:00
1 parent 2001539755
commit 35b467c04f
3 files changed
+45 -18

No files matched your search

@@ -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");
}
}