1 2 Previous Next 16 Replies Latest reply on Apr 22, 2014 10:04 AM by Randall Hauch

    help on modeshape with mangodb

    Ant DASS LEYO Newbie

      Hello,

      I'm new to modeshape and mangodb universe.

      i'm creating  a simple application java(maven based) using the ide eclipse kepler.

      i need badly a tutorial or an architecture which explains step by the process to do my appli.

      Currently i have created a repository and(idont have any idea about workspace .......) added 3 nodes to it.

      i'm blocked at the following point i want it to save the repository in a base mongodb.......

      advance thanks for your precious replies............

      cordially

      Antoni

        • 1. Re: help on modeshape with mangodb
          Randall Hauch Master

          Please read the Getting Started guide, which talks about how to configure ModeShape and Infinispan. We also have quite a few examples, though none that explicitly use only MongoDB for storage. To do that, you'll want to replace Infinispan's loader with the MongoDB loader.

          • 2. Re: help on modeshape with mangodb
            Ant DASS LEYO Newbie

            thanks for ur quick reply ; but i need more information.

            just i would like to know whether  the repositories are considered as docuemnts in mongodb .

            cdt

            • 3. Re: help on modeshape with mangodb
              Randall Hauch Master

              No, repositories are more akin to a database. Asking to store a ModeShape repository into a JSON document is like asking to store an Oracle database in a JSON document: technically you could, but it'd be entirely useless.

               

              Please read the concepts for more detail. ModeShape is a hierarchical database that contains potentially millions of nodes arranged in a tree structure. These nodes can be modified in a strongly-consistent (transactional) manner. ModeShape can (optionally) enforce structural constraints (e.g., a schema), though how much is entirely up to you. Hierarchical database are optimized for navigation of the tree structure, but you can also query the entire repository to find all nodes that satisfy a set of criteria using a SQL-like language. ModeShape has lots of other features; please see documentation.

               

              MongoDB is a document database that stores JSON documents for a given key. These documents have relationship to each other, and you cannot modify multiple documents in a single transaction because MongoDB is not strongly-consistent.

              • 4. Re: help on modeshape with mangodb
                Ant DASS LEYO Newbie

                hello,

                sorry to disturb u

                i'm confused ; Modeshape is considered as database and mongodb is also considered as a database.

                is there any basic java program demonstration.

                 

                i'm blocked at this point.

                As per my observation a repository will contain one or more workspaces ; one workspace contains several nodes in tree architecture.

                once the nodes are created we can save it in a databse that is a repository.........

                 

                here is a part of my code.

                 

                 

                   // Get the repository
                   repository = engine.getRepository(repositoryName);

                 

                   // Create a session ...
                   session = repository.login("default");

                 

                   // Create the '/files' node that is an 'nt:folder' ...
                   Node root = session.getRootNode();
                   Node filesNode = root.addNode("files", "nt:folder");

                 

                 

                 

                   Node fileNode =  filesNode.addNode("modeshape_logo.jpg", "nt:file");
                   Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
                   Binary binary = session.getValueFactory().createBinary(stream);
                   contentNode.setProperty("jcr:data", binary);
                   session.save();
                   Node doc = session.getNode("/files/modeshape_logo.jpg");  
                   Node imageContent = doc.getNode("jcr:content");

                 

                   InputStream is = content.getStream();
                   Image image = ImageIO.read(is);

                 

                 

                   /* -----Insert sur la bdd------------*/
                   MongoClient mongo = new MongoClient("localhost", 27017);
                  
                   /*---Database---*/
                   DB db = mongo.getDB("mshapedb");
                   

                DBCollection table = db.getCollection("mshptb");

                 

                   BasicDBObject document1 = new BasicDBObject();
                   document1.put("name", "Antoni2");
                   document1.put("streamreader",<<<< i would like to can i put the repsoirtory or node by node .....................>>>>>>>>); // I want to
                   table.insert(document1);
                  

                 

                 

                advance thanks .......

                ²
                • 5. Re: help on modeshape with mangodb
                  Randall Hauch Master

                  i'm confused ; Modeshape is considered as database and mongodb is also considered as a database.

                  Yes.

                  i'm confused ; Modeshape is considered as database and mongodb is also considered as a database.

                  is there any basic java program demonstration.

                   

                  Yes, we have several complete examples, plus lots of documentation.

                   

                  As per my observation a repository will contain one or more workspaces ; one workspace contains several nodes in tree architecture.

                  Yes, see here for documentation of these concepts.

                  once the nodes are created we can save it in a databse that is a repository.........

                   

                  Actually, this is maybe where you're problem is. Once you create the nodes and save the session, those nodes are persisted by ModeShape and will forever be there until you either change/remove them or destroy the persistent storage. See here for a high-level overview of ModeShape's persistence.

                   

                  here is a part of my code.

                   

                   

                    // Get the repository
                    repository = engine.getRepository(repositoryName);

                   

                    // Create a session ...
                    session = repository.login("default");

                   

                    // Create the '/files' node that is an 'nt:folder' ...
                    Node root = session.getRootNode();
                    Node filesNode = root.addNode("files", "nt:folder");

                   

                   

                   

                    Node fileNode =  filesNode.addNode("modeshape_logo.jpg", "nt:file");
                    Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
                    Binary binary = session.getValueFactory().createBinary(stream);
                    contentNode.setProperty("jcr:data", binary);
                    session.save();
                   

                  Okay, at this point you've added a "files" folder under the root (with an absolute path of "/files"), and into that you've placed a file node (at "/files/modeshape_logo.jpg") and its resource node (at "/files/modeshape_logo.jpg/jcr:content", with the content of the JPG file that was in the stream) into the repository, and you've saved this. That means that these nodes are persisted inside ModeShape using a (real) transaction.

                   

                  You can continue over time using separate sessions to add more and more nodes (for other files, customer data, medical records, whatever) to this same workspace (and/or other workspaces), and even change or remove nodes and their properties when needed. Yes, their application is adding content (nodes and properties), but it is also probably reading and using the persisted content. Isn't that the point of a database? To store data for later usage?

                   

                   

                  InputStream is = content.getStream();
                    Image image = ImageIO.read(is);

                   

                  What is "content"? Obviously it has an InputStream that you want to read, but where does it come from, and how does it relate to the nodes in the repository or even the JPG file with which you created those nodes?

                   

                  InputStream is = content.getStream();
                    Image image = ImageIO.read(is);

                   

                   

                    /* -----Insert sur la bdd------------*/
                    MongoClient mongo = new MongoClient("localhost", 27017);
                   
                    /*---Database---*/
                    DB db = mongo.getDB("mshapedb");
                    

                  DBCollection table = db.getCollection("mshptb");

                   

                    BasicDBObject document1 = new BasicDBObject();
                    document1.put("name", "Antoni2");
                    document1.put("streamreader",<<<< i would like to can i put the repsoirtory or node by node .....................>>>>>>>>); // I want to
                    table.insert(document1);
                   

                   

                  Obviously you're trying to put some kind of stream content into MongoDB, but what? Why would you want to put one kind of database content into another database?

                   

                  Please explain what you are trying to accomplish. Perhaps try explaining it using a relational database and MongoDB rather than ModeShape and MongoDB.

                  • 6. Re: help on modeshape with mangodb
                    Ant DASS LEYO Newbie

                    hello,

                     

                    the aim of the project is an electronic document management.

                    since modeshape proposes search ; addition deletion etc......

                    we have decided to use it for these services and for the storage mongodb.

                     

                    As i have no idea,  i started to create the nodes and save the workspace that contains these nodes into the database(mongodb).

                     

                     

                    i think the node can be considered as a document in mongodb(like a record in rdbmbs).

                    if it is so how can i maintian the hirerachy storage..........

                     

                    Yes, we have several complete examples, plus lots of documentation.

                    fyi the links leads to page not found 404......

                    • 7. Re: help on modeshape with mangodb
                      Randall Hauch Master

                      the aim of the project is an electronic document management.

                      since modeshape proposes search ; addition deletion etc......

                      we have decided to use it for these services and for the storage mongodb.

                       

                      Okay, that is a very good use case for ModeShape, and many people use it like that.

                       

                      When ModeShape persist its content, you can configure it to do so in a variety of places. ModeShape directly uses Infinispan, and you configure ModeShape's persistence by configuring Infinispan and its cache store. Several options are available: on local disk, in a shared relational database, in Cassandra, and others, including in MongoDB. However, as ModeShape is a transactional system, I'd be concerned about using it with MongoDB storage, which is not transactional. It's something I've not done, nor have I hear of others using it. (Again, we inherit all of Infinispan's persistence options, all of which makes sense for Infinispan but not all of which might make sense for the conservative way that ModeShape uses Infinispan.)

                       

                      As i have no idea,  i started to create the nodes and save the workspace that contains these nodes into the database(mongodb).

                       

                       

                      That's fine, as long as you configure ModeShape (and Infinispan) to store its data inside MongoDB. If you do this, then you would always access the data through ModeShape and never through MongoDB, since in doing so you would essentially access ModeShape's internal representation of the repository data, not the publicly accessible nodes and properties that ModeShape exposes.

                       

                      Yes, we have several complete examples, plus lots of documentation.

                      fyi the links leads to page not found 404......

                      Both of those links work for me, and they are publicly accessible without logins on the respective sites. Here they are again:

                       

                      https://github.com/ModeShape/modeshape-examples

                      https://docs.jboss.org/author/display/MODE/Home

                      • 8. Re: help on modeshape with mangodb
                        Ant DASS LEYO Newbie

                         

                        hello,

                         

                        Repository repository = ...

                        Session session = repository.login("assets");

                        Node root = session.getRootNode();

                         

                        // Find a node by absolute path ...

                        Node nyc = session.getNode("/facilities/NYC");

                         

                         

                         

                        I have doubt on the following explination ; as we see the the above image ...............

                         

                        // Or find a nodes by relative path ...

                        Node cargo = root.getNode("vehicles/cargo"); cargo contains the address of cargo

                         

                         

                        the"JF2SH636X9G700001" number is attached to the passenger not to cargo

                         

                        for me it should be

                        Node veh1 = cargo.getNode("JF2SH636X9G700001");

                         

                        could not get it..................

                        Node veh1 = passenger.getNode("JF2SH636X9G700001");

                         

                         

                         

                         

                        Node transit = veh1.getNode("../../transit");

                         

                        Sos Advance thanks......

                        • 9. Re: help on modeshape with mangodb
                          Randall Hauch Master

                          The diagram might be wrong.

                           

                          You may want to print the subgraph, and we provide the JcrTools utility class with methods to do this. The class is in the "modeshape-jcr-api" JAR file that your application should already be using.

                          • 10. Re: help on modeshape with mangodb
                            Ant DASS LEYO Newbie

                            hello sir,

                            Could you please valid my steps are correct.

                            i create the repository and nodes and i would like to save it in a mongodb database.

                            i saw some using infinispan configurator.xml and in pm.xml they make it point it to h2 database (their case might be h2).

                            So to summarise one creates the node child node etc .... on one side and on the other hand he creates the database and using infinispan configurator he makes a link between modeshape and mongodb.......

                             

                            advance thanks .........

                            • 11. Re: help on modeshape with mangodb
                              Randall Hauch Master

                              Yes, you have to change the Infinispan configuration as described in the link I sent earlier, changing from the loader using H2 to using MongoDB. Again, I'm not sure whether it will work, and please make sure that you set up MongoDB correctly to have the desired amount of consistency.

                               

                              Then your ModeShape configuration would be unchanged, unless you also want to store binaries in our MongoDB BinaryStore. Change from using the file system binary store to using the MongoDB binary store; see here for documentation.

                              • 12. Re: help on modeshape with mangodb
                                Ant DASS LEYO Newbie

                                hello sir,

                                Thanks for your precious information.

                                Taking into account that mangodb will not be suitable ; the decision is made that i should do it with sqlserver(via hibernate).

                                so if i'm correct i should change the connection in inifinspan towards a sqlserver.

                                and i should add dependcies in pom.xml the link sqlserver.

                                 

                                Another question in your exemple  jdbc store with h2, you have created one node but if see the infinispan config.xml( shown below) i cant see where ur linking the node into the database.

                                 

                                <namedCache name="persisted_repository">
                                    <persistence passivation="false">
                                        <stringKeyedJdbcStore xmlns="urn:infinispan:config:jdbc:6.0"
                                                fetchPersistentState="false"
                                                ignoreModifications="false"
                                                purgeOnStartup="false">
                                            <connectionPool
                                                    connectionUrl="jdbc:h2:file:target/content/db;DB_CLOSE_DELAY=-1"
                                                    driverClass="org.h2.Driver"
                                                    username="sa"/>
                                            <stringKeyedTable
                                                    prefix="ISPN_STRING_TABLE"
                                                    createOnStart="true"
                                                    dropOnExit="false">
                                                <idColumn name="ID_COLUMN" type="VARCHAR(255)"/>
                                                <dataColumn name="DATA_COLUMN" type="BINARY"/>
                                                <timestampColumn name="TIMESTAMP_COLUMN" type="BIGINT"/>
                                            </stringKeyedTable>
                                       </stringKeyedJdbcStore>

                                https://github.com/ModeShape/modeshape-examples/tree/master/modeshape-jdbc-store-example

                                 

                                any idea or exemple(staps) for inifinispan with sqlserver

                                advance thanks............

                                • 13. Re: help on modeshape with mangodb
                                  Horia Chiorean Master

                                  If you're using ModeShape 4.0.0.Alpha1: https://github.com/ModeShape/modeshape/blob/master/modeshape-jcr/src/test/resources/config/infinispan-sqlserver2008.xml

                                  If you're using ModeShape 3.x: modeshape/modeshape-jcr/src/test/resources/config/infinispan-sqlserver2008.xml at modeshape-3.7.2.Final · ModeShape/mode…

                                   

                                  If you're using 3.x, we really recommend using the latest - 3.7.2 - because it contains some fixes specifically around SQLServer.

                                   

                                  In the same "config" folder on GitHub as the above files, you should have corresponding repository JSON configuration files which show how to configure the Database Binary Store, in case you want to store binaries in SQL Server as well.

                                  • 14. Re: help on modeshape with mangodb
                                    Ant DASS LEYO Newbie

                                    thank you for your reply.

                                    i added this infinispan in the ressource. of my project...........

                                    then what should i do in pom.xml....

                                    i'm searching for a simple exemple project(maven eclipse) which shows the manipulation done in pom.xml and simple storage of an node de modeshape into the sql server and how to retreive it ?

                                    advance thanks......

                                    1 2 Previous Next