Example usage for org.springframework.transaction.support DefaultTransactionDefinition setName

List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition setName

Introduction

In this page you can find the example usage for org.springframework.transaction.support DefaultTransactionDefinition setName.

Prototype

public final void setName(String name) 

Source Link

Document

Set the name of this transaction.

Usage

From source file:com.krawler.spring.common.CommonFnController.java

public ModelAndView saveUsers(HttpServletRequest request, HttpServletResponse response) {
    HashMap hm = null;/*from w ww. ja v  a  2s.  c o m*/
    String msg = "";
    Boolean success = false;
    JSONObject jobj = new JSONObject();
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("CF_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    TransactionStatus status = txnManager.getTransaction(def);
    try {
        hm = new FileUploadHandler().getItems(request);
        HashMap<String, Object> requestMap = generateMap(hm);
        KwlReturnObject rtObj = profileHandlerDAOObj.saveUser(requestMap);
        User usr = (User) rtObj.getEntityList().get(0);
        String imageName = ((FileItem) (hm.get("userimage"))).getName();
        if (StringUtil.isNullOrEmpty(imageName) == false) {
            String fileName = usr.getUserID() + FileUploadHandler.getImageExt();
            usr.setImage(ProfileImageServlet.ImgBasePath + fileName);
            new FileUploadHandler().uploadImage((FileItem) hm.get("userimage"), fileName,
                    StorageHandler.GetProfileImgStorePath(), 100, 100, false, false);
        }
        success = true;
        msg = messageSource.getMessage("acc.rem.189", null, RequestContextUtils.getLocale(request));
        txnManager.commit(status);
    } catch (ServiceException ex) {
        success = false;
        msg = ex.getMessage();
        txnManager.rollback(status);
        Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, "saveUsers", ex);
    } catch (Exception ex) {
        msg = "" + ex.getMessage();
        success = false;
        txnManager.rollback(status);
        Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, "saveUsers", ex);
    } finally {
        try {
            jobj.put("success", success);
            jobj.put("msg", msg);
        } catch (com.krawler.utils.json.base.JSONException ex) {
            Logger.getLogger(CommonFnController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    // }
    return new ModelAndView("jsonView_ex", "model", jobj.toString());
}

From source file:cn.uncode.dal.internal.shards.transaction.MultiDataSourcesTransactionManager.java

@Override
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {

    MultiDataSourcesTransactionStatus transactionStatus = new MultiDataSourcesTransactionStatus();

    log.debug("Operation '" + definition.getName() + "' starting transaction.");

    for (DataSource dataSource : dataSources) {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(
                definition);//  w w w  .  j a va 2  s  . c o  m
        defaultTransactionDefinition.setName(definition.getName());

        PlatformTransactionManager txManager = this.transactionManagers.get(dataSource);
        TransactionStatus status = txManager.getTransaction(defaultTransactionDefinition);

        TransactionSynchronizationManager.setCurrentTransactionName(defaultTransactionDefinition.getName());

        transactionStatus.put(dataSource, status);
    }

    return transactionStatus;

}

From source file:ru.apertum.qsystem.server.model.calendar.CalendarTableModel.java

/**
 *  ./*from  w  w  w.  j  a  va 2 s  . com*/
 */
public void save() {
    QLog.l().logger().info("?  ID = " + calcId);

    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("SomeTxName");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = Spring.getInstance().getTxManager().getTransaction(def);
    try {
        final LinkedList<FreeDay> dels = new LinkedList<>();
        for (FreeDay bad : days_del) {
            boolean f = true;
            for (FreeDay good : days) {
                if (good.equals(bad)) {
                    f = false;
                }
            }
            if (f) {
                dels.add(bad);
            }
        }
        Spring.getInstance().getHt().deleteAll(dels);
        Spring.getInstance().getHt().saveOrUpdateAll(days);
    } catch (Exception ex) {
        Spring.getInstance().getTxManager().rollback(status);
        throw new ClientException(
                " ?  ?   (JDBC).\n    ,  , ? ? ? ?,     ?.\n ? (Ctrl + S)    ? ? ? ?.\n\n["
                        + ex.getLocalizedMessage() + "]\n(" + ex.toString() + ")");
    }
    Spring.getInstance().getTxManager().commit(status);
    QLog.l().logger().debug("  ");
    //     
    days_del = new ArrayList<>(days);
}

From source file:org.ohmage.query.impl.ImageQueries.java

@Override
public void markImageAsProcessed(final UUID imageId) throws DataAccessException {

    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Marking an image as processed.");

    try {/*w  ww  . j  a v  a 2 s. co  m*/
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);

        try {
            getJdbcTemplate().update("UPDATE url_based_resource " + "SET processed = true " + "WHERE uuid = ?",
                    new Object[] { imageId.toString() });
        } catch (org.springframework.dao.DataAccessException e) {
            transactionManager.rollback(status);
            throw new DataAccessException(
                    "Error executing SQL '" + SQL_DELETE_IMAGE + "' with parameter: " + imageId, e);
        }

        // Commit the transaction.
        try {
            transactionManager.commit(status);
        } catch (TransactionException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while committing the transaction.", e);
        }
    } catch (TransactionException e) {
        throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
}

From source file:org.ohmage.query.impl.ImageQueries.java

@Override
public void deleteImage(UUID imageId) throws DataAccessException {
    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Deleting an image.");

    try {/*from ww w.j a  va 2s.  c  o  m*/
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);

        URL imageUrl = getImageUrl(imageId);

        try {
            getJdbcTemplate().update(SQL_DELETE_IMAGE, new Object[] { imageId.toString() });
        } catch (org.springframework.dao.DataAccessException e) {
            transactionManager.rollback(status);
            throw new DataAccessException(
                    "Error executing SQL '" + SQL_DELETE_IMAGE + "' with parameter: " + imageId, e);
        }

        if (imageUrl != null) {
            deleteImageDiskOnly(imageUrl);
        }

        // Commit the transaction.
        try {
            transactionManager.commit(status);
        } catch (TransactionException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while committing the transaction.", e);
        }
    } catch (TransactionException e) {
        throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
}

From source file:org.malaguna.cmdit.service.ServiceDelegate.java

private TransactionStatus getTxStatus(String action, boolean readOnly, String isolation, String propagation) {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();

    def.setName(action);

    //Set readOnly configuration
    def.setReadOnly(readOnly);/* w w  w.j a  v a 2 s . co  m*/

    //Set isolation configuration
    if (isolation.equals(Command.ISOLATION_DEFAULT)) {
        def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_DEFAULT);
    } else if (isolation.equals(Command.ISOLATION_READ_COMMITED)) {
        def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_READ_COMMITTED);
    } else if (isolation.equals(Command.ISOLATION_READ_UNCOMMITED)) {
        def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    } else if (isolation.equals(Command.ISOLATION_REPEATABLE_READ)) {
        def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_REPEATABLE_READ);
    } else if (isolation.equals(Command.ISOLATION_SERIALIZABLE)) {
        def.setIsolationLevel(DefaultTransactionDefinition.ISOLATION_SERIALIZABLE);
    }

    //Set propagation configuration
    if (propagation.equals(Command.PROPAGATION_REQUIRED)) {
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRED);
    } else if (propagation.equals(Command.PROPAGATION_MANDATORY)) {
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_MANDATORY);
    } else if (propagation.equals(Command.PROPAGATION_NESTED)) {
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_NESTED);
    } else if (propagation.equals(Command.PROPAGATION_NEVER)) {
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_NEVER);
    } else if (propagation.equals(Command.PROPAGATION_NOT_SUPPORTED)) {
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_NOT_SUPPORTED);
    } else if (propagation.equals(Command.PROPAGATION_REQUIRES_NEW)) {
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
    } else if (propagation.equals(Command.PROPAGATION_SUPPORTS)) {
        def.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_SUPPORTS);
    }

    return txManager.getTransaction(def);
}

