Skip to content
Permalink
Browse files
Update dependencies and cleanup code
  • Loading branch information
stariy95 committed Jun 21, 2022
1 parent 4a6e406 commit 6660898fe123da349c04329fcee54ccc22c3657a
Showing 5 changed files with 45 additions and 11 deletions.
@@ -12,10 +12,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<bootique.version>2.0.M1</bootique.version>
<cayenne.version>4.2.M2</cayenne.version>
<bootique.version>2.0.1</bootique.version>
<cayenne.version>4.2.RC1</cayenne.version>

<postgres.jdbc.version>9.4.1209</postgres.jdbc.version>
<postgres.jdbc.version>42.3.3</postgres.jdbc.version>
<mysql.jdbc.version>8.0.28</mysql.jdbc.version>
<slf4j.version>1.7.30</slf4j.version>

@@ -14,6 +14,9 @@
import org.apache.cayenne.query.SQLExec;
import org.apache.cayenne.value.Wkt;

/**
* Command that demonstrates usage of the {@link Wkt} type
*/
public class GeoTestCommand extends CommandWithMetadata {

@Inject
@@ -5,7 +5,6 @@
import javax.inject.Provider;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.bootique.cli.Cli;
import io.bootique.command.CommandOutcome;
import io.bootique.command.CommandWithMetadata;
@@ -15,7 +14,11 @@
import org.apache.cayenne.demo.model.TestJson;
import org.apache.cayenne.query.ObjectSelect;
import org.apache.cayenne.query.SQLExec;
import org.apache.cayenne.value.Json;

/**
* Command that demonstrates usage of the {@link Json} type
*/
class JsonTestCommand extends CommandWithMetadata {

@Inject
@@ -45,12 +48,10 @@ public CommandOutcome run(Cli cli) {
}

private void createJsonObject(ObjectContext context) {
Pojo pojo = new Pojo(123, "abc", false);

TestJson testJson = context.newObject(TestJson.class);
ObjectNode objectNode = new ObjectNode(objectMapper.getNodeFactory());
objectNode.put("test", 123);
objectNode.put("field1", "abc");
objectNode.put("field2", false);
testJson.setJson(objectNode);
testJson.setJson(objectMapper.valueToTree(pojo));
context.commitChanges();
}

@@ -71,4 +72,31 @@ private void getKey(ObjectContext context) {
System.out.println("JSON values for path 'test':");
testValues.forEach(v -> System.out.println("\t" + v));
}

/**
* Simple value-object to convert to Json
*/
static class Pojo {
private final int test;
private final String field1;
private final boolean field2;

Pojo(int test, String field1, boolean field2) {
this.test = test;
this.field1 = field1;
this.field2 = field2;
}

public int getTest() {
return test;
}

public String getField1() {
return field1;
}

public boolean isField2() {
return field2;
}
}
}
@@ -7,6 +7,9 @@
import org.apache.cayenne.value.Json;
import org.apache.cayenne.di.Inject;

/**
* This value type allows to use Jackson's {@link ObjectNode} directly as a Json value
*/
public class JsonValueType implements ValueObjectType<ObjectNode, Json> {

@Inject
@@ -12,5 +12,5 @@ cayenne:
datasource: geo
createSchema: true
maps:
- location: classpath:demo.map.xml
name: map1
map1:
location: classpath:demo.map.xml

0 comments on commit 6660898

Please sign in to comment.