Skip to content

Commit

Permalink
MODE-2545 Removes XA support for JcrSession and refactors a bunch of …
Browse files Browse the repository at this point in the history
…transaction-related code
  • Loading branch information
Horia Chiorean committed Dec 10, 2015
1 parent e75ebbc commit a4e5a3e
Show file tree
Hide file tree
Showing 28 changed files with 329 additions and 519 deletions.
2 changes: 1 addition & 1 deletion modeshape-jca-rar/src/main/resources/META-INF/ra.xml
Expand Up @@ -49,7 +49,7 @@
<connection-interface>javax.jcr.Session</connection-interface>
<connection-impl-class>org.modeshape.jca.JcrSessionHandle</connection-impl-class>
</connection-definition>
<transaction-support>XATransaction</transaction-support>
<transaction-support>LocalTransaction</transaction-support>
<reauthentication-support>false</reauthentication-support>
</outbound-resourceadapter>
</resourceadapter>
Expand Down
@@ -0,0 +1,77 @@
/*
* ModeShape (http://www.modeshape.org)
*
* 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.modeshape.jca;

import javax.resource.ResourceException;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.LocalTransactionException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import org.modeshape.common.annotation.Immutable;
import org.modeshape.jcr.txn.Transactions;

/**
* ModeShape's JCA implementation of a {@link javax.resource.spi.LocalTransaction}.
*
* @author Horia Chiorean (hchiorea@redhat.com)
*/
@Immutable
public final class JcrLocalTransaction implements LocalTransaction {

private final Transactions transactions;

protected JcrLocalTransaction(Transactions transactions) {
this.transactions = transactions;
}

@Override
public void begin() throws ResourceException {
try {
transactions.begin();
} catch (NotSupportedException | SystemException e) {
throw new LocalTransactionException(e);
}
}

@Override
public void commit() throws ResourceException {
try {
final Transactions.Transaction transaction = transactions.currentModeShapeTransaction();
if (transaction == null) {
throw new LocalTransactionException("A local transaction does not exist");
}
transaction.commit();
} catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException e) {
throw new LocalTransactionException(e);
}
}

@Override
public void rollback() throws ResourceException {
final Transactions.Transaction transaction = transactions.currentModeShapeTransaction();
if (transaction == null) {
throw new LocalTransactionException("A local transaction does not exist");
}
try {
transaction.rollback();
} catch (SystemException e) {
throw new LocalTransactionException(e);
}
}
}
Expand Up @@ -30,8 +30,9 @@
import javax.resource.spi.ManagedConnectionMetaData;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;

import org.modeshape.common.logging.Logger;
import org.modeshape.jcr.JcrSession;
import org.modeshape.jcr.txn.Transactions;


