Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.
*/

package org.apache.ignite.internal.transactions.proxy;

import org.apache.ignite.client.ClientTransaction;
import org.apache.ignite.internal.util.typedef.internal.S;

/**
* Represents {@link TransactionProxy} implementation that uses {@link ClientTransaction} to perform transaction
* operations.
*/
public class ClientTransactionProxy implements TransactionProxy {
/** */
private final ClientTransaction tx;

/** */
public ClientTransactionProxy(ClientTransaction tx) {
this.tx = tx;
}

/** {@inheritDoc} */
@Override public void commit() {
tx.commit();
}

/** {@inheritDoc} */
@Override public void rollback() {
tx.rollback();
}

/** {@inheritDoc} */
@Override public void close() {
tx.close();
}

/** {@inheritDoc} */
@Override public boolean setRollbackOnly() {
throw new UnsupportedOperationException("Operation is not supported by thin client.");
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(ClientTransactionProxy.class, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.
*/

package org.apache.ignite.internal.transactions.proxy;

import org.apache.ignite.client.ClientTransactions;
import org.apache.ignite.transactions.TransactionConcurrency;
import org.apache.ignite.transactions.TransactionIsolation;

/**
* Represents {@link TransactionProxyFactory} implementation that uses Ignite thin client transaction facade to start
* new transaction.
*/
public class ClientTransactionProxyFactory implements TransactionProxyFactory {
/** */
private final ClientTransactions txs;

/** */
public ClientTransactionProxyFactory(ClientTransactions txs) {
this.txs = txs;
}

/** {@inheritDoc} */
@Override public TransactionProxy txStart(
TransactionConcurrency concurrency,
TransactionIsolation isolation,
long timeout
) {
return new ClientTransactionProxy(txs.txStart(concurrency, isolation, timeout));
}

/** {@inheritDoc} */
@Override public boolean equals(Object other) {
if (this == other)
return true;

if (other == null || getClass() != other.getClass())
return false;

return txs.equals(((ClientTransactionProxyFactory)other).txs);
}

/** {@inheritDoc} */
@Override public int hashCode() {
return txs.hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.
*/

package org.apache.ignite.internal.transactions.proxy;

import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.transactions.Transaction;

/**
* Represents {@link TransactionProxy} implementation that uses {@link Transaction} to perform transaction
* operations.
*/
public class IgniteTransactionProxy implements TransactionProxy {
/** */
private final Transaction tx;

/** */
public IgniteTransactionProxy(Transaction tx) {
this.tx = tx;
}

/** {@inheritDoc} */
@Override public void commit() {
tx.commit();
}

/** {@inheritDoc} */
@Override public void rollback() {
tx.rollback();
}

/** {@inheritDoc} */
@Override public void close() {
tx.close();
}

/** {@inheritDoc} */
@Override public boolean setRollbackOnly() {
return tx.setRollbackOnly();
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(IgniteTransactionProxy.class, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.
*/

package org.apache.ignite.internal.transactions.proxy;

import java.util.Objects;
import org.apache.ignite.IgniteTransactions;
import org.apache.ignite.transactions.TransactionConcurrency;
import org.apache.ignite.transactions.TransactionIsolation;

/**
* Represents {@link TransactionProxyFactory} implementation that uses Ignite node transaction facade to start new
* transaction.
*/
public class IgniteTransactionProxyFactory implements TransactionProxyFactory {
/** */
private final IgniteTransactions txs;

/** */
public IgniteTransactionProxyFactory(IgniteTransactions txs) {
this.txs = txs;
}

/** {@inheritDoc} */
@Override public TransactionProxy txStart(
TransactionConcurrency concurrency,
TransactionIsolation isolation,
long timeout
) {
return new IgniteTransactionProxy(txs.txStart(concurrency, isolation, timeout, 0));
}

/** {@inheritDoc} */
@Override public boolean equals(Object other) {
if (this == other)
return true;

if (other == null || getClass() != other.getClass())
return false;

return txs.equals(((IgniteTransactionProxyFactory)other).txs);
}

/** {@inheritDoc} */
@Override public int hashCode() {
return Objects.hash(txs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*/

package org.apache.ignite.internal.transactions.proxy;

/** Represents Ignite client-independent transaction operations. */
public interface TransactionProxy extends AutoCloseable {
/** Commits this transaction. */
public void commit();

/** Rolls back this transaction. */
public void rollback();

/** Ends the transaction. Transaction will be rolled back if it has not been committed. */
@Override public void close();

/**
* Modify the transaction associated with the current thread such that the
* only possible outcome of the transaction is to roll back the
* transaction.
*
* @return {@code True} if rollback-only flag was set as a result of this operation,
* {@code false} if it was already set prior to this call or could not be set
* because transaction is already finishing up committing or rolling back.
*/
public boolean setRollbackOnly();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.
*/

package org.apache.ignite.internal.transactions.proxy;

import org.apache.ignite.transactions.TransactionConcurrency;
import org.apache.ignite.transactions.TransactionIsolation;

/** Represents Ignite client-independent transaction factory. */
public interface TransactionProxyFactory {
/** Starts transaction with specified concurrency, isolation and timeout. */
public TransactionProxy txStart(TransactionConcurrency concurrency, TransactionIsolation isolation, long timeout);
}
Loading