Improve JCR
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 17 Jun 2010 19:51:51 +0000 (19:51 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 17 Jun 2010 19:51:51 +0000 (19:51 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@3606 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

15 files changed:
server/modules/org.argeo.server.ext.jackrabbit/.project [new file with mode: 0644]
server/modules/org.argeo.server.ext.jackrabbit/.settings/org.eclipse.pde.core.prefs [new file with mode: 0644]
server/modules/org.argeo.server.ext.jackrabbit/META-INF/MANIFEST.MF [new file with mode: 0644]
server/modules/org.argeo.server.ext.jackrabbit/build.properties [new file with mode: 0644]
server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/fs/db/sybase.ddl [new file with mode: 0644]
server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/journal/sybase.ddl [new file with mode: 0644]
server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/persistence/bundle/sybase.ddl [new file with mode: 0644]
server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/persistence/db/sybase.ddl [new file with mode: 0644]
server/modules/org.argeo.server.jdbc/.project [new file with mode: 0644]
server/modules/org.argeo.server.jdbc/.settings/org.eclipse.pde.core.prefs [new file with mode: 0644]
server/modules/org.argeo.server.jdbc/META-INF/MANIFEST.MF
server/modules/org.argeo.server.jdbc/build.properties [new file with mode: 0644]
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrResourceAdapter.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java

diff --git a/server/modules/org.argeo.server.ext.jackrabbit/.project b/server/modules/org.argeo.server.ext.jackrabbit/.project
new file mode 100644 (file)
index 0000000..e9939b5
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>org.argeo.server.ext.jackrabbit</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+       </natures>
+</projectDescription>
diff --git a/server/modules/org.argeo.server.ext.jackrabbit/.settings/org.eclipse.pde.core.prefs b/server/modules/org.argeo.server.ext.jackrabbit/.settings/org.eclipse.pde.core.prefs
new file mode 100644 (file)
index 0000000..32c9e3f
--- /dev/null
@@ -0,0 +1,4 @@
+#Tue Jun 15 19:05:36 CEST 2010
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/server/modules/org.argeo.server.ext.jackrabbit/META-INF/MANIFEST.MF b/server/modules/org.argeo.server.ext.jackrabbit/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..1b8b610
--- /dev/null
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Jackrabbit
+Bundle-SymbolicName: org.argeo.server.ext.jackrabbit
+Bundle-Version: 1.0.0.qualifier
+Fragment-Host: org.argeo.dep.osgi.jackrabbit
diff --git a/server/modules/org.argeo.server.ext.jackrabbit/build.properties b/server/modules/org.argeo.server.ext.jackrabbit/build.properties
new file mode 100644 (file)
index 0000000..5f22cdd
--- /dev/null
@@ -0,0 +1 @@
+bin.includes = META-INF/
diff --git a/server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/fs/db/sybase.ddl b/server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/fs/db/sybase.ddl
new file mode 100644 (file)
index 0000000..fb8a0e8
--- /dev/null
@@ -0,0 +1,16 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+create table ${schemaObjectPrefix}FSENTRY (FSENTRY_PATH varchar(2048) not null, FSENTRY_NAME varchar(255) not null, FSENTRY_DATA image null, FSENTRY_LASTMOD decimal(19,0) not null, FSENTRY_LENGTH decimal(19,0) not null)
+#create unique index ${schemaObjectPrefix}FSENTRY_IDX on ${schemaObjectPrefix}FSENTRY (FSENTRY_PATH, FSENTRY_NAME)
diff --git a/server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/journal/sybase.ddl b/server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/journal/sybase.ddl
new file mode 100644 (file)
index 0000000..d0f6242
--- /dev/null
@@ -0,0 +1,22 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more\r
+#  contributor license agreements.  See the NOTICE file distributed with\r
+#  this work for additional information regarding copyright ownership.\r
+#  The ASF licenses this file to You under the Apache License, Version 2.0\r
+#  (the "License"); you may not use this file except in compliance with\r
+#  the License.  You may obtain a copy of the License at\r
+#\r
+#      http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+#  Unless required by applicable law or agreed to in writing, software\r
+#  distributed under the License is distributed on an "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+#  See the License for the specific language governing permissions and\r
+#  limitations under the License.\r
+\r
+create table ${schemaObjectPrefix}JOURNAL (REVISION_ID decimal(19,0) NOT NULL, JOURNAL_ID varchar(255), PRODUCER_ID varchar(255), REVISION_DATA IMAGE)\r
+create unique index ${schemaObjectPrefix}JOURNAL_IDX on ${schemaObjectPrefix}JOURNAL (REVISION_ID)\r
+create table ${schemaObjectPrefix}GLOBAL_REVISION (REVISION_ID decimal(19,0) NOT NULL)\r
+create unique index ${schemaObjectPrefix}GLOBAL_REVISION_IDX on ${schemaObjectPrefix}GLOBAL_REVISION (REVISION_ID)\r
+\r
+# Inserting the one and only revision counter record now helps avoiding race conditions\r
+insert into ${schemaObjectPrefix}GLOBAL_REVISION VALUES(0)\r
diff --git a/server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/persistence/bundle/sybase.ddl b/server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/persistence/bundle/sybase.ddl
new file mode 100644 (file)
index 0000000..47c6b71
--- /dev/null
@@ -0,0 +1,22 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+create table ${schemaObjectPrefix}BUNDLE (NODE_ID binary(16) not null, BUNDLE_DATA image not null)
+create unique index ${schemaObjectPrefix}BUNDLE_IDX on ${schemaObjectPrefix}BUNDLE (NODE_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID binary(16) not null, REFS_DATA image not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(64) not null, BINVAL_DATA image not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
+#create table ${schemaObjectPrefix}NAMES (ID INTEGER IDENTITY(1,1) PRIMARY KEY, NAME varchar(255) COLLATE Latin1_General_CS_AS not null)
+create table ${schemaObjectPrefix}NAMES (ID INTEGER IDENTITY PRIMARY KEY, NAME varchar(255))
diff --git a/server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/persistence/db/sybase.ddl b/server/modules/org.argeo.server.ext.jackrabbit/org/apache/jackrabbit/core/persistence/db/sybase.ddl
new file mode 100644 (file)
index 0000000..2bde323
--- /dev/null
@@ -0,0 +1,22 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA image not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar(1024) not null, PROP_DATA image not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA image not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(1024) not null, BINVAL_DATA image not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
diff --git a/server/modules/org.argeo.server.jdbc/.project b/server/modules/org.argeo.server.jdbc/.project
new file mode 100644 (file)
index 0000000..283257b
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>org.argeo.server.jdbc</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+       </natures>
+</projectDescription>
diff --git a/server/modules/org.argeo.server.jdbc/.settings/org.eclipse.pde.core.prefs b/server/modules/org.argeo.server.jdbc/.settings/org.eclipse.pde.core.prefs
new file mode 100644 (file)
index 0000000..e9fc089
--- /dev/null
@@ -0,0 +1,4 @@
+#Tue Jun 15 17:44:26 CEST 2010
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
index 94f4577342828be8608ba4ef4b8d6275c1b58b9e..14fd4f1f728b6db90855e742f1589e64792ca1a6 100644 (file)
@@ -9,3 +9,4 @@ Import-Package: com.microsoft.sqlserver.jdbc;resolution:=optional,
  org.apache.derby.jdbc;resolution:=optional,
  org.hsqldb;resolution:=optional,
  org.postgresql;resolution:=optional
+Bundle-Name: Argeo Spring JDBC Extension
diff --git a/server/modules/org.argeo.server.jdbc/build.properties b/server/modules/org.argeo.server.jdbc/build.properties
new file mode 100644 (file)
index 0000000..5f22cdd
--- /dev/null
@@ -0,0 +1 @@
+bin.includes = META-INF/
index c5225204b6ab03a6de81f529f3b0580c3aaf2d3a..c0d00447d7a81b1366a2f7b139cd56cb8905818a 100644 (file)
@@ -114,14 +114,16 @@ public class JcrResourceAdapter {
 
                        Node fileNode = (Node) session().getItem(path);
                        Node contentNode = fileNode.getNode("jcr:content");
-                       fileNode.checkout();
+                       if (versioning)
+                               fileNode.checkout();
                        contentNode.setProperty("jcr:data", in);
                        Calendar lastModified = Calendar.getInstance();
                        // lastModified.setTimeInMillis(file.lastModified());
                        contentNode.setProperty("jcr:lastModified", lastModified);
 
                        session().save();
-                       fileNode.checkin();
+                       if (versioning)
+                               fileNode.checkin();
 
                        if (log.isDebugEnabled())
                                log.debug("Updated " + path);
index d3174a1cace4427be061598273b2039b529968c7..caf2abdb09cec4ff834850698c8fafcb0c568f90 100644 (file)
@@ -18,9 +18,17 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
 
+/** Utility methods to simplify common JCR operations. */
 public class JcrUtils {
        private final static Log log = LogFactory.getLog(JcrUtils.class);
 
+       /**
+        * Queries one single node.
+        * 
+        * @return one single node or null if none was found
+        * @throws ArgeoException
+        *             if more than one node was found
+        */
        public static Node querySingleNode(Query query) {
                NodeIterator nodeIterator;
                try {
@@ -40,12 +48,14 @@ public class JcrUtils {
                return node;
        }
 
+       /** Removes forbidden characters from a path, replacing them with '_' */
        public static String removeForbiddenCharacters(String str) {
                return str.replace('[', '_').replace(']', '_').replace('/', '_')
                                .replace('*', '_');
 
        }
 
+       /** Retrieves the parent path of the provided path */
        public static String parentPath(String path) {
                if (path.equals("/"))
                        throw new ArgeoException("Root path '/' has no parent path");
@@ -59,7 +69,13 @@ public class JcrUtils {
                return pathT.substring(0, index);
        }
 
+       /** The provided data as a path ('/' at the end, not the beginning) */
        public static String dateAsPath(Calendar cal) {
+               return dateAsPath(cal, false);
+       }
+
+       /** The provided data as a path ('/' at the end, not the beginning) */
+       public static String dateAsPath(Calendar cal, Boolean addHour) {
                StringBuffer buf = new StringBuffer(14);
                buf.append('Y').append(cal.get(Calendar.YEAR));// 5
                buf.append('/');// 1
@@ -74,6 +90,13 @@ public class JcrUtils {
                        buf.append(0);
                buf.append('D').append(day);// 3
                buf.append('/');// 1
+               if (addHour) {
+                       int hour = cal.get(Calendar.HOUR_OF_DAY);
+                       if (hour < 10)
+                               buf.append(0);
+                       buf.append('H').append(hour);// 3
+                       buf.append('/');// 1
+               }
                return buf.toString();
 
        }
@@ -94,10 +117,12 @@ public class JcrUtils {
                return path.substring(index + 1);
        }
 
+       /** Creates the nodes making path, if they don't exist. */
        public static Node mkdirs(Session session, String path) {
                return mkdirs(session, path, null, false);
        }
 
+       /** Creates the nodes making path, if they don't exist. */
        public static Node mkdirs(Session session, String path, String type,
                        Boolean versioning) {
                try {
@@ -164,37 +189,42 @@ public class JcrUtils {
        }
 
        /** Recursively outputs the contents of the given node. */
-       public static void debug(Node node) throws RepositoryException {
-               // First output the node path
-               log.debug(node.getPath());
-               // Skip the virtual (and large!) jcr:system subtree
-               if (node.getName().equals(ArgeoJcrConstants.JCR_SYSTEM)) {
-                       return;
-               }
+       public static void debug(Node node) {
+               try {
+                       // First output the node path
+                       log.debug(node.getPath());
+                       // Skip the virtual (and large!) jcr:system subtree
+                       if (node.getName().equals(ArgeoJcrConstants.JCR_SYSTEM)) {
+                               return;
+                       }
 
-               // Then the children nodes (recursive)
-               NodeIterator it = node.getNodes();
-               while (it.hasNext()) {
-                       Node childNode = it.nextNode();
-                       debug(childNode);
-               }
+                       // Then the children nodes (recursive)
+                       NodeIterator it = node.getNodes();
+                       while (it.hasNext()) {
+                               Node childNode = it.nextNode();
+                               debug(childNode);
+                       }
 
-               // Then output the properties
-               PropertyIterator properties = node.getProperties();
-               // log.debug("Property are : ");
-
-               while (properties.hasNext()) {
-                       Property property = properties.nextProperty();
-                       if (property.getDefinition().isMultiple()) {
-                               // A multi-valued property, print all values
-                               Value[] values = property.getValues();
-                               for (int i = 0; i < values.length; i++) {
-                                       log.debug(property.getPath() + "=" + values[i].getString());
+                       // Then output the properties
+                       PropertyIterator properties = node.getProperties();
+                       // log.debug("Property are : ");
+
+                       while (properties.hasNext()) {
+                               Property property = properties.nextProperty();
+                               if (property.getDefinition().isMultiple()) {
+                                       // A multi-valued property, print all values
+                                       Value[] values = property.getValues();
+                                       for (int i = 0; i < values.length; i++) {
+                                               log.debug(property.getPath() + "="
+                                                               + values[i].getString());
+                                       }
+                               } else {
+                                       // A single-valued property
+                                       log.debug(property.getPath() + "=" + property.getString());
                                }
-                       } else {
-                               // A single-valued property
-                               log.debug(property.getPath() + "=" + property.getString());
                        }
+               } catch (Exception e) {
+                       log.error("Could not debug " + node, e);
                }
 
        }
index 9996b7bd1f8e48e6ab6a07b1767c5f03b7300d01..f26a255abebc7fdcfee7c3f0e78213b816034b8d 100644 (file)
@@ -10,6 +10,7 @@ import java.util.List;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -62,7 +63,9 @@ public class ThreadBoundJcrSessionFactory implements FactoryBean,
 
        protected Session login() {
                try {
-                       Session sess = repository.login();
+                       SimpleCredentials sc = new SimpleCredentials("demo", "demo"
+                                       .toCharArray());
+                       Session sess = repository.login(sc);
                        if (log.isTraceEnabled())
                                log.trace("Log in to JCR session " + sess + "; userId="
                                                + sess.getUserID());