/**
Expand All @@ -56,7 +57,8 @@ public class JcrManagedConnection implements ManagedConnection {
private final List<ConnectionEventListener> listeners = new CopyOnWriteArrayList<ConnectionEventListener>();

private final JcrConnectionRequestInfo cri;
private Session session;
private JcrSession session;
private Transactions transactions;

// Handles.
private final List<JcrSessionHandle> handles = new CopyOnWriteArrayList<JcrSessionHandle>();
Expand All @@ -76,6 +78,7 @@ public JcrManagedConnection( JcrManagedConnectionFactory mcf,

// init repository and open session
this.session = openSession();
this.transactions = session.getRepository().transactions();
}

/**
Expand Down Expand Up @@ -120,11 +123,11 @@ private void removeHandle( JcrSessionHandle handle ) {
* @return new JCR session handle object.
* @throws ResourceException if there is an error opening the session
*/
private Session openSession() throws ResourceException {
private JcrSession openSession() throws ResourceException {
try {
Repository repo = mcf.getRepository();
Session s = repo.login(cri.getCredentials(), cri.getWorkspace());
return s;
return (JcrSession) s;
} catch (RepositoryException e) {
throw new ResourceException("Failed to create session: " + e.getMessage(), e);
}
Expand Down Expand Up @@ -172,6 +175,7 @@ public void associateConnection( Object connection ) throws ResourceException {
public void cleanup() throws ResourceException {
this.session.logout();
this.session = openSession();
this.transactions = session.getRepository().transactions();
this.handles.clear();
}

Expand Down Expand Up @@ -229,7 +233,7 @@ protected void closeHandle( JcrSessionHandle handle ) {
/**
* Gets the log writer for this ManagedConnection instance.
*
* @return Character ourput stream associated with this Managed-Connection instance
* @return Character output stream associated with this Managed-Connection instance
* @throws ResourceException generic exception if operation fails
*/
@Override
Expand All @@ -256,7 +260,7 @@ public void setLogWriter( PrintWriter out ) throws ResourceException {
*/
@Override
public LocalTransaction getLocalTransaction() throws ResourceException {
return null;
return new JcrLocalTransaction(transactions);
}

/**
Expand All @@ -267,7 +271,7 @@ public LocalTransaction getLocalTransaction() throws ResourceException {
*/
@Override
public XAResource getXAResource() throws ResourceException {
return (XAResource)session;
throw new UnsupportedOperationException("ModeShape 5 does not support XA");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modeshape-jca/src/test/resources/ironjacamar.xml
Expand Up @@ -27,7 +27,7 @@
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema
http://www.jboss.org/ironjacamar/schema/ironjacamar_1_0.xsd">

<transaction-support>XATransaction</transaction-support>
<transaction-support>LocalTransaction</transaction-support>

<connection-definitions>
<connection-definition class-name="org.modeshape.jca.JcrManagedConnectionFactory" jndi-name="java:/eis/JcrCciConnectionFactory" pool-name="JcrCciConnectionFactory">
Expand Down
33 changes: 8 additions & 25 deletions modeshape-jcr/src/main/java/org/modeshape/jcr/JcrRepository.java
Expand Up @@ -103,12 +103,10 @@
import org.modeshape.jcr.cache.NodeCache;
import org.modeshape.jcr.cache.NodeKey;
import org.modeshape.jcr.cache.RepositoryCache;
import org.modeshape.jcr.cache.RepositoryEnvironment;
import org.modeshape.jcr.cache.SessionCache;
import org.modeshape.jcr.cache.WorkspaceNotFoundException;
import org.modeshape.jcr.cache.document.DocumentStore;
import org.modeshape.jcr.cache.document.LocalDocumentStore;
import org.modeshape.jcr.cache.document.TransactionalWorkspaceCaches;
import org.modeshape.jcr.clustering.ClusteringService;
import org.modeshape.jcr.federation.FederatedDocumentStore;
import org.modeshape.jcr.journal.ChangeJournal;
Expand Down Expand Up @@ -420,6 +418,10 @@ protected final boolean doShutdown(boolean rollback) {
return true;
}

public Transactions transactions() {
return runningState().transactions;
}

protected final IndexManager getIndexManager() {
return runningState().queryManager().getIndexManager();
}
Expand Down Expand Up @@ -685,13 +687,8 @@ public synchronized JcrSession login( final Credentials credentials,
SecurityContext securityContext = sessionContext.getSecurityContext();
boolean writable = JcrSession.hasRole(securityContext, ModeShapeRoles.READWRITE, repoName, workspaceName)
|| JcrSession.hasRole(securityContext, ModeShapeRoles.ADMIN, repoName, workspaceName);
JcrSession session = null;
if (running.useXaSessions()) {
session = new JcrXaSession(this, workspaceName, sessionContext, attributes, !writable);
} else {
session = new JcrSession(this, workspaceName, sessionContext, attributes, !writable);
}

JcrSession session = new JcrSession(this, workspaceName, sessionContext, attributes, !writable);

// Need to make sure that the user has access to this session
session.checkWorkspacePermission(workspaceName, ModeShapePermissions.READ);
running.addSession(session, false);
Expand Down Expand Up @@ -931,8 +928,8 @@ protected class RunningState {
private final ExecutionContext context;
private final ExecutionContext internalWorkerContext;
private final ReadWriteLock activeSessionLock = new ReentrantReadWriteLock();
private final WeakHashMap<JcrSession, Object> activeSessions = new WeakHashMap<JcrSession, Object>();
private final WeakHashMap<JcrSession, Object> internalSessions = new WeakHashMap<JcrSession, Object>();
private final WeakHashMap<JcrSession, Object> activeSessions = new WeakHashMap<>();
private final WeakHashMap<JcrSession, Object> internalSessions = new WeakHashMap<>();
private final RepositoryStatistics statistics;
private final RepositoryStatisticsBean mbean;
private final BinaryStore binaryStore;
Expand All @@ -944,7 +941,6 @@ protected class RunningState {
private final TextExtractors extractors;
private final ChangeBus changeBus;
private final ExecutorService changeDispatchingQueue;
private final boolean useXaSessions;
private final MimeTypeDetector mimeTypeDetector;
private final BackupService backupService;
private final InitialContentImporter initialContentImporter;
Expand Down Expand Up @@ -1164,8 +1160,6 @@ protected RunningState( JcrRepository.RunningState other,
this.statistics.set(ValueMetric.WORKSPACE_COUNT, cache.getWorkspaceNames().size());
}

this.useXaSessions = this.transactions instanceof SynchronizedTransactions;

if (other != null && !change.securityChanged) {
this.authenticators = other.authenticators;
this.anonymousCredentialsIfSuppliedCredentialsFail = other.anonymousCredentialsIfSuppliedCredentialsFail;
Expand Down Expand Up @@ -1383,10 +1377,6 @@ protected final Sequencers sequencers() {
return sequencers;
}

protected final boolean useXaSessions() {
return useXaSessions;
}

final String name() {
return repositoryName();
}
Expand Down Expand Up @@ -1878,14 +1868,12 @@ void resumeExistingUserTransaction() throws SystemException {
}

protected class JcrRepositoryEnvironment implements RepositoryEnvironment {
private final TransactionalWorkspaceCaches transactionalWorkspaceCacheFactory;
private final Transactions transactions;
private final String journalId;

protected JcrRepositoryEnvironment( Transactions transactions,
String journalId ) {
this.transactions = transactions;
this.transactionalWorkspaceCacheFactory = new TransactionalWorkspaceCaches(transactions);
this.journalId = journalId;
}

Expand All @@ -1894,11 +1882,6 @@ public Transactions getTransactions() {
return transactions;
}

@Override
public TransactionalWorkspaceCaches getTransactionalWorkspaceCacheFactory() {
return transactionalWorkspaceCacheFactory;
}

@Override
public String journalId() {
return journalId;
Expand Down
101 changes: 0 additions & 101 deletions modeshape-jcr/src/main/java/org/modeshape/jcr/JcrXaSession.java

This file was deleted.

0 comments on commit a4e5a3e

Please sign in to comment.