Hi Andreas,

Andreas Kollegger wrote:
> Hi,
> 
> I'd like to expose data stored in an external database as resource nodes
> in Sling. Access to the database is already wrapped in an OSGi service
> (MyService.java), and there is a Java model for the data (MyModel.java).
> From what I can understand from reading the examples, searching the
> mailing list and looking at documentation, the steps to integrate with
> Sling could be:
> 
> 1. MyResourceProvider implements ResourceProvider
>     - bridge to MyService for getting data rows
>     - provider.roots = /my/resources/
>     - sub-path of root used to select row in table
> (/my/resources/3245.html retrieves row index 3245 as Resource)
>     - listChildren() of root would list all database rows (probably add
> query params to limit number of rows returned)
>     - getResource() returns a MyResourceWrapper
> 
> 2. MyResourceWrapper implements Resource
>     - wraps MyModel
>     - resourceType = my/Model
>     - adaptable to javax.jcr.Node (exposing columns as node properties)
it depends on your application (code) but I think making your resource
adaptable to ValueMap (jcr resources are adaptable to value map as well)
is more generic. It allows you to access different kind of resources
(backed by jcr, backed by your db provider) in a unique way. And the
ValueMap interface is easier to use than jcr Node :)

> That would take care of read access to the data. I can then easily add
> scripts to render the data as appropriate.
Sounds good to me :)

> 
> Write access is a little less clear to me. I'd like to have a servlet
> which handles json, xml or form POSTs for anything submitted to the path
> of my ResourceProvider. I think I need to do this:
> 
> 1. MyResourceTypeProvider implements JcrResourceTypeProvider
>     - provider.roots = /my/resources
>     - any node below the root is returned as resourceType my/Model,
> otherwise return null
> 
> 2. MyPostServlet extends SlingAllMethodsServlet
>     - registered to handle nodes of type my/Model
>     - override doPost() to handle data based on content-type
>     - creates new database entries using MyService
> 
> That would allow the creation of a new database row by posting an
> appropriate json or xml file to /my/resource/*.html . For the form data,
> I'd conform to the SlingPostServlet interface to remain compatible with
> generic node editing.
> 
> Am I thinking about this correctly, or is their a more appropriate
> Sling-Way?
Hmm not sure :) I guess your idea should work. Now, for updating db data
it should already work if your resource is adaptable to PersistableValueMap.

For adding/deleting resources something like the above might work. We
are thinking of extending the resource provider interface to get
better support for these use cases. This is one of the topics for the
near future, so maybe we should start thinking about this (again) now :)

Regards
Carsten
-- 
Carsten Ziegeler
cziege...@apache.org

Reply via email to