1 2 Previous Next 20 Replies Latest reply on Aug 24, 2012 9:27 AM by asilchenko

    Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final

      I am looking into configuring JDBC connection to MySQL database  to work with ModeShape. It seems that stantalone-modeshape.xml file has Infinispan configuration. Is this the right place to configure database connection? Thank you very much.

       

      Best Regards,

      Anna

        • 1. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
          rhauch

          Yes, that is the correct location. It's a configuration file for all of AS7 that's been tailored for use with ModeShape. However, please see JDBC configuration in AS7.1.1.

          • 2. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final

            Hi Randal,

            I am having trouble finding where exactly (in stantalone-modeshape.xml file or maybe other file) I can include  my database configuration paramenters for connecting to mysql database?

            <comment>DATABASE PARAMETERS</comment>

            <entry key="database.location">localhost</entry>

            <entry key="database.name">mysqldb</entry>

            <entry key="database.port">3306</entry>

            <entry key="database.user">user</entry>

            <entry key="database.password">password</entry>

            <entry key="database.driver">com.mysql.jdbc.Driver</entry>

            Could you please help with actual example of a code snippet which utilizes these parameters?

             

            Hopefully, my question makes sense if my understanding of how ModeShape is working with an existing database is correct. Thank you very much.

            • 3. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
              rhauch

              We don't yet have anything in the ModeShape documentation about setting up a JDBC data source. We should and will, but simply haven't yet because this really just entails setting up Infinispan and JDBC data sources in a stock AS7. After all, our goal is that ModeShape becomes yet another service inside AS7 (eventually we'll even have integration into the AS7 Console), so we're not going to want to duplicate much of the AS7 documentation. Having said that, however, we need to make it easier for people to get started with ModeShape, and setting up Infinispan and JDBC persistence is something we need to cover.

               

              In the mean time, you can use the AS7 Console to add/configure data sources (see its documentation) or by directly modifying the AS7 installation files (or using AS7's Command Line Interface); see documentation and blog post. This blog post might also be helpful, since it specifically covers MySQL.

               

              The "datasources" subsystem will look something like this:

               

              <subsystem xmlns="urn:jboss:domain:datasources:1.0">
                <datasources>
                  ...
                  <datasource jndi-name="java:/mydb" pool-name="my_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
                    <connection-url>jdbc:mysql://localhost:3306/mysqldb</connection-url>
                    <driver>mysql</driver>
                    <security>
                      <user-name>user</user-name>
                      <password>password</password>
                    </security>
                    <statement>
                      <prepared-statement-cache-size>100</prepared-statement-cache-size>
                      <share-prepared-statements/>
                    </statement>
                  </datasource>
                  ...
                </datasources>
                <drivers>
                  <driver name="mysql" module="com.mysql"/>
                  ...
                </drivers>
              </subsystem>
              

               

              The "<driver>mysql</driver>" in the "datasource" fragment contains the name of the "mysql" driver component, while the driver's "module" attribute value of "com.mysql" is actually the AS7 module that you should have added as part of the process of adding a new driver library. (AS7 uses a module-based classloading system that helps isolate all of the classloaders of the various deployed apps, components and modules in AS7. The classloader isolation is a huge advantage, but at the slight cost of increased work at setup time.)

               

              BTW, all of this actually can be added using the CLI. In fact, the CLI supports scripts, making it very easy to alter the configuration of one or more installations in a repeatable way.

               

              Hope this helps!

              • 4. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final

                Thank you for your response. I modified standalone-modeshape.xml and my newly added data source is showing up in the console panel but when click on it, getting this error:

                Unexpected HTTP response: 500  Request { "address" => [ ("subsystem" => "datasources"), ("data-source" => "annadb"), ("statistics" => "pool") ], "operation" => "read-resource", "include-runtime" => true }  Response  Internal Server Error { "outcome" => "failed", "failure-description" => "JBAS014739: No handler for read-resource at address [ (\"subsystem\" => \"datasources\"), (\"data-source\" => \"annadb\"), (\"statistics\" => \"pool\") ]", "rolled-back" => true }

                Not sure what am I missing in the configuration. Thank you very much!

                 

                Best Regards,

                Anna

                • 5. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
                  rhauch
                  JBAS014739: No handler for read-resource at address [ (\"subsystem\" => \"datasources\"), (\"data-source\" => \"annadb\"), (\"statistics\" => \"pool\") ]", "rolled-back" => true }

                   

                  This seems to imply that the data source was not completely defined. Check that the connection pool referenced by the "pool-name" your data source is defined properly. If you have any other questions or problems, you might try using the Console or asking in the JBoss AS7 forums.

                  • 6. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final

                    My problem was fixed by adding the driver and creating directory structure for the driver files under "AS7/modules" folder. So the database is showing up without any errors now in the console.

                     

                    I am looking into documentation for ModeShape's REST  and how to use it with repositories: "Using Repositories with REST in AS7" https://docs.jboss.org/author/display/MODE/Using+Repositories+with+REST+in+AS7

                     

                    Could you help with examples how to use ModeShape's REST with my JDBC data source? Maybe provide a few example URL REST calls similar as given in the doc "Using Repositories with REST in AS7" ? Thank you very much.

                     

                    Best Regards,

                    Anna

                    • 7. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
                      rhauch

                      My problem was fixed by adding the driver and creating directory structure for the driver files under "AS7/modules" folder. So the database is showing up without any errors now in the console.

                      Great, I'm glad it's working now.

                       

                       

                      I am looking into documentation for ModeShape's REST  and how to use it with repositories: "Using Repositories with REST in AS7" https://docs.jboss.org/author/display/MODE/Using+Repositories+with+REST+in+AS7

                       

                      Could you help with examples how to use ModeShape's REST with my JDBC data source? Maybe provide a few example URL REST calls similar as given in the doc "Using Repositories with REST in AS7" ? Thank you very much.

                       

                      The MySQL data source that you set up previously is used by the Infinispan cache to persist all information stored in the cache. A ModeShape repository uses this cache (each repository should have its own dedicated cache) to manage the nodes and properties. But how all that works is important for configuring the repository, but is irrelevant to how clients use the ModeShape repository.

                       

                      When your application uses ModeShape's JCR API, RESTful service, WebDAV service, or ModeShape's JDBC data source, your application is accessing/modifying content in the repository, and is completely independent of how the repository is configured to persist/cluster its content.

                       

                      So if you want your applications use the ModeShape RESTful service, then the documentation at https://docs.jboss.org/author/display/MODE/Using+Repositories+with+REST+in+AS7 describes all the various commands with examples. (Note that when we release ModeShape 3.0.0.Beta3 this week, we'll add a new version of the RESTful API; see https://docs.jboss.org/author/display/MODE/ModeShape%27s+REST+Service for more detail on each method and how they'll work.)

                      • 8. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final

                        I am little confused, sorry. Can ModeShape's RESTful service interface (or any other service interface from Modeshape software package) be used against JDBC datasource I have just configured? Thank you very much.

                        • 9. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
                          rhauch

                          Anna Silchenko-Wei wrote:

                           

                          I am little confused, sorry. Can ModeShape's RESTful service interface (or any other service interface from Modeshape software package) be used against JDBC datasource I have just configured? Thank you very much.

                          You're referring to the MySQL data source? No, ModeShape's RESTful service talks (via JCR API) to the repository, which talks to Infinispan, which (if configured correctly) can persist information in your MySQL data source.

                          • 10. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final

                            You are saying that ModeShape's RESTful service ... can persist information in  MySQL data source, correct?

                            • 11. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
                              rhauch

                              You are saying that ModeShape's RESTful service ... can persist information in  MySQL data source, correct?

                              Not directly. The RESTful service internally will use the JCR API to manipulate the content in the repository, and the repository will internally store that information in the database. But ModeShape will set up the schema for the database (of its own design); IOW, you cannot have ModeShape access an existing database and present that through the JCR API or RESTful API.

                               

                              Can you explain what you are trying to do?

                              • 12. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final

                                So, ModeShape's RESTful service  can persist information in database if the schema for the database (and/or database configuration setup) is in compliance with what ModeShape is expecting, correct?

                                 

                                I am trying to setup datasource(s) (preferably mysql to start with) and utilize ModeShape's for example RESTful service (or  other? - I am still reading through Modeshape's functional capabilities) for persisting data.

                                 

                                Thanks!

                                • 13. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final
                                  rhauch

                                  So, ModeShape's RESTful service  can persist information in database if the schema for the database (and/or database configuration setup) is in compliance with what ModeShape is expecting, correct?

                                  Yes. That means that no other applications can really use that database.

                                   

                                  I am trying to setup datasource(s) (preferably mysql to start with) and utilize ModeShape's for example RESTful service (or  other? - I am still reading through Modeshape's functional capabilities) for persisting data.

                                   

                                  You should think of ModeShape as a data store (like other SQL and NoSQL databases), except that it is hierarchical in nature (rather than relational, document, or key-value oriented). It is transactional and can be distributed in a cluster (for scalability, high availability, etc) where admins can expand or reduce the cluster at any time as needed; this is different than relational database and some NoSQL databases, which tend to only cluster using master-slave nodes that have to transition when the master goes down. It also has a host of other features that set it apart from most of the NoSQL databases: queries, observation, hierarchical, flexible & dynamic schema, flexible validation, structured and unstructured storage, etc.

                                   

                                  ModeShape is hierarchical in nature, which means that clients don't insert rows or documents, but rather create/read/update/modify a structure of nodes and properties. This is somewhat analogous to an application creating a structure of files and folders on the file system, except if you could attach arbitrary properties to the files; the hiearchial nature of a file system is similar to the hieararchical nature of the node structure.

                                   

                                  So with this in mind, you can use ModeShape via the JCR API (only for in-process clients to directly interact with the Node and Property objects), via the RESTful API (for remote clients via HTTP requests/responses that send/receive representations of the nodes and update the nodes and properties, which is why the RESTful service documentation is written in terms of "nodes" and "properties"), via the WebDAV API (so remote clients can mount the repository as an external file system, which represents the node structure as folders and files), or via ModeShape's JDBC driver (for in-process or remote clients that use JDBC to query the repository content via the JCR-SQL2 language and obtain tuple-based result sets like other JDBC drivers). BTW, .

                                   

                                  Note that if you use a ModeShape repository that persists its hierarchical node content in MySQL, then any and all changes you make to the node structure (via JCR, REST, or WebDAV; JDBC driver is for queries only) will be persisted in the MySQL database, where each node is represented as a row in a single table (where each row contains a key, timestamp, a BLOB value, and a few other values).

                                   

                                  I hope this helps!

                                  • 14. Re: Configuring DB connection via Infinispan in ModeShape 3.0.0.b2 in JBoss7.1.1.Final

                                    Thank you for general description of how things  it helps to understand the big picture. I have Modeshape installed and configured. I also have an additional msql datasource added as described above.

                                     

                                    Now, can I easily create a simple node (with some basic test data) in either one of available datasource?

                                     

                                    I have these data sources:

                                    ModeShapeDS

                                    java:/datasources/ModeShapeDS

                                    true

                                    annadb

                                    java:/annadb

                                    true

                                    Could you please help with actual example how to create a node? I have template URL:

                                    URL: http://<host>:<port>/<context>/<repository_name>/<workspace_name>/items/<node_path>

                                    But how actual URL would look like in my case? Could you please help with an example?

                                     

                                    Thank you very much!

                                    1 2 Previous Next