What command are you running to build? I would just start with "mvn clean
install"

For JSONB support I use this class (basically). But in addition you will
probably want an immutable (or optionally immutable) version of Map because
changes to the Map attribute itself won't be detected by Cayenne unless you
reset the attribute value on the entity, like
myEntityObject.setMyAttribute(new JsonMap(map)). In the Cayenne data
map/model you use the OTHER jdbc type.

*import* java.sql.CallableStatement;

*import* java.sql.PreparedStatement;

*import* java.sql.ResultSet;

*import* java.util.Collection;


*import* org.apache.cayenne.access.DataNode;

*import* org.apache.cayenne.access.types.ExtendedType;

*import* org.apache.cayenne.configuration.server.ServerRuntime;

*import* org.apache.cayenne.eof.JsonList;

*import* org.codehaus.jackson.map.ObjectMapper;

*import* org.postgresql.util.PGobject;


*public* *class* JsonbType<T> *implements* ExtendedType<T> {


*private* *static* *final* String *DB_TYPE* = "jsonb";


/**

* Call this at startup time to register with the Cayenne runtime.

* *@param* javaClass with user-created properties (getters and setters)

*/

*public* *static* <T> *void* registerWithRuntime(ServerRuntime runtime,
Class<T> javaClass){

JsonbType<T> jsonbType = *new* JsonbType<T>(javaClass);


Collection<DataNode> nodes = runtime.getDataDomain().getDataNodes();

*for* (DataNode node : nodes) {

node.getAdapter().getExtendedTypes().registerType(jsonbType);

}

}


*private* *final* Class<T> clazz;


*public* JsonbType(Class<T> clazz) {

*this*.clazz = clazz;

*try* {

clazz.getConstructor(*new* Class[0]);

} *catch* (NoSuchMethodException | SecurityException e) {

*throw* *new* RuntimeException("Json type " + clazz.getName() + " does not
have a no-args constructor");

}

}


@Override

*public* String getClassName() {

*return* clazz.getName();

}


@Override

*public* T materializeObject(ResultSet rs, *int* index, *int* type) *throws*
Exception {

String json = rs.getString(index);

*return* materialize(json);

}


@Override

*public* T materializeObject(CallableStatement rs, *int* index, *int* type)
*throws* Exception {

String json = rs.getString(index);

*return* materialize(json);

}


*private* T materialize(String json) {

*if* (json != *null*) {

*try* {

T value = *new* ObjectMapper().readValue(json, clazz);

*if* (value *instanceof* JsonList) {

((JsonList<?>)value).freeze();

} *else* *if* (value *instanceof* JsonMap) {

((JsonMap)value).freeze();

}

*return* value;

} *catch* (Exception e) {

*throw* *new* RuntimeException("Failed to deserialize value of type " +
clazz.getSimpleName() + " from " + json + ". " + e.getMessage(), e);

}

} *else* {

*return* *null*;

}

}


@Override

*public* *void* setJdbcObject(

PreparedStatement statement,

T value,

*int* pos,

*int* type,

*int* scale) *throws* Exception {


*if* (value == *null*) {

statement.setNull(pos, type);

} *else* {

String json;

*try* {

json = *new* ObjectMapper().writeValueAsString(value);

} *catch* (Exception e) {

*throw* *new* RuntimeException("Failed to serialize value of type " +
clazz.getSimpleName()
+ " from " + value + ". " + e.getMessage());

}


PGobject dataObject = *new* PGobject();

dataObject.setType(*DB_TYPE*);

dataObject.setValue(json);

statement.setObject(pos, dataObject);

}

}


@Override

*public* String toString(T value) {

*return* value.toString();

}


}


On Tue, May 26, 2020 at 5:17 AM Malcolm Edgar <malcolm.ed...@gmail.com>
wrote:

> Hi All,
>
> I am wanting to build the Cayenne master branch to explore adding support
> for Postgres JSON, JSONB data types.  I am getting the following build
> error resolving the cayenne-maven-plugin when building on Windows or Linux
> / WSL.
>
> Does anyone have suggestions for how to resolve this?
>
> Thanks for your help.
>
> regards Malcolm
>
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time:  5.206 s
> [INFO] Finished at: 2020-05-26T11:16:12+10:00
> [INFO]
> ------------------------------------------------------------------------
> [ERROR] Plugin
> org.apache.cayenne.plugins:cayenne-maven-plugin:4.2.M2-SNAPSHOT or one of
> its dependencies could not be resolved: Could not find artifact
> org.apache.cayenne.plugins:cayenne-maven-plugin:jar:4.2.M2-SNAPSHOT ->
> [Help 1]
> org.apache.maven.plugin.PluginResolutionException: Plugin
> org.apache.cayenne.plugins:cayenne-maven-plugin:4.2.M2-SNAPSHOT or one of
> its dependencies could not be resolved: Could not find artifact
> org.apache.cayenne.plugins:cayenne-maven-plugin:jar:4.2.M2-SNAPSHOT
>     at
> org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve
> (DefaultPluginDependenciesResolver.java:131)
>     at
>
> org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor
> (DefaultMavenPluginManager.java:182)
>     at
>
> org.apache.maven.plugin.internal.DefaultMavenPluginManager.getMojoDescriptor
> (DefaultMavenPluginManager.java:286)
>     at org.apache.maven.plugin.DefaultBuildPluginManager.getMojoDescriptor
> (DefaultBuildPluginManager.java:244)
>

Reply via email to