Hi Kevin,

within...

On 17/03/2011 09:20, Kevin Meyer wrote:
Dan, Rob?

In the SQL object store AbstractJdbcFieldMapping, the method
"public void initializeField(ObjectAdapter object, Results rs)"
explicitly converts the record set field into a string, then uses
"field.getSpecification().getFacet(EncodableFacet.class).fromEncodedString(valueString)"
to create an object adapter from the string.

This is quite messy and obviously will kill anything like a BLOB (e.g. an
image!)
Well, not necessarily. There's nothing to prevent your value type to encode itself as a string, eg using base 64 encoding. What you will need to do is to write and register a ValueSemanticsProvider for the value type that you want to persist though (there are plenty of implementations in the codebase to look at; basically your VSP will need to implement getEncoderDecoder() method as a minimum).

The other thing to do is to register the VSP. If this is a custom value type, then you can annotate it with @Value. Otherwise, you'll need to register the VSP in isis.properties; have a look at ValueFacetFactoryTest#testSemanticsProviderNameCanBePickedUpFromConfiguration for details on the syntax:

isis.core.progmodel.value.com.mycompany.myapp.MyValueSemanticProvider.semanticsProviderName=com.mycompany.myapp.MyValueSemanticProvider


How do I directly create (for example) an ObjectAdapter containing an Isis
applib Date value, to pass on to
"((OneToOneAssociation) field).initAssociation(object, restoredValue);"

I guess the real requirement is creating the ObjectAdapter (for the
retrieved value object) to pass on to "initAssociation".

I'm not sure that you do need to do this if you use VSPs, but to answer your question: you can use:

IsisContext().getPersistenceSession().getAdapterManager().adapterFor(object).

If you look at the implementation (AdapterManagerDefault) then you'll see that we look for a ValueFacet on the spec of the provided object. If so, we create a "standalone" adapter to wrap the value.


The same would go for the other values (e.g. Image), and extend to custom
written value types (ValueSemanticsProvider? but I see that being handled
by an AbstractJdbcFieldMapping class implementation).
I didn't write the AJFM, but as you've noted it's implementation is hard-coded to only encode to strings, and it then leverages the VSP#EncoderDecoder to do the heavy lifting.

If you wanted to have support to something else (eg Images to BLOBs), then I think we'd need to define something equivalent mechanism to allow values to be marshalled to other types (eg byte[]). However, only objectstores are likely to need this, so I'd probably want us to introduce an applib scoped to each objectstore (eg sql/applib) for these value types. You can see I do a similar thing for Restful viewer and Wicket viewer.


HTH
Dan

In short - I am trying to move away from fetching/storing properties as
strings. This started with recoding the Sql object store to use prepared
statements with inserted objects (e.g. WHERE value = ?) instead of (WHERE
value = 'zorkmid').

Regards,
Kevin



Reply via email to