use of org.qi4j.api.property.StateHolder in project qi4j-sdk by Qi4j.
the class ValueCompositeRequestWriter method writeRequest.
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException {
if (requestObject instanceof ValueComposite) {
// Value as parameter
final ValueComposite valueObject = (ValueComposite) requestObject;
if (request.getMethod().equals(Method.GET)) {
StateHolder holder = spi.stateOf(valueObject);
final ValueDescriptor descriptor = spi.valueDescriptorFor(valueObject);
final Reference ref = request.getResourceRef();
ref.setQuery(null);
try {
for (PropertyDescriptor propertyDescriptor : descriptor.state().properties()) {
Object value = holder.propertyFor(propertyDescriptor.accessor()).get();
String param;
if (value == null) {
param = null;
} else {
param = valueSerializer.serialize(value);
}
ref.addQueryParameter(propertyDescriptor.qualifiedName().name(), param);
}
} catch (ValueSerializationException e) {
throw new ResourceException(e);
}
} else {
request.setEntity(new WriterRepresentation(MediaType.APPLICATION_JSON) {
@Override
public void write(Writer writer) throws IOException {
setCharacterSet(CharacterSet.UTF_8);
valueSerializer.serialize(valueObject, new WriterOutputStream(writer));
}
});
}
return true;
}
return false;
}
use of org.qi4j.api.property.StateHolder in project qi4j-sdk by Qi4j.
the class AbstractSQLIndexing method storePropertiesOfVC.
private //
Integer storePropertiesOfVC(//
Map<QualifiedName, PreparedStatement> qNameInsertPSs, //
PreparedStatement insertAllQNamesPS, //
Integer propertyPK, //
Long entityPK, //
Object property) throws SQLException {
ValueDescriptor vDesc = this._qi4SPI.valueDescriptorFor((ValueComposite) property);
StateHolder state = Qi4j.FUNCTION_COMPOSITE_INSTANCE_OF.map((ValueComposite) property).state();
Integer originalPropertyPK = propertyPK;
++propertyPK;
for (PropertyDescriptor pDesc : vDesc.state().properties()) {
propertyPK = //
this.insertProperty(//
qNameInsertPSs, //
insertAllQNamesPS, //
propertyPK, //
entityPK, //
pDesc.qualifiedName(), //
state.propertyFor(pDesc.accessor()).get(), //
originalPropertyPK);
}
return propertyPK;
}
Aggregations