From source file:org.businessmanager.dao.GenericDaoImpl.java

@Override
public TransactionStatus getTransaction() {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("CustomTransaction");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    return txManager.getTransaction(def);
}

From source file:com.krawler.spring.organizationChart.organizationChartController.java

public ModelAndView insertNode(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jobj = new JSONObject();
    JSONObject jobj1 = new JSONObject();
    String retMsg = "";
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {//from w  w w. j  a va  2  s  .c  o m

        String parentid = StringUtil.checkForNull(request.getParameter("fromId"));
        String childid = StringUtil.checkForNull(request.getParameter("userid"));

        HashMap<String, Object> hm = organizationService.insertNode(parentid, childid);

        boolean success = Boolean.parseBoolean(hm.get("success").toString());
        User parent = (User) hm.get("parent");
        User child = (User) hm.get("child");

        if (parent != null && child != null) {
            auditTrailDAOObj.insertAuditLog(AuditAction.ORGANIZATION_CHART_NODE_ASSIGNED,
                    child.getFirstName() + " " + child.getLastName() + " re-assigned to "
                            + parent.getFirstName() + " " + parent.getLastName(),
                    request, "0");
        }

        if (success) {
            retMsg = "{success:true}";
        } else {
            retMsg = "{success:false,msg:\""
                    + messageSource.getMessage("hrms.common.not.assign.parent.node.employee.role", null,
                            "Could not assign because, parent node has Employee role.",
                            RequestContextUtils.getLocale(request))
                    + "\"}";
        }
        jobj.put("data", retMsg);

        jobj1.put("valid", true);
        jobj1.put("data", jobj);
        jobj1.put("success", true);
        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn("General exception in insertNode()", e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj1.toString());
}

From source file:com.krawler.spring.organizationChart.organizationChartController.java

public ModelAndView updateNode(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jobj = new JSONObject();
    JSONObject jobj1 = new JSONObject();
    String retMsg = "";
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {//ww w.j a  v  a  2s  .  c o  m

        String childid = request.getParameter("nodeid");
        String parentid = request.getParameter("fromId");

        HashMap<String, Object> hm = organizationService.updateNode(parentid, childid);

        boolean success = Boolean.parseBoolean(hm.get("success").toString());
        User parent = (User) hm.get("parent");
        User child = (User) hm.get("child");

        if (parent != null && child != null) {
            auditTrailDAOObj.insertAuditLog(AuditAction.ORGANIZATION_CHART_NODE_ASSIGNED,
                    child.getFirstName() + " " + child.getLastName() + " re-assigned to "
                            + parent.getFirstName() + " " + parent.getLastName(),
                    request, "0");
        }

        if (success) {
            retMsg = "{success:true}";
        } else {
            retMsg = "{success:false,msg:\""
                    + messageSource.getMessage("hrms.common.not.assign.parent.node.employee.role", null,
                            "Could not assign because, parent node has Employee role.",
                            RequestContextUtils.getLocale(request))
                    + "\"}";
        }
        jobj.put("data", retMsg);

        jobj1.put("valid", true);
        jobj1.put("data", jobj);
        jobj1.put("success", true);
        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn("General exception in updateNode()", e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj1.toString());
}

From source file:org.ohmage.query.impl.AnnotationQueries.java

@Override
public void deleteAnnotation(final UUID annotationId) throws DataAccessException {
    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Deleting an annotation.");

    try {//w  w  w . j  a  v  a2s.  c  om
        // Begin the transaction.
        PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource());
        TransactionStatus status = transactionManager.getTransaction(def);

        try {
            getJdbcTemplate().update(SQL_DELETE_ANNOTATION, annotationId.toString());
        } catch (org.springframework.dao.DataAccessException e) {

            transactionManager.rollback(status);
            throw new DataAccessException("Error executing SQL '" + SQL_DELETE_ANNOTATION + "' with parameter: "
                    + annotationId.toString(), e);
        }

        // Commit the transaction.
        try {
            transactionManager.commit(status);
        } catch (TransactionException e) {
            transactionManager.rollback(status);
            throw new DataAccessException("Error while committing the transaction.", e);
        }
    } catch (TransactionException e) {
        throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
}