Search in sources :

Example 1 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MMovementLine method setOrderLine.

//	beforeSave
/** 
	 *      Set Distribution Order Line. 
	 *      Does not set Quantity! 
	 *      @param oLine order line 
	 *      @param M_Locator_ID locator 
	 *      @param Qty used only to find suitable locator 
	 */
public void setOrderLine(MDDOrderLine oLine, BigDecimal Qty, boolean isReceipt) {
    setDD_OrderLine_ID(oLine.getDD_OrderLine_ID());
    setLine(oLine.getLine());
    //setC_UOM_ID(oLine.getC_UOM_ID()); 
    MProduct product = oLine.getProduct();
    if (product == null) {
        set_ValueNoCheck(COLUMNNAME_M_Product_ID, null);
        set_ValueNoCheck(COLUMNNAME_M_AttributeSetInstance_ID, null);
        set_ValueNoCheck(COLUMNNAME_M_AttributeSetInstanceTo_ID, null);
        set_ValueNoCheck(COLUMNNAME_M_Locator_ID, null);
        set_ValueNoCheck(COLUMNNAME_M_LocatorTo_ID, null);
    } else {
        setM_Product_ID(oLine.getM_Product_ID());
        setM_AttributeSetInstance_ID(oLine.getM_AttributeSetInstance_ID());
        setM_AttributeSetInstanceTo_ID(oLine.getM_AttributeSetInstanceTo_ID());
        // 
        if (product.isItem()) {
            MWarehouse warehouse = MWarehouse.get(getCtx(), oLine.getParent().getM_Warehouse_ID());
            MLocator locator = MLocator.getDefault(warehouse);
            if (locator == null)
                throw new AdempiereException("@M_Warehouse_ID@ " + warehouse.getName() + " @M_Locator_ID@ @IsDefault@ @NotFound@");
            if (isReceipt) {
                setM_Locator_ID(locator.getM_Locator_ID());
                setM_LocatorTo_ID(oLine.getM_LocatorTo_ID());
            } else {
                setM_Locator_ID(oLine.getM_Locator_ID());
                setM_LocatorTo_ID(locator.getM_Locator_ID());
            }
        } else {
            set_ValueNoCheck(COLUMNNAME_M_Locator_ID, null);
            set_ValueNoCheck(COLUMNNAME_M_LocatorTo_ID, null);
        }
    }
    setDescription(oLine.getDescription());
    this.setMovementQty(Qty);
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 2 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MMigrationStep method applySQL.

/**
	 * Apply SQL
	 * @param rollback
	 * @return
	 */
private String applySQL(boolean rollback) {
    String sqlStatements = rollback ? getRollbackStatement() : getSQLStatement();
    Boolean isParse = true;
    // The parse column was added to AD_MigrationStep just prior to release 3.8.0.
    if (this.get_ColumnIndex(MMigrationStep.COLUMNNAME_Parse) >= 0)
        isParse = isParse();
    if (sqlStatements == null || sqlStatements.trim().length() == 0 || sqlStatements.equals(";")) {
        bailout("No SQL to execute.");
    }
    // applied/rolled-back but take no action.
    if (getDBType().equals(MMigrationStep.DBTYPE_AllDatabaseTypes) || (DB.isOracle() && getDBType().equals(MMigrationStep.DBTYPE_Oracle)) || (DB.isPostgreSQL() && getDBType().equals(MMigrationStep.DBTYPE_Postgres))) {
        //	Synchronize column first
        getParent().syncColumn();
        //	
        Connection conn = DB.getConnectionRW();
        Statement stmt = null;
        try {
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            //  Parse the statement based on semi-colons
            if (isParse) {
                StringTokenizer tokens = new StringTokenizer(sqlStatements, ";");
                while (tokens.hasMoreTokens()) {
                    final String sql = tokens.nextToken().trim();
                    if (sql != null && sql.length() > 0)
                        stmt.addBatch(sql);
                }
                stmt.executeBatch();
            } else {
                // Don't parse.  Assume its a single statement.
                stmt.executeUpdate(sqlStatements);
            }
            conn.commit();
            setStatusCode(rollback ? MMigrationStep.STATUSCODE_Unapplied : MMigrationStep.STATUSCODE_Applied);
            setApply(rollback ? MMigrationStep.APPLY_Apply : MMigrationStep.APPLY_Rollback);
            setErrorMsg(null);
            conn.close();
        } catch (SQLException e) {
            java.sql.SQLException ne = e.getNextException();
            // many errors, we could be left with a lot of hanging connections.
            try {
                conn.rollback();
                conn.close();
            } catch (SQLException se) {
                // all out of luck
                ;
            }
            setErrorMsg(rollback ? "Rollback failed. " : "Application failed. ");
            if (ne != null) {
                setErrorMsg(getErrorMsg() + ne.toString());
            }
            setErrorMsg(getErrorMsg() + "\n" + e.toString());
            setApply(rollback ? MMigrationStep.APPLY_Rollback : MMigrationStep.APPLY_Apply);
            if (!rollback)
                setStatusCode(MMigrationStep.STATUSCODE_Failed);
            log.severe(this.toString() + " " + getErrorMsg());
            throw new AdempiereException(this.toString() + " " + getErrorMsg(), e);
        } finally {
            DB.close(stmt);
            saveEx(null);
        }
    } else {
        setStatusCode(rollback ? MMigrationStep.STATUSCODE_Unapplied : MMigrationStep.STATUSCODE_Applied);
        setApply(rollback ? MMigrationStep.APPLY_Apply : MMigrationStep.APPLY_Rollback);
        setErrorMsg(null);
        saveEx(null);
    }
    return rollback ? "successfully rolled back" : "successfully applied";
}
Also used : StringTokenizer(java.util.StringTokenizer) SQLException(java.sql.SQLException) Statement(java.sql.Statement) AdempiereException(org.adempiere.exceptions.AdempiereException) Connection(java.sql.Connection)

Example 3 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class CleanUpGW method updatePeriods.

private void updatePeriods() {
    // Update the date columns
    PreparedStatement pstm = null;
    ResultSet rs = null;
    try {
        pstm = DB.prepareStatement(m_sql + sqlOrderBy, get_TrxName());
        rs = pstm.executeQuery();
        String tableName = null;
        String columnName = null;
        while (rs.next()) {
            tableName = rs.getString(1);
            columnName = rs.getString(2);
            setPeriods(tableName, columnName);
        }
    } catch (SQLException e) {
        log.log(Level.SEVERE, e.getLocalizedMessage());
        throw new AdempiereException("", e);
    } finally {
        DB.close(rs, pstm);
    }
}
Also used : SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 4 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class CleanUpGW method setPeriods.

private void setPeriods(String tableName, String columnName) {
    //update periods according to the new dates
    String dateAcctColumn = null;
    MTable table = MTable.get(getCtx(), tableName);
    MColumn periodColumn = table.getColumn("C_Period_ID");
    if (periodColumn != null) {
        MColumn dateaAcctColumn = table.getColumn("DateAcct");
        MColumn assetDepDateColumn = table.getColumn("AssetDepreciationDate");
        if (dateaAcctColumn != null)
            dateAcctColumn = dateaAcctColumn.getColumnName();
        else if (assetDepDateColumn != null)
            dateAcctColumn = assetDepDateColumn.getColumnName();
        if (dateAcctColumn != null) {
            log.fine("Table: " + tableName + " dateAcctColumn: " + dateAcctColumn);
            String updatePeriodSql = "update " + tableName + " set " + " C_Period_ID=(SELECT C_Period_ID from C_Period WHERE " + dateAcctColumn + " BETWEEN StartDate and EndDate and AD_Client_ID=" + gw_client_id + ") WHERE AD_Client_ID=" + gw_client_id;
            PreparedStatement pstm = null;
            try {
                pstm = DB.prepareStatement(updatePeriodSql, get_TrxName());
                pstm.executeUpdate();
            } catch (SQLException e) {
                log.log(Level.SEVERE, e.getLocalizedMessage());
                throw new AdempiereException("Problem in updating periods according to new accounting values.", e);
            } finally {
                DB.close(pstm);
            }
        }
    }
}
Also used : MColumn(org.compiere.model.MColumn) MTable(org.compiere.model.MTable) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) PreparedStatement(java.sql.PreparedStatement)

Example 5 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class CleanUpGW method clearSessionLog.

private void clearSessionLog() {
    String deleteSessionLogSQL = "DELETE FROM AD_Session where AD_Client_ID=" + gw_client_id;
    PreparedStatement pstm = null;
    try {
        pstm = DB.prepareStatement(deleteSessionLogSQL, get_TrxName());
        pstm.executeUpdate();
    } catch (SQLException e) {
        log.log(Level.SEVERE, e.getLocalizedMessage());
        throw new AdempiereException("Problem deleting the GardenWorld session log", e);
    } finally {
        DB.close(pstm);
    }
}
Also used : SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

AdempiereException (org.adempiere.exceptions.AdempiereException)326 BigDecimal (java.math.BigDecimal)79 SQLException (java.sql.SQLException)46 ArrayList (java.util.ArrayList)36 ResultSet (java.sql.ResultSet)33 PreparedStatement (java.sql.PreparedStatement)31 Timestamp (java.sql.Timestamp)31 MProduct (org.compiere.model.MProduct)28 List (java.util.List)25 Query (org.compiere.model.Query)20 File (java.io.File)17 Properties (java.util.Properties)16 PO (org.compiere.model.PO)16 Env (org.compiere.util.Env)15 MBPartner (org.compiere.model.MBPartner)14 ImmutableList (com.google.common.collect.ImmutableList)12 I_M_HU (de.metas.handlingunits.model.I_M_HU)12 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)12 ProcessInfo (org.compiere.process.ProcessInfo)12 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)11