Search in sources :

Example 31 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class Info method testCount.

//  executeQuery
/**
	 * 	Test Row Count
	 *	@return true if display
	 */
private boolean testCount() {
    long start = System.currentTimeMillis();
    String dynWhere = getSQLWhere();
    StringBuffer sql = new StringBuffer(m_sqlCount);
    if (dynWhere.length() > 0)
        //  includes first AND
        sql.append(dynWhere);
    //	Variables
    String countSql = Msg.parseTranslation(Env.getCtx(), sql.toString());
    countSql = MRole.getDefault().addAccessSQL(countSql, getTableName(), MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
    log.finer(countSql);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    int no = -1;
    try {
        pstmt = DB.prepareStatement(countSql, null);
        setParameters(pstmt, true);
        rs = pstmt.executeQuery();
        if (rs.next())
            no = rs.getInt(1);
    } catch (Exception e) {
        log.log(Level.SEVERE, countSql, e);
        no = -2;
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    log.fine("#" + no + " - " + (System.currentTimeMillis() - start) + "ms");
    //Armen: add role checking (Patch #1694788 )
    MRole role = MRole.getDefault();
    if (role.isQueryMax(no))
        return ADialog.ask(p_WindowNo, this, "InfoHighRecordCount", String.valueOf(no));
    return true;
}
Also used : MRole(org.compiere.model.MRole) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 32 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class Find method getQuery.

//	cmd_refresh
/**************************************************************************
	 *	Get Query - Retrieve result
	 *  @return String representation of query
	 */
public MQuery getQuery() {
    MRole role = MRole.getDefault();
    if (role.isQueryMax(getTotalRecords()) && !m_isCancel) {
        m_query = MQuery.getNoRecordQuery(m_tableName, false);
        m_total = 0;
        log.warning("Query - over max");
    } else
        log.info("Query=" + m_query);
    return m_query;
}
Also used : MRole(org.compiere.model.MRole)

Example 33 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class Find method getNoOfRecords.

//	getTotalRecords
/**
	 *	Get the number of records of target tab
	 *  @param query where clause for target tab
	 * 	@param alertZeroRecords show dialog if there are no records
	 *  @return number of selected records;
	 *          if the results are more then allowed this method will return 0
	 */
private int getNoOfRecords(MQuery query, boolean alertZeroRecords) {
    log.config("" + query);
    StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM ");
    sql.append(m_tableName);
    boolean hasWhere = false;
    if (m_whereExtended != null && m_whereExtended.length() > 0) {
        sql.append(" WHERE ").append(m_whereExtended);
        hasWhere = true;
    }
    if (query != null && query.isActive()) {
        if (hasWhere)
            sql.append(" AND ");
        else
            sql.append(" WHERE ");
        sql.append(query.getWhereClause());
    }
    //	Add Access
    String finalSQL = MRole.getDefault().addAccessSQL(sql.toString(), m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    finalSQL = Env.parseContext(Env.getCtx(), m_targetWindowNo, finalSQL, false);
    Env.setContext(Env.getCtx(), m_targetWindowNo, TABNO, GridTab.CTX_FindSQL, finalSQL);
    //  Execute Qusery
    m_total = 999999;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        stmt = DB.createStatement();
        rs = stmt.executeQuery(finalSQL);
        if (rs.next())
            m_total = rs.getInt(1);
    } catch (SQLException e) {
        log.log(Level.SEVERE, finalSQL, e);
    } finally {
        DB.close(rs, stmt);
        rs = null;
        stmt = null;
    }
    MRole role = MRole.getDefault();
    //	No Records
    if (m_total == 0 && alertZeroRecords)
        ADialog.info(m_targetWindowNo, this, "FindZeroRecords");
    else //	More then allowed
    if (query != null && role.isQueryMax(m_total)) {
        ADialog.error(m_targetWindowNo, this, "FindOverMax", m_total + " > " + role.getMaxQueryRecords());
        // return 0 if more then allowed - teo_sarca [ 1708717 ]
        m_total = 0;
    } else
        log.config("#" + m_total);
    //
    if (query != null)
        statusBar.setStatusToolTip(query.getWhereClause());
    return m_total;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) MRole(org.compiere.model.MRole) ResultSet(java.sql.ResultSet)

Example 34 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class FindWindow method getQuery.

//  parseValue
/**************************************************************************
     *  Get Query - Retrieve result
     *  @return String representation of query
     */
public MQuery getQuery() {
    MRole role = MRole.getDefault();
    if (role.isQueryMax(getTotalRecords()) && !m_isCancel) {
        m_query = MQuery.getNoRecordQuery(m_tableName, false);
        m_total = 0;
        log.warning("Query - over max");
    } else
        log.info("Query=" + m_query);
    return m_query;
}
Also used : MRole(org.compiere.model.MRole)

Example 35 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class MPrintFormat method getItems.

//	setItems
/**
	 * 	Get active Items
	 * 	@return items
	 */
private MPrintFormatItem[] getItems() {
    ArrayList<MPrintFormatItem> list = new ArrayList<MPrintFormatItem>();
    String sql = "SELECT * FROM AD_PrintFormatItem pfi " + "WHERE pfi.AD_PrintFormat_ID=? AND pfi.IsActive='Y'" + //	Display restrictions - Passwords, etc.
    " AND NOT EXISTS (SELECT * FROM AD_Field f " + "WHERE pfi.AD_Column_ID=f.AD_Column_ID" + " AND (f.IsEncrypted='Y' OR f.ObscureType IS NOT NULL))" + "ORDER BY SeqNo";
    MRole role = MRole.getDefault(getCtx(), false);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        pstmt.setInt(1, get_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            MPrintFormatItem pfi = new MPrintFormatItem(p_ctx, rs, get_TrxName());
            if (role.isColumnAccess(getAD_Table_ID(), pfi.getAD_Column_ID(), true))
                list.add(pfi);
        }
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //
    MPrintFormatItem[] retValue = new MPrintFormatItem[list.size()];
    list.toArray(retValue);
    return retValue;
}
Also used : SQLException(java.sql.SQLException) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CPreparedStatement(org.compiere.util.CPreparedStatement)

Aggregations

MRole (org.compiere.model.MRole)42 PreparedStatement (java.sql.PreparedStatement)14 ResultSet (java.sql.ResultSet)14 SQLException (java.sql.SQLException)11 ArrayList (java.util.ArrayList)7 Point (java.awt.Point)4 Properties (java.util.Properties)4 BigDecimal (java.math.BigDecimal)3 Statement (java.sql.Statement)3 GridField (org.compiere.model.GridField)3 GridTab (org.compiere.model.GridTab)3 QName (javax.xml.namespace.QName)2 MBrowse (org.adempiere.model.MBrowse)2 XFireFault (org.codehaus.xfire.fault.XFireFault)2 ICreateFrom (org.compiere.grid.ICreateFrom)2 MOrgInfo (org.compiere.model.MOrgInfo)2 MProcess (org.compiere.model.MProcess)2 MTable (org.compiere.model.MTable)2 MWFActivity (org.compiere.wf.MWFActivity)2 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)2