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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations