Skip to content

Commit

Permalink
TEIID-5563 removing the resource dependency from the engine
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Dec 17, 2018
1 parent b46c388 commit db7d938
Show file tree
Hide file tree
Showing 27 changed files with 330 additions and 329 deletions.
5 changes: 5 additions & 0 deletions api/pom.xml
Expand Up @@ -31,6 +31,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</dependency>

</dependencies>
</project>
132 changes: 132 additions & 0 deletions api/src/main/java/org/teiid/resource/api/XAImporter.java
@@ -0,0 +1,132 @@
/*
* Copyright Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags and
* the COPYRIGHT.txt file distributed with this work.
*
* 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.teiid.resource.api;

import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;

/**
* Provides the functionality of an XATerminator and the ability to import the relevant
* transaction.
*/
public interface XAImporter {

/**
* Provide the {@link Transaction} for the given {@link Xid}
* @param transactionManager
* @param xid
* @param transactionTimeout
* @return
* @throws XAException
*/
Transaction importTransaction(TransactionManager transactionManager, Xid xid, int transactionTimeout) throws XAException;

/**
* Commits the global transaction specified by xid.
*
* @param xid A global transaction identifier
*
* @param onePhase If true, the resource manager should use a one-phase
* commit protocol to commit the work done on behalf of xid.
*
* @exception XAException An error has occurred. Possible XAExceptions
* are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR,
* XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
*
* <P>If the resource manager did not commit the transaction and the
* parameter onePhase is set to true, the resource manager may throw
* one of the XA_RB* exceptions. Upon return, the resource manager has
* rolled back the branch's work and has released all held resources.
*/
void commit(Xid xid, boolean onePhase) throws XAException;

/**
* Tells the resource manager to forget about a heuristically
* completed transaction branch.
*
* @param xid A global transaction identifier.
*
* @exception XAException An error has occurred. Possible exception
* values are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or
* XAER_PROTO.
*/
void forget(Xid xid) throws XAException;

/**
* Ask the resource manager to prepare for a transaction commit
* of the transaction specified in xid.
*
* @param xid A global transaction identifier.
*
* @exception XAException An error has occurred. Possible exception
* values are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL,
* or XAER_PROTO.
*
* @return A value indicating the resource manager's vote on the
* outcome of the transaction. The possible values are: XA_RDONLY
* or XA_OK. These constants are defined in
* <code> javax.transaction.xa.XAResource</code> interface.
* If the resource manager wants to roll back the
* transaction, it should do so by raising an appropriate XAException
* in the prepare method.
*/
int prepare(Xid xid) throws XAException;

/**
* Obtains a list of prepared transaction branches from a resource
* manager. The transaction manager calls this method during recovery
* to obtain the list of transaction branches that are currently in
* prepared or heuristically completed states.
*
* @param flag One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS
* must be used when no other flags are set in the parameter. These
* constants are defined in <code>javax.transaction.xa.XAResource</code>
* interface.
*
* @exception XAException An error has occurred. Possible values are
* XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and XAER_PROTO.
*
* @return The resource manager returns zero or more XIDs of the
* transaction branches that are currently in a prepared or
* heuristically completed state. If an error occurs during the
* operation, the resource manager should throw the appropriate
* XAException.
*/
Xid[] recover(int flag) throws XAException;

/**
* Informs the resource manager to roll back work done on behalf
* of a transaction branch.
*
* @param xid A global transaction identifier.
*
* @exception XAException An error has occurred. Possible XAExceptions are
* XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR, XAER_RMFAIL,
* XAER_NOTA, XAER_INVAL, or XAER_PROTO.
*
* <p>If the transaction branch is already marked rollback-only the
* resource manager may throw one of the XA_RB* exceptions. Upon return,
* the resource manager has rolled back the branch's work and has released
* all held resources.
*/
void rollback(Xid xid) throws XAException;

}
4 changes: 4 additions & 0 deletions connectors/webservice/translator-ws/pom.xml
Expand Up @@ -18,6 +18,10 @@
<dependency>
<groupId>org.teiid</groupId>
<artifactId>teiid-common-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.xml.ws</groupId>
<artifactId>jboss-jaxws-api_2.3_spec</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
Expand Down
5 changes: 0 additions & 5 deletions engine/pom.xml
Expand Up @@ -86,11 +86,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.resource</groupId>
<artifactId>jboss-connector-api_1.7_spec</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
Expand Down
Expand Up @@ -27,7 +27,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

import javax.activation.DataSource;
import javax.resource.ResourceException;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.Source;
import javax.xml.transform.stax.StAXSource;
Expand Down Expand Up @@ -362,7 +361,7 @@ public synchronized void execute() throws TranslatorException {
if (connection instanceof WrappedConnection) {
try {
unwrapped = ((WrappedConnection)connection).unwrap();
} catch (ResourceException e) {
} catch (Exception e) {
throw new TranslatorException(QueryPlugin.Event.TEIID30477, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30477, this.manager.getConnectionName()));
}
}
Expand Down
Expand Up @@ -18,10 +18,6 @@

package org.teiid.dqp.internal.process;

import javax.resource.spi.work.Work;
import javax.resource.spi.work.WorkEvent;
import javax.resource.spi.work.WorkListener;

import org.teiid.logging.LogManager;


Expand All @@ -30,7 +26,7 @@
* Represents a task that performs work that may take more than one processing pass to complete.
* During processing the WorkItem may receive events asynchronously through the moreWork method.
*/
public abstract class AbstractWorkItem implements Work, WorkListener {
public abstract class AbstractWorkItem implements Runnable {

enum ThreadState {
MORE_WORK, WORKING, IDLE, DONE
Expand Down Expand Up @@ -134,24 +130,4 @@ protected void pauseProcessing() {

public abstract String toString();

@Override
public void release() {

}

@Override
public void workAccepted(WorkEvent arg0) {
}

@Override
public void workCompleted(WorkEvent arg0) {
}

@Override
public void workRejected(WorkEvent event) {
}

@Override
public void workStarted(WorkEvent arg0) {
}
}
Expand Up @@ -23,14 +23,12 @@
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

import javax.resource.spi.work.Work;

import org.teiid.dqp.internal.process.DQPCore.CompletionListener;
import org.teiid.dqp.internal.process.ThreadReuseExecutor.PrioritizedRunnable;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;

public final class FutureWork<T> extends FutureTask<T> implements PrioritizedRunnable, Work {
public final class FutureWork<T> extends FutureTask<T> implements PrioritizedRunnable {
private int priority;
private long creationTime = System.currentTimeMillis();
private DQPWorkContext workContext = DQPWorkContext.getWorkContext();
Expand Down Expand Up @@ -79,11 +77,6 @@ public DQPWorkContext getDqpWorkContext() {
return workContext;
}

@Override
public void release() {

}

synchronized void addCompletionListener(CompletionListener<T> completionListener) {
if (this.isDone()) {
completionListener.onCompletion(this);
Expand Down
Expand Up @@ -22,8 +22,6 @@
import java.nio.charset.Charset;
import java.sql.SQLException;

import javax.resource.spi.work.Work;

import org.teiid.client.lob.LobChunk;
import org.teiid.client.util.ResultsReceiver;
import org.teiid.core.TeiidComponentException;
Expand All @@ -38,7 +36,7 @@
import org.teiid.query.QueryPlugin;


public class LobWorkItem implements Work {
public class LobWorkItem implements Runnable {

private RequestWorkItem parent;
private int chunkSize;
Expand Down Expand Up @@ -135,8 +133,4 @@ synchronized void setResultsReceiver(ResultsReceiver<LobChunk> resultsReceiver)
this.resultsReceiver = resultsReceiver;
}

@Override
public void release() {

}
}
Expand Up @@ -1334,15 +1334,6 @@ public long getProcessingTimestamp() {
return processingTimestamp;
}

@Override
public void release() {
try {
requestCancel("WorkManager requested release"); //$NON-NLS-1$
} catch (TeiidComponentException e) {
LogManager.logWarning(LogConstants.CTX_DQP, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30026,requestID));
}
}

private void done() {
doneProducingBatches();
addToCache();
Expand Down
Expand Up @@ -32,8 +32,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import javax.resource.spi.work.Work;

import org.teiid.adminapi.impl.WorkerPoolStatisticsMetadata;
import org.teiid.core.util.NamedThreadFactory;
import org.teiid.logging.LogConstants;
Expand Down Expand Up @@ -77,7 +75,7 @@ public interface PrioritizedRunnable extends Runnable {

}

public static class RunnableWrapper implements PrioritizedRunnable, Work {
public static class RunnableWrapper implements PrioritizedRunnable {
Runnable r;
DQPWorkContext workContext = DQPWorkContext.getWorkContext();
long creationTime;
Expand Down Expand Up @@ -119,11 +117,6 @@ public DQPWorkContext getDqpWorkContext() {
return workContext;
}

@Override
public void release() {

}

}

private final ThreadPoolExecutor tpe;
Expand Down

0 comments on commit db7d938

Please sign in to comment.