3 Replies Latest reply on Feb 11, 2014 3:15 AM by hchiorean

    Modeshape Config for MSSQL

    singhl1

      I have a working mode-shape config that works on a  Spring, Java, MSSQL, Web based system.

       

      The data is written to the file system with the following json file

       

      {

          "name": "repository",

          "jndiName": "",

          "workspaces": {

              "predefined": ["Library"],

              "default": "Library",

              "allowCreation": true

          },

          "security": {

              "anonymous": {

                  "roles": ["readonly", "readwrite", "admin"],

                  "useOnFailedLogin": true

              }

          },

          "storage": {

              "cacheName": "repository",

              "binaryStorage": {

                  "type": "file",

                  "directory": /Library/binaries"

              }

          },

          "query": {

              "enabled": true,

              "enableFullTextSearch": true,

              "indexStorage": {

                  "type": "filesystem",

                  "location": "/Library/indexes",

                  "lockingStrategy": "native",

                  "fileSystemAccessType": "auto"

              },

              "indexing": {

                  "rebuildOnStartup": {

                      "when": "if_missing",

                      "mode": "async"

                  }

              },

              "textExtracting": {

                  "extractors": {

                      "tikaExtractor": {

                          "name": "Tika content-based extractor",

                          "classname": "tika"

                      }

                  }

              }

          },

          "sequencing": {

              "removeDerivedContentWithOriginal": true,

              "sequencers": {

                  "Images in separate location": {

                      "classname": "ImageSequencer",

                      "pathExpression": "default://(*.(gif|png|pict|jpg))/jcr:content[@jcr:data] => default:/sequenced/images/$1"

                  }

              }

          },

          "node-types": ["common_mixin.cnd"]

      }

       

      And the following java code:

       

                  repositoryConfiguration = RepositoryConfiguration.read(jcrconfigresource.getFile());

       

                  // Create the Infinispan configuration via a Local Environment ...
                  ConfigurationBuilder builder = new ConfigurationBuilder();
                  Configuration cacheConfig = builder.transaction()
                          .transactionManagerLookup(getInfinispanTransactionmanager)
                          .transactionMode(TransactionMode.TRANSACTIONAL)
                          .autoCommit(true)
                          .lockingMode(LockingMode.PESSIMISTIC)
                          .loaders()
                          .passivation(false)
                          .shared(false)
                          .preload(false)
                          .addFileCacheStore()
                          .async()
                          .threadPoolSize(10)
                          .enabled(true)
                          .fetchPersistentState(false)
                          .purgeOnStartup(false)
                          .addProperty("location", "/Library/content")
                          .build();

       

                  environment = new LocalEnvironment();
                  Configuration newConfig = environment.defineCache(repositoryConfiguration.getCacheName(), cacheConfig);
                  repositoryConfiguration = repositoryConfiguration.with(environment);

       

       

      I want to change this to save everything to a database (MSSQL for production and H2 for dev/test), this means everything, the storage, query and sequencing, is this:

       

      possible?

       

      if so I have seen the post for https://github.com/ModeShape/modeshape-examples/tree/master/modeshape-jdbc-store-example

      how can this be adapted to fit my scenario. A lot of the stuff seems to be configured for filesystem - not database?

       

      Also is it possible to port an existing file based repo to this new db based repo?

       

      Many thanks in advance.

        • 1. Re: Modeshape Config for MSSQL
          rhauch

          You can definitely store your repository content (including binary values) inside a RDBMS. That example stores content, but doesn't do binary values (it probably should); see here for documentation on the database binary store, which can be configured as easily as:

           

                "binaryStorage" : {

                      "type"  : "database",

                      "driverClass" : "org.h2.Driver",

                      "url" : "jdbc:h2:mem:target/db/h2/modeshape",

                      "username" : "sa"

                  }

           

          or (if you are registering JDBC DataSource in JNDI):

           

                  "binaryStorage" : {

                      "type"  : "database",

                      "dataSourceJndiName" : "java:/myDataSource"

                  }

           

          Now, sequencing only work against changing content in a running repository, so there's nothing to configure with them about database persistence.

           

          Indexes, on the other hand, really will perform horribly if they are stored in a database. We've found it best to have each repository instance (whether in the same or in separate clustered processes) to have their own local index stored on the file system (or in memory the repository is tiny enough).

          1 of 1 people found this helpful
          • 2. Re: Modeshape Config for MSSQL
            singhl1

            Thanks Randall - that all clear.

             

             

            One further question is it possible to port an existing file based repo to this new db based repo? We  are currently file based and want to move to db, but have existing data we would want to port,

             

            Thanks in advance.

            1 of 1 people found this helpful
            • 3. Re: Modeshape Config for MSSQL
              hchiorean

              The Infinispan binary format is different between a FS store and an RDBMS store. That being said, ModeShape does offer a full backup/restore option via which it writes out all the repo content as JSON files and then re-imports those JSON files (Backup and restore - ModeShape 3 - Project Documentation Editor).

               

              So one thing you can try is:

              1. do a full backup of the repository that has the content stored on the FS
              2. change the repo config to store data in a RDBMS
              3. do a full restore using the backup files created in step (1).

               

              You can also see the way backup/restore API works here: modeshape/modeshape-jcr/src/test/java/org/modeshape/jcr/RepositoryBackupTest.java at modeshape-3.7.1.Final · ModeShape/m…