use of org.apache.commons.collections.keyvalue.MultiKey in project ribbon by Netflix.
the class NFHttpClientFactory method getNFHttpClient.
public static NFHttpClient getNFHttpClient(String host, int port) {
MultiKey mk = new MultiKey(host, port);
NFHttpClient client = clientMap.get(mk);
if (client == null) {
client = new NFHttpClient(host, port);
clientMap.put(mk, client);
}
return client;
}
use of org.apache.commons.collections.keyvalue.MultiKey in project adempiere by adempiere.
the class MAssetAcct method forA_Asset_ID.
/**
* Get asset accounting.
* @param ctx context
* @param A_Asset_ID asset
* @param postingType Posting type
* @param dateAcct check ValidFrom
* @return asset accounting for the given asset
*/
public static MAssetAcct forA_Asset_ID(Properties ctx, int A_Asset_ID, String postingType, Timestamp dateAcct, String trxName) {
MultiKey key = new MultiKey(A_Asset_ID, postingType, dateAcct);
MAssetAcct acct = null;
if (trxName == null) {
// do not use cache
//acct = s_cacheAsset.get(key);
}
if (acct != null) {
return acct;
}
//
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer whereClause = new StringBuffer(COLUMNNAME_A_Asset_ID + "=? AND " + COLUMNNAME_PostingType + "=?");
params.add(A_Asset_ID);
params.add(postingType);
if (dateAcct != null) {
whereClause.append(" AND " + COLUMNNAME_ValidFrom).append("<=?");
params.add(dateAcct);
}
acct = new Query(ctx, Table_Name, whereClause.toString(), trxName).setParameters(params).setOrderBy(COLUMNNAME_ValidFrom + " DESC NULLS LAST").first();
if (trxName == null) {
addToCache(acct, key);
}
return acct;
}
use of org.apache.commons.collections.keyvalue.MultiKey in project adempiere by adempiere.
the class MTableScriptValidator method getModelValidatorRules.
// get
/**
* Get Model Validation Script Rules for a table/event
* @param ctx context
* @param table_id AD_Table_ID
* @param event Event
* @return array of MTableScriptValidator or null if error or no validators found
*/
public static List<MTableScriptValidator> getModelValidatorRules(Properties ctx, int ad_table_id, String event) {
// Try cache
final MultiKey key = new MultiKey(ad_table_id, event);
List<MTableScriptValidator> mvrs = s_cacheTableEvent.get(key);
if (mvrs != null) {
if (mvrs.size() > 0)
return mvrs;
else
return null;
}
//
// Fetch now
final String whereClause = "AD_Table_ID=? AND EventModelValidator=?";
mvrs = new Query(ctx, Table_Name, whereClause, null).setParameters(ad_table_id, event).setOnlyActiveRecords(true).setOrderBy(COLUMNNAME_SeqNo).list();
// Store to cache
for (MTableScriptValidator rule : mvrs) {
s_cache.put(rule.get_ID(), rule);
}
// Store to cache
if (mvrs != null)
s_cacheTableEvent.put(key, mvrs);
//
if (mvrs != null && mvrs.size() > 0)
return mvrs;
else
return null;
}
use of org.apache.commons.collections.keyvalue.MultiKey in project adempiere by adempiere.
the class RequisitionPOCreate method newOrder.
// process
/**
* Create new Order
* @param rLine request line
* @param C_BPartner_ID b.partner
* @throws Exception
*/
private void newOrder(MRequisitionLine rLine, int C_BPartner_ID) throws Exception {
if (m_order != null) {
closeOrder();
}
// BPartner
if (m_bpartner == null || C_BPartner_ID != m_bpartner.get_ID()) {
m_bpartner = MBPartner.get(getCtx(), C_BPartner_ID);
}
// Order
Timestamp DateRequired = rLine.getDateRequired();
int M_PriceList_ID = rLine.getParent().getM_PriceList_ID();
MultiKey key = new MultiKey(C_BPartner_ID, DateRequired, M_PriceList_ID);
m_order = m_cacheOrders.get(key);
if (m_order == null) {
m_order = new MOrder(getCtx(), 0, get_TrxName());
m_order.setAD_Org_ID(rLine.getAD_Org_ID());
m_order.setM_Warehouse_ID(rLine.getParent().getM_Warehouse_ID());
m_order.setDatePromised(DateRequired);
m_order.setIsSOTrx(false);
m_order.setC_DocTypeTarget_ID();
m_order.setBPartner(m_bpartner);
m_order.setM_PriceList_ID(M_PriceList_ID);
// default po document type
if (!p_ConsolidateDocument) {
m_order.setDescription(Msg.getElement(getCtx(), "M_Requisition_ID") + ": " + rLine.getParent().getDocumentNo());
}
// Prepare Save
m_order.saveEx();
// Put to cache
m_cacheOrders.put(key, m_order);
}
m_M_Requisition_ID = rLine.getM_Requisition_ID();
}
use of org.apache.commons.collections.keyvalue.MultiKey in project adempiere by adempiere.
the class MDepreciationWorkfile method get.
/**
* Get/load workfile from cache (if trxName is null)
* @param ctx
* @param A_Asset_ID
* @param postingType
* @param trxName
* @return workfile
*/
public static MDepreciationWorkfile get(Properties ctx, int A_Asset_ID, String postingType, String trxName) {
if (A_Asset_ID <= 0 || postingType == null) {
return null;
}
final MultiKey key = new MultiKey(A_Asset_ID, postingType);
if (trxName == null) {
MDepreciationWorkfile wk = s_cacheAsset.get(key);
if (wk != null)
return wk;
}
/* @win temporary change as this code is causing duplicate create MDepreciationWorkfile on asset addition
final String whereClause = COLUMNNAME_A_Asset_ID+"=?"
+" AND "+COLUMNNAME_PostingType+"=? AND "+COLUMNNAME_A_QTY_Current+">?";
MDepreciationWorkfile wk = new Query(ctx, MDepreciationWorkfile.Table_Name, whereClause, trxName)
.setParameters(new Object[]{A_Asset_ID, postingType, 0})
.firstOnly();
*/
final String whereClause = COLUMNNAME_A_Asset_ID + "=?" + " AND " + COLUMNNAME_PostingType + "=? ";
MDepreciationWorkfile wk = new Query(ctx, MDepreciationWorkfile.Table_Name, whereClause, trxName).setParameters(new Object[] { A_Asset_ID, postingType }).firstOnly();
if (trxName == null && wk != null) {
s_cacheAsset.put(key, wk);
}
return wk;
}