Search in sources :

Example 16 with DBException

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

the class MLanguage method maintain.

//	afterSave
/**************************************************************************
	 * 	Maintain Translation
	 *	@param add if true add missing records - otherwise delete
	 *	@return number of records deleted/inserted
	 */
public int maintain(boolean add) {
    String sql = "SELECT TableName FROM AD_Table WHERE TableName LIKE '%_Trl' ORDER BY TableName";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    int retNo = 0;
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            if (add)
                retNo += addTable(rs.getString(1));
            else
                retNo += deleteTable(rs.getString(1));
        }
    } catch (SQLException e) {
        throw new DBException(e, sql);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    return retNo;
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 17 with DBException

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

the class Aging method doIt.

//	prepare
/**
	 * 	DoIt
	 *	@return Message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("StatementDate=" + p_StatementDate + ", IsSOTrx=" + p_IsSOTrx + ", C_Currency_ID=" + p_C_Currency_ID + ", AD_Org_ID=" + p_AD_Org_ID + ", C_BP_Group_ID=" + p_C_BP_Group_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + ", IsListInvoices=" + p_IsListInvoices);
    //FR 1933937
    String dateacct = DB.TO_DATE(p_StatementDate);
    StringBuffer sql = new StringBuffer();
    sql.append(// 1..4 
    "SELECT bp.C_BP_Group_ID, oi.C_BPartner_ID,oi.C_Invoice_ID,oi.C_InvoicePaySchedule_ID, " + //	5..6
    "oi.C_Currency_ID, oi.IsSOTrx, " + //	7..10
    "oi.DateInvoiced, oi.NetDays,oi.DueDate,oi.DaysDue, ");
    if (p_C_Currency_ID == 0) {
        if (//FR 1933937
        !p_DateAcct) {
            //	11..13
            sql.append(" oi.GrandTotal, oi.PaidAmt, oi.OpenAmt ");
        } else {
            //	11..13
            sql.append(" oi.GrandTotal, invoicePaidToDate(oi.C_Invoice_ID, oi.C_Currency_ID, 1," + dateacct + ") AS PaidAmt, invoiceOpenToDate(oi.C_Invoice_ID,oi.C_InvoicePaySchedule_ID," + dateacct + ") AS OpenAmt ");
        }
    } else {
        String s = ",oi.C_Currency_ID," + p_C_Currency_ID + ",oi.DateAcct,oi.C_ConversionType_ID,oi.AD_Client_ID,oi.AD_Org_ID)";
        //	11
        sql.append("currencyConvert(oi.GrandTotal").append(s);
        if (!p_DateAcct) {
            // 12
            sql.append(", currencyConvert(oi.PaidAmt").append(s).append(", currencyConvert(oi.OpenAmt").append(// 13
            s);
        } else {
            // 12
            sql.append(", currencyConvert(invoicePaidToDate(oi.C_Invoice_ID, oi.C_Currency_ID, 1," + dateacct + ")").append(s).append(", currencyConvert(invoiceOpenToDate(oi.C_Invoice_ID,oi.C_InvoicePaySchedule_ID," + dateacct + ")").append(// 13
            s);
        }
    }
    //	14..17
    sql.append(",oi.C_Activity_ID,oi.C_Campaign_ID,oi.C_Project_ID,oi.AD_Org_ID ");
    if (//FR 1933937
    !p_DateAcct) {
        sql.append(" FROM RV_OpenItem oi");
    } else {
        sql.append(" FROM RV_OpenItemToDate oi");
    }
    sql.append(" INNER JOIN C_BPartner bp ON (oi.C_BPartner_ID=bp.C_BPartner_ID) " + "WHERE oi.ISSoTrx=").append(p_IsSOTrx ? "'Y'" : "'N'");
    if (p_C_BPartner_ID > 0) {
        sql.append(" AND oi.C_BPartner_ID=").append(p_C_BPartner_ID);
    } else if (p_C_BP_Group_ID > 0) {
        sql.append(" AND bp.C_BP_Group_ID=").append(p_C_BP_Group_ID);
    }
    if (// BF 2655587
    p_AD_Org_ID > 0) {
        sql.append(" AND oi.AD_Org_ID=").append(p_AD_Org_ID);
    }
    if (//FR 1933937
    p_DateAcct) {
        sql.append(" AND invoiceOpenToDate(oi.C_Invoice_ID,oi.C_InvoicePaySchedule_ID," + dateacct + ") <> 0 ");
    }
    sql.append(" ORDER BY oi.C_BPartner_ID, oi.C_Currency_ID, oi.C_Invoice_ID");
    log.finest(sql.toString());
    String finalSql = MRole.getDefault(getCtx(), false).addAccessSQL(sql.toString(), "oi", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
    log.finer(finalSql);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    //
    MAging aging = null;
    int counter = 0;
    int rows = 0;
    int AD_PInstance_ID = getAD_PInstance_ID();
    //
    try {
        pstmt = DB.prepareStatement(finalSql, get_TrxName());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int C_BP_Group_ID = rs.getInt(1);
            int C_BPartner_ID = rs.getInt(2);
            int C_Invoice_ID = p_IsListInvoices ? rs.getInt(3) : 0;
            int C_InvoicePaySchedule_ID = p_IsListInvoices ? rs.getInt(4) : 0;
            int C_Currency_ID = rs.getInt(5);
            boolean IsSOTrx = "Y".equals(rs.getString(6));
            //
            Timestamp DateInvoiced = rs.getTimestamp(7);
            int NetDays = rs.getInt(8);
            Timestamp DueDate = rs.getTimestamp(9);
            //	Days Due
            int DaysDue = //	based on today
            rs.getInt(10) + m_statementOffset;
            //
            BigDecimal GrandTotal = rs.getBigDecimal(11);
            BigDecimal PaidAmt = rs.getBigDecimal(12);
            BigDecimal OpenAmt = rs.getBigDecimal(13);
            //
            int C_Activity_ID = p_IsListInvoices ? rs.getInt(14) : 0;
            int C_Campaign_ID = p_IsListInvoices ? rs.getInt(15) : 0;
            int C_Project_ID = p_IsListInvoices ? rs.getInt(16) : 0;
            int AD_Org_ID = rs.getInt(17);
            rows++;
            //	New Aging Row
            if (//	Key
            aging == null || AD_PInstance_ID != aging.getAD_PInstance_ID() || C_BPartner_ID != aging.getC_BPartner_ID() || C_Currency_ID != aging.getC_Currency_ID() || C_Invoice_ID != aging.getC_Invoice_ID() || C_InvoicePaySchedule_ID != aging.getC_InvoicePaySchedule_ID()) {
                if (aging != null) {
                    aging.saveEx();
                    log.fine("#" + ++counter + " - " + aging);
                }
                aging = new MAging(getCtx(), AD_PInstance_ID, p_StatementDate, C_BPartner_ID, C_Currency_ID, C_Invoice_ID, C_InvoicePaySchedule_ID, C_BP_Group_ID, AD_Org_ID, DueDate, IsSOTrx, get_TrxName());
                aging.setC_Activity_ID(C_Activity_ID);
                aging.setC_Campaign_ID(C_Campaign_ID);
                aging.setC_Project_ID(C_Project_ID);
                aging.set_ValueOfColumn("C_BankAccount_ID", 0);
                aging.set_ValueOfColumn("C_CashFlow_ID", 0);
                aging.setDateAcct(p_DateAcct);
            }
            //	Fill Buckets
            aging.add(DueDate, DaysDue, GrandTotal, OpenAmt);
        }
        if (aging != null) {
            aging.saveEx();
            counter++;
            log.fine("#" + counter + " - " + aging);
        }
    } catch (SQLException e) {
        throw new DBException(e, finalSql);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	
    log.info("#" + counter + " - rows=" + rows);
    return "";
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) MAging(org.compiere.model.MAging) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 18 with DBException

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

the class MWFNode method loadTrl.

//	loadNext
/**
	 * 	Load Translation
	 */
private void loadTrl() {
    if (Env.isBaseLanguage(getCtx(), "AD_Workflow") || get_ID() == 0)
        return;
    final String sql = "SELECT Name, Description, Help FROM AD_WF_Node_Trl" + " WHERE AD_WF_Node_ID=? AND AD_Language=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        pstmt.setInt(1, get_ID());
        pstmt.setString(2, Env.getAD_Language(getCtx()));
        rs = pstmt.executeQuery();
        if (rs.next()) {
            m_name_trl = rs.getString(1);
            m_description_trl = rs.getString(2);
            m_help_trl = rs.getString(3);
            m_translated = true;
        }
    } catch (SQLException e) {
        //log.log(Level.SEVERE, sql, e);
        throw new DBException(e, sql);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    log.fine("Trl=" + m_translated);
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 19 with DBException

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

the class MSystem method setDBInfo.

//	setInternalUsers
/**
	 * 	Set DB Info
	 */
private void setDBInfo() {
    String dbAddress = CConnection.get().getConnectionURL();
    setDBAddress(dbAddress.toLowerCase());
    //
    if (!Ini.isClient()) {
        int noProcessors = Runtime.getRuntime().availableProcessors();
        setNoProcessors(noProcessors);
    }
    //
    String dbName = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String sql = null;
    try {
        String dbType = CConnection.get().getDatabase().getName();
        sql = getDBInfoSQL(dbType);
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            //	dbAddress = rs.getString(1);
            dbName = rs.getString(2);
            setDBInstance(dbName.toLowerCase());
        }
    } catch (SQLException e) {
        throw new DBException(e, sql);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 20 with DBException

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

the class MSystem method getProfileInfo.

//	getStatisticsInfo
/**
	 * 	Get Profile Info
	 * 	@param recalc recalculate
	 *	@return profile
	 */
public String getProfileInfo(boolean recalc) {
    String s = super.getProfileInfo();
    if (s == null || recalc) {
        final String sql = "SELECT Value FROM AD_Client " + " WHERE IsActive='Y' ORDER BY AD_Client_ID DESC";
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        StringBuffer sb = new StringBuffer();
        try {
            pstmt = DB.prepareStatement(sql, null);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                sb.append(rs.getString(1)).append('|');
            }
        } catch (SQLException e) {
            throw new DBException(e, sql);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
        s = sb.toString();
    }
    return s;
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

DBException (org.adempiere.exceptions.DBException)89 SQLException (java.sql.SQLException)82 PreparedStatement (java.sql.PreparedStatement)75 ResultSet (java.sql.ResultSet)75 BigDecimal (java.math.BigDecimal)27 ArrayList (java.util.ArrayList)23 Timestamp (java.sql.Timestamp)15 POResultSet (org.compiere.model.POResultSet)8 AdempiereException (org.adempiere.exceptions.AdempiereException)6 KeyNamePair (org.compiere.util.KeyNamePair)5 Connection (java.sql.Connection)4 Savepoint (java.sql.Savepoint)4 MProduct (org.compiere.model.MProduct)4 Trx (org.compiere.util.Trx)4 Date (java.util.Date)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IDColumn (org.compiere.minigrid.IDColumn)2 MLocator (org.compiere.model.MLocator)2 MTable (org.compiere.model.MTable)2 MUOM (org.compiere.model.MUOM)2