jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r725696 - in /jackrabbit/sandbox/jackrabbit-jdbc2jcr/src: main/java/org/apache/jackrabbit/jdbc/ test/java/org/apache/jackrabbit/jdbc/
Date Thu, 11 Dec 2008 14:25:20 GMT
Author: jukka
Date: Thu Dec 11 06:25:20 2008
New Revision: 725696

URL: http://svn.apache.org/viewvc?rev=725696&view=rev
Log:
jdbc2jcr: More work on the view configuration mechanism. Tests pass again.

Added:
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/jdbc.cnd
  (with props)
Modified:
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRColumn.java
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRConnection.java
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRView.java
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/JCRDriverTest.java

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRColumn.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRColumn.java?rev=725696&r1=725695&r2=725696&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRColumn.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRColumn.java
Thu Dec 11 06:25:20 2008
@@ -20,6 +20,7 @@
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.sql.SQLException;
+import java.sql.Types;
 import java.util.Calendar;
 
 import javax.jcr.Node;
@@ -62,6 +63,26 @@
         return type;
     }
 
+    public String getColumnTypeName() {
+        switch (type) {
+        case Types.ARRAY:
+            return "VARCHAR(1000)";
+            // return "ARRAY"; // TODO How to handle this?
+        case Types.BIGINT:
+            return "BIGINT";
+        case Types.BLOB:
+            return "BLOB";
+        case Types.BOOLEAN:
+            return "BOOLEAN";
+        case Types.DOUBLE:
+            return "DOUBLE";
+        case Types.TIMESTAMP:
+            return "TIMESTAMP";
+        default:
+            return "VARCHAR(1000)";
+        }
+    }
+
     public boolean isNullable() {
         return nullable;
     }

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRConnection.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRConnection.java?rev=725696&r1=725695&r2=725696&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRConnection.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRConnection.java
Thu Dec 11 06:25:20 2008
@@ -82,7 +82,7 @@
     private void createViews() throws SQLException {
         Statement statement = getDelegate().createStatement();
         try {
-            String jdbc = session.getNamespacePrefix("jdbc");
+            String jdbc = session.getNamespacePrefix(JCRDriver.JDBC_NAMESPACE);
             QueryManager manager = session.getWorkspace().getQueryManager();
             Query query = manager.createQuery(
                     "//element(*," + jdbc + ":view)", Query.XPATH);
@@ -92,7 +92,8 @@
                 try {
                     createView(statement, node);
                 } catch (RepositoryException e) {
-                    // TODO: log warning
+                    // TODO: better handling of the error
+                    e.printStackTrace();
                 }
             }
         } catch (RepositoryException e) {
@@ -105,20 +106,11 @@
 
     private void createView(Statement statement, Node node)
             throws SQLException, RepositoryException {
-        String name = node.getName();
-        String query = node.getProperty("jdbc:query").getString();
-        String columns = node.getProperty("columns").getString();
-        statement.executeUpdate(
-                "CREATE FUNCTION jcr_sql( statement VARCHAR(1000) )"
-                + " RETURNS TABLE ("
-                + " jcr_path VARCHAR(1000)"
-                + " ) LANGUAGE JAVA"
-                + " PARAMETER STYLE DERBY_JDBC_RESULT_SET"
-                + " NO SQL EXTERNAL NAME"
-                + " 'org.apache.jackrabbit.jdbc.JCRResultSet.jcrSQL'");
-        statement.executeUpdate(
-                "CREATE VIEW nt_base AS SELECT * FROM TABLE"
-                + " (jcr_sql('SELECT jcr:path FROM nt:base')) nodes");
+        JCRView view = new JCRView(node);
+        views.put(view.getName(), view);
+        statement.executeUpdate(view.getFunctionSQL());
+        statement.executeUpdate(view.getViewSQL(
+                tmp.getPath(), view.getName()));
     }
 
     public JCRView getView(String key) throws SQLException {

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java?rev=725696&r1=725695&r2=725696&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
Thu Dec 11 06:25:20 2008
@@ -27,6 +27,9 @@
 
 public class JCRDriver extends EmbeddedDriver {
 
+    public static final String JDBC_NAMESPACE =
+        "http://jackrabbit.apache.org/ns/2008/jdbc";
+
     @Override
     public Connection connect(String url, Properties info) throws SQLException {
         try {

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRView.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRView.java?rev=725696&r1=725695&r2=725696&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRView.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRView.java
Thu Dec 11 06:25:20 2008
@@ -78,7 +78,7 @@
         columns.add(new JCRColumn(
                 "jcr_mixinTypes", "jcr:mixinTypes", Types.ARRAY, false));
 
-        String jdbc = session.getNamespacePrefix("jdbc");
+        String jdbc = session.getNamespacePrefix(JCRDriver.JDBC_NAMESPACE);
         NodeIterator nodes = node.getNodes();
         while (nodes.hasNext()) {
             Node column = nodes.nextNode();
@@ -131,6 +131,52 @@
         }
     }
 
+    public String getName() {
+        return name;
+    }
+
+    public String getFunctionSQL() {
+        StringBuilder builder = new StringBuilder("CREATE FUNCTION jdbc2jcr_");
+        builder.append(getName()); // TODO escape
+        builder.append(" ( connectionKey VARCHAR(100), viewKey VARCHAR(100) )");
+        builder.append(" RETURNS TABLE (");
+
+        int i = 0;
+        for (JCRColumn column : columns) {
+            if (i++ > 0) {
+                builder.append(",");
+            }
+            builder.append(" ");
+            builder.append(column.getColumnName()); // TODO escape
+            builder.append(" ");
+            builder.append(column.getColumnTypeName());
+        }
+
+        builder.append(" )");
+        builder.append(" LANGUAGE JAVA");
+        builder.append(" PARAMETER STYLE DERBY_JDBC_RESULT_SET");
+        builder.append(" NO SQL");
+        builder.append(" EXTERNAL NAME");
+        builder.append(" 'org.apache.jackrabbit.jdbc.JCRResultSet.jcrQuery'");
+
+        System.out.println(builder);
+        return builder.toString();
+    }
+
+    public String getViewSQL(String connection, String view) {
+        StringBuilder builder = new StringBuilder("CREATE VIEW ");
+        builder.append(getName());
+        builder.append(" AS SELECT * FROM TABLE (jdbc2jcr_");
+        builder.append(getName());
+        builder.append("('");
+        builder.append(connection); // TODO: escape
+        builder.append("', '");
+        builder.append(view); // TODO: escape
+        builder.append("')) nodes");
+        System.out.println(builder);
+        return builder.toString();
+    }
+
     public int findColumn(String columnLabel) throws SQLException {
         int index = 1;
         for (JCRColumn column : columns) {
@@ -207,6 +253,10 @@
         return getColumn(column).getColumnType();
     }
 
+    public String getColumnTypeName(int column) throws SQLException {
+        return getColumn(column).getColumnTypeName();
+    }
+
     public int isNullable(int column) throws SQLException {
         if (getColumn(column).isNullable()) {
             return columnNullable;
@@ -221,26 +271,6 @@
         return getColumnName(column);
     }
 
-    public String getColumnTypeName(int column) throws SQLException {
-        // Use just the fixed set of types form JCRColumn
-        switch (getColumnType(column)) {
-        case Types.ARRAY:
-            return "ARRAY";
-        case Types.BIGINT:
-            return "BIGINT";
-        case Types.BLOB:
-            return "BLOB";
-        case Types.BOOLEAN:
-            return "BOOLEAN";
-        case Types.DOUBLE:
-            return "DOUBLE";
-        case Types.TIMESTAMP:
-            return "TIMESTAMP";
-        default:
-            return "VARCHAR";
-        }
-    }
-
     public String getColumnClassName(int column) throws SQLException {
         // Use just the fixed set of types form JCRColumn
         switch (getColumnType(column)) {

Added: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/jdbc.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/jdbc.cnd?rev=725696&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/jdbc.cnd
(added)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/jdbc.cnd
Thu Dec 11 06:25:20 2008
@@ -0,0 +1,5 @@
+<jdbc = 'http://jackrabbit.apache.org/ns/2008/jdbc'>
+
+[jdbc:view] > nt:unstructured
+
+[jdbc:column] > nt:unstructured

Propchange: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/jdbc.cnd
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java?rev=725696&r1=725695&r2=725696&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
Thu Dec 11 06:25:20 2008
@@ -27,6 +27,7 @@
 import javax.jcr.SimpleCredentials;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.testng.annotations.AfterSuite;
@@ -70,6 +71,16 @@
             Node root = session.getRootNode();
             Node test = root.addNode("test");
             test.setProperty("text", "Hello");
+
+            JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager)
+                session.getWorkspace().getNodeTypeManager();
+            manager.registerNodeTypes(
+                    JCRDriver.class.getResourceAsStream("jdbc.cnd"),
+                    JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+            Node views = root.addNode("views");
+            Node allNodes = views.addNode("all_nodes", "jdbc:view");
+            Node ntBase = views.addNode("nt_base", "jdbc:view");
+
             session.save();
         } finally {
             session.logout();

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/JCRDriverTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/JCRDriverTest.java?rev=725696&r1=725695&r2=725696&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/JCRDriverTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/JCRDriverTest.java
Thu Dec 11 06:25:20 2008
@@ -33,13 +33,13 @@
             Statement statement = connection.createStatement();
             try {
                 ResultSet rs = statement.executeQuery(
-                        "SELECT a.jcr_path as path, COUNT(*) as children"
+                        "SELECT a.jcr_path as path, a.jcr_primaryType as type,  COUNT(*)
as children"
                         + " FROM nt_base AS a JOIN nt_base AS b"
                         + " ON (a.jcr_path || '/' = SUBSTR(b.jcr_path, 1, LENGTH(a.jcr_path)
+ 1))"
-                        + " GROUP BY a.jcr_path");
+                        + " GROUP BY a.jcr_path, a.jcr_primaryType");
                 try {
                     while (rs.next()) {
-                        System.out.println(rs.getString(1) + " has " + rs.getInt(2) + " descendants");
+                        System.out.println(rs.getString(1) + "(" + rs.getString(2) + ") has
" + rs.getInt(3) + " descendants");
                     }
                 } finally {
                     rs.close();



Mime
View raw message