Package com.scooterframework.transaction

Examples of com.scooterframework.transaction.ImplicitTransactionManager


     *
     * @param newTarget a record to be attached
     * @return updated AssociatedRecord
     */
    public AssociatedRecord attach(ActiveRecord newTarget) {
        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        AssociatedRecord assoc = null;
        try {
            tm.beginTransactionImplicit();
           
            assoc = internal_attach(newTarget);
           
            tm.commitTransactionImplicit();
        }
        catch(GenericException ex) {
            tm.rollbackTransactionImplicit();
            throw ex;
        }
        finally {
            tm.releaseResourcesImplicit();
        }
        return assoc;
    }
View Full Code Here


     * for definition of dependent record.</p>
     *
     * @param removeDependent whether dependent record should be deleted or now.
     */
    public void detach(boolean removeDependent) {
        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        try {
            tm.beginTransactionImplicit();
           
            internal_detach(removeDependent);
           
            tm.commitTransactionImplicit();
        }
        catch(GenericException ex) {
            tm.rollbackTransactionImplicit();
            throw ex;
        }
        finally {
            tm.releaseResourcesImplicit();
        }
    }
View Full Code Here

     * dependent on the owner or not. </p>
     *
     * <p>This method has no effect if the reverse relation is has-many. </p>
     */
    public void delete() {
        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        try {
            tm.beginTransactionImplicit();
           
            internal_delete();
           
            tm.commitTransactionImplicit();
        }
        catch(GenericException ex) {
            tm.rollbackTransactionImplicit();
            throw ex;
        }
        finally {
            tm.releaseResourcesImplicit();
        }
    }
View Full Code Here

     * This is equivalent to detach() first and attach(record) later.
     *
     * @return updated AssociatedRecord
     */
    public AssociatedRecord replace(ActiveRecord record) {
        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        AssociatedRecord assr = null;
       
        try {
            tm.beginTransactionImplicit();
            detach(false);
            assr = attach(record);
            tm.commitTransactionImplicit();
        }
        catch(Exception ex) {
            tm.rollbackTransactionImplicit();
            throw new RelationException(ex);
        }
        finally {
            tm.releaseResourcesImplicit();
        }
        return assr;
    }
View Full Code Here

   *
     * @param changedOnly  true if only changed fields are included in SQL query
     * @return a new ActiveRecord instance.
     */
    public ActiveRecord create(boolean changedOnly) {
        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        ActiveRecord r = null;

        try {
            tm.beginTransactionImplicit();

            beforeCreate();
            r = internal_create(changedOnly);
            afterCreate();

            tm.commitTransactionImplicit();
           
            ActiveRecordUtil.getGateway(getClass()).getModelCacheClient().clearCache("create");
        }
        catch(BaseSQLException bdex) {
            tm.rollbackTransactionImplicit();
            throw bdex;
        }
        finally {
            tm.releaseResourcesImplicit();
        }

        return r;
    }
View Full Code Here

   * @return number of records updated
   */
    public int update(boolean changedOnly) {
        if (isFreezed()) throw new InvalidOperationException(this, "update", "freezed");

        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        int updateCount = -1;

        try {
            tm.beginTransactionImplicit();

            beforeUpdate();

      updateCount = internal_update(changedOnly);

      if (updateCount > 1)
        log.warn("Should only update one, but actually updated "
            + updateCount + " records.");

      afterUpdate();

            tm.commitTransactionImplicit();
           
            ActiveRecordUtil.getGateway(getClass()).getModelCacheClient().clearCache("update");
        }
        catch(BaseSQLException bdex) {
            tm.rollbackTransactionImplicit();
            throw bdex;
        }
        finally {
            tm.releaseResourcesImplicit();
        }

        return updateCount;
    }
View Full Code Here

        if (processorType == null || processorName == null)
            throw new IllegalArgumentException("processorType or processorName is null.");

        if (inputs == null) inputs = new HashMap<String, Object>();

        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        OmniDTO returnTO = null;

        try {
            tm.beginTransactionImplicit();

            //if (log.isDebugEnabled()) displayDS((String)inputs.get(DataProcessor.input_key_database_connection_name), "beforeConnection");

            UserDatabaseConnection connection = findOrCreateConnection(inputs);

            //if (log.isDebugEnabled()) displayDS((String)inputs.get(DataProcessor.input_key_database_connection_name), "beforeExecute");
            returnTO = executeKeepConnection(connection, inputs, processorType, processorName, outputFilters);
            //if (log.isDebugEnabled()) displayDS((String)inputs.get(DataProcessor.input_key_database_connection_name), "afterExecute");

            tm.commitTransactionImplicit();
            //if (log.isDebugEnabled()) displayDS((String)inputs.get(DataProcessor.input_key_database_connection_name), "afterCommit");
        }
        catch(BaseSQLException bdex) {
            tm.rollbackTransactionImplicit();
            throw bdex;
        }
        finally {
            tm.releaseResourcesImplicit();
            displayDS((String)inputs.get(DataProcessor.input_key_database_connection_name), "afterRelease");
        }

        return returnTO;
    }
View Full Code Here

    public Collection<OmniDTO> execute(Collection<InputInfo> inputInfoList)
    throws BaseSQLException {
        if (inputInfoList == null)
            throw new IllegalArgumentException("inputs list is null.");

        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        Collection<OmniDTO> returnTOList = new ArrayList<OmniDTO>();

        try {
            tm.beginTransactionImplicit();

            for (InputInfo ip : inputInfoList) {
                UserDatabaseConnection connection = findOrCreateConnection(ip);
                OmniDTO returnTO = executeKeepConnection(connection, ip.getInputs(), ip.getProcessorType(), ip.getProcessorName(), ip.getOutputFilters());
                returnTOList.add(returnTO);

                //now execute child InputInfo
                Collection<InputInfo> childList = ip.getChildInputInfoObjects();
                for (InputInfo childIp : childList) {
                    OmniDTO returnTO2 = executeKeepConnection(connection, childIp.getInputs(), childIp.getProcessorType(), childIp.getProcessorName(), childIp.getOutputFilters());
                    returnTO.addChildrenOmniDTOToList(returnTO2);
                }
            }

            tm.commitTransactionImplicit();
        }
        catch(BaseSQLException bdex) {
            tm.rollbackTransactionImplicit();
            throw bdex;
        }
        finally {
            tm.releaseResourcesImplicit();
        }

        return returnTOList;
    }
View Full Code Here

    public OmniDTO retrieveMasterDetails(InputInfo inputInfo)
    throws BaseSQLException {
        if (inputInfo == null)
            throw new IllegalArgumentException("inputInfo is null.");

        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        OmniDTO returnTO = null;

        try {
            tm.beginTransactionImplicit();

            InputInfo ip = inputInfo;
            UserDatabaseConnection udc = findOrCreateConnection(ip);
            udc.getConnection().setReadOnly(true);

            returnTO = executeKeepConnection(udc, ip.getInputs(), ip.getProcessorType(), ip.getProcessorName(), ip.getOutputFilters());
            log.debug("parent: " + returnTO);

            //now execute child InputInfo
            Collection<InputInfo> childList = ip.getChildInputInfoObjects();
            for (InputInfo childIp : childList) {
                // find all input parameters in childIp that need data from parent
                List<String> connectorList = new ArrayList<String>();
                Map<String, Object> childInputs = childIp.getInputs();
                childInputs = convertKeyCase(childInputs);
                for (Map.Entry<String, Object> entry : childInputs.entrySet()) {
                    String key = entry.getKey();
                    String value = (String)childInputs.get(key);
                    if (key != null && key.startsWith("&")) connectorList.add(value);
                }

                // create a select union query
                String query = null;
                if (DataProcessorTypes.NAMED_SQL_STATEMENT_PROCESSOR.equals(childIp.getProcessorType())) {
                    query = SqlConfig.getInstance().getSql(childIp.getProcessorName());
                }
                else
                if (DataProcessorTypes.DIRECT_SQL_STATEMENT_PROCESSOR.equals(childIp.getProcessorType())) {
                    query = childIp.getProcessorName();
                }

                log.debug("child query1: " + query);

                // check if parent has data
                boolean parentHasData = false;
                TableData parentRt = null;
                if (returnTO != null) {
                    parentRt = returnTO.getTableData(ip.getProcessorName());
                    if (parentRt != null) {
                        int size = parentRt.getAllRows().size();
                        if (size > 0) parentHasData = true;
                    }
                }

                // construct child query
                String childQuery = "";
                if (query != null && connectorList.size() > 0 && parentHasData) {
                    childQuery = getNewChildQuery(query, childIp, parentRt.getAllRows());
                }
                else {
                    childQuery = query;
                }

                log.debug("child query2: " + childQuery);

                if (parentHasData) {
                    udc = findOrCreateConnection(childIp);

                    OmniDTO returnTO2 =
                        executeKeepConnection(udc,
                                              childIp.getInputs(),
                                              DataProcessorTypes.DIRECT_SQL_STATEMENT_PROCESSOR,
                                              childQuery,
                                              childIp.getOutputFilters());

                    // merge child records with corresponding parent record
                    if (returnTO2 != null) {
                        linkParentWithChild(parentRt,
                                            returnTO2.getTableData(childQuery),
                                            childIp.getProcessorName(),
                                            connectorList);
                    }

                    log.debug("returnTO2: " + returnTO2);
                }
            }
        }
        catch(SQLException ex) {
            throw new BaseSQLException(ex);
        }
        catch(BaseSQLException bdex) {
            throw bdex;
        }
        finally {
            tm.releaseResourcesImplicit();
        }

        return returnTO;
    }
View Full Code Here

     * @return int number of records deleted
     */
    public int delete() {
        if (isFreezed() || isNewRecord()) return -1;

        ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
        int count = -1;

        try {
            tm.beginTransactionImplicit();

            beforeDelete();

            before_internal_delete();

            //populate a Map with primary key values
            String[] pkNames = rowInfo.getPrimaryKeyColumnNames();
            if (pkNames == null || pkNames.length == 0) pkNames = rowInfo.getColumnNames();

            int size = pkNames.length;
            Map<String, Object> inputs = new HashMap<String, Object>();
            for (int i=0; i< size; i++) {
                String columnName = pkNames[i];
                Object columnData = rowData.getField(columnName);
                inputs.put(columnName, columnData);
            }

            count = ActiveRecordUtil.getGateway(getClass()).deleteAll(inputs);

            after_internal_delete();

            afterDelete();

            freeze();

            tm.commitTransactionImplicit();
        }
        catch(BaseSQLException bdex) {
            tm.rollbackTransactionImplicit();
            throw bdex;
        }
        finally {
            tm.releaseResourcesImplicit();
        }

        return count;
    }
View Full Code Here

TOP

Related Classes of com.scooterframework.transaction.ImplicitTransactionManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.