本文整理汇总了Java中javax.jdo.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于javax.jdo包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCommit
import javax.jdo.Transaction; //导入依赖的package包/类
@Override
protected void doCommit(DefaultTransactionStatus status) {
JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
if (status.isDebug()) {
logger.debug("Committing JDO transaction on PersistenceManager [" +
txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
}
try {
Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
tx.commit();
}
catch (JDOException ex) {
// Assumably failed to flush changes to database.
throw convertJdoAccessException(ex);
}
}
示例2: doRollback
import javax.jdo.Transaction; //导入依赖的package包/类
@Override
protected void doRollback(DefaultTransactionStatus status) {
JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
if (status.isDebug()) {
logger.debug("Rolling back JDO transaction on PersistenceManager [" +
txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
}
try {
Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
if (tx.isActive()) {
tx.rollback();
}
}
catch (JDOException ex) {
throw new TransactionSystemException("Could not roll back JDO transaction", ex);
}
}
示例3: alterUser
import javax.jdo.Transaction; //导入依赖的package包/类
@Override
public void alterUser(String name, String newPassword) throws MetaException {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
MUser mUser = (MUser) getUser(name);
mUser.setPassword(newPassword);
pm.makePersistent(mUser);
tx.commit();
} catch (RuntimeException e) {
throw new MetaException("failed to alter user '" + name + "'", e);
} finally {
if (tx.isActive())
tx.rollback();
}
}
示例4: dropUser
import javax.jdo.Transaction; //导入依赖的package包/类
@Override
public void dropUser(String name) throws MetaException {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.deletePersistent(getUser(name));
tx.commit();
} catch (RuntimeException e) {
throw new MetaException("failed to drop user '" + name + "'", e);
} finally {
if (tx.isActive())
tx.rollback();
}
}
示例5: commentOnUser
import javax.jdo.Transaction; //导入依赖的package包/类
@Override
public void commentOnUser(String comment, String name) throws MetaException {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
MUser mUser = (MUser) getUser(name);
mUser.setComment(comment);
pm.makePersistent(mUser);
tx.commit();
} catch (RuntimeException e) {
throw new MetaException("failed to comment on user '" + name + "'", e);
} finally {
if (tx.isActive())
tx.rollback();
}
}
示例6: dropJdbcDataSource
import javax.jdo.Transaction; //导入依赖的package包/类
@Override
public void dropJdbcDataSource(String name) throws MetaException {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.deletePersistent(getDataSource(name));
tx.commit();
} catch (RuntimeException e) {
throw new MetaException("failed to drop dataSource '" + name + "' - " + e.getMessage(), e);
} finally {
if (tx.isActive())
tx.rollback();
}
}
示例7: addSystemPrivileges
import javax.jdo.Transaction; //导入依赖的package包/类
@Override
public void addSystemPrivileges(List<SystemPrivilege> sysPrivs, List<String> userNames) throws MetaException {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
for (String userName : userNames) {
MUser mUser = (MUser) getUser(userName);
for (SystemPrivilege sysPriv : sysPrivs)
mUser.addSystemPrivilege(sysPriv);
pm.makePersistent(mUser);
}
tx.commit();
} catch (Exception e) {
throw new MetaException("failed to add system privileges to users", e);
} finally {
if (tx.isActive())
tx.rollback();
}
}
示例8: removeSystemPrivileges
import javax.jdo.Transaction; //导入依赖的package包/类
@Override
public void removeSystemPrivileges(List<SystemPrivilege> sysPrivs, List<String> userNames) throws MetaException {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
for (String userName : userNames) {
MUser mUser = (MUser) getUser(userName);
for (SystemPrivilege sysPriv : sysPrivs)
mUser.removeSystemPrivilege(sysPriv);
pm.makePersistent(mUser);
}
tx.commit();
} catch (Exception e) {
throw new MetaException("failed to remove system privileges from users", e);
} finally {
if (tx.isActive())
tx.rollback();
}
}
示例9: delTbl
import javax.jdo.Transaction; //导入依赖的package包/类
public void delTbl(String dbName, String tblName) {
TableMeta tblMeta = getTbl(dbName, tblName);
if(tblMeta == null)
return;
List<ColumnMeta> columnMetas = tblMeta.getCols();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
for(ColumnMeta columnMeta : columnMetas) {
pm.deletePersistent(columnMeta);
}
pm.deletePersistent(tblMeta);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
}
示例10: deleteCustomer
import javax.jdo.Transaction; //导入依赖的package包/类
/**
* Delete Customer from datastore.
* Deletes the given customer from the datastore calling the PersistenceManager's
* deletePersistent() method.
* @param customer
* : the customer instance to delete
*/
public static void deleteCustomer(Customer customer) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
customer = pm.getObjectById(Customer.class, customer.getKey());
String email = customer.getUser().getUserEmail().getEmail();
tx.begin();
pm.deletePersistent(customer);
tx.commit();
log.info("Customer \"" + email + "\" deleted successfully from datastore.");
}
finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
示例11: updateCustomerPassword
import javax.jdo.Transaction; //导入依赖的package包/类
/**
* Update Customer password in datastore.
* Update's the customer's password in the datastore.
* @param email
* : the email of the customer whose password will be changed
* @param newPassword
* : the new password for this customer
* @throws MissingRequiredFieldsException
*/
public static void updateCustomerPassword(Email email, String newPassword)
throws MissingRequiredFieldsException {
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
Key key = KeyFactory.createKey(Customer.class.getSimpleName(), email.getEmail());
Customer customer = pm.getObjectById(Customer.class, key);
tx.begin();
customer.getUser().setUserPassword(newPassword);
tx.commit();
log.info("Customer \"" + email.getEmail() + "\"'s password updated in datastore.");
}
finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
示例12: updateCustomerStatus
import javax.jdo.Transaction; //导入依赖的package包/类
/**
* Update Customer status in datastore.
* Update's the customer's status in the datastore.
* @param email
* : the email of the customer whose status will be changed
* @param status
* : the status to be assigned to this customer
* @throws MissingRequiredFieldsException
*/
public static void updateCustomerStatus(Email email, Customer.Status status)
throws MissingRequiredFieldsException {
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
Key key = KeyFactory.createKey(Customer.class.getSimpleName(), email.getEmail());
Customer customer = pm.getObjectById(Customer.class, key);
tx.begin();
customer.setCustomerStatus(status);
tx.commit();
log.info("Customer \"" + email.getEmail() + "\"'s status updated in datastore.");
}
finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
示例13: updateCustomerCloudSyncCommand
import javax.jdo.Transaction; //导入依赖的package包/类
/**
* Update Customer cloud sync command.
* Update's the given customer's cloud sync command in the datastore.
* @param email
* : the email of the customer whose attributes will be updated
* @param cloudSyncCommand
* : the cloud sync message to set
*/
public static void updateCustomerCloudSyncCommand(Email email,
CloudSyncCommand cloudSyncCommand) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
Key key = KeyFactory.createKey(Customer.class.getSimpleName(),
email.getEmail());
Customer customer = pm.getObjectById(Customer.class, key);
CloudSyncCommand previousCloudSyncCommand = customer.getCloudSyncCommand();
tx.begin();
pm.deletePersistent(previousCloudSyncCommand);
customer.setCloudSyncCommand(cloudSyncCommand);
tx.commit();
log.info("Customer \"" + email.getEmail() +
"\"'s cloud sync command updated.");
}
finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
示例14: putStationType
import javax.jdo.Transaction; //导入依赖的package包/类
/**
* Put StationType into datastore.
* Stations the given StationType instance in the datastore calling the
* PersistenceManager's makePersistent() method.
* @param stationType
* : the StationType instance to store
*/
public static void putStationType(StationType stationType) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(stationType);
tx.commit();
log.info("StationType \"" + stationType.getStationTypeName() +
"\" stored successfully in datastore.");
}
finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
示例15: deleteStationType
import javax.jdo.Transaction; //导入依赖的package包/类
/**
* Delete StationType from datastore.
* Deletes the StationType corresponding to the given key
* from the datastore calling the PersistenceManager's
* deletePersistent() method.
* @param key
* : the key of the StationType instance to delete
*/
public static void deleteStationType(Long key) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
StationType stationType = pm.getObjectById(StationType.class, key);
String StationTypeName = stationType.getStationTypeName();
tx.begin();
pm.deletePersistent(stationType);
tx.commit();
log.info("StationType \"" + StationTypeName +
"\" deleted successfully from datastore.");
}
finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}