Skip to content

Commit

Permalink
[Blazebit#841] Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobe91 committed Jul 20, 2020
1 parent ed8b44d commit b6c651e
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 49 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,6 @@ In IntelliJ when defining the Oracle database, go to the Advanced tab an specify

When using the Oracle docker container via `docker_db.sh oracle` you might want to specify the following properties when executing tests `-Djdbc.url=jdbc:oracle:thin:@192.168.99.100:1521/xe -Djdbc.user=SYSTEM -Djdbc.password=oracle`

### JDBC Driver

You have to install the JDBC driver manually. If you install Oracle XE locally, you can take it from $ORACLE_HOME/jdbc otherwise download it from http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
Copy the jar to $M2_HOME/com/oracle/ojdbc14/10.2.0.4.0/ojdbc14-10.2.0.4.0.jar and you should be good to go.

If you use the docker container, extract the jdbc driver from the container via `docker cp oracle:/u01/app/oracle/product/11.2.0/xe/jdbc/lib/ojdbc6.jar ojdbc.jar`

`mvn -q install:install-file -Dfile=ojdbc.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -DgeneratePom=true`

### Install Oracle locally

Download Oracle XE from http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public class PostgreSQLJsonGetFunction extends AbstractJsonGetFunction {

@Override
protected void render0(FunctionRenderContext context) {
context.addChunk("cast(");
context.addArgument(0);
context.addChunk("::json");
context.addChunk(" as json)");
context.addChunk("#>>'{");
addUnquotedArgument(context, 1);
for (int i = 2; i < context.getArgumentsSize(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ protected void render0(FunctionRenderContext context) {
context.addArgument(0);
context.addChunk(", '" + jsonPath + "', CONVERT(bit, json_value(concat('{\"val\": ', temp.val, '}'), '$.val'))) ");

context.addChunk("else json_modify(");
context.addChunk("else case when LOWER(temp.val) = 'null' ");
context.addChunk("then ");
context.addChunk("json_modify(");
context.addArgument(0);
context.addChunk(", '" + jsonPath + "', json_value(concat('{\"val\": ', temp.val, '}'), '$.val')) end");
context.addChunk(", 'strict " + jsonPath + "', json_value(concat('{\"val\": ', temp.val, '}'), '$.val')) ");
context.addChunk("else ");
context.addChunk("json_modify(");
context.addArgument(0);
context.addChunk(", '" + jsonPath + "', json_value(concat('{\"val\": ', temp.val, '}'), '$.val')) end end");

context.addChunk(") else json_modify(");
context.addArgument(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ protected void render0(FunctionRenderContext context) {
List<Object> jsonPathElements = AbstractJsonGetFunction.retrieveJsonPathElements(context, 2);

context.addChunk("(select ");
context.addChunk("case when lower(temp.val) = 'null' then json_set(");
context.addArgument(0);
context.addChunk(",'");
context.addChunk(AbstractJsonGetFunction.toJsonPath(jsonPathElements, jsonPathElements.size(), true));
context.addChunk("', null) else ");
context.addChunk("json_merge_patch(");
context.addArgument(0);
context.addChunk(", concat('");
Expand All @@ -44,7 +49,7 @@ protected void render0(FunctionRenderContext context) {
for (int i = jsonPathElements.size() - 1; i >= 0; i--) {
endJsonPathElement(context, jsonPathElements, i);
}
context.addChunk("'))");
context.addChunk("')) end");

context.addChunk(" from (values row(");
context.addArgument(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class PostgreSQLJsonSetFunction extends AbstractJsonSetFunction {

@Override
protected void render0(FunctionRenderContext context) {
context.addChunk("jsonb_set(");
context.addChunk("jsonb_set(cast(");
context.addArgument(0);
context.addChunk("::jsonb,");
context.addChunk(" as jsonb),");
context.addChunk("'{");
addUnquotedArgument(context, 2);
for (int i = 3; i < context.getArgumentsSize(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,38 @@ private JpqlFunctionUtil() {
}

public static String unquoteSingleQuotes(String s) {
if (s.length() >= 2) {
if (s.charAt(0) == '\'' && s.charAt(s.length() - 1) == '\'') {
return s.substring(1, s.length() - 1);
}
}
return s;
return unquote(s, '\'');
}

public static String unquoteDoubleQuotes(String s) {
if (s.length() >= 2) {
if (s.charAt(0) == '\"' && s.charAt(s.length() - 1) == '\"') {
return s.substring(1, s.length() - 1);
return unquote(s, '\"');
}

private static String unquote(String s, char quoteCharacter) {
if (!s.isEmpty() && s.charAt(0) != quoteCharacter) {
return s;
}
StringBuilder sb = new StringBuilder(s.length());
boolean quote = false;
for (int i = 1; i < s.length() - 1; i++) {
final char c = s.charAt(i);
if (quote) {
quote = false;
if (c != quoteCharacter) {
sb.append(quoteCharacter);
}
sb.append(c);
} else {
if (c == quoteCharacter) {
quote = true;
} else {
sb.append(c);
}
}
}
return s;
if (quote) {
sb.append(quoteCharacter);
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@
public class JpqlFunctionUtilTest {

@Test
public void testUnquote() {
public void testUnquoteSingleQuotes() {
assertEquals("0", JpqlFunctionUtil.unquoteSingleQuotes("0"));
assertEquals("0", JpqlFunctionUtil.unquoteSingleQuotes("'0'"));
assertEquals("'0'", JpqlFunctionUtil.unquoteSingleQuotes("''0''"));
}

@Test
public void testUnquoteDoubleQuotes() {
assertEquals("0", JpqlFunctionUtil.unquoteDoubleQuotes("0"));
assertEquals("0", JpqlFunctionUtil.unquoteDoubleQuotes("\"0\""));
assertEquals("\"0\"", JpqlFunctionUtil.unquoteDoubleQuotes("\"\"0\"\""));
}
}
1 change: 0 additions & 1 deletion core/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>18.3.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ public void testJsonSet() throws JsonProcessingException {
}

@Test
@Category({ NoH2.class, NoSQLite.class, NoFirebird.class, NoMySQL.class, NoOracle.class })
@Category({ NoH2.class, NoSQLite.class, NoFirebird.class, NoMySQLOld.class, NoOracle.class })
public void testJsonSetNull() throws JsonProcessingException {
List<Tuple> objectRootResult = cbf.create(em, Tuple.class).from(JsonDocument.class, "d")
.select("d.content")
// json_set with value null not supported for Oracle and MySQL
// json_set with value null not supported for Oracle
.select("json_set(d.content, 'null', 'K1', 0, 'K2')")
.select("json_set(d.content, 'null', 'K1', 0)")
.where("id").eq(1L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,24 @@ Syntax: `BASE64 ( bytes )`

Returns a Base64 encoded string that represents the passed bytes.

==== JSON_GET

Sytax: `JSON_GET(jsonDocument, pathSegment1, ..., pathSegmentN)`

Where `pathSegmentN` is a quoted json key or array index.

Returns the json node within the `jsonDocument` designated by the path segments.

==== JSON_SET

Sytax: `JSON_SET(jsonDocument, newValue, pathSegment1, ..., pathSegmentN)`

Where `newValue` is a quoted json node and `pathSegmentN` is a quoted json key or array index.

Returns the modified `jsonDocument` that results from replacing the json node designated by the path segments with `newValue`.

Setting JSON `null` is not supported for Oracle.

==== STRING_JSON_AGG function

Syntax: `STRING_JSON_AGG ( key1, value1, ..., keyN, valueN )`
Expand Down
8 changes: 4 additions & 4 deletions entity-view/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@
</build>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<scope>test</scope>
</dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
Expand Down
4 changes: 2 additions & 2 deletions integration/deltaspike-data/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@
</build>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions integration/querydsl/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@
</build>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions integration/spring-data/testsuite/webflux/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@
</build>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions integration/spring-data/testsuite/webmvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@
</build>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ public void setCorrelatedSubqueryExpression() {

UpdateCriteriaBuilder<Document> criteriaBuilder = query.createCriteriaBuilder(em);
assertEquals("UPDATE Document d SET d.idx = (SELECT " + function("CAST_INTEGER", "COUNT(owner)") + " FROM d.owner owner) + 1", criteriaBuilder.getQueryString());
criteriaBuilder.getQuery().executeUpdate();
criteriaBuilder.getQuery();
}
}
6 changes: 3 additions & 3 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>18.3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
5 changes: 1 addition & 4 deletions travis/before_script_oracle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
# Sets up environment for Blaze-Persistence backend MSSQL at travis-ci.com
#

docker run --shm-size=1536m --name oracle -d -p 1521:1521 quillbuilduser/oracle-18-xe

docker cp oracle:/u01/app/oracle/product/11.2.0/xe/jdbc/lib/ojdbc6.jar ojdbc.jar
mvn install:install-file -Dfile=ojdbc.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -DgeneratePom=true
docker run --shm-size=1536m --name oracle -d -p 1521:1521 quillbuilduser/oracle-18-xe

0 comments on commit b6c651e

Please sign in to comment.