You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by dp...@apache.org on 2005/08/08 10:11:35 UTC

svn commit: r230772 [2/2] - in /incubator/jackrabbit/trunk/contrib/jca: ./ applications/ applications/test/ deploy/ deploy/jboss/ deploy/jboss/4.x/ src/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jackrabbit/ src/java/org/apache/ja...

Added: incubator/jackrabbit/trunk/contrib/jca/src/java/org/apache/jackrabbit/jca/JCASessionHandle.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jca/src/java/org/apache/jackrabbit/jca/JCASessionHandle.java?rev=230772&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jca/src/java/org/apache/jackrabbit/jca/JCASessionHandle.java (added)
+++ incubator/jackrabbit/trunk/contrib/jca/src/java/org/apache/jackrabbit/jca/JCASessionHandle.java Mon Aug  8 01:11:09 2005
@@ -0,0 +1,330 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.jca;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.Credentials;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.InvalidSerializedDataException;
+import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.LoginException;
+import javax.jcr.NamespaceException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ValueFactory;
+import javax.jcr.Workspace;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.version.VersionException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.AccessControlException;
+
+/**
+ * This class implements the JCA implementation of session.
+ */
+public final class JCASessionHandle
+        implements Session {
+
+    /**
+     * Managed connection.
+     */
+    private JCAManagedConnection mc;
+
+    /**
+     * Construct a new session.
+     */
+    public JCASessionHandle(JCAManagedConnection mc) {
+        this.mc = mc;
+    }
+
+    /**
+     * Return the managed connection.
+     */
+    public JCAManagedConnection getManagedConnection() {
+        return mc;
+    }
+
+    /**
+     * Set the managed connection.
+     */
+    public void setManagedConnection(JCAManagedConnection mc) {
+        this.mc = mc;
+    }
+
+    /**
+     * Return the session.
+     */
+    private Session getSession() {
+        return mc.getSession(this);
+    }
+
+    /**
+     * Return the repository.
+     */
+    public Repository getRepository() {
+        return getSession().getRepository();
+    }
+
+    /**
+     * Return the user id.
+     */
+    public String getUserID() {
+        return getSession().getUserID();
+    }
+
+    /**
+     * Return the attribute.
+     */
+    public Object getAttribute(String name) {
+        return getSession().getAttribute(name);
+    }
+
+    /**
+     * Return the attribute names.
+     */
+    public String[] getAttributeNames() {
+        return getSession().getAttributeNames();
+    }
+
+    /**
+     * Return the workspace.
+     */
+    public Workspace getWorkspace() {
+        return getSession().getWorkspace();
+    }
+
+    /**
+     * Impersonate another user.
+     */
+    public Session impersonate(Credentials cred)
+            throws LoginException, RepositoryException {
+        throw new RepositoryException("impersonate(..) not supported in managed environment");
+    }
+
+    /**
+     * Return the root node.
+     */
+    public Node getRootNode()
+            throws RepositoryException {
+        return getSession().getRootNode();
+    }
+
+    /**
+     * Return node by UUID.
+     */
+    public Node getNodeByUUID(String uuid)
+            throws ItemNotFoundException, RepositoryException {
+        return getSession().getNodeByUUID(uuid);
+    }
+
+    /**
+     * Return the item.
+     */
+    public Item getItem(String arg0)
+            throws PathNotFoundException, RepositoryException {
+        return getSession().getItem(arg0);
+    }
+
+    /**
+     * Return true if item exists.
+     */
+    public boolean itemExists(String arg0)
+            throws RepositoryException {
+        return getSession().itemExists(arg0);
+    }
+
+    /**
+     * Move the item.
+     */
+    public void move(String arg0, String arg1)
+            throws ItemExistsException, PathNotFoundException, VersionException,
+            ConstraintViolationException, LockException, RepositoryException {
+        getSession().move(arg0, arg1);
+    }
+
+    /**
+     * Save the session.
+     */
+    public void save()
+            throws AccessDeniedException, ItemExistsException,
+            ConstraintViolationException, InvalidItemStateException, VersionException,
+            LockException, NoSuchNodeTypeException, RepositoryException {
+        getSession().save();
+    }
+
+    /**
+     * Refresh the session.
+     */
+    public void refresh(boolean arg0)
+            throws RepositoryException {
+        getSession().refresh(arg0);
+    }
+
+    /**
+     * Return true if it has pending changes.
+     */
+    public boolean hasPendingChanges()
+            throws RepositoryException {
+        return getSession().hasPendingChanges();
+    }
+
+    /**
+     * Return the value factory.
+     */
+    public ValueFactory getValueFactory()
+            throws UnsupportedRepositoryOperationException, RepositoryException {
+        return getSession().getValueFactory();
+    }
+
+    /**
+     * Check permission.
+     */
+    public void checkPermission(String arg0, String arg1)
+            throws AccessControlException, RepositoryException {
+        getSession().checkPermission(arg0, arg1);
+    }
+
+    /**
+     * Return the import content handler.
+     */
+    public ContentHandler getImportContentHandler(String arg0, int arg1)
+            throws PathNotFoundException, ConstraintViolationException, VersionException,
+            LockException, RepositoryException {
+        return getSession().getImportContentHandler(arg0, arg1);
+    }
+
+    /**
+     * Import XML content.
+     */
+    public void importXML(String arg0, InputStream arg1, int arg2)
+            throws IOException, PathNotFoundException, ItemExistsException,
+            ConstraintViolationException, VersionException, InvalidSerializedDataException,
+            LockException, RepositoryException {
+        getSession().importXML(arg0, arg1, arg2);
+    }
+
+    /**
+     * Export system view.
+     */
+    public void exportSystemView(String arg0, ContentHandler arg1, boolean arg2, boolean arg3)
+            throws PathNotFoundException, SAXException, RepositoryException {
+        getSession().exportSystemView(arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * Export system view.
+     */
+    public void exportSystemView(String arg0, OutputStream arg1, boolean arg2, boolean arg3)
+            throws IOException, PathNotFoundException, RepositoryException {
+        getSession().exportSystemView(arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * Export document view.
+     */
+    public void exportDocumentView(String arg0, ContentHandler arg1, boolean arg2, boolean arg3)
+            throws PathNotFoundException, SAXException, RepositoryException {
+        getSession().exportDocumentView(arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * Export document view.
+     */
+    public void exportDocumentView(String arg0, OutputStream arg1, boolean arg2, boolean arg3)
+            throws IOException, PathNotFoundException, RepositoryException {
+        getSession().exportDocumentView(arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * Set namespace prefix.
+     */
+    public void setNamespacePrefix(String arg0, String arg1)
+            throws NamespaceException, RepositoryException {
+        getSession().setNamespacePrefix(arg0, arg1);
+    }
+
+    /**
+     * Return namespace prefixes.
+     */
+    public String[] getNamespacePrefixes()
+            throws RepositoryException {
+        return getSession().getNamespacePrefixes();
+    }
+
+    /**
+     * Return namespace URI.
+     */
+    public String getNamespaceURI(String arg0)
+            throws NamespaceException, RepositoryException {
+        return getSession().getNamespaceURI(arg0);
+    }
+
+    /**
+     * Return namespace prefix.
+     */
+    public String getNamespacePrefix(String arg0)
+            throws NamespaceException, RepositoryException {
+        return getSession().getNamespacePrefix(arg0);
+    }
+
+    /**
+     * Logout the session.
+     */
+    public void logout() {
+        mc.closeHandle(this);
+    }
+
+    /**
+     * Return true if session is live.
+     */
+    public boolean isLive() {
+        return getSession().isLive();
+    }
+
+    /**
+     * Add lock token.
+     */
+    public void addLockToken(String arg0) {
+        getSession().addLockToken(arg0);
+    }
+
+    /**
+     * Return the lock tokens.
+     */
+    public String[] getLockTokens() {
+        return getSession().getLockTokens();
+    }
+
+    /**
+     * Remove lock token.
+     */
+    public void removeLockToken(String arg0) {
+        getSession().removeLockToken(arg0);
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jca/src/java/org/apache/jackrabbit/jca/JCASessionHandle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jca/src/rar/META-INF/ra.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jca/src/rar/META-INF/ra.xml?rev=230772&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jca/src/rar/META-INF/ra.xml (added)
+++ incubator/jackrabbit/trunk/contrib/jca/src/rar/META-INF/ra.xml Mon Aug  8 01:11:09 2005
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE connector PUBLIC
+    '-//Sun Microsystems, Inc.//DTD Connector 1.0//EN'
+    'http://java.sun.com/dtd/connector_1_0.dtd'>
+<connector>
+    <display-name>Jackrabbit JCR Adapter</display-name>
+    <vendor-name>Apache.org</vendor-name>
+    <spec-version>1.0</spec-version>
+    <eis-type>JCR Adapter</eis-type>
+    <version>1.0</version>
+    
+    <license>
+	<description>ASF</description>
+	<license-required>false</license-required>
+    </license>
+
+    <resourceadapter>
+	<managedconnectionfactory-class>org.apache.jackrabbit.jca.JCAManagedConnectionFactory</managedconnectionfactory-class>
+	<connectionfactory-interface>javax.jcr.Repository</connectionfactory-interface>
+	<connectionfactory-impl-class>org.apache.jackrabbit.jca.JCARepositoryHandle</connectionfactory-impl-class>
+	<connection-interface>javax.jcr.Session</connection-interface>
+	<connection-impl-class>org.apache.jackrabbit.jca.JCASessionHandle</connection-impl-class>
+	<transaction-support>XATransaction</transaction-support>
+	<config-property>
+	    <config-property-name>HomeDir</config-property-name>
+	    <config-property-type>java.lang.String</config-property-type>
+	</config-property>
+	<config-property>
+	    <config-property-name>ConfigFile</config-property-name>
+	    <config-property-type>java.lang.String</config-property-type>
+	</config-property>
+	<reauthentication-support>false</reauthentication-support>	
+    </resourceadapter>
+</connector>
+	   
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jca/src/rar/META-INF/ra.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/AbstractTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/AbstractTestCase.java?rev=230772&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/AbstractTestCase.java (added)
+++ incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/AbstractTestCase.java Mon Aug  8 01:11:09 2005
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.jca.test;
+
+import junit.framework.TestCase;
+import org.apache.jackrabbit.jca.JCAManagedConnectionFactory;
+
+import javax.jcr.Credentials;
+import javax.jcr.SimpleCredentials;
+
+/**
+ * This implements the abstract test case.
+ */
+public abstract class AbstractTestCase
+        extends TestCase {
+
+    /**
+     * Repository home directory.
+     */
+    public final static String JCR_HOME_DIR =
+            "applications/test";
+
+    /**
+     * Repository configuration file.
+     */
+    public final static String JCR_CONFIG_FILE =
+            "applications/test/repository.xml";
+
+    /**
+     * Default credentials.
+     */
+    public final static Credentials JCR_SUPERUSER =
+            new SimpleCredentials("superuser", new char[0]);
+
+    /**
+     * Anonymous credentials.
+     */
+    public final static Credentials JCR_ANONUSER =
+            new SimpleCredentials("anonymous", new char[0]);
+
+    /**
+     * Repository workspace.
+     */
+    public final static String JCR_WORKSPACE =
+            "default";
+
+    /**
+     * Managed connection factory.
+     */
+    protected JCAManagedConnectionFactory mcf;
+
+    /**
+     * Setup the test.
+     */
+    protected void setUp()
+            throws Exception {
+        // Construct the managed connection factory
+        this.mcf = new JCAManagedConnectionFactory();
+        this.mcf.setHomeDir("c:\\dev\\jcr");
+        this.mcf.setConfigFile("c:\\dev\\jcr\\repository.xml");
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/AbstractTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java?rev=230772&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java (added)
+++ incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java Mon Aug  8 01:11:09 2005
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.jca.test;
+
+import org.apache.jackrabbit.jca.JCAConnectionRequestInfo;
+import org.apache.jackrabbit.jca.JCARepositoryHandle;
+import org.apache.jackrabbit.jca.JCASessionHandle;
+
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.naming.Referenceable;
+import javax.resource.spi.ManagedConnection;
+import java.io.Serializable;
+import java.util.HashSet;
+
+/**
+ * This case executes tests on the connection factory.
+ */
+public final class ConnectionFactoryTest
+        extends AbstractTestCase {
+
+    /**
+     * Test the connection factory allocation.
+     */
+    public void testAllocation()
+            throws Exception {
+
+        // Create the connection factory
+        Object cf = mcf.createConnectionFactory();
+        assertTrue(cf instanceof JCARepositoryHandle);
+        Repository repository = (Repository) cf;
+
+        // Open a new session
+        Session session = repository.login(JCR_SUPERUSER);
+        assertTrue(session != null);
+        assertTrue(session instanceof JCASessionHandle);
+
+        // Logout session
+        session.logout();
+    }
+
+    /**
+     * Test the connection matching.
+     */
+    public void testMatching()
+            throws Exception {
+
+        // Create connection request infos
+        JCAConnectionRequestInfo cri1 = new JCAConnectionRequestInfo(JCR_SUPERUSER, JCR_WORKSPACE);
+        JCAConnectionRequestInfo cri2 = new JCAConnectionRequestInfo(JCR_ANONUSER, JCR_WORKSPACE);
+
+        // Check if not same
+        assertNotSame(cri1, cri2);
+
+        // Allocate connections
+        ManagedConnection mc1 = mcf.createManagedConnection(null, cri1);
+        ManagedConnection mc2 = mcf.createManagedConnection(null, cri2);
+
+        // Check if not same
+        assertTrue(mc1 != mc2);
+
+        // Create a sef of connections
+        HashSet connectionSet = new HashSet();
+        connectionSet.add(mc1);
+        connectionSet.add(mc2);
+        
+        // Match the first connection
+        JCAConnectionRequestInfo cri3 = new JCAConnectionRequestInfo(cri1);
+        assertTrue((cri1 != cri3) && cri1.equals(cri3));
+        ManagedConnection mc3 = mcf.matchManagedConnections(connectionSet, null, cri3);
+        assertTrue(mc1 == mc3);
+
+        // Match the second connection
+        JCAConnectionRequestInfo cri4 = new JCAConnectionRequestInfo(cri2);
+        assertTrue((cri2 != cri4) && cri2.equals(cri4));
+        ManagedConnection mc4 = mcf.matchManagedConnections(connectionSet, null, cri4);
+        assertTrue(mc2 == mc4);
+    }
+
+    /**
+     * Test if the connection factory is serializable.
+     */
+    public void testSerializable()
+            throws Exception {
+
+        // Create the connection factory
+        Object cf = mcf.createConnectionFactory();
+        
+        // Check if serializable and referenceable
+        assertTrue(cf != null);
+        assertTrue(cf instanceof Serializable);
+        assertTrue(cf instanceof Referenceable);
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jca/src/test/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native