1 Reply Latest reply on Feb 20, 2012 2:05 AM by Brian Wallis

    Loading a CND and using a JPA connector

    Brian Wallis Master

      I have a simple cnd schema for a half dozen node types and I am using a jpa repository connector in modeshape 2.7.0. The node definitions do not seem to be persisted and if I try to reload them it doesn't seem to work unless I delete and recreate the database or use the "create" autoGenerateSchema value.

       

      Should the node definitions be persisted somewhere or do I need to reload them everytime I startup? If persisted, where does this happen?

       

       

      The code to load the cnd file is as follows:

       

      {code}

                  Repository repository = engine.getRepository("Harvey repository");

                  Session session = repository.login();

                  Workspace workspace = session.getWorkspace();

                  org.modeshape.jcr.api.nodetype.NodeTypeManager nodeTypeManager = (org.modeshape.jcr.api.nodetype.NodeTypeManager) workspace.getNodeTypeManager();

                  System.out.println("Parse the cnd file");

                  InputStream myCndStream = HarveyTest.class.getClassLoader().getResourceAsStream("harvey.cnd");

                  nodeTypeManager.registerNodeTypes(myCndStream, true);

                  System.out.println("File parsed");

                  System.out.println("List the new nodes");

                  NodeTypeIterator it = nodeTypeManager.getAllNodeTypes();

                  while(it.hasNext())

                  {

                            Object o = it.next();

                            NodeType nt = (NodeType)o;

                            printNodeDetails(nt,false);

                  }

      {code}

       

      My connector configuration is

       

      {code=xml}

      <?xml version="1.0" encoding="UTF-8"?>

       

      <configuration xmlns:mode="http://www.modeshape.org/1.0"

        xmlns:jcr="http://www.jcp.org/jcr/1.0">

       

        <!-- Define the JCR repositories -->

        <mode:repositories>

        <mode:repository jcr:name="Harvey repository" mode:source="JPA Store">

        <mode:options jcr:primaryType="mode:options">

        </mode:options>

        </mode:repository>

        </mode:repositories>

       

        <mode:sources jcr:primaryType="nt:unstructured">

        <mode:source jcr:name="JPA Store"

        mode:classname="org.modeshape.connector.store.jpa.JpaSource"

        mode:driverClassName="com.mysql.jdbc.Driver"

        mode:username="xxx"

        mode:password="xxxxxx"

        mode:url="jdbc:mysql://localhost:3306/mode"

        mode:maximumConnectionsInPool="5"

        mode:model="Simple"

        mode:dialect="org.hibernate.dialect.MySQL5Dialect"

        mode:referentialIntegrityEnforced="true"

        mode:largeValueSizeInBytes="10000"

        mode:retryLimit="3"

        mode:compressData="false"

        mode:predefinedWorkspaceNames="default,system"

        mode:showSql="false"

        mode:autoGenerateSchema="disable"

        mode:creatingWorkspacesAllowed="true"

        mode:defaultWorkspaceName="default">

        </mode:source>

        </mode:sources>

       

        <mode:sequencers>

        </mode:sequencers>

       

      </configuration>

      {code}

       

      If I run the code once with mode:autoGenerateSchema set to create and then a second time with it set to disable (to use the one created the first time) then the parsing and listing of the node types fails the second time.

       

      First time when I list the nodes I get (I get this every time I run it with "create" for autoGenerateSchema).

       

      {code}

      Parse the cnd file

      File parsed

      List the new nodes

      [inf:document] abstract=false mixin=false queryable=true

      inf:type(1)

      ....

      {code}

       

      If I set autogenerate schema to "validate" or "disable" or "update" and run the code again I get the following

       

      {code}

      Parse the cnd file

      File parsed

      List the new nodes

      [ns001:document] abstract=false mixin=false queryable=true

      ns001:type(1)

        ....

      {code}

       

      Note the wrong namespace value of "ns001".

       

      The cnd is:

       

      {code}

      <inf = 'http://infomedix.com.au/inf'>

       

      ....

       

      [inf:document] > nt:folder, mix:referenceable orderable

      - inf:type (STRING) mandatory

      + inf:metadata (inf:metadata)

      + inf:contents (inf:content) primary mandatory multiple

       

      ....

      {code}

        • 1. Re: Loading a CND and using a JPA connector
          Brian Wallis Master

          To answer my own question, configuring a persistent system source helps :-)

           

          I added the following to my config:

           

          {code}

            <mode:options jcr:primaryType="mode:options">

            <systemSourceName jcr:primaryType="mode:option" mode:value="system@JPA Store" />

            </mode:options>

          {code}

          So I've dumped the system namespace into the same set of DB tables as the default workspace. Not sure if it should be separate or the same.

           

          Now the cnd definitions hang around and I don't get the odd namespaces "ns001".

           

          If I try to reload the cnd with allowUpdate set to false I get a NodeTypeExists exception.

           

          All working as expected now.