Author: doogie
Date: Fri May 4 21:58:10 2012 New Revision: 1334211 URL: http://svn.apache.org/viewvc?rev=1334211&view=rev Log: OPTIMIZE: Use TransactionUtil.doNewTransaction, instead of suspending it locally; makes the code simpler to follow. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java?rev=1334211&r1=1334210&r2=1334211&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java Fri May 4 21:58:10 2012 @@ -22,6 +22,7 @@ import java.security.NoSuchAlgorithmExce import java.util.HashMap; import java.util.Map; import java.util.Random; +import java.util.concurrent.Callable; import javax.crypto.SecretKey; import javax.transaction.Transaction; @@ -134,59 +135,20 @@ public class EntityCrypto { } catch (NoSuchAlgorithmException e) { throw new EntityCryptoException(e); } - GenericValue newValue = delegator.makeValue("EntityKeyStore"); + final GenericValue newValue = delegator.makeValue("EntityKeyStore"); newValue.set("keyText", StringUtil.toHexString(key.getEncoded())); newValue.set("keyName", hashedKeyName); - Transaction parentTransaction = null; - boolean beganTrans = false; try { - beganTrans = TransactionUtil.begin(); - } catch (GenericTransactionException e) { - throw new EntityCryptoException(e); - } - - if (!beganTrans) { - try { - parentTransaction = TransactionUtil.suspend(); - } catch (GenericTransactionException e) { - throw new EntityCryptoException(e); - } - - // now start a new transaction - try { - beganTrans = TransactionUtil.begin(); - } catch (GenericTransactionException e) { - throw new EntityCryptoException(e); - } - } - - try { - delegator.create(newValue); + TransactionUtil.doNewTransaction(new Callable<Void>() { + public Void call() throws Exception { + delegator.create(newValue); + return null; + } + }, "storing encrypted key", 0, true); } catch (GenericEntityException e) { - try { - TransactionUtil.rollback(beganTrans, "Error creating encrypted value", e); - } catch (GenericTransactionException e1) { - Debug.logError(e1, "Could not rollback transaction", module); - } throw new EntityCryptoException(e); - } finally { - try { - TransactionUtil.commit(beganTrans); - } catch (GenericTransactionException e) { - throw new EntityCryptoException(e); - } - // resume the parent transaction - if (parentTransaction != null) { - try { - TransactionUtil.resume(parentTransaction); - } catch (GenericTransactionException e) { - throw new EntityCryptoException(e); - } - } } - - return key; } else { byte[] keyBytes = StringUtil.fromHexString(keyValue.getString("keyText")); |
Free forum by Nabble | Edit this page |