5 Replies Latest reply on Sep 28, 2012 1:03 PM by Randall Hauch

    CRUD examples via REST with ModeShape in MySQL datasource

    Newbie

      Hi Randall,

      Thank you so much for all your great help adn CRUD examples using REST  in the "default" workspace of the "sample" repository at https://community.jboss.org/thread/204071?tstart=0

      Could you help with similar CRUD examples on mysql datasource configured in ModeShape? (My ultimate goal will be using Madeshape's fererated search capabilities on a couple of datasources/respositories  later on.)

       

      Thank you very much!

      Anna

        • 1. Re: CRUD examples via REST with ModeShape in MySQL datasource
          Randall Hauch Master

          Could you help with similar CRUD examples on mysql datasource configured in ModeShape? (My ultimate goal will be using Madeshape's fererated search capabilities on a couple of datasources/respositories  later on.)

          If you've set up your repository to use an Infinispan cache backed by your MySQL data source (via Infinispan's cache store mechanism), then the nodes and properties you've already created with the RESTful service will be stored in that database.

           

          But it's important to realize that ModeShape clients only work with nodes and properties, and never directly with any other information system. This will be true even when we add federation capabilities to 3.1, you'll still use the RESTful API, JCR API, WebDAV, etc. to talk with ModeShape to create/read/udpate/delete node content, but internally the ModeShape repository will access external the configured information systems and present their data as part of the node structure of the repository itself. That is, client applications will only see the node structures.

           

          P.S. ModeShape 2.x had federation via a backend connector framework. And there were two flavors of connectors: storage connectors (e.g., JDBC via JPA, Infinispan, JBoss Cache, disk storage, etc.) and external system connectors (e.g., SVN, database metadata, file system content, etc.). The storage connectors were replaced in ModeShape 3.0 by Infinispan's cache stores, and the equivalent of the external system connectors will appear in 3.1.

          • 2. Re: CRUD examples via REST with ModeShape in MySQL datasource
            Newbie
            If you've set up your repository to use an Infinispan cache backed by your MySQL data source (via Infinispan's cache store mechanism), then the nodes and properties you've already created with the RESTful service will be stored in that database.

            I think I did but not sure. Is there a way to check it? Because I am not seeing anything created in  mysql database. I have created a few nodes based on your previous post and can see the content using browser, for example, http://localhost:8080/modeshape-rest/sample/default/items/newNode

             

            Thank you,

            Anna

            • 3. Re: CRUD examples via REST with ModeShape in MySQL datasource
              Randall Hauch Master

              I think I did but not sure. Is there a way to check it? Because I am not seeing anything created in  mysql database. I have created a few nodes based on your previous post and can see the content using browser, for example, http://localhost:8080/modeshape-rest/sample/default/items/newNode

              You're probably running into the same Infinispan bug that is talked about in these posts: JDBC configuration in AS7.1.1 and AS7 string-keyed-jdbc-store configuration

              • 4. Re: CRUD examples via REST with ModeShape in MySQL datasource
                Newbie

                I don't have any errors in my logs, everything seemed worked well and I am not sure how the Infinispan bug you are referring to in your previous reply relates to my question. But, again, I am just trying to learn about ModeShape.

                 

                Your CRUD examples in the previous post were VERY helpful (https://community.jboss.org/thread/204071?tstart=0). Thank you so much for that. Could you help with similar CRUD examples using MOdeShape to create data in mysql database?

                 

                Thank you very much.

                Anna

                • 5. Re: CRUD examples via REST with ModeShape in MySQL datasource
                  Randall Hauch Master

                  Your CRUD examples in the previous post were VERY helpful (https://community.jboss.org/thread/204071?tstart=0). Thank you so much for that. Could you help with similar CRUD examples using MOdeShape to create data in mysql database?

                   

                  In your first post on this thread, you refer to another thread in which you state you're using ModeShape 3 with JBoss AS7. In that thread you mention that you successfully created a JDBC DataSource for your MySQL database. The ModeShape repository (or repositories) are configured within that same AS7 configuration file, and each repository will reference an Infinispan cache that will also be configured in the same file. Here's part of the relevant section from the "standalone-modeshape.xml" file that we provide in the kit for a starting point:

                   

                          <subsystem xmlns="urn:jboss:domain:modeshape:1.0">

                              <!-- A sample repository that uses the "sample" cache in the "modeshape" Infinispan container. All content, binary values,

                                   and indexes are stored within the server's data directory. This is the simplest way to configure a repository

                                   that uses defaults for everything; feel free to change and specify other configuration options.  -->

                              <repository name="sample"/>

                               ...

                          </subsystem>


                  Implicit on the "repository" element is a "cache-container" attribute whose value is "modeshape" (AS7 automatically removes this because it is the default). Also implicit on this element is a "cache-name" attribute with value of "sample"; since it is the same name as the repository, it also is not needed. You can provide them, and will need to if the default values are not used.

                   

                  This tells ModeShape that the "sample" repository should use and persist its content within the Infinispan cache named "sample" in the Infinispan cache container named "modeshape". You have to then configure the Infinispan cache (used by a repository) how to persist its data. Once again, the "standalone-modeshape.xml" file has an example of how to store the cach data on the file system; here's a portion of that file:

                   

                          <subsystem xmlns="urn:jboss:domain:infinispan:1.2" default-cache-container="hibernate">

                              ...

                              <!-- Each ModeShape repository uses one (or more) cache in a cache container. We define a single container

                                   named "modeshape" (other names require specifying the container names in each repository configuration,

                                   with a "sample" cache (each repository assumes the cache name matches the repository name). -->

                              <cache-container name="modeshape" default-cache="sample">

                                  <local-cache name="sample">

                                      <!-- ModeShape requires transactions -->

                                      <transaction mode="NON_XA"/>

                                      <!-- Use a cache with file-backed write-through storage. File-backed storage is simple, but not necessarily the fastest. -->

                                      <file-store passivation="false" path="modeshape/store/sample" relative-to="jboss.server.data.dir" purge="false"/>

                                  </local-cache>

                                   ...

                              </cache-container>

                          </subsystem>


                  Note the "file-store" section, which configures the "sample" cache to store the information on the file system (within the AS7 installation's data directory).

                   

                  To store in MySQL, you need to replace this "file-store" fragment. Infinispan has two options: string-based and binary-based JDBC storage. The AS7 string-keyed-jdbc-store configuration thread shows how to configure the string-based JDBC storage; see the AS7 and Infinispan documentation for other alternatives.

                   

                  Once this is all configured, any nodes and properties you add to the repository (whether you use the JCR API or the REST API) will be stored in your database within tables and in a format defined by Infinispan. You will NOT be able to use ModeShape to access existing data in an existing database - it simply does not do that because ModeShape itself is a form of a database.

                   

                  I hope this helps.