IDEMPIERE 4287 (#247)

* IDEMPIERE-4287 Cache API not thread safe and inconsistent with Context
add support to make PO immutable

* IDEMPIERE-4287 Cache API not thread safe and inconsistent with Context
- added thread safe Immutable and Copy cache implementation for PO.
- migrate most of PO cache to immutable and copy cache.
- added pos sales order test.

* IDEMPIERE-4287 Cache API not thread safe and inconsistent with Context
- add test case for initial client setup and bank statement
- fix error for image editor, location editor, locator editor, initial
client setup, complete bank statement and migrate storage provider.

* IDEMPIERE-4287 Cache API not thread safe and inconsistent with Context
- added ImmutablePOSupport interface. Model class implement this
interface for immutable PO support.
- remove usage of cache for transaction table (rfq, invoice, inventory).
- add getCopy method to some model class to support getting an
updateable copy of PO from the otherwise immutable PO cache.
- the added getCopy method is use to return updateable PO for indirect
PO reference, for e.g MColumn.getAD_Table() and MOrderLine.getProduct.
This commit is contained in:
hengsin 2020-09-21 14:03:00 +08:00 committed by GitHub
parent 9509d95c7c
commit dd2ef468b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
223 changed files with 12310 additions and 1883 deletions

View File

@ -172,6 +172,7 @@ public class InitialClientSetup extends SvrProcess
*/
protected String doIt () throws Exception
{
boolean isDryRun = "Y".equalsIgnoreCase(Env.getContext(Env.getCtx(), Env.RUNNING_UNIT_TESTING_TEST_CASE));
StringBuilder msglog = new StringBuilder("InitialClientSetup")
.append(": ClientName=").append(p_ClientName)
@ -261,7 +262,7 @@ public class InitialClientSetup extends SvrProcess
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "CoaFile") + " " + p_CoAFile + " " + Msg.getMsg(Env.getCtx(), "is empty"));
// Process
MSetup ms = new MSetup(Env.getCtx(), WINDOW_THIS_PROCESS);
MSetup ms = new MSetup(Env.getCtx(), WINDOW_THIS_PROCESS, isDryRun);
try {
if (! ms.createClient(p_ClientName, p_OrgValue, p_OrgName, p_AdminUserName, p_NormalUserName
, p_Phone, p_Phone2, p_Fax, p_EMail, p_TaxID, p_AdminUserEmail, p_NormalUserEmail, p_IsSetInitialPassword)) {
@ -289,7 +290,9 @@ public class InitialClientSetup extends SvrProcess
addLog(ms.getInfo());
// Create Print Documents
PrintUtil.setupPrintForm(ms.getAD_Client_ID());
PrintUtil.setupPrintForm(ms.getAD_Client_ID(), isDryRun ? ms.getTrxName() : null);
if (isDryRun)
ms.rollback();
} catch (Exception e) {
ms.rollback();
throw e;

View File

@ -59,8 +59,7 @@ public class ConvertLead extends SvrProcess {
if (p_AD_User_ID <= 0)
throw new FillMandatoryException("AD_User_ID");
MUser lead = MUser.get(getCtx(), p_AD_User_ID);
lead.set_TrxName(get_TrxName());
MUser lead = new MUser(getCtx(), p_AD_User_ID, get_TrxName());
if (!lead.isSalesLead() && lead.getC_BPartner_ID() != 0)
throw new AdempiereUserError("Lead already converted");

View File

@ -29,6 +29,7 @@ import org.compiere.model.MColumn;
import org.compiere.model.MElementValue;
import org.compiere.model.X_I_ElementValue;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* Import Accounts from I_ElementValue
@ -605,7 +606,7 @@ public class ImportAccount extends SvrProcess
{
if (m_createNewCombination)
{
MAccount acct = MAccount.get(getCtx(), C_ValidCombination_ID);
MAccount acct = new MAccount(Env.getCtx(), C_ValidCombination_ID, (String)null);
acct.setAccount_ID(C_ElementValue_ID);
if (acct.save())
{

View File

@ -79,8 +79,7 @@ public class UserPassword extends SvrProcess
{
if (log.isLoggable(Level.INFO)) log.info ("AD_User_ID=" + p_AD_User_ID + " from " + getAD_User_ID());
MUser user = MUser.get(getCtx(), p_AD_User_ID);
user.load(get_TrxName());
MUser user = new MUser(getCtx(), p_AD_User_ID, get_TrxName());
MUser operator = MUser.get(getCtx(), getAD_User_ID());
if (log.isLoggable(Level.FINE)) log.fine("User=" + user + ", Operator=" + operator);

View File

@ -157,7 +157,7 @@ public class MigrateStorageProvider extends SvrProcess {
// for each client
for (int clientid : clients) {
idxClient++;
MClientInfo clientInfo = MClientInfo.get(getCtx(), clientid);
MClientInfo clientInfo = MClientInfo.getCopy(getCtx(), clientid, (String)null);
MClient client = MClient.get(getCtx(), clientid);
int odometer = 10;

View File

@ -50,6 +50,7 @@ Export-Package: bsh,
org.compiere.wf,
org.eevolution.model,
org.idempiere.broadcast,
org.idempiere.cache,
org.idempiere.distributed,
org.idempiere.fa.service.api,
org.idempiere.model

View File

@ -17,9 +17,10 @@ import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.model.X_AD_BroadcastMessage;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
*
@ -27,14 +28,14 @@ import org.compiere.util.Env;
* @author Deepak Pansheriya
*
*/
public class MBroadcastMessage extends X_AD_BroadcastMessage
public class MBroadcastMessage extends X_AD_BroadcastMessage implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 1908264699133879072L;
private static final long serialVersionUID = -5402131480890468471L;
static private CCache<Integer,MBroadcastMessage> s_cache = new CCache<Integer,MBroadcastMessage>("AD_BroadcastMessage", 30, 60);
static private ImmutableIntPOCache<Integer,MBroadcastMessage> s_cache = new ImmutableIntPOCache<Integer,MBroadcastMessage>("AD_BroadcastMessage", 30, 60);
public MBroadcastMessage(Properties ctx, int AD_BroadcastMessage_ID,
String trxName)
@ -47,16 +48,67 @@ public class MBroadcastMessage extends X_AD_BroadcastMessage
{
super(ctx, rs, trxName);
}
/**
*
* @param copy
*/
public MBroadcastMessage(MBroadcastMessage copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MBroadcastMessage(Properties ctx, MBroadcastMessage copy)
{
this(ctx, copy, (String)null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MBroadcastMessage(Properties ctx, MBroadcastMessage copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get MBroadcastMessage from cache (immutable)
* @param AD_BroadcastMessage_ID
* @return MBroadcastMessage or null
*/
public static MBroadcastMessage get (int AD_BroadcastMessage_ID)
{
return get(Env.getCtx(), AD_BroadcastMessage_ID);
}
/**
* Get MBroadcastMessage from cache (immutable)
* @param ctx
* @param AD_BroadcastMessage_ID
* @return MBroadcastMessage or null
*/
public static MBroadcastMessage get (Properties ctx, int AD_BroadcastMessage_ID)
{
Integer key = Integer.valueOf(AD_BroadcastMessage_ID);
MBroadcastMessage retValue = (MBroadcastMessage)s_cache.get(key);
MBroadcastMessage retValue = s_cache.get(ctx, key, e -> new MBroadcastMessage(ctx, e));
if (retValue == null)
{
retValue = new MBroadcastMessage (ctx, AD_BroadcastMessage_ID, null);
s_cache.put(key, retValue);
retValue = new MBroadcastMessage (ctx, AD_BroadcastMessage_ID, (String)null);
if (retValue.get_ID() == AD_BroadcastMessage_ID)
{
s_cache.put(key, retValue, e -> new MBroadcastMessage(Env.getCtx(), e));
return retValue;
}
return null;
}
return retValue;
} // get
@ -116,4 +168,12 @@ public class MBroadcastMessage extends X_AD_BroadcastMessage
return true;
}
@Override
public MBroadcastMessage markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
}

View File

@ -22,9 +22,10 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Account Object Entity to maintain all segment values.
@ -35,14 +36,14 @@ import org.compiere.util.Env;
* <li>RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335
* @version $Id: MAccount.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $
*/
public class MAccount extends X_C_ValidCombination
public class MAccount extends X_C_ValidCombination implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 7980515458720808532L;
private static final long serialVersionUID = 1927316490582718406L;
private static final CCache<Integer, MAccount> s_cache = new CCache<Integer, MAccount>(Table_Name, 100);
private static final ImmutableIntPOCache<Integer, MAccount> s_cache = new ImmutableIntPOCache<Integer, MAccount>(Table_Name, 100);
/*
* Deprecated - use the same method with trxName instead
@ -359,29 +360,35 @@ public class MAccount extends X_C_ValidCombination
return vc;
} // getDefault
/**
* Get Account
* @param ctx context
* Get Account from cache (immutable)
* @param C_ValidCombination_ID combination
* @return Account
*/
public static MAccount get (int C_ValidCombination_ID)
{
return get(Env.getCtx(), C_ValidCombination_ID);
}
/**
* Get Account from cache (immutable)
* @param ctx context
* @param C_ValidCombination_ID combination
* @return Immutable instance of Account
*/
public static MAccount get (Properties ctx, int C_ValidCombination_ID)
{
MAccount account = s_cache.get(C_ValidCombination_ID);
if (account != null && account.getCtx() == ctx)
MAccount account = s_cache.get(ctx, C_ValidCombination_ID, e -> new MAccount(ctx, e));
if (account != null)
return account;
account = new MAccount(ctx, C_ValidCombination_ID, null);
account = new MAccount(ctx, C_ValidCombination_ID, (String)null);
if (account.getC_ValidCombination_ID() == C_ValidCombination_ID)
{
s_cache.put(C_ValidCombination_ID, account);
s_cache.put(C_ValidCombination_ID, account, e -> new MAccount(Env.getCtx(), e));
return account;
}
else
{
return null;
}
return null;
} // getAccount
/**
@ -447,6 +454,38 @@ public class MAccount extends X_C_ValidCombination
setC_AcctSchema_ID(as.getC_AcctSchema_ID());
} // Account
/**
*
* @param copy
*/
public MAccount(MAccount copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAccount(Properties ctx, MAccount copy)
{
this(ctx, copy, (String)null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAccount(Properties ctx, MAccount copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_accountEV = copy.m_accountEV != null ? new MElementValue(ctx, copy.m_accountEV, trxName) : null;
}
/** Account Segment */
private MElementValue m_accountEV = null;
@ -521,7 +560,11 @@ public class MAccount extends X_C_ValidCombination
if (m_accountEV == null)
{
if (getAccount_ID() != 0)
{
m_accountEV = new MElementValue(getCtx(), getAccount_ID(), get_TrxName());
if (is_Immutable())
m_accountEV.markImmutable();
}
}
return m_accountEV;
} // setAccount
@ -838,6 +881,17 @@ public class MAccount extends X_C_ValidCombination
} // beforeSave
@Override
public MAccount markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
if (m_accountEV != null)
m_accountEV.markImmutable();
return this;
}
/**
* Test
* @param args

View File

@ -18,13 +18,17 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.report.MReportTree;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Accounting Schema Model (base)
@ -34,26 +38,37 @@ import org.compiere.util.KeyNamePair;
* <li>RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335
* @version $Id: MAcctSchema.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $
*/
public class MAcctSchema extends X_C_AcctSchema
public class MAcctSchema extends X_C_AcctSchema implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 8940388112876468770L;
private static final long serialVersionUID = 405097978362430053L;
/**
* Get AccountSchema of Client
* Get AccountSchema
* @param C_AcctSchema_ID schema id
* @return Accounting schema
*/
public static MAcctSchema get (int C_AcctSchema_ID)
{
return get(Env.getCtx(), C_AcctSchema_ID);
}
/**
* Get AccountSchema
* @param ctx context
* @param C_AcctSchema_ID schema id
* @return Accounting schema
*/
public static MAcctSchema get (Properties ctx, int C_AcctSchema_ID)
{
return get(ctx, C_AcctSchema_ID, null);
return get(ctx, C_AcctSchema_ID, (String)null);
} // get
/**
* Get AccountSchema of Client
* Get AccountSchema
* @param ctx context
* @param C_AcctSchema_ID schema id
* @param trxName optional trx
@ -63,15 +78,34 @@ public class MAcctSchema extends X_C_AcctSchema
{
// Check Cache
Integer key = Integer.valueOf(C_AcctSchema_ID);
MAcctSchema retValue = (MAcctSchema)s_cache.get(key);
MAcctSchema retValue = s_cache.get(ctx, key, e -> new MAcctSchema(ctx, e));
if (retValue != null)
return retValue;
retValue = new MAcctSchema (ctx, C_AcctSchema_ID, trxName);
if (trxName == null)
s_cache.put(key, retValue);
return retValue;
if (retValue.get_ID() == C_AcctSchema_ID)
{
s_cache.put(key, retValue, e -> new MAcctSchema(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MAcctSchema from cache
* @param ctx
* @param C_AcctSchema_ID
* @param trxName
* @return MAcctSchema
*/
public static MAcctSchema getCopy(Properties ctx, int C_AcctSchema_ID, String trxName)
{
MAcctSchema as = get(ctx, C_AcctSchema_ID, trxName);
if (as != null)
as = new MAcctSchema(ctx, as, trxName);
return as;
}
/**
* Get AccountSchema of Client
* @param ctx context
@ -95,7 +129,12 @@ public class MAcctSchema extends X_C_AcctSchema
// Check Cache
Integer key = Integer.valueOf(AD_Client_ID);
if (s_schema.containsKey(key))
return (MAcctSchema[])s_schema.get(key);
{
if (ctx == Env.getCtx())
return s_schema.get(key);
else
return Arrays.stream(s_schema.get(key)).map(e -> { return new MAcctSchema(ctx, e).markImmutable(); }).toArray(MAcctSchema[]::new);
}
// Create New
ArrayList<MAcctSchema> list = new ArrayList<MAcctSchema>();
@ -124,22 +163,27 @@ public class MAcctSchema extends X_C_AcctSchema
{
if (acctschema.get_ID() != info.getC_AcctSchema1_ID()) // already in list
{
if (acctschema.get_ID() != 0)
if (acctschema.get_ID() != 0)
{
acctschema.markImmutable();
list.add(acctschema);
}
}
}
// Save
MAcctSchema[] retValue = new MAcctSchema [list.size()];
list.toArray(retValue);
if (trxName == null)
if (ctx == Env.getCtx())
s_schema.put(key, retValue);
else
s_schema.put(key, Arrays.stream(retValue).map(e -> {return new MAcctSchema(Env.getCtx(), e).markImmutable();}).toArray(MAcctSchema[]::new));
return retValue;
} // getClientAcctSchema
/** Cache of Client AcctSchema Arrays **/
private static CCache<Integer,MAcctSchema[]> s_schema = new CCache<Integer,MAcctSchema[]>(I_AD_ClientInfo.Table_Name, I_AD_ClientInfo.Table_Name+"|MAcctSchema[]", 3, 120, true); // 3 clients
/** Cache of AcctSchemas **/
private static CCache<Integer,MAcctSchema> s_cache = new CCache<Integer,MAcctSchema>(Table_Name, 3, 120, true); // 3 accounting schemas
private static ImmutableIntPOCache<Integer,MAcctSchema> s_cache = new ImmutableIntPOCache<Integer,MAcctSchema>(Table_Name, 3, 120, true); // 3 accounting schemas
/**************************************************************************
@ -200,6 +244,46 @@ public class MAcctSchema extends X_C_AcctSchema
setName (msgset.toString());
} // MAcctSchema
/**
*
* @param copy
*/
public MAcctSchema(MAcctSchema copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAcctSchema(Properties ctx, MAcctSchema copy)
{
this(ctx, copy, (String)null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAcctSchema(Properties ctx, MAcctSchema copy, String trxName)
{
super(ctx, 0, trxName);
copyPO(copy);
this.m_gl = copy.m_gl != null ? new MAcctSchemaGL(ctx, copy.m_gl) : null;
this.m_default = copy.m_default != null ? new MAcctSchemaDefault(ctx, copy.m_default) : null;
this.m_SuspenseError_Acct = copy.m_SuspenseError_Acct != null ? new MAccount(ctx, copy.m_SuspenseError_Acct) : null;
this.m_CurrencyBalancing_Acct = copy.m_CurrencyBalancing_Acct != null ? new MAccount(ctx, copy.m_CurrencyBalancing_Acct) : null;
this.m_DueTo_Acct = copy.m_DueTo_Acct != null ? new MAccount(ctx, copy.m_DueTo_Acct) : null;
this.m_DueFrom_Acct = copy.m_DueFrom_Acct != null ? new MAccount(ctx, copy.m_DueFrom_Acct) : null;
this.m_stdPrecision = copy.m_stdPrecision;
this.m_costPrecision = copy.m_costPrecision;
this.m_onlyOrg = copy.m_onlyOrg != null ? new MOrg(ctx, copy.m_onlyOrg) : null;
this.m_onlyOrgs = copy.m_onlyOrgs;
}
/** GL Info */
private MAcctSchemaGL m_gl = null;
@ -261,7 +345,11 @@ public class MAcctSchema extends X_C_AcctSchema
public MAcctSchemaGL getAcctSchemaGL()
{
if (m_gl == null)
{
m_gl = MAcctSchemaGL.get(getCtx(), getC_AcctSchema_ID());
if (m_gl != null && is_Immutable())
m_gl.markImmutable();
}
if (m_gl == null)
throw new IllegalStateException("No GL Definition for C_AcctSchema_ID=" + getC_AcctSchema_ID());
return m_gl;
@ -274,7 +362,11 @@ public class MAcctSchema extends X_C_AcctSchema
public MAcctSchemaDefault getAcctSchemaDefault()
{
if (m_default == null)
{
m_default = MAcctSchemaDefault.get(getCtx(), getC_AcctSchema_ID());
if (m_default != null && is_Immutable())
m_default.markImmutable();
}
if (m_default == null)
throw new IllegalStateException("No Default Definition for C_AcctSchema_ID=" + getC_AcctSchema_ID());
return m_default;
@ -314,7 +406,7 @@ public class MAcctSchema extends X_C_AcctSchema
if (m_gl == null)
getAcctSchemaGL();
int C_ValidCombination_ID = m_gl.getSuspenseBalancing_Acct();
m_SuspenseError_Acct = MAccount.get(getCtx(), C_ValidCombination_ID);
m_SuspenseError_Acct = MAccount.get(C_ValidCombination_ID);
return m_SuspenseError_Acct;
} // getSuspenseBalancing_Acct
@ -340,7 +432,7 @@ public class MAcctSchema extends X_C_AcctSchema
if (m_gl == null)
getAcctSchemaGL();
int C_ValidCombination_ID = m_gl.getCurrencyBalancing_Acct();
m_CurrencyBalancing_Acct = MAccount.get(getCtx(), C_ValidCombination_ID);
m_CurrencyBalancing_Acct = MAccount.get(C_ValidCombination_ID);
return m_CurrencyBalancing_Acct;
} // getCurrencyBalancing_Acct
@ -357,7 +449,7 @@ public class MAcctSchema extends X_C_AcctSchema
if (m_gl == null)
getAcctSchemaGL();
int C_ValidCombination_ID = m_gl.getIntercompanyDueTo_Acct();
m_DueTo_Acct = MAccount.get(getCtx(), C_ValidCombination_ID);
m_DueTo_Acct = MAccount.get(C_ValidCombination_ID);
return m_DueTo_Acct;
} // getDueTo_Acct
@ -373,7 +465,7 @@ public class MAcctSchema extends X_C_AcctSchema
if (m_gl == null)
getAcctSchemaGL();
int C_ValidCombination_ID = m_gl.getIntercompanyDueFrom_Acct();
m_DueFrom_Acct = MAccount.get(getCtx(), C_ValidCombination_ID);
m_DueFrom_Acct = MAccount.get(C_ValidCombination_ID);
return m_DueFrom_Acct;
} // getDueFrom_Acct
@ -416,7 +508,7 @@ public class MAcctSchema extends X_C_AcctSchema
if (getAD_OrgOnly_ID() == AD_Org_ID)
return false;
if (m_onlyOrg == null)
m_onlyOrg = MOrg.get(getCtx(), getAD_OrgOnly_ID());
m_onlyOrg = MOrg.get(getAD_OrgOnly_ID());
// Not Summary Only - i.e. skip it
if (!m_onlyOrg.isSummary())
return true;
@ -625,4 +717,18 @@ public class MAcctSchema extends X_C_AcctSchema
return true;
} // beforeSave
@Override
public MAcctSchema markImmutable()
{
if (is_Immutable())
return this;
makeImmutable();
if (m_gl != null)
m_gl.markImmutable();
if (m_default != null)
m_default.markImmutable();
return this;
}
} // MAcctSchema

View File

@ -21,7 +21,9 @@ import java.util.ArrayList;
import java.util.Properties;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Default Accounts for MAcctSchema
@ -31,14 +33,13 @@ import org.compiere.util.KeyNamePair;
* <li>RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335
* @version $Id: MAcctSchemaDefault.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
*/
public class MAcctSchemaDefault extends X_C_AcctSchema_Default
public class MAcctSchemaDefault extends X_C_AcctSchema_Default implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 199959007595802866L;
/**
*
*/
private static final long serialVersionUID = -7966846617443248102L;
/**
* Get Accounting Schema Default Info
@ -79,6 +80,37 @@ public class MAcctSchemaDefault extends X_C_AcctSchema_Default
super(ctx, rs, trxName);
} // MAcctSchemaDefault
/**
*
* @param copy
*/
public MAcctSchemaDefault(MAcctSchemaDefault copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAcctSchemaDefault(Properties ctx, MAcctSchemaDefault copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAcctSchemaDefault(Properties ctx, MAcctSchemaDefault copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get Realized Gain Acct for currency
* @param C_Currency_ID currency
@ -152,4 +184,13 @@ public class MAcctSchemaDefault extends X_C_AcctSchema_Default
return true;
} // beforeSave
@Override
public MAcctSchemaDefault markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MAcctSchemaDefault

View File

@ -28,6 +28,7 @@ import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.compiere.util.Msg;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Account Schema Element Object
@ -38,15 +39,15 @@ import org.compiere.util.Msg;
* @author victor.perez@e-evolution.com, www.e-evolution.com
* <li>RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335
*/
public class MAcctSchemaElement extends X_C_AcctSchema_Element
public class MAcctSchemaElement extends X_C_AcctSchema_Element implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -4642928142654938659L;
private static final long serialVersionUID = -747934131394469553L;
/**
* Factory: Return ArrayList of Account Schema Elements
* Get ArrayList of Account Schema Elements from cache
* @param as Accounting Schema
* @return ArrayList with Elements
*/
@ -71,12 +72,13 @@ public class MAcctSchemaElement extends X_C_AcctSchema_Element
if (s_log.isLoggable(Level.FINE)) s_log.fine(" - " + ase);
if (ase.isMandatory() && ase.getDefaultValue() == 0)
s_log.log(Level.SEVERE, "No default value for " + ase.getName());
ase.markImmutable();
list.add(ase);
}
retValue = new MAcctSchemaElement[list.size()];
list.toArray(retValue);
s_cache.put (key, retValue);
s_cache.put(key, retValue);
return retValue;
} // getAcctSchemaElements
@ -238,6 +240,38 @@ public class MAcctSchemaElement extends X_C_AcctSchema_Element
} // MAcctSchemaElement
/**
*
* @param copy
*/
public MAcctSchemaElement(MAcctSchemaElement copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAcctSchemaElement(Properties ctx, MAcctSchemaElement copy)
{
this(ctx, copy, (String)null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAcctSchemaElement(Properties ctx, MAcctSchemaElement copy, String trxName)
{
super(ctx, 0, trxName);
copyPO(copy);
this.m_ColumnName = copy.m_ColumnName;
}
/** User Element Column Name */
private String m_ColumnName = null;
@ -538,5 +572,14 @@ public class MAcctSchemaElement extends X_C_AcctSchema_Element
s_cache.clear();
return success;
} // afterDelete
@Override
public MAcctSchemaElement markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // AcctSchemaElement

View File

@ -21,7 +21,9 @@ import java.util.ArrayList;
import java.util.Properties;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.idempiere.cache.ImmutablePOSupport;
@ -33,15 +35,13 @@ import org.compiere.util.KeyNamePair;
* @author victor.perez@e-evolution.com, www.e-evolution.com
* <li>RF [ 2214883 ] Remove SQL code and Replace for Query http://sourceforge.net/tracker/index.php?func=detail&aid=2214883&group_id=176962&atid=879335
*/
public class MAcctSchemaGL extends X_C_AcctSchema_GL
public class MAcctSchemaGL extends X_C_AcctSchema_GL implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 5303102649110271896L;
/**
*
*/
private static final long serialVersionUID = -53120274583638950L;
/**
* Get Accounting Schema GL Info
@ -89,6 +89,37 @@ public class MAcctSchemaGL extends X_C_AcctSchema_GL
super(ctx, rs, trxName);
} // MAcctSchemaGL
/**
*
* @param copy
*/
public MAcctSchemaGL(MAcctSchemaGL copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAcctSchemaGL(Properties ctx, MAcctSchemaGL copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAcctSchemaGL(Properties ctx, MAcctSchemaGL copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get Acct Info list
* @return list
@ -131,4 +162,13 @@ public class MAcctSchemaGL extends X_C_AcctSchema_GL
return true;
} // beforeSave
@Override
public MAcctSchemaGL markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MAcctSchemaGL

View File

@ -19,7 +19,9 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
@ -31,18 +33,28 @@ import org.compiere.util.CCache;
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2736867 ] Add caching support to MActivity
*/
public class MActivity extends X_C_Activity
public class MActivity extends X_C_Activity implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 3014706648686670575L;
private static final long serialVersionUID = -5939026057597689130L;
/** Static Cache */
private static CCache<Integer, MActivity> s_cache = new CCache<Integer, MActivity>(Table_Name, 30);
private static ImmutableIntPOCache<Integer, MActivity> s_cache = new ImmutableIntPOCache<Integer, MActivity>(Table_Name, 30);
/**
* Get/Load Activity [CACHED]
* Get/Load Activity [CACHED] (immutable)
* @param C_Activity_ID
* @return activity or null
*/
public static MActivity get(int C_Activity_ID)
{
return get(Env.getCtx(), C_Activity_ID);
}
/**
* Get/Load Activity [CACHED] (immutable)
* @param ctx context
* @param C_Activity_ID
* @return activity or null
@ -54,22 +66,19 @@ public class MActivity extends X_C_Activity
return null;
}
// Try cache
MActivity activity = s_cache.get(C_Activity_ID);
MActivity activity = s_cache.get(ctx, C_Activity_ID, e -> new MActivity(ctx, e));
if (activity != null)
{
return activity;
}
// Load from DB
activity = new MActivity(ctx, C_Activity_ID, null);
activity = new MActivity(ctx, C_Activity_ID, (String)null);
if (activity.get_ID() == C_Activity_ID)
{
s_cache.put(C_Activity_ID, activity);
s_cache.put(C_Activity_ID, activity, e -> new MActivity(Env.getCtx(), e));
return activity;
}
else
{
activity = null;
}
return activity;
return null;
}
/**
@ -94,6 +103,36 @@ public class MActivity extends X_C_Activity
super(ctx, rs, trxName);
} // MActivity
/**
*
* @param copy
*/
public MActivity(MActivity copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MActivity(Properties ctx, MActivity copy)
{
this(ctx, copy, (String)null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MActivity(Properties ctx, MActivity copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* After Save.
@ -131,4 +170,13 @@ public class MActivity extends X_C_Activity
return success;
} // afterDelete
@Override
public MActivity markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MActivity

View File

@ -21,7 +21,6 @@ import java.sql.Timestamp;
import java.util.List;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -82,8 +81,8 @@ public class MAlertProcessor extends X_AD_AlertProcessor
super(ctx, rs, trxName);
} // MAlertProcessor
/** Cache: AD_AlertProcessor -> Alerts array */
private static CCache<Integer, MAlert[]> s_cacheAlerts = new CCache<Integer, MAlert[]>(I_AD_Alert.Table_Name, "AD_Alert|AlertProcessor", 10, false);
/** Cache: Alerts array */
private MAlert[] m_alerts = null;
/**
* Get Server ID
@ -145,9 +144,8 @@ public class MAlertProcessor extends X_AD_AlertProcessor
*/
public MAlert[] getAlerts (boolean reload)
{
MAlert[] alerts = s_cacheAlerts.get(get_ID());
if (alerts != null && !reload)
return alerts;
if (m_alerts != null && !reload)
return m_alerts;
final String whereClause ="AD_AlertProcessor_ID=?";
List <MAlert> list = new Query(getCtx(), I_AD_Alert.Table_Name, whereClause, null)
@ -156,10 +154,9 @@ public class MAlertProcessor extends X_AD_AlertProcessor
.list();
//
alerts = new MAlert[list.size ()];
list.toArray (alerts);
s_cacheAlerts.put(get_ID(), alerts);
return alerts;
m_alerts = new MAlert[list.size ()];
list.toArray (m_alerts);
return m_alerts;
} // getAlerts
/**

View File

@ -262,6 +262,38 @@ public class MAsset extends X_A_Asset
}
/**
*
* @param copy
*/
public MAsset(MAsset copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAsset(Properties ctx, MAsset copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAsset(Properties ctx, MAsset copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_DateAcct = copy.m_DateAcct;
}
/**
* Set Asset Group; also it sets other default fields
* @param assetGroup
@ -278,7 +310,7 @@ public class MAsset extends X_A_Asset
}
public MAssetGroup getAssetGroup() {
return MAssetGroup.get(getCtx(), getA_Asset_Group_ID());
return MAssetGroup.getCopy(getCtx(), getA_Asset_Group_ID(), get_TrxName());
}
/**

View File

@ -6,20 +6,22 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Asset Acct Model
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*/
public class MAssetAcct extends X_A_Asset_Acct
public class MAssetAcct extends X_A_Asset_Acct implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -3919172418904053712L;
private static final long serialVersionUID = -8898773839204909595L;
/**
* DO NOT USE DIRECTLY
@ -38,32 +40,69 @@ public class MAssetAcct extends X_A_Asset_Acct
super (ctx, rs, trxName);
}
/** Static Cache: A_Asset_Acct_ID -> MAssetAcct */
private static CCache<Integer,MAssetAcct> s_cache = new CCache<Integer,MAssetAcct>(Table_Name, 5);
/**
*
* @param copy
*/
public MAssetAcct(MAssetAcct copy)
{
this(Env.getCtx(), copy);
}
/**
* Get Asset Accounting (from cache)
*
* @param ctx
* @param copy
*/
public MAssetAcct(Properties ctx, MAssetAcct copy)
{
this(ctx, copy, (String)null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAssetAcct(Properties ctx, MAssetAcct copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** Static Cache: A_Asset_Acct_ID -> MAssetAcct */
private static ImmutableIntPOCache<Integer,MAssetAcct> s_cache = new ImmutableIntPOCache<Integer,MAssetAcct>(Table_Name, 5);
/**
* Get Asset Accounting (from cache) (immutable)
* @param A_Asset_Acct_ID asset accounting id
* @return asset accounting or null if not found
*/
public static MAssetAcct get (int A_Asset_Acct_ID)
{
return get(Env.getCtx(), A_Asset_Acct_ID);
}
/**
* Get Asset Accounting (from cache) (immutable)
* @param ctx context
* @param A_Asset_Acct_ID asset accounting id
* @return asset accounting or null if not found
*/
public static MAssetAcct get (Properties ctx, int A_Asset_Acct_ID)
{
MAssetAcct acct = s_cache.get(A_Asset_Acct_ID);
MAssetAcct acct = s_cache.get(ctx, A_Asset_Acct_ID, e -> new MAssetAcct(ctx, e));
if (acct != null)
return acct;
acct = new MAssetAcct(ctx, A_Asset_Acct_ID, (String)null);
if (acct.get_ID() == A_Asset_Acct_ID)
{
s_cache.put(A_Asset_Acct_ID, acct, e -> new MAssetAcct(Env.getCtx(), e));
return acct;
}
acct = new MAssetAcct(ctx, A_Asset_Acct_ID, null);
if (acct.get_ID() > 0)
{
addToCache(acct);
}
else
{
acct = null;
}
return acct;
return null;
}
/**
@ -91,22 +130,13 @@ public class MAssetAcct extends X_A_Asset_Acct
.setParameters(params)
.setOrderBy(COLUMNNAME_ValidFrom+" DESC NULLS LAST")
.first();
if (trxName == null)
if (acct.get_ID() > 0)
{
addToCache(acct);
s_cache.put(acct.get_ID(), acct, e -> new MAssetAcct(Env.getCtx(), e));
}
return acct;
}
private static void addToCache(MAssetAcct acct)
{
if (acct == null || acct.get_ID() <= 0)
{
return;
}
s_cache.put(acct.get_ID(), acct);
}
/**
* Create new asset accounting from asset group accounting
* @param asset asset
@ -143,7 +173,7 @@ public class MAssetAcct extends X_A_Asset_Acct
public MAcctSchema getC_AcctSchema()
{
return MAcctSchema.get(getCtx(), getC_AcctSchema_ID());
return MAcctSchema.getCopy(getCtx(), getC_AcctSchema_ID(), get_TrxName());
}
public MAccount getP_Asset_Acct(int M_Product_ID)
@ -162,5 +192,13 @@ public class MAssetAcct extends X_A_Asset_Acct
return true;
}
@Override
public MAssetAcct markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // class MAssetAcct

View File

@ -6,21 +6,23 @@ import java.util.Calendar;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.fa.feature.UseLifeImpl;
/** Asset Class
* @author Teo Sarca, SC Arhipac SRL
* @version $Id$
*/
public class MAssetClass extends X_A_Asset_Class
public class MAssetClass extends X_A_Asset_Class implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -6526341869523579715L;
private static final long serialVersionUID = -7805056592418891872L;
/**
*
@ -40,12 +42,51 @@ public class MAssetClass extends X_A_Asset_Class
super (ctx, rs, trxName);
} // MAssetClass
/**
*
* @param copy
*/
public MAssetClass(MAssetClass copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAssetClass(Properties ctx, MAssetClass copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAssetClass(Properties ctx, MAssetClass copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** */
private static CCache<Integer, MAssetClass> s_cache = new CCache<Integer, MAssetClass>(Table_Name, 20);
private static ImmutableIntPOCache<Integer, MAssetClass> s_cache = new ImmutableIntPOCache<Integer, MAssetClass>(Table_Name, 20);
/** Get Asset Class from cache
* @param id A_Asset_Class_ID
* @return MAssetClass or null if not found
*/
public static MAssetClass get(int id) {
return get(Env.getCtx(), id);
}
/** Get Asset Class from cache
* @param ctx context
* @param id A_Asset_Class_ID
* @param id A_Asset_Class_ID
* @return MAssetClass or null if not found
*/
public static MAssetClass get(Properties ctx, int id) {
@ -53,14 +94,16 @@ public class MAssetClass extends X_A_Asset_Class
return null;
}
MAssetClass assetClass = s_cache.get(id);
MAssetClass assetClass = s_cache.get(ctx, id, e -> new MAssetClass(ctx, e));
if (assetClass == null) {
assetClass = new MAssetClass(ctx, id, null);
}
if (assetClass.get_ID() != id) {
assetClass = new MAssetClass(ctx, id, (String)null);
if (assetClass.get_ID() == id) {
s_cache.put(id, assetClass, e -> new MAssetClass(Env.getCtx(), e));
return assetClass;
}
return null;
}
s_cache.put(id, assetClass);
}
return assetClass;
} // get
@ -209,4 +252,14 @@ public class MAssetClass extends X_A_Asset_Class
}
return true;
}
@Override
public MAssetClass markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
}

View File

@ -3,22 +3,25 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Asset Group Model
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*/
public class MAssetGroup extends X_A_Asset_Group
public class MAssetGroup extends X_A_Asset_Group implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -173157506404569463L;
private static final long serialVersionUID = 2605166916393528396L;
/** Cache: ID -> MAssetGroup */
private static CCache<Integer, MAssetGroup> s_cache = new CCache<Integer, MAssetGroup>(Table_Name, 10, 0);
private static ImmutableIntPOCache<Integer, MAssetGroup> s_cache = new ImmutableIntPOCache<Integer, MAssetGroup>(Table_Name, 10, 0);
/**
* Default Constructor
@ -40,6 +43,47 @@ public class MAssetGroup extends X_A_Asset_Group
super (ctx, rs, trxName);
} // MAssetGroup
/**
*
* @param copy
*/
public MAssetGroup(MAssetGroup copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAssetGroup(Properties ctx, MAssetGroup copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAssetGroup(Properties ctx, MAssetGroup copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get Asset Group [CACHE]
* @param A_Asset_Group_ID asset group id
* @return asset group or null
*/
public static MAssetGroup get(int A_Asset_Group_ID)
{
return get(Env.getCtx(), A_Asset_Group_ID);
}
/**
* Get Asset Group [CACHE]
* @param ctx context
@ -51,17 +95,32 @@ public class MAssetGroup extends X_A_Asset_Group
if (A_Asset_Group_ID <= 0)
return null;
// Try cache
MAssetGroup ag = s_cache.get(A_Asset_Group_ID);
MAssetGroup ag = s_cache.get(ctx, A_Asset_Group_ID, e -> new MAssetGroup(ctx, e));
if (ag != null)
return ag;
// Load
ag = new MAssetGroup(ctx, A_Asset_Group_ID, null);
if (ag != null && ag.get_ID() != A_Asset_Group_ID)
ag = null;
else
s_cache.put(A_Asset_Group_ID, ag);
//
return ag;
ag = new MAssetGroup(ctx, A_Asset_Group_ID, (String)null);
if (ag.get_ID() == A_Asset_Group_ID)
{
s_cache.put(A_Asset_Group_ID, ag, e -> new MAssetGroup(Env.getCtx(), e));
return ag;
}
return null;
}
/**
* Get updateable copy of MAssetGroup from cache
* @param ctx
* @param A_Asset_Group_ID
* @param trxName
* @return MAssetGroup
*/
public static MAssetGroup getCopy(Properties ctx, int A_Asset_Group_ID, String trxName)
{
MAssetGroup grp = get(A_Asset_Group_ID);
if (grp != null)
grp = new MAssetGroup(ctx, grp, trxName);
return grp;
}
/**
@ -170,5 +229,15 @@ public class MAssetGroup extends X_A_Asset_Group
//
return true;
}
@Override
public MAssetGroup markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MAssetGroup

View File

@ -73,14 +73,7 @@ public class MAssetGroupAcct extends X_A_Asset_Group_Acct
if (m_parent == null)
{
int A_Asset_Group_ID = getA_Asset_Group_ID();
if (is_new())
{
m_parent = new MAssetGroup(getCtx(), A_Asset_Group_ID, get_TrxName());
}
else
{
m_parent = MAssetGroup.get(getCtx(), A_Asset_Group_ID);
}
m_parent = MAssetGroup.getCopy(getCtx(), A_Asset_Group_ID, get_TrxName());
}
return m_parent;
}

View File

@ -4,19 +4,20 @@ import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.ArhRuntimeException;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Asset Type
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*/
public class MAssetType extends X_A_Asset_Type
public class MAssetType extends X_A_Asset_Type implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -1371478760221357780L;
private static final long serialVersionUID = -5511421754249363729L;
private static final String A_ASSET_TYPE_MFX = "MFX"; // HARDCODED - you must create a Asset Type with Value=MFX to indicate is Fixed Asset
private static final String A_ASSET_TYPE_INV = "INV"; // HARDCODED - you must create a Asset Type with Value=MFX to indicate is Inventory Object
@ -36,9 +37,20 @@ public class MAssetType extends X_A_Asset_Type
};
/** Static Cache: A_Asset_Type.A_Asset_Type_ID-> MAssetType */
private static CCache<Integer,MAssetType> s_cache = new CCache<Integer,MAssetType>(Table_Name, 10, 0);
private static ImmutableIntPOCache<Integer,MAssetType> s_cache = new ImmutableIntPOCache<Integer,MAssetType>(Table_Name, 10, 0);
/** Get Asset Type
/**
* Get Asset Type from cache (immutable)
* @param A_Asset_Type_ID
* @return asset type object
*/
public static MAssetType get (int A_Asset_Type_ID)
{
return get(Env.getCtx(), A_Asset_Type_ID);
}
/**
* Get Asset Type from cache (immutable)
* @param ctx context
* @param A_Asset_Type_ID
* @return asset type object
@ -47,29 +59,17 @@ public class MAssetType extends X_A_Asset_Type
{
if (A_Asset_Type_ID <= 0)
return null;
MAssetType o = s_cache.get(A_Asset_Type_ID);
MAssetType o = s_cache.get(ctx, A_Asset_Type_ID, e -> new MAssetType(ctx, e));
if (o != null)
return o;
o = new MAssetType(ctx, A_Asset_Type_ID, null);
if (o.get_ID() > 0) {
s_cache.put(A_Asset_Type_ID, o);
o = new MAssetType(ctx, A_Asset_Type_ID, (String)null);
if (o.get_ID() == A_Asset_Type_ID) {
s_cache.put(A_Asset_Type_ID, o, e -> new MAssetType(Env.getCtx(), e));
return o;
}
return null;
}
/** Get Asset Type
* @param ctx context
* @param id id as Number
* @return asset type object
*/
public static MAssetType get (Properties ctx, Object id)
{
if (id == null)
return null;
return get(ctx, ((Number)id).intValue());
}
/** Standard Constructor */
public MAssetType (Properties ctx, int A_Asset_Type_ID, String trxName)
{
@ -82,6 +82,37 @@ public class MAssetType extends X_A_Asset_Type
super (ctx, rs, trxName);
}
/**
*
* @param copy
*/
public MAssetType(MAssetType copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAssetType(Properties ctx, MAssetType copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAssetType(Properties ctx, MAssetType copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** Is Fixed Asset
*/
public boolean isFixedAsset()
@ -197,6 +228,15 @@ public class MAssetType extends X_A_Asset_Type
return true;
}
@Override
public MAssetType markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
/** Callout Class */
public static class Callout extends CalloutEngine
{

View File

@ -20,6 +20,7 @@ import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -27,6 +28,7 @@ import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Product Attribute
@ -34,13 +36,12 @@ import org.compiere.util.Env;
* @author Jorg Janke
* @version $Id: MAttribute.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
*/
public class MAttribute extends X_M_Attribute
public class MAttribute extends X_M_Attribute implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 7869800574413317999L;
private static final long serialVersionUID = 7513117649181926813L;
/**
* Get Attributes Of Client
@ -112,6 +113,38 @@ public class MAttribute extends X_M_Attribute
super(ctx, rs, trxName);
} // MAttribute
/**
*
* @param copy
*/
public MAttribute(MAttribute copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAttribute(Properties ctx, MAttribute copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAttribute(Properties ctx, MAttribute copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_values = copy.m_values != null ? Arrays.stream(copy.m_values).map(e -> {return new MAttributeValue(ctx, e, trxName);}).toArray(MAttributeValue[]::new) : null;
}
/** Values */
private MAttributeValue[] m_values = null;
@ -127,7 +160,7 @@ public class MAttribute extends X_M_Attribute
List<MAttributeValue> list = new ArrayList<MAttributeValue>();
if (!isMandatory())
list.add (null);
list = new Query(getCtx(),I_M_AttributeValue.Table_Name,whereClause,null)
list = new Query(getCtx(),I_M_AttributeValue.Table_Name,whereClause,get_TrxName())
.setParameters(getM_Attribute_ID())
.setOrderBy("Value")
.list();
@ -270,4 +303,13 @@ public class MAttribute extends X_M_Attribute
return success;
} // afterSave
@Override
public MAttribute markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MAttribute

View File

@ -20,12 +20,15 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.adempiere.exceptions.DBException;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Product Attribute Set
@ -36,13 +39,23 @@ import org.compiere.util.DB;
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2214883 ] Remove SQL code and Replace for Query
*/
public class MAttributeSet extends X_M_AttributeSet
public class MAttributeSet extends X_M_AttributeSet implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -187568054160926817L;
private static final long serialVersionUID = -6570475541239019293L;
/**
* Get MAttributeSet from Cache
* @param M_AttributeSet_ID id
* @return MAttributeSet
*/
public static MAttributeSet get (int M_AttributeSet_ID)
{
return get(Env.getCtx(), M_AttributeSet_ID);
}
/**
* Get MAttributeSet from Cache
* @param ctx context
@ -52,18 +65,35 @@ public class MAttributeSet extends X_M_AttributeSet
public static MAttributeSet get (Properties ctx, int M_AttributeSet_ID)
{
Integer key = Integer.valueOf(M_AttributeSet_ID);
MAttributeSet retValue = (MAttributeSet) s_cache.get (key);
MAttributeSet retValue = s_cache.get (ctx, key, e -> new MAttributeSet(ctx, e));
if (retValue != null)
return retValue;
retValue = new MAttributeSet (ctx, M_AttributeSet_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MAttributeSet (ctx, M_AttributeSet_ID, (String)null);
if (retValue.get_ID () == M_AttributeSet_ID)
{
s_cache.put (key, retValue, e -> new MAttributeSet(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MAttributeSet from cache
* @param ctx
* @param M_AttributeSet_ID
* @return MAttributeSet
*/
public static MAttributeSet getCopy(Properties ctx, int M_AttributeSet_ID, String trxName)
{
MAttributeSet mas = get(M_AttributeSet_ID);
if (mas != null)
mas = new MAttributeSet(ctx, mas, trxName);
return mas;
}
/** Cache */
private static CCache<Integer,MAttributeSet> s_cache
= new CCache<Integer,MAttributeSet> (Table_Name, 20);
private static ImmutableIntPOCache<Integer,MAttributeSet> s_cache
= new ImmutableIntPOCache<Integer,MAttributeSet> (Table_Name, 20);
/**
@ -100,17 +130,53 @@ public class MAttributeSet extends X_M_AttributeSet
super(ctx, rs, trxName);
} // MAttributeSet
/**
*
* @param copy
*/
public MAttributeSet(MAttributeSet copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAttributeSet(Properties ctx, MAttributeSet copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAttributeSet(Properties ctx, MAttributeSet copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_instanceAttributes = copy.m_instanceAttributes != null ? Arrays.stream(copy.m_instanceAttributes).map(e -> {return new MAttribute(ctx, e, trxName);}).toArray(MAttribute[]::new) : null;
this.m_productAttributes = copy.m_productAttributes != null ? Arrays.stream(copy.m_productAttributes).map(e -> {return new MAttribute(ctx, e, trxName);}).toArray(MAttribute[]::new) : null;
this.m_excludes = copy.m_excludes != null ? Arrays.copyOf(copy.m_excludes, copy.m_excludes.length) : null;
this.m_excludeLots = copy.m_excludeLots != null ? Arrays.copyOf(copy.m_excludeLots, copy.m_excludeLots.length) : null;
this.m_excludeSerNos = copy.m_excludeSerNos != null ? Arrays.copyOf(copy.m_excludeSerNos, copy.m_excludeSerNos.length) : null;
}
/** Instance Attributes */
private MAttribute[] m_instanceAttributes = null;
/** Instance Attributes */
private MAttribute[] m_productAttributes = null;
/** Entry Exclude */
private X_M_AttributeSetExclude[] m_excludes = null;
private MAttributeSetExclude[] m_excludes = null;
/** Lot create Exclude */
private X_M_LotCtlExclude[] m_excludeLots = null;
private MLotCtlExclude[] m_excludeLots = null;
/** Serial No create Exclude */
private X_M_SerNoCtlExclude[] m_excludeSerNos = null;
private MSerNoCtlExclude[] m_excludeSerNos = null;
/**
* Get Attribute Array
@ -158,11 +224,15 @@ public class MAttributeSet extends X_M_AttributeSet
{
m_instanceAttributes = new MAttribute[list.size()];
list.toArray (m_instanceAttributes);
if (m_instanceAttributes.length > 0 && is_Immutable())
Arrays.stream(m_instanceAttributes).forEach(e -> e.markImmutable());
}
else
{
m_productAttributes = new MAttribute[list.size()];
list.toArray (m_productAttributes);
if (m_productAttributes.length > 0 && is_Immutable())
Arrays.stream(m_productAttributes).forEach(e -> e.markImmutable());
}
}
//
@ -245,12 +315,12 @@ public class MAttributeSet extends X_M_AttributeSet
private void loadExcludes() {
if (m_excludes == null)
{
final String whereClause = X_M_AttributeSetExclude.COLUMNNAME_M_AttributeSet_ID+"=?";
List<X_M_AttributeSetExclude> list = new Query(getCtx(), X_M_AttributeSetExclude.Table_Name, whereClause, null)
final String whereClause = MAttributeSetExclude.COLUMNNAME_M_AttributeSet_ID+"=?";
List<MAttributeSetExclude> list = new Query(getCtx(), MAttributeSetExclude.Table_Name, whereClause, null)
.setParameters(get_ID())
.setOnlyActiveRecords(true)
.list();
m_excludes = new X_M_AttributeSetExclude[list.size ()];
m_excludes = new MAttributeSetExclude[list.size ()];
list.toArray (m_excludes);
}
}
@ -267,12 +337,12 @@ public class MAttributeSet extends X_M_AttributeSet
return true;
if (m_excludeLots == null)
{
final String whereClause = X_M_LotCtlExclude.COLUMNNAME_M_LotCtl_ID+"=?";
List<X_M_LotCtlExclude> list = new Query(getCtx(), X_M_LotCtlExclude.Table_Name, whereClause, null)
final String whereClause = MLotCtlExclude.COLUMNNAME_M_LotCtl_ID+"=?";
List<MLotCtlExclude> list = new Query(getCtx(), MLotCtlExclude.Table_Name, whereClause, null)
.setParameters(getM_LotCtl_ID())
.setOnlyActiveRecords(true)
.list();
m_excludeLots = new X_M_LotCtlExclude[list.size ()];
m_excludeLots = new MLotCtlExclude[list.size ()];
list.toArray (m_excludeLots);
}
// Find it
@ -301,12 +371,12 @@ public class MAttributeSet extends X_M_AttributeSet
return true;
if (m_excludeSerNos == null)
{
final String whereClause = X_M_SerNoCtlExclude.COLUMNNAME_M_SerNoCtl_ID+"=?";
List<X_M_SerNoCtlExclude> list = new Query(getCtx(), X_M_SerNoCtlExclude.Table_Name, whereClause, null)
final String whereClause = MSerNoCtlExclude.COLUMNNAME_M_SerNoCtl_ID+"=?";
List<MSerNoCtlExclude> list = new Query(getCtx(), MSerNoCtlExclude.Table_Name, whereClause, null)
.setParameters(getM_SerNoCtl_ID())
.setOnlyActiveRecords(true)
.list();
m_excludeSerNos = new X_M_SerNoCtlExclude[list.size ()];
m_excludeSerNos = new MSerNoCtlExclude[list.size ()];
list.toArray (m_excludeSerNos);
}
// Find it
@ -442,4 +512,17 @@ public class MAttributeSet extends X_M_AttributeSet
return success;
} // afterSave
@Override
public MAttributeSet markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
if (m_instanceAttributes != null && m_instanceAttributes.length > 0)
Arrays.stream(m_instanceAttributes).forEach(e -> e.markImmutable());
if (m_productAttributes != null && m_productAttributes.length > 0)
Arrays.stream(m_productAttributes).forEach(e -> e.markImmutable());
return this;
}
} // MAttributeSet

View File

@ -0,0 +1,89 @@
/**********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Trek Global Corporation *
* - Heng Sin Low *
**********************************************************************/
package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.Env;
/**
* @author hengsin
*
*/
public class MAttributeSetExclude extends X_M_AttributeSetExclude {
/**
*
*/
private static final long serialVersionUID = -2977401481745176882L;
/**
* @param ctx
* @param M_AttributeSetExclude_ID
* @param trxName
*/
public MAttributeSetExclude(Properties ctx, int M_AttributeSetExclude_ID, String trxName) {
super(ctx, M_AttributeSetExclude_ID, trxName);
}
/**
* @param ctx
* @param rs
* @param trxName
*/
public MAttributeSetExclude(Properties ctx, ResultSet rs, String trxName) {
super(ctx, rs, trxName);
}
/**
*
* @param copy
*/
public MAttributeSetExclude(MAttributeSetExclude copy) {
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAttributeSetExclude(Properties ctx, MAttributeSetExclude copy) {
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAttributeSetExclude(Properties ctx, MAttributeSetExclude copy, String trxName) {
this(ctx, 0, trxName);
copyPO(copy);
}
}

View File

@ -19,6 +19,8 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.Env;
/**
* Product Attribute Value
*
@ -62,6 +64,36 @@ public class MAttributeValue extends X_M_AttributeValue
super(ctx, rs, trxName);
} // MAttributeValue
/**
*
* @param copy
*/
public MAttributeValue(MAttributeValue copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MAttributeValue(Properties ctx, MAttributeValue copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MAttributeValue(Properties ctx, MAttributeValue copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* String Representation
* @return info

View File

@ -20,25 +20,36 @@ import java.sql.ResultSet;
import java.util.List;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* BOM Model
* @author Jorg Janke
* @version $Id: MBOM.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
*/
public class MBOM extends X_M_BOM
public class MBOM extends X_M_BOM implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -8885316310068284701L;
private static final long serialVersionUID = -6311001492891936078L;
/**
* Get BOM from Cache
* Get BOM from Cache (immutable)
* @param M_BOM_ID id
* @return MBOM
*/
public static MBOM get (int M_BOM_ID)
{
return get(Env.getCtx(), M_BOM_ID);
}
/**
* Get BOM from Cache (immutable)
* @param ctx context
* @param M_BOM_ID id
* @return MBOM
@ -46,15 +57,33 @@ public class MBOM extends X_M_BOM
public static MBOM get (Properties ctx, int M_BOM_ID)
{
Integer key = Integer.valueOf(M_BOM_ID);
MBOM retValue = (MBOM) s_cache.get (key);
MBOM retValue = (MBOM) s_cache.get (ctx, key, e -> new MBOM(ctx, e));
if (retValue != null)
return retValue;
retValue = new MBOM (ctx, M_BOM_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MBOM (ctx, M_BOM_ID, (String)null);
if (retValue.get_ID () == M_BOM_ID)
{
s_cache.put (key, retValue, e -> new MBOM(Env.getCtx(), e));
return retValue.markImmutable();
}
return null;
} // get
/**
* Get updateable copy of MBOM from cache
* @param ctx
* @param M_BOM_ID
* @param trxName
* @return MBOM
*/
public static MBOM getCopy(Properties ctx, int M_BOM_ID, String trxName)
{
MBOM bom = get(M_BOM_ID);
if (bom != null)
bom = new MBOM(ctx, bom, trxName);
return bom;
}
/**
* Get BOMs Of Product
* @param ctx context
@ -80,8 +109,8 @@ public class MBOM extends X_M_BOM
} // getOfProduct
/** Cache */
private static CCache<Integer,MBOM> s_cache
= new CCache<Integer,MBOM>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MBOM> s_cache
= new ImmutableIntPOCache<Integer,MBOM>(Table_Name, 20);
/** Logger */
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger (MBOM.class);
@ -116,6 +145,37 @@ public class MBOM extends X_M_BOM
super (ctx, rs, trxName);
} // MBOM
/**
*
* @param copy
*/
public MBOM(MBOM copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MBOM(Properties ctx, MBOM copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MBOM(Properties ctx, MBOM copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Before Save
* @param newRecord new
@ -161,4 +221,12 @@ public class MBOM extends X_M_BOM
return true;
} // beforeSave
@Override
public MBOM markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MBOM

View File

@ -113,7 +113,7 @@ public class MBOMProduct extends X_M_BOMProduct
private MBOM getBOM()
{
if (m_bom == null && getM_BOM_ID() != 0)
m_bom = MBOM.get(getCtx(), getM_BOM_ID());
m_bom = MBOM.getCopy(getCtx(), getM_BOM_ID(), get_TrxName());
return m_bom;
} // getBOM

View File

@ -115,6 +115,38 @@ public class MBPBankAccount extends X_C_BP_BankAccount
setA_Country(location.getCountryName());
} // MBP_BankAccount
/**
*
* @param copy
*/
public MBPBankAccount(MBPBankAccount copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MBPBankAccount(Properties ctx, MBPBankAccount copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MBPBankAccount(Properties ctx, MBPBankAccount copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_bank = copy.m_bank != null ? new MBank(ctx, copy.m_bank, trxName) : null;
}
/** Bank Link */
private MBank m_bank = null;

View File

@ -23,11 +23,12 @@ import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.cache.IntPOCopyCache;
/**
* Business Partner Group Model
@ -35,33 +36,36 @@ import org.compiere.util.Util;
* @author Jorg Janke
* @version $Id: MBPGroup.java,v 1.4 2006/09/23 15:54:22 jjanke Exp $
*/
public class MBPGroup extends X_C_BP_Group
public class MBPGroup extends X_C_BP_Group implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 8897399796117872715L;
private static final long serialVersionUID = 1155912422087010656L;
/**
* Get MBPGroup from Cache
* Get MBPGroup from Cache (immutable)
* @param C_BP_Group_ID id
* @return MBPGroup
*/
public static MBPGroup get (int C_BP_Group_ID)
{
return get(Env.getCtx(), C_BP_Group_ID);
}
/**
* Get MBPGroup from Cache (immutable)
* @param ctx context
* @param C_BP_Group_ID id
* @return MBPGroup
*/
public static MBPGroup get (Properties ctx, int C_BP_Group_ID)
{
Integer key = Integer.valueOf(C_BP_Group_ID);
MBPGroup retValue = (MBPGroup) s_cache.get (key);
if (retValue != null)
return retValue;
retValue = new MBPGroup (ctx, C_BP_Group_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
return get(ctx, C_BP_Group_ID, (String)null);
} // get
/**
*
* Get MBPGroup from cache (immutable)
* @param ctx
* @param C_BP_Group_ID
* @param trxName
@ -69,10 +73,32 @@ public class MBPGroup extends X_C_BP_Group
*/
public static MBPGroup get (Properties ctx, int C_BP_Group_ID, String trxName)
{
if (Util.isEmpty(trxName, true))
return get(ctx, C_BP_Group_ID);
else
return new MBPGroup (ctx, C_BP_Group_ID, trxName);
Integer key = Integer.valueOf(C_BP_Group_ID);
MBPGroup retValue = s_cache.get (ctx, key, e -> new MBPGroup(ctx, e));
if (retValue != null)
return retValue;
retValue = new MBPGroup (ctx, C_BP_Group_ID, trxName);
if (retValue.get_ID () == C_BP_Group_ID)
{
s_cache.put (key, retValue, e -> new MBPGroup(Env.getCtx(), e));
return retValue;
}
return null;
}
/**
* Get updateable copy of MBPGroup from cache
* @param ctx
* @param C_BP_Group_ID
* @param trxName
* @return MBPGroup
*/
public static MBPGroup getCopy(Properties ctx, int C_BP_Group_ID, String trxName)
{
MBPGroup group = get(ctx, C_BP_Group_ID, trxName);
if (group != null)
group = new MBPGroup(ctx, group, trxName);
return group;
}
/**
@ -84,7 +110,7 @@ public class MBPGroup extends X_C_BP_Group
{
int AD_Client_ID = Env.getAD_Client_ID(ctx);
Integer key = Integer.valueOf(AD_Client_ID);
MBPGroup retValue = (MBPGroup) s_cacheDefault.get (key);
MBPGroup retValue = s_cacheDefault.get (key, e -> new MBPGroup(ctx, e));
if (retValue != null)
return retValue;
@ -100,9 +126,11 @@ public class MBPGroup extends X_C_BP_Group
rs = pstmt.executeQuery ();
if (rs.next ())
{
retValue = new MBPGroup (ctx, rs, null);
if (retValue.get_ID () != 0)
s_cacheDefault.put (key, retValue);
retValue = new MBPGroup (ctx, rs, (String)null);
if (retValue.get_ID () != 0)
{
s_cacheDefault.put (key, retValue, e -> new MBPGroup(Env.getCtx(), e));
}
}
}
catch (Exception e)
@ -162,11 +190,11 @@ public class MBPGroup extends X_C_BP_Group
} // getOfBPartner
/** Cache */
private static CCache<Integer,MBPGroup> s_cache
= new CCache<Integer,MBPGroup>(Table_Name, 10);
private static ImmutableIntPOCache<Integer,MBPGroup> s_cache
= new ImmutableIntPOCache<Integer,MBPGroup>(Table_Name, 10);
/** Default Cache */
private static CCache<Integer,MBPGroup> s_cacheDefault
= new CCache<Integer,MBPGroup>(Table_Name, MBPGroup.class.getName()+".Default", 5);
private static IntPOCopyCache<Integer,MBPGroup> s_cacheDefault
= new IntPOCopyCache<Integer,MBPGroup>(Table_Name, MBPGroup.class.getName()+".Default", 5);
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MBPGroup.class);
@ -200,6 +228,36 @@ public class MBPGroup extends X_C_BP_Group
super(ctx, rs, trxName);
} // MBPGroup
/**
*
* @param copy
*/
public MBPGroup(MBPGroup copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MBPGroup(Properties ctx, MBPGroup copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MBPGroup(Properties ctx, MBPGroup copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get Credit Watch Percent
@ -246,4 +304,12 @@ public class MBPGroup extends X_C_BP_Group
return success;
} // afterSave
@Override
public MBPGroup markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MBPGroup

View File

@ -21,6 +21,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;
import java.util.logging.Level;
@ -28,6 +29,7 @@ import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Business Partner Model
@ -42,12 +44,12 @@ import org.compiere.util.Msg;
* <LI>BF [ 2041226 ] BP Open Balance should count only Completed Invoice
* <LI>BF [ 2498949 ] BP Get Not Invoiced Shipment Value return null
*/
public class MBPartner extends X_C_BPartner
public class MBPartner extends X_C_BPartner implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 5534148976588041343L;
private static final long serialVersionUID = 2256035503713773448L;
/**
* Get Empty Template Business Partner
@ -323,7 +325,43 @@ public class MBPartner extends X_C_BPartner
setC_BP_Group_ID(impBP.getC_BP_Group_ID());
} // MBPartner
/**
*
* @param copy
*/
public MBPartner(MBPartner copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MBPartner(Properties ctx, MBPartner copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MBPartner(Properties ctx, MBPartner copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_contacts = copy.m_contacts != null ? Arrays.stream(copy.m_contacts).map(e -> {return new MUser(ctx, e, trxName);}).toArray(MUser[]::new) : null;
this.m_locations = copy.m_locations != null ? Arrays.stream(copy.m_locations).map(e -> {return new MBPartnerLocation(ctx, e, trxName);}).toArray(MBPartnerLocation[]::new) : null;
this.m_accounts = copy.m_accounts != null ? Arrays.stream(copy.m_accounts).map(e -> {return new MBPBankAccount(ctx, e, trxName);}).toArray(MBPBankAccount[]::new) : null;
this.m_primaryC_BPartner_Location_ID = copy.m_primaryC_BPartner_Location_ID;
this.m_primaryAD_User_ID = copy.m_primaryAD_User_ID;
this.m_group = copy.m_group != null ? new MBPGroup(ctx, copy.m_group, trxName) : null;
}
/** Users */
protected MUser[] m_contacts = null;
/** Addressed */
@ -843,7 +881,7 @@ public class MBPartner extends X_C_BPartner
if (getC_BP_Group_ID() == 0)
m_group = MBPGroup.getDefault(getCtx());
else
m_group = MBPGroup.get(getCtx(), getC_BP_Group_ID(), get_TrxName());
m_group = MBPGroup.getCopy(getCtx(), getC_BP_Group_ID(), get_TrxName());
}
return m_group;
} // getBPGroup
@ -994,4 +1032,13 @@ public class MBPartner extends X_C_BPartner
return true;
}
@Override
public MBPartner markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MBPartner

View File

@ -20,6 +20,8 @@ import java.sql.ResultSet;
import java.util.List;
import java.util.Properties;
import org.compiere.util.Env;
/**
* Partner Location Model
*
@ -122,6 +124,40 @@ public class MBPartnerLocation extends X_C_BPartner_Location {
super(ctx, rs, trxName);
} // MBPartner_Location
/**
*
* @param copy
*/
public MBPartnerLocation(MBPartnerLocation copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MBPartnerLocation(Properties ctx, MBPartnerLocation copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MBPartnerLocation(Properties ctx, MBPartnerLocation copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_location = copy.m_location != null ? new MLocation(ctx, copy.m_location, trxName) : null;
this.m_uniqueName = copy.m_uniqueName;
this.m_unique = copy.m_unique;
}
/** Cached Location */
private MLocation m_location = null;
/** Unique Name */
@ -136,7 +172,7 @@ public class MBPartnerLocation extends X_C_BPartner_Location {
*/
public MLocation getLocation(boolean requery) {
if (requery || m_location == null)
m_location = MLocation.get(getCtx(), getC_Location_ID(), get_TrxName());
m_location = MLocation.getCopy(getCtx(), getC_Location_ID(), get_TrxName());
return m_location;
} // getLocation

View File

@ -19,7 +19,9 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Bank Model
@ -27,16 +29,25 @@ import org.compiere.util.CCache;
* @author Jorg Janke
* @version $Id: MBank.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
*/
public class MBank extends X_C_Bank
{
public class MBank extends X_C_Bank implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 3459010882027283811L;
private static final long serialVersionUID = 5093713970786841175L;
/**
* Get MBank from Cache
* Get MBank from Cache (immutable)
* @param C_Bank_ID id
* @return MBank
*/
public static MBank get (int C_Bank_ID)
{
return get(Env.getCtx(), C_Bank_ID);
}
/**
* Get MBank from Cache (immutable)
* @param ctx context
* @param C_Bank_ID id
* @return MBank
@ -44,18 +55,36 @@ public class MBank extends X_C_Bank
public static MBank get (Properties ctx, int C_Bank_ID)
{
Integer key = Integer.valueOf(C_Bank_ID);
MBank retValue = (MBank)s_cache.get (key);
MBank retValue = s_cache.get (ctx, key, e -> new MBank(ctx, e));
if (retValue != null)
return retValue;
retValue = new MBank (ctx, C_Bank_ID, null);
if (retValue.get_ID() != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MBank (ctx, C_Bank_ID, (String)null);
if (retValue.get_ID() == C_Bank_ID)
{
s_cache.put (key, retValue, e -> new MBank(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MBank from cache
* @param ctx
* @param C_Bank_ID
* @param trxName
* @return MBank
*/
public static MBank getCopy(Properties ctx, int C_Bank_ID, String trxName)
{
MBank bank = get(C_Bank_ID);
if (bank != null)
bank = new MBank(ctx, bank, trxName);
return bank;
}
/** Cache */
private static CCache<Integer,MBank> s_cache =
new CCache<Integer,MBank> (Table_Name, 3);
private static ImmutableIntPOCache<Integer,MBank> s_cache =
new ImmutableIntPOCache<Integer,MBank> (Table_Name, 3);
/**************************************************************************
@ -80,6 +109,46 @@ public class MBank extends X_C_Bank
super (ctx, rs, trxName);
} // MBank
/**
*
* @param copy
*/
public MBank(MBank copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MBank(Properties ctx, MBank copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MBank(Properties ctx, MBank copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
public MBank markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
/**
* String Representation
* @return info

View File

@ -19,11 +19,12 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.IBAN;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
@ -32,15 +33,25 @@ import org.compiere.util.Util;
* @author Jorg Janke
* @version $Id: MBankAccount.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
*/
public class MBankAccount extends X_C_BankAccount
public class MBankAccount extends X_C_BankAccount implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -110709935374907275L;
private static final long serialVersionUID = -3792366454862697171L;
/**
* Get BankAccount from Cache
* Get BankAccount from Cache (immutable)
* @param C_BankAccount_ID id
* @return MBankAccount
*/
public static MBankAccount get (int C_BankAccount_ID)
{
return get(Env.getCtx(), C_BankAccount_ID);
}
/**
* Get BankAccount from Cache (immutable)
* @param ctx context
* @param C_BankAccount_ID id
* @return MBankAccount
@ -48,18 +59,36 @@ public class MBankAccount extends X_C_BankAccount
public static MBankAccount get (Properties ctx, int C_BankAccount_ID)
{
Integer key = Integer.valueOf(C_BankAccount_ID);
MBankAccount retValue = (MBankAccount) s_cache.get (key);
MBankAccount retValue = s_cache.get (ctx, key, e -> new MBankAccount(ctx, e));
if (retValue != null)
return retValue;
retValue = new MBankAccount (ctx, C_BankAccount_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MBankAccount (ctx, C_BankAccount_ID, (String)null);
if (retValue.get_ID () == C_BankAccount_ID)
{
s_cache.put (key, retValue, e -> new MBankAccount(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MBankAccount from cache
* @param ctx
* @param C_BankAccount_ID
* @param trxName
* @return MBankAccount
*/
public static MBankAccount getCopy(Properties ctx, int C_BankAccount_ID, String trxName)
{
MBankAccount mba = get(C_BankAccount_ID);
if (mba != null)
mba = new MBankAccount(ctx, mba, trxName);
return mba;
}
/** Cache */
private static CCache<Integer,MBankAccount> s_cache
= new CCache<Integer,MBankAccount>(Table_Name, 5);
private static ImmutableIntPOCache<Integer,MBankAccount> s_cache
= new ImmutableIntPOCache<Integer,MBankAccount>(Table_Name, 5);
/**
* Bank Account Model
@ -92,6 +121,37 @@ public class MBankAccount extends X_C_BankAccount
super(ctx, rs, trxName);
} // MBankAccount
/**
*
* @param copy
*/
public MBankAccount(MBankAccount copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MBankAccount(Properties ctx, MBankAccount copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MBankAccount(Properties ctx, MBankAccount copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* String representation
* @return info
@ -111,7 +171,7 @@ public class MBankAccount extends X_C_BankAccount
*/
public MBank getBank()
{
return MBank.get(getCtx(), getC_Bank_ID());
return MBank.getCopy(getCtx(), getC_Bank_ID(), get_TrxName());
} // getBank
/**
@ -159,4 +219,13 @@ public class MBankAccount extends X_C_BankAccount
return success;
} // afterSave
@Override
public MBankAccount markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MBankAccount

View File

@ -180,7 +180,7 @@ public class MBankStatement extends X_C_BankStatement implements DocAction
*/
public MBankAccount getBankAccount()
{
return MBankAccount.get(getCtx(), getC_BankAccount_ID());
return MBankAccount.getCopy(getCtx(), getC_BankAccount_ID(), (String)null);
} // getBankAccount
/**

View File

@ -20,9 +20,10 @@ import java.sql.ResultSet;
import java.util.Locale;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Calendar Model
@ -30,16 +31,25 @@ import org.compiere.util.Msg;
* @author Jorg Janke
* @version $Id: MCalendar.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
*/
public class MCalendar extends X_C_Calendar
public class MCalendar extends X_C_Calendar implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 7721451326626542420L;
private static final long serialVersionUID = 6036302512252100576L;
/**
* Get MCalendar from Cache
* Get MCalendar from Cache (immutable)
* @param C_Calendar_ID id
* @return MCalendar
*/
public static MCalendar get (int C_Calendar_ID)
{
return get(Env.getCtx(), C_Calendar_ID);
}
/**
* Get MCalendar from Cache (immutable)
* @param ctx context
* @param C_Calendar_ID id
* @return MCalendar
@ -47,15 +57,33 @@ public class MCalendar extends X_C_Calendar
public static MCalendar get (Properties ctx, int C_Calendar_ID)
{
Integer key = Integer.valueOf(C_Calendar_ID);
MCalendar retValue = (MCalendar) s_cache.get (key);
MCalendar retValue = s_cache.get (ctx, key, e -> new MCalendar(ctx, e));
if (retValue != null)
return retValue;
retValue = new MCalendar (ctx, C_Calendar_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MCalendar (ctx, C_Calendar_ID, (String)null);
if (retValue.get_ID () == C_Calendar_ID)
{
s_cache.put (key, retValue, e -> new MCalendar(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MCalendar from cache
* @param ctx
* @param C_Calendar_ID
* @param trxName
* @return MCalendar
*/
public static MCalendar getCopy(Properties ctx, int C_Calendar_ID, String trxName)
{
MCalendar calendar = get(C_Calendar_ID);
if (calendar != null)
calendar = new MCalendar(ctx, calendar, trxName);
return calendar;
}
/**
* Get Default Calendar for Client
* @param ctx context
@ -65,7 +93,7 @@ public class MCalendar extends X_C_Calendar
public static MCalendar getDefault (Properties ctx, int AD_Client_ID)
{
MClientInfo info = MClientInfo.get(ctx, AD_Client_ID);
return get (ctx, info.getC_Calendar_ID());
return getCopy(ctx, info.getC_Calendar_ID(), (String)null);
} // getDefault
/**
@ -79,8 +107,8 @@ public class MCalendar extends X_C_Calendar
} // getDefault
/** Cache */
private static CCache<Integer,MCalendar> s_cache
= new CCache<Integer,MCalendar>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MCalendar> s_cache
= new ImmutableIntPOCache<Integer,MCalendar>(Table_Name, 20);
/*************************************************************************
@ -117,6 +145,31 @@ public class MCalendar extends X_C_Calendar
setName(msgset.toString());
} // MCalendar
/**
*
* @param copy
*/
public MCalendar(MCalendar copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MCalendar(Properties ctx, MCalendar copy)
{
this(ctx, copy, (String) null);
}
public MCalendar(Properties ctx, MCalendar copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Create (current) Calendar Year
* @param locale locale
@ -133,4 +186,13 @@ public class MCalendar extends X_C_Calendar
return year;
} // createYear
@Override
public MCalendar markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MCalendar

View File

@ -237,7 +237,7 @@ public class MCash extends X_C_Cash implements DocAction
public MCashBook getCashBook()
{
if (m_book == null)
m_book = MCashBook.get(getCtx(), getC_CashBook_ID());
m_book = MCashBook.getCopy(getCtx(), getC_CashBook_ID(), get_TrxName());
return m_book;
} // getCashBook

View File

@ -17,11 +17,12 @@
package org.compiere.model;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Cash Book Model
@ -30,43 +31,71 @@ import org.compiere.util.CLogger;
* @version $Id: MCashBook.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
* @author red1 - FR: [ 2214883 ] Remove SQL code and Replace for Query
*/
public class MCashBook extends X_C_CashBook
public class MCashBook extends X_C_CashBook implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 3991585668643587699L;
private static final long serialVersionUID = -743516751730874877L;
/**
* Get MCashBook from Cache
* Get MCashBook from Cache (immutable))
* @param C_CashBook_ID id
* @return MCashBook
*/
public static MCashBook get (int C_CashBook_ID)
{
return get(Env.getCtx(), C_CashBook_ID);
}
/**
* Get MCashBook from Cache (immutable)
* @param ctx context
* @param C_CashBook_ID id
* @return MCashBook
*/
public static MCashBook get (Properties ctx, int C_CashBook_ID)
{
return get(ctx, C_CashBook_ID, null);
return get(ctx, C_CashBook_ID, (String)null);
} // get
/**
* Gets MCashBook from Cache under transaction scope
* Gets MCashBook from Cache (immutabble)
* @param ctx context
* @param C_CashBook_ID id of cashbook to load
* @param trxName transaction name
* @param trxName transaction to load mcashbook if it is not in cache
* @return Cashbook
*/
public static MCashBook get(Properties ctx, int C_CashBook_ID, String trxName)
{
Integer key = Integer.valueOf(C_CashBook_ID);
MCashBook retValue = (MCashBook) s_cache.get (key);
MCashBook retValue = s_cache.get (ctx, key, e -> new MCashBook(ctx, e));
if (retValue != null)
return retValue;
retValue = new MCashBook (ctx, C_CashBook_ID, trxName);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
if (retValue.get_ID () == C_CashBook_ID)
{
s_cache.put (key, retValue, e -> new MCashBook(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MCashBook from cache
* @param ctx
* @param C_CashBook_ID
* @param trxName
* @return MCashBook
*/
public static MCashBook getCopy(Properties ctx, int C_CashBook_ID, String trxName)
{
MCashBook cb = get(ctx, C_CashBook_ID, trxName);
if (cb != null)
cb = new MCashBook(ctx, cb, trxName);
return cb;
}
/**
* Get CashBook for Org and Currency
* @param ctx context
@ -77,12 +106,11 @@ public class MCashBook extends X_C_CashBook
public static MCashBook get (Properties ctx, int AD_Org_ID, int C_Currency_ID)
{
// Try from cache
Iterator<MCashBook> it = s_cache.values().iterator();
while (it.hasNext())
MCashBook[] it = s_cache.values().toArray(new MCashBook[0]);
for (MCashBook cb : it)
{
MCashBook cb = (MCashBook)it.next();
if (cb.getAD_Org_ID() == AD_Org_ID && cb.getC_Currency_ID() == C_Currency_ID)
return cb;
return new MCashBook(ctx, cb);
}
// Get from DB
@ -92,17 +120,17 @@ public class MCashBook extends X_C_CashBook
.setOrderBy("IsDefault DESC")
.first();
if (retValue!=null)
{
Integer key = Integer.valueOf(retValue.getC_CashBook_ID());
s_cache.put (key, retValue);
}
{
Integer key = Integer.valueOf(retValue.getC_CashBook_ID());
s_cache.put (key, new MCashBook(Env.getCtx(), retValue));
}
return retValue;
} // get
/** Cache */
private static CCache<Integer,MCashBook> s_cache
= new CCache<Integer,MCashBook>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MCashBook> s_cache
= new ImmutableIntPOCache<Integer,MCashBook>(Table_Name, 20);
/** Static Logger */
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger (MCashBook.class);
@ -129,6 +157,37 @@ public class MCashBook extends X_C_CashBook
super(ctx, rs, trxName);
} // MCashBook
/**
*
* @param copy
*/
public MCashBook(MCashBook copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MCashBook(Properties ctx, MCashBook copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MCashBook(Properties ctx, MCashBook copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* After Save
* @param newRecord new
@ -143,4 +202,13 @@ public class MCashBook extends X_C_CashBook
return success;
} // afterSave
@Override
public MCashBook markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MCashBook

View File

@ -86,13 +86,10 @@ public class MCashLine extends X_C_CashLine
setClientOrg(cash);
setC_Cash_ID(cash.getC_Cash_ID());
m_parent = cash;
m_cashBook = m_parent.getCashBook();
} // MCashLine
/** Parent */
protected MCash m_parent = null;
/** Cash Book */
protected MCashBook m_cashBook = null;
/** Bank Account */
protected MBankAccount m_bankAccount = null;
/** Invoice */
@ -241,9 +238,7 @@ public class MCashLine extends X_C_CashLine
*/
public MCashBook getCashBook()
{
if (m_cashBook == null)
m_cashBook = MCashBook.get(getCtx(), getParent().getC_CashBook_ID());
return m_cashBook;
return getParent().getCashBook();
} // getCashBook
/**
@ -253,7 +248,7 @@ public class MCashLine extends X_C_CashLine
public MBankAccount getBankAccount()
{
if (m_bankAccount == null && getC_BankAccount_ID() != 0)
m_bankAccount = MBankAccount.get(getCtx(), getC_BankAccount_ID());
m_bankAccount = MBankAccount.getCopy(getCtx(), getC_BankAccount_ID(), get_TrxName());
return m_bankAccount;
} // getBankAccount

View File

@ -20,10 +20,11 @@ import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Charge Model
@ -34,12 +35,12 @@ import org.compiere.util.Env;
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2214883 ] Remove SQL code and Replace for Query
*/
public class MCharge extends X_C_Charge
public class MCharge extends X_C_Charge implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -4628105180010713510L;
private static final long serialVersionUID = 1978008783808254164L;
/**
* Get Charge Account
@ -80,7 +81,17 @@ public class MCharge extends X_C_Charge
} // getAccount
/**
* Get MCharge from Cache
* Get MCharge from Cache (immutable)
* @param C_Charge_ID id
* @return MCharge
*/
public static MCharge get (int C_Charge_ID)
{
return get(Env.getCtx(), C_Charge_ID);
}
/**
* Get MCharge from Cache (immutable)
* @param ctx context
* @param C_Charge_ID id
* @return MCharge
@ -88,18 +99,36 @@ public class MCharge extends X_C_Charge
public static MCharge get (Properties ctx, int C_Charge_ID)
{
Integer key = Integer.valueOf(C_Charge_ID);
MCharge retValue = (MCharge)s_cache.get (key);
MCharge retValue = (MCharge)s_cache.get (ctx, key, e -> new MCharge(ctx, e));
if (retValue != null)
return retValue;
retValue = new MCharge (ctx, C_Charge_ID, null);
if (retValue.get_ID() != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MCharge (ctx, C_Charge_ID, (String)null);
if (retValue.get_ID() == C_Charge_ID)
{
s_cache.put (key, retValue, e -> new MCharge(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MCharge from cache
* @param ctx
* @param C_Charge_ID
* @param trxName
* @return MCharge
*/
public static MCharge getCopy(Properties ctx, int C_Charge_ID, String trxName)
{
MCharge charge = get(C_Charge_ID);
if (charge != null)
charge = new MCharge(ctx, charge, trxName);
return charge;
}
/** Cache */
private static CCache<Integer, MCharge> s_cache
= new CCache<Integer, MCharge> (Table_Name, 10);
private static ImmutableIntPOCache<Integer, MCharge> s_cache
= new ImmutableIntPOCache<Integer, MCharge> (Table_Name, 10);
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MCharge.class);
@ -136,6 +165,37 @@ public class MCharge extends X_C_Charge
super(ctx, rs, trxName);
} // MCharge
/**
*
* @param copy
*/
public MCharge(MCharge copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MCharge(Properties ctx, MCharge copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MCharge(Properties ctx, MCharge copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* After Save
* @param newRecord new
@ -150,4 +210,13 @@ public class MCharge extends X_C_Charge
return success;
} // afterSave
@Override
public MCharge markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MCharge

View File

@ -19,7 +19,9 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Chat Type Model
@ -27,15 +29,25 @@ import org.compiere.util.CCache;
* @author Jorg Janke
* @version $Id: MChatType.java,v 1.2 2006/07/30 00:51:03 jjanke Exp $
*/
public class MChatType extends X_CM_ChatType
public class MChatType extends X_CM_ChatType implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -7933150405119053730L;
private static final long serialVersionUID = 973259852970379643L;
/**
* Get MChatType from Cache
* Get MChatType from Cache (immutable)
* @param CM_ChatType_ID id
* @return MChatType
*/
public static MChatType get (int CM_ChatType_ID)
{
return get(Env.getCtx(), CM_ChatType_ID);
}
/**
* Get MChatType from Cache (immutable)
* @param ctx context
* @param CM_ChatType_ID id
* @return MChatType
@ -43,18 +55,21 @@ public class MChatType extends X_CM_ChatType
public static MChatType get (Properties ctx, int CM_ChatType_ID)
{
Integer key = Integer.valueOf(CM_ChatType_ID);
MChatType retValue = (MChatType)s_cache.get (key);
MChatType retValue = s_cache.get (ctx, key, e -> new MChatType(ctx, e));
if (retValue != null)
return retValue;
retValue = new MChatType (ctx, CM_ChatType_ID, null);
if (retValue.get_ID () != CM_ChatType_ID)
s_cache.put (key, retValue);
return retValue;
retValue = new MChatType (ctx, CM_ChatType_ID, (String)null);
if (retValue.get_ID () == CM_ChatType_ID)
{
s_cache.put (key, retValue, e -> new MChatType(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer, MChatType> s_cache
= new CCache<Integer, MChatType> (Table_Name, 20);
private static ImmutableIntPOCache<Integer, MChatType> s_cache
= new ImmutableIntPOCache<Integer, MChatType> (Table_Name, 20);
/**
* Standard Constructor
@ -80,4 +95,44 @@ public class MChatType extends X_CM_ChatType
super (ctx, rs, trxName);
} // MChatType
/**
*
* @param copy
*/
public MChatType(MChatType copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MChatType(Properties ctx, MChatType copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MChatType(Properties ctx, MChatType copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
public MChatType markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MChatType

View File

@ -22,8 +22,10 @@ import java.text.Collator;
import java.util.Comparator;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Location City Model (Value Object)
@ -31,15 +33,25 @@ import org.compiere.util.CLogger;
* @author Mario Calderon / Carlos Ruiz
*/
public class MCity extends X_C_City
implements Comparator<Object>, Serializable
implements Comparator<Object>, Serializable, ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -8905525315954621942L;
private static final long serialVersionUID = -3716470269471334172L;
/**
* Get City (cached)
* Get City (cached) (immutable)
* @param C_City_ID ID
* @return City
*/
public static MCity get (int C_City_ID)
{
return get(Env.getCtx(), C_City_ID);
}
/**
* Get City (cached) (immutable)
* @param ctx context
* @param C_City_ID ID
* @return City
@ -47,20 +59,20 @@ public class MCity extends X_C_City
public static MCity get (Properties ctx, int C_City_ID)
{
Integer key = Integer.valueOf(C_City_ID);
MCity r = s_Cities.get(key);
MCity r = s_Cities.get(ctx, key, e -> new MCity(ctx, e));
if (r != null)
return r;
r = new MCity (ctx, C_City_ID, null);
r = new MCity (ctx, C_City_ID, (String)null);
if (r.getC_City_ID() == C_City_ID)
{
s_Cities.put(key, r);
s_Cities.put(key, r, e -> new MCity(Env.getCtx(), e));
return r;
}
return null;
} // get
/** City Cache */
private static CCache<Integer,MCity> s_Cities = new CCache<Integer,MCity>(Table_Name, 20);;
private static ImmutableIntPOCache<Integer,MCity> s_Cities = new ImmutableIntPOCache<Integer,MCity>(Table_Name, 20);;
/** Static Logger */
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger (MCity.class);
@ -105,6 +117,36 @@ public class MCity extends X_C_City
setName(cityName);
} // MCity
/**
*
* @param copy
*/
public MCity(MCity copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MCity(Properties ctx, MCity copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MCity(Properties ctx, MCity copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Return Name
* @return Name
@ -132,4 +174,13 @@ public class MCity extends X_C_City
return collator.compare(s1, s2);
} // compare
@Override
public MCity markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MCity

View File

@ -32,12 +32,13 @@ import java.util.logging.Level;
import javax.mail.internet.InternetAddress;
import org.compiere.db.CConnection;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.EMail;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Client Model
@ -51,15 +52,25 @@ import org.compiere.util.Language;
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1886480 ] Print Format Item Trl not updated even if not multilingual
*/
public class MClient extends X_AD_Client
{
public class MClient extends X_AD_Client implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 8418331925351272377L;
private static final long serialVersionUID = 1820358079361924020L;
/**
* Get client
* Get client from cache (immutable)
* @param AD_Client_ID id
* @return client
*/
public static MClient get (int AD_Client_ID)
{
return get(Env.getCtx(), AD_Client_ID);
}
/**
* Get client from cache (immutable)
* @param ctx context
* @param AD_Client_ID id
* @return client
@ -67,11 +78,11 @@ public class MClient extends X_AD_Client
public static MClient get (Properties ctx, int AD_Client_ID)
{
Integer key = Integer.valueOf(AD_Client_ID);
MClient client = (MClient)s_cache.get(key);
MClient client = (MClient)s_cache.get(ctx, key, e -> new MClient(ctx, e));
if (client != null)
return client;
client = new MClient (ctx, AD_Client_ID, null);
s_cache.put (key, client);
client = new MClient (ctx, AD_Client_ID, (String)null);
s_cache.put (key, client, e -> new MClient(Env.getCtx(), e));
return client;
} // get
@ -93,11 +104,11 @@ public class MClient extends X_AD_Client
*/
public static MClient[] getAll (Properties ctx, String orderBy)
{
List<MClient> list = new Query(ctx,I_AD_Client.Table_Name,null,null)
List<MClient> list = new Query(ctx,I_AD_Client.Table_Name,(String)null,(String)null)
.setOrderBy(orderBy)
.list();
for(MClient client:list ){
s_cache.put (Integer.valueOf(client.getAD_Client_ID()), client);
s_cache.put (Integer.valueOf(client.getAD_Client_ID()), client, e -> new MClient(Env.getCtx(), e));
}
MClient[] retValue = new MClient[list.size ()];
list.toArray (retValue);
@ -118,7 +129,7 @@ public class MClient extends X_AD_Client
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger (MClient.class);
/** Cache */
private static CCache<Integer,MClient> s_cache = new CCache<Integer,MClient>(Table_Name, 3, 120, true);
private static ImmutableIntPOCache<Integer,MClient> s_cache = new ImmutableIntPOCache<Integer,MClient>(Table_Name, 3, 120, true);
/**************************************************************************
@ -185,6 +196,40 @@ public class MClient extends X_AD_Client
this (ctx, Env.getAD_Client_ID(ctx), trxName);
} // MClient
/**
*
* @param copy
*/
public MClient(MClient copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MClient(Properties ctx, MClient copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MClient(Properties ctx, MClient copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_info = copy.m_info != null ? new MClientInfo(ctx, copy.m_info, trxName) : null;
this.m_AD_Tree_Account_ID = copy.m_AD_Tree_Account_ID;
this.m_fieldAccess = copy.m_fieldAccess != null ? new ArrayList<Integer>(copy.m_fieldAccess) : null;
}
/** Client Info */
private MClientInfo m_info = null;
/** Language */
@ -201,7 +246,12 @@ public class MClient extends X_AD_Client
public MClientInfo getInfo()
{
if (m_info == null)
m_info = MClientInfo.get (getCtx(), getAD_Client_ID(), get_TrxName());
{
if (is_Immutable())
m_info = MClientInfo.get (getCtx(), getAD_Client_ID(), get_TrxName());
else
m_info = MClientInfo.getCopy(getCtx(), getAD_Client_ID(), get_TrxName());
}
return m_info;
} // getMClientInfo
@ -437,7 +487,7 @@ public class MClient extends X_AD_Client
{
int C_AcctSchema_ID = m_info.getC_AcctSchema1_ID();
if (C_AcctSchema_ID != 0)
return MAcctSchema.get(getCtx(), C_AcctSchema_ID);
return MAcctSchema.getCopy(getCtx(), C_AcctSchema_ID, get_TrxName());
}
return null;
} // getMClientInfo
@ -1141,6 +1191,17 @@ public class MClient extends X_AD_Client
return s;
} // getSMTPHost
@Override
public MClient markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
if (m_info != null)
m_info.markImmutable();
return this;
}
// IDEMPIERE-722
private static final String MAIL_SEND_CREDENTIALS_USER = "U";
private static final String MAIL_SEND_CREDENTIALS_CLIENT = "C";

View File

@ -22,10 +22,11 @@ import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Client Info Model
@ -33,16 +34,25 @@ import org.compiere.util.Env;
* @author Jorg Janke
* @version $Id: MClientInfo.java,v 1.2 2006/07/30 00:58:37 jjanke Exp $
*/
public class MClientInfo extends X_AD_ClientInfo
public class MClientInfo extends X_AD_ClientInfo implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 4861006368856890116L;
private static final long serialVersionUID = 4707948832203223893L;
/**
* Get Client Info
* Get Client Info from cache (immutable)
* @param AD_Client_ID id
* @return Client Info
*/
public static MClientInfo get (int AD_Client_ID)
{
return get(Env.getCtx(), AD_Client_ID);
}
/**
* Get Client Info from cache (immutable)
* @param ctx context
* @param AD_Client_ID id
* @return Client Info
@ -53,7 +63,7 @@ public class MClientInfo extends X_AD_ClientInfo
} // get
/**
* Get Client Info
* Get Client Info from cache (immutable)
* @param ctx context
* @param AD_Client_ID id
* @param trxName optional trx
@ -62,7 +72,7 @@ public class MClientInfo extends X_AD_ClientInfo
public static MClientInfo get (Properties ctx, int AD_Client_ID, String trxName)
{
Integer key = Integer.valueOf(AD_Client_ID);
MClientInfo info = (MClientInfo)s_cache.get(key);
MClientInfo info = s_cache.get(ctx, key, e -> new MClientInfo(ctx, e));
if (info != null)
return info;
//
@ -76,9 +86,8 @@ public class MClientInfo extends X_AD_ClientInfo
rs = pstmt.executeQuery ();
if (rs.next ())
{
info = new MClientInfo (ctx, rs, null);
if (trxName == null)
s_cache.put (key, info);
info = new MClientInfo (ctx, rs, trxName);
s_cache.put (key, info, e -> new MClientInfo(Env.getCtx(), e));
}
}
catch (SQLException ex)
@ -95,6 +104,15 @@ public class MClientInfo extends X_AD_ClientInfo
return info;
} // get
/**
* Get optionally cached client
* @return client
*/
public static MClientInfo get ()
{
return get(Env.getCtx());
}
/**
* Get optionally cached client
* @param ctx context
@ -105,8 +123,23 @@ public class MClientInfo extends X_AD_ClientInfo
return get (ctx, Env.getAD_Client_ID(ctx), null);
} // get
/**
* Get updateable copy of MClientInfo from cache
* @param ctx
* @param AD_Client_ID
* @param trxName
* @return MClientInfo
*/
public static MClientInfo getCopy(Properties ctx, int AD_Client_ID, String trxName)
{
MClientInfo ci = get(ctx, AD_Client_ID, trxName);
if (ci != null)
ci = new MClientInfo(ctx, ci, trxName);
return ci;
}
/** Cache */
private static CCache<Integer,MClientInfo> s_cache = new CCache<Integer,MClientInfo>(Table_Name, 2);
private static ImmutableIntPOCache<Integer,MClientInfo> s_cache = new ImmutableIntPOCache<Integer,MClientInfo>(Table_Name, 2);
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MClientInfo.class);
@ -169,6 +202,37 @@ public class MClientInfo extends X_AD_ClientInfo
m_createNew = true;
} // MClientInfo
/**
*
* @param copy
*/
public MClientInfo(MClientInfo copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MClientInfo(Properties ctx, MClientInfo copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MClientInfo(Properties ctx, MClientInfo copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_acctSchema = copy.m_acctSchema != null ? new MAcctSchema(ctx, copy.m_acctSchema, trxName) : null;
}
/** Account Schema */
private MAcctSchema m_acctSchema = null;
@ -182,7 +246,11 @@ public class MClientInfo extends X_AD_ClientInfo
public MAcctSchema getMAcctSchema1()
{
if (m_acctSchema == null && getC_AcctSchema1_ID() != 0)
m_acctSchema = new MAcctSchema (getCtx(), getC_AcctSchema1_ID(), null);
{
m_acctSchema = new MAcctSchema (getCtx(), getC_AcctSchema1_ID(), get_TrxName());
if (is_Immutable())
m_acctSchema.markImmutable();
}
return m_acctSchema;
} // getMAcctSchema1
@ -214,4 +282,15 @@ public class MClientInfo extends X_AD_ClientInfo
return saveUpdate();
} // save
@Override
public MClientInfo markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
if (m_acctSchema != null)
m_acctSchema.markImmutable();
return this;
}
} // MClientInfo

View File

@ -24,6 +24,7 @@ import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* Client Share Info
@ -142,6 +143,38 @@ public class MClientShare extends X_AD_ClientShare
super (ctx, rs, trxName);
} // MClientShare
/**
*
* @param copy
*/
public MClientShare(MClientShare copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MClientShare(Properties ctx, MClientShare copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MClientShare(Properties ctx, MClientShare copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_table = copy.m_table != null ? new MTable(ctx, copy.m_table, trxName) : null;
}
/** The Table */
private MTable m_table = null;
@ -170,7 +203,7 @@ public class MClientShare extends X_AD_ClientShare
public MTable getTable()
{
if (m_table == null)
m_table = MTable.get(getCtx(), getAD_Table_ID());
m_table = MTable.getCopy(getCtx(), getAD_Table_ID(), get_TrxName());
return m_table;
} // getTable

View File

@ -23,8 +23,9 @@ import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.print.MPrintColor;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Performance Color Schema
@ -32,12 +33,12 @@ import org.compiere.util.Env;
* @author Jorg Janke
* @version $Id: MColorSchema.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
*/
public class MColorSchema extends X_PA_ColorSchema
public class MColorSchema extends X_PA_ColorSchema implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 4645092884363283719L;
private static final long serialVersionUID = -3730457542399382168L;
/**
* Get Color
@ -74,6 +75,15 @@ public class MColorSchema extends X_PA_ColorSchema
return cs.getColor(percent);
} // getColor
/**
* Get MColorSchema from Cache
* @param PA_ColorSchema_ID id
* @return MColorSchema
*/
public static MColorSchema get (int PA_ColorSchema_ID)
{
return get(Env.getCtx(), PA_ColorSchema_ID);
}
/**
* Get MColorSchema from Cache
@ -90,18 +100,36 @@ public class MColorSchema extends X_PA_ColorSchema
return retValue;
}
Integer key = Integer.valueOf(PA_ColorSchema_ID);
MColorSchema retValue = (MColorSchema)s_cache.get (key);
MColorSchema retValue = s_cache.get (ctx, key, e -> new MColorSchema(ctx, e));
if (retValue != null)
return retValue;
retValue = new MColorSchema (ctx, PA_ColorSchema_ID, null);
if (retValue.get_ID() != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MColorSchema (ctx, PA_ColorSchema_ID, (String)null);
if (retValue.get_ID() == PA_ColorSchema_ID)
{
s_cache.put (key, retValue, e -> new MColorSchema(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MColorSchema from cache
* @param ctx
* @param PA_ColorSchema_ID
* @param trxName
* @return MColorSchema
*/
public static MColorSchema getCopy(Properties ctx, int PA_ColorSchema_ID, String trxName)
{
MColorSchema cs = get(PA_ColorSchema_ID);
if (cs != null)
cs = new MColorSchema(ctx, cs, trxName);
return cs;
}
/** Cache */
private static CCache<Integer, MColorSchema> s_cache
= new CCache<Integer, MColorSchema> (Table_Name, 20);
private static ImmutableIntPOCache<Integer, MColorSchema> s_cache
= new ImmutableIntPOCache<Integer, MColorSchema> (Table_Name, 20);
/**
* Standard Constructor
@ -133,6 +161,37 @@ public class MColorSchema extends X_PA_ColorSchema
super (ctx, rs, trxName);
} // MColorSchema
/**
*
* @param copy
*/
public MColorSchema(MColorSchema copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MColorSchema(Properties ctx, MColorSchema copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MColorSchema(Properties ctx, MColorSchema copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Set Default.
* Red (50) - Yellow (100) - Green
@ -210,4 +269,13 @@ public class MColorSchema extends X_PA_ColorSchema
return sb.toString ();
} // toString
@Override
public MColorSchema markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MColorSchema

View File

@ -34,13 +34,14 @@ import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.compiere.db.AdempiereDatabase;
import org.compiere.db.Database;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Persistent Column Model
@ -48,20 +49,36 @@ import org.compiere.util.Util;
* @author Jorg Janke
* @version $Id: MColumn.java,v 1.6 2006/08/09 05:23:49 jjanke Exp $
*/
public class MColumn extends X_AD_Column
public class MColumn extends X_AD_Column implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 5934334786732835926L;
private static final long serialVersionUID = -1841918268550762201L;
/**
* Get MColumn from Cache (immutable)
* @param AD_Column_ID id
* @return MColumn
*/
public static MColumn get (int AD_Column_ID)
{
return get(Env.getCtx(), AD_Column_ID);
}
/**
* Get MColumn from Cache (immutable)
* @param ctx context
* @param AD_Column_ID id
* @return MColumn
*/
public static MColumn get (Properties ctx, int AD_Column_ID)
{
return get(ctx, AD_Column_ID, null);
}
/**
* Get MColumn from Cache
* Get MColumn from Cache (immutable)
* @param ctx context
* @param AD_Column_ID id
* @param trxName trx
@ -70,17 +87,34 @@ public class MColumn extends X_AD_Column
public static MColumn get(Properties ctx, int AD_Column_ID, String trxName)
{
Integer key = Integer.valueOf(AD_Column_ID);
MColumn retValue = (MColumn) s_cache.get (key);
if (retValue != null) {
retValue.set_TrxName(trxName);
MColumn retValue = (MColumn) s_cache.get (ctx, key, e -> new MColumn(ctx, e));
if (retValue != null)
return retValue;
retValue = new MColumn (ctx, AD_Column_ID, trxName);
if (retValue.get_ID () == AD_Column_ID)
{
s_cache.put (key, retValue, e -> new MColumn(Env.getCtx(), e));
return retValue;
}
retValue = new MColumn (ctx, AD_Column_ID, trxName);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
return null;
} // get
/**
* Get updateable copy of MColumn from cache
* @param ctx
* @param AD_Column_ID
* @param trxName
* @return MColumn
*/
public static MColumn getCopy(Properties ctx, int AD_Column_ID, String trxName)
{
MColumn column = get(ctx, AD_Column_ID, trxName);
if (column != null)
column = new MColumn(ctx, column, trxName);
return column;
}
/**
* Get MColumn given TableName and ColumnName
* @param ctx context
@ -115,7 +149,7 @@ public class MColumn extends X_AD_Column
} // getColumnName
/** Cache */
private static CCache<Integer,MColumn> s_cache = new CCache<Integer,MColumn>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MColumn> s_cache = new ImmutableIntPOCache<Integer,MColumn>(Table_Name, 20);
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MColumn.class);
@ -172,7 +206,36 @@ public class MColumn extends X_AD_Column
setEntityType(parent.getEntityType());
} // MColumn
/**
*
* @param copy
*/
public MColumn(MColumn copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MColumn(Properties ctx, MColumn copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MColumn(Properties ctx, MColumn copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Is Standard Column
* @return true for AD_Client_ID, etc.
@ -867,7 +930,7 @@ public class MColumn extends X_AD_Column
@Override
public I_AD_Table getAD_Table() throws RuntimeException {
MTable table = MTable.get(getCtx(), getAD_Table_ID(), get_TrxName());
MTable table = MTable.getCopy(getCtx(), getAD_Table_ID(), get_TrxName());
return table;
}
@ -1195,4 +1258,13 @@ public class MColumn extends X_AD_Column
return rvalue + " - " + sql;
}
@Override
public MColumn markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MColumn

View File

@ -112,6 +112,37 @@ public class MContactInterest extends X_R_ContactInterest
super(ctx, rs, trxName);
} // MContactInterest
/**
*
* @param copy
*/
public MContactInterest(MContactInterest copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MContactInterest(Properties ctx, MContactInterest copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MContactInterest(Properties ctx, MContactInterest copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MContactInterest.class);

View File

@ -21,6 +21,7 @@ import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* Currency Conversion Type Model
@ -95,4 +96,34 @@ public class MConversionType extends X_C_ConversionType
super(ctx, rs, trxName);
} // MConversionType
/**
*
* @param copy
*/
public MConversionType(MConversionType copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MConversionType(Properties ctx, MConversionType copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MConversionType(Properties ctx, MConversionType copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
} // MConversionType

View File

@ -1639,7 +1639,7 @@ public class MCost extends X_M_Cost
int M_CostElement_ID = getM_CostElement_ID();
if (M_CostElement_ID == 0)
return null;
return MCostElement.get(getCtx(), M_CostElement_ID);
return MCostElement.getCopy(getCtx(), M_CostElement_ID, get_TrxName());
} // getCostElement
/**

View File

@ -21,11 +21,12 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Cost Element Model
@ -38,14 +39,12 @@ import org.compiere.util.Msg;
* @author red1
* <li>FR: [ 2214883 ] Remove SQL code and Replace for Query -- JUnit tested
*/
public class MCostElement extends X_M_CostElement
public class MCostElement extends X_M_CostElement implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 3423495977508725440L;
private static final long serialVersionUID = 4914952212171251715L;
/**
* Get Material Cost Element or create it
@ -179,7 +178,17 @@ public class MCostElement extends X_M_CostElement
// end MZ
/**
* Get Cost Element from Cache
* Get Cost Element from Cache (immutable)
* @param M_CostElement_ID id
* @return Cost Element
*/
public static MCostElement get (int M_CostElement_ID)
{
return get(Env.getCtx(), M_CostElement_ID);
}
/**
* Get Cost Element from Cache (immutable)
* @param ctx context
* @param M_CostElement_ID id
* @return Cost Element
@ -187,15 +196,32 @@ public class MCostElement extends X_M_CostElement
public static MCostElement get (Properties ctx, int M_CostElement_ID)
{
Integer key = Integer.valueOf(M_CostElement_ID);
MCostElement retValue = (MCostElement) s_cache.get (key);
MCostElement retValue = s_cache.get (ctx, key, e -> new MCostElement(ctx, e));
if (retValue != null)
return retValue;
retValue = new MCostElement (ctx, M_CostElement_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MCostElement (ctx, M_CostElement_ID, (String)null);
if (retValue.get_ID () == M_CostElement_ID)
{
s_cache.put (key, retValue, e -> new MCostElement(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MCostElement from cache
* @param ctx
* @param M_CostElement_ID
* @param trxName
* @return MCostElement
*/
public static MCostElement getCopy(Properties ctx, int M_CostElement_ID, String trxName)
{
MCostElement ce = get(M_CostElement_ID);
if (ce != null)
ce = new MCostElement(ctx, ce, trxName);
return ce;
}
/**
* Get All Cost Elements for current AD_Client_ID
@ -232,7 +258,7 @@ public class MCostElement extends X_M_CostElement
}
/** Cache */
protected static CCache<Integer,MCostElement> s_cache = new CCache<Integer,MCostElement>(Table_Name, 20);
protected static ImmutableIntPOCache<Integer,MCostElement> s_cache = new ImmutableIntPOCache<Integer,MCostElement>(Table_Name, 20);
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MCostElement.class);
@ -266,6 +292,37 @@ public class MCostElement extends X_M_CostElement
super (ctx, rs, trxName);
} // MCostElement
/**
*
* @param copy
*/
public MCostElement(MCostElement copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MCostElement(Properties ctx, MCostElement copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MCostElement(Properties ctx, MCostElement copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Before Save
* @param newRecord new
@ -472,4 +529,13 @@ public class MCostElement extends X_M_CostElement
return sb.toString ();
} // toString
@Override
public MCostElement markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MCostElement

View File

@ -23,15 +23,18 @@ import java.sql.ResultSet;
import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Location Country Model (Value Object)
@ -43,29 +46,39 @@ import org.compiere.util.Language;
* <li>BF [ 2695078 ] Country is not translated on invoice
*/
public class MCountry extends X_C_Country
implements Comparator<Object>, Serializable
implements Comparator<Object>, Serializable, ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -4966707939803861163L;
private static final long serialVersionUID = 6102749517340832365L;
/**
* Get Country (cached)
* @param ctx context
* Get Country (cached) (immutable)
* @param C_Country_ID ID
* @return Country
*/
public static MCountry get (int C_Country_ID)
{
return get(Env.getCtx(), C_Country_ID);
}
/**
* Get Country (Immutable, cached)
* @param ctx context
* @param C_Country_ID ID
* @return Country
*/
public static MCountry get (Properties ctx, int C_Country_ID)
{
loadAllCountriesIfNeeded(ctx);
MCountry c = s_countries.get(C_Country_ID);
loadAllCountriesIfNeeded();
MCountry c = s_countries.get(ctx, C_Country_ID, e -> new MCountry(ctx, e));
if (c != null)
return c;
c = new MCountry (ctx, C_Country_ID, null);
c = new MCountry (ctx, C_Country_ID, (String)null);
if (c.getC_Country_ID() == C_Country_ID)
{
s_countries.put(C_Country_ID, c);
s_countries.put(C_Country_ID, c, e -> new MCountry(Env.getCtx(), e));
return c;
}
return null;
@ -73,54 +86,72 @@ public class MCountry extends X_C_Country
/**
* Get Default Country
* @param ctx context
* @param ctx ignore
* @return Country
* @deprecated
*/
public static MCountry getDefault (Properties ctx)
{
int clientID = Env.getAD_Client_ID(ctx);
return getDefault();
}
/**
* Get Default Country (immutable)
* @return Country
*/
public static MCountry getDefault ()
{
int clientID = Env.getAD_Client_ID(Env.getCtx());
MCountry c = s_default.get(clientID);
if (c != null)
return c;
loadDefaultCountry(ctx);
loadDefaultCountry();
c = s_default.get(clientID);
return c;
} // get
/**
* Return Countries as Array
* @param ctx context
* @param ctx ignore
* @return MCountry Array
* @deprecated
*/
public static MCountry[] getCountries(Properties ctx)
{
loadAllCountriesIfNeeded(ctx);
MCountry[] retValue = new MCountry[s_countries.size()];
s_countries.values().toArray(retValue);
Arrays.sort(retValue, new MCountry(ctx, 0, null));
return getCountries();
}
/**
* Return Countries as Array
* @return MCountry Array
*/
public static MCountry[] getCountries()
{
loadAllCountriesIfNeeded();
MCountry[] retValue = s_countries.values().toArray(new MCountry[0]);
Arrays.sort(retValue, new MCountry(Env.getCtx(), 0, null));
return retValue;
} // getCountries
private static synchronized void loadAllCountriesIfNeeded(Properties ctx) {
private static synchronized void loadAllCountriesIfNeeded() {
if (s_countries == null || s_countries.isEmpty()) {
loadAllCountries(ctx);
loadAllCountries();
}
}
/**
* Load Countries.
* Set Default Language to Client Language
* @param ctx context
*/
private static synchronized void loadAllCountries (Properties ctx)
private static synchronized void loadAllCountries ()
{
MClient client = MClient.get (ctx);
MLanguage lang = MLanguage.get(ctx, client.getAD_Language());
MClient client = MClient.get (Env.getCtx());
MLanguage lang = MLanguage.get(Env.getCtx(), client.getAD_Language());
//
if (s_countries == null)
s_countries = new CCache<Integer,MCountry>(Table_Name, 250);
List<MCountry> countries = new Query(ctx, Table_Name, "", null)
s_countries = new ImmutableIntPOCache<Integer,MCountry>(Table_Name, 250);
List<MCountry> countries = new Query(Env.getCtx(), Table_Name, "", null)
.setOnlyActiveRecords(true)
.list();
for (MCountry c : countries) {
@ -135,19 +166,20 @@ public class MCountry extends X_C_Country
/**
* Load Default Country for actual client on context
* @param ctx
*/
private static void loadDefaultCountry(Properties ctx) {
loadAllCountriesIfNeeded(ctx);
MClient client = MClient.get (ctx);
private static void loadDefaultCountry() {
loadAllCountriesIfNeeded();
MClient client = MClient.get (Env.getCtx());
MCountry found = s_default.get(client.getAD_Client_ID());
if (found != null)
return;
MLanguage lang = MLanguage.get(ctx, client.getAD_Language());
MLanguage lang = MLanguage.get(Env.getCtx(), client.getAD_Language());
MCountry usa = null;
for (Entry<Integer, MCountry> cachedEntry : s_countries.entrySet()) {
//create local instance to avoid concurrent modification exception
Map<Integer, MCountry> countries = new HashMap<Integer, MCountry>(s_countries);
for (Entry<Integer, MCountry> cachedEntry : countries.entrySet()) {
MCountry c = cachedEntry.getValue();
// Country code of Client Language
if (lang != null && lang.getCountryCode().equals(c.getCountryCode())) {
@ -161,7 +193,7 @@ public class MCountry extends X_C_Country
s_default.put(client.getAD_Client_ID(), found);
else
s_default.put(client.getAD_Client_ID(), usa);
if (s_log.isLoggable(Level.FINE)) s_log.fine("#" + s_countries.size()
if (s_log.isLoggable(Level.FINE)) s_log.fine("#" + countries.size()
+ " - Default=" + s_default);
}
@ -182,9 +214,9 @@ public class MCountry extends X_C_Country
private static String s_AD_Language = null;
/** Country Cache */
private static CCache<Integer,MCountry> s_countries = null;
private static ImmutableIntPOCache<Integer,MCountry> s_countries = null;
/** Default Country */
private static CCache<Integer,MCountry> s_default = new CCache<Integer,MCountry>(Table_Name, Table_Name+"|Default", 3);
private static ImmutableIntPOCache<Integer,MCountry> s_default = new ImmutableIntPOCache<Integer,MCountry>(Table_Name, Table_Name+"|Default", 3);
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MCountry.class);
// Default DisplaySequence */
@ -223,6 +255,37 @@ public class MCountry extends X_C_Country
super(ctx, rs, trxName);
} // MCountry
/**
*
* @param copy
*/
public MCountry(MCountry copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MCountry(Properties ctx, MCountry copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MCountry(Properties ctx, MCountry copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Return Name - translated if DisplayLanguage is set.
* @return Name
@ -306,7 +369,7 @@ public class MCountry extends X_C_Country
|| getC_Country_ID() == 0
|| !isHasRegion())
return false;
MRegion[] regions = MRegion.getRegions(getCtx(), getC_Country_ID());
MRegion[] regions = MRegion.getRegions(getC_Country_ID());
for (int i = 0; i < regions.length; i++)
{
if (C_Region_ID == regions[i].getC_Region_ID())
@ -315,6 +378,15 @@ public class MCountry extends X_C_Country
return false;
} // isValidRegion
@Override
public MCountry markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
/**************************************************************************
* Insert Countries
* @param args none

View File

@ -27,42 +27,54 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Country Group Model
*/
public class MCountryGroup extends X_C_CountryGroup
public class MCountryGroup extends X_C_CountryGroup implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 4986629677773273899L;
private static final long serialVersionUID = 8489673276196368210L;
/**
* Get Country Group (cached)
* Get Country Group (cached) (immutable)
* @param C_CountryGroup_ID ID
* @return Country Group
*/
public static MCountryGroup get (int C_CountryGroup_ID)
{
return get(Env.getCtx(), C_CountryGroup_ID);
}
/**
* Get Country Group (cached) (immutable)
* @param ctx context
* @param C_CountryGroup_ID ID
* @return Country Group
*/
public static MCountryGroup get (Properties ctx, int C_CountryGroup_ID)
{
MCountryGroup c = s_cache.get(C_CountryGroup_ID);
MCountryGroup c = s_cache.get(ctx, C_CountryGroup_ID, e -> new MCountryGroup(ctx, e));
if (c != null)
return c;
c = new MCountryGroup (ctx, C_CountryGroup_ID, null);
c = new MCountryGroup (ctx, C_CountryGroup_ID, (String)null);
if (c.getC_CountryGroup_ID() == C_CountryGroup_ID)
{
s_cache.put(C_CountryGroup_ID, c);
s_cache.put(C_CountryGroup_ID, c, e -> new MCountryGroup(Env.getCtx(), e));
return c;
}
return null;
} // get
/** Cache */
private static CCache<Integer,MCountryGroup> s_cache = new CCache<Integer,MCountryGroup>(Table_Name, 5);
private static ImmutableIntPOCache<Integer,MCountryGroup> s_cache = new ImmutableIntPOCache<Integer,MCountryGroup>(Table_Name, 5);
/** Static Logger */
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger (MCountryGroup.class);
@ -89,6 +101,46 @@ public class MCountryGroup extends X_C_CountryGroup
super(ctx, rs, trxName);
} // MCountryGroup
/**
*
* @param copy
*/
public MCountryGroup(MCountryGroup copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MCountryGroup(Properties ctx, MCountryGroup copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MCountryGroup(Properties ctx, MCountryGroup copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
public MCountryGroup markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
public static boolean countryGroupContains(int c_CountryGroup_ID, int c_Country_ID) {
if (c_CountryGroup_ID == 0 || c_Country_ID == 0)

View File

@ -29,26 +29,26 @@ import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.cache.ImmutablePOCache;
/**
* Context Help Message Model
*
* @author Carlos Ruiz
*/
public class MCtxHelpMsg extends X_AD_CtxHelpMsg {
public class MCtxHelpMsg extends X_AD_CtxHelpMsg implements ImmutablePOSupport {
/**
*
*/
private static final long serialVersionUID = -7208965344525556184L;
private static final long serialVersionUID = 3148838750037103261L;
/** Logging */
private static CLogger s_log = CLogger.getCLogger(MCtxHelpMsg.class);
/** Context Help Message Cache */
private static CCache<String, MCtxHelpMsg> s_cache = new CCache<String, MCtxHelpMsg>(Table_Name, 10);
private static ImmutablePOCache<String, MCtxHelpMsg> s_cache = new ImmutablePOCache<String, MCtxHelpMsg>(Table_Name, 10);
/**
* Standard Constructor
@ -71,12 +71,49 @@ public class MCtxHelpMsg extends X_AD_CtxHelpMsg {
} // MCtxHelpMsg
/**
* Get the context help message defined for the type, recordid, client, org
*
* @param copy
*/
public MCtxHelpMsg(MCtxHelpMsg copy) {
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MCtxHelpMsg(Properties ctx, MCtxHelpMsg copy) {
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MCtxHelpMsg(Properties ctx, MCtxHelpMsg copy, String trxName) {
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get the context help message defined for the type, recordid, client, org (immutable)
* @param ctxtype
* @param recordId
* @return the context message record
*/
public static MCtxHelpMsg get(String ctxType, int recordId) {
return get(Env.getCtx(), ctxType, recordId);
}
/**
* Get the context help message defined for the type, recordid, client, org (immutable)
* @param ctxtype
* @param recordId
* @return an immutable instance of context message record (if any)
*/
public static MCtxHelpMsg get(Properties ctx, String ctxType, int recordId) {
StringBuilder key = new StringBuilder()
.append(ctxType).append("|")
@ -85,7 +122,7 @@ public class MCtxHelpMsg extends X_AD_CtxHelpMsg {
.append(Env.getAD_Org_ID(ctx));
MCtxHelpMsg retValue = null;
if (s_cache.containsKey(key.toString())) {
retValue = s_cache.get(key.toString());
retValue = s_cache.get(ctx, key.toString(), e -> new MCtxHelpMsg(ctx, e));
if (s_log.isLoggable(Level.FINEST)) s_log.finest("Cache: " + retValue);
return retValue;
}
@ -97,7 +134,7 @@ public class MCtxHelpMsg extends X_AD_CtxHelpMsg {
.setParameters(Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx), AD_CtxHelp_ID)
.first();
}
s_cache.put(key.toString(), retValue);
s_cache.put(key.toString(), retValue, e -> new MCtxHelpMsg(Env.getCtx(), e));
return retValue;
}
@ -159,5 +196,13 @@ public class MCtxHelpMsg extends X_AD_CtxHelpMsg {
super.setClientOrg(AD_Client_ID, AD_Org_ID);
}
@Override
public MCtxHelpMsg markImmutable() {
if (is_Immutable())
return this;
super.makeImmutable();
return this;
}
} // MCtxHelpMsg

View File

@ -19,19 +19,22 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.cache.ImmutablePOCache;
/**
* Currency Model.
*
* @author Jorg Janke
*/
public class MCurrency extends X_C_Currency
public class MCurrency extends X_C_Currency implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 2262097171335518186L;
private static final long serialVersionUID = 4325153934518648373L;
/**
* Currency Constructor
@ -85,14 +88,54 @@ public class MCurrency extends X_C_Currency
setIsEuro (false);
} // MCurrency
/** Store System Currencies **/
private static CCache<Integer,MCurrency> s_currencies = new CCache<Integer,MCurrency>(Table_Name, 50);
/** Cache System Currencies by using ISO code as key **/
private static CCache<String,MCurrency> s_currenciesISO = new CCache<String,MCurrency>(Table_Name, "C_CurrencyISO", 50);
/**
*
* @param copy
*/
public MCurrency(MCurrency copy)
{
this(Env.getCtx(), copy);
}
/**
* Get Currency using ISO code
*
* @param ctx
* @param copy
*/
public MCurrency(Properties ctx, MCurrency copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MCurrency(Properties ctx, MCurrency copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** Store System Currencies **/
private static ImmutableIntPOCache<Integer,MCurrency> s_currencies = new ImmutableIntPOCache<Integer,MCurrency>(Table_Name, 50);
/** Cache System Currencies by using ISO code as key **/
private static ImmutablePOCache<String,MCurrency> s_currenciesISO = new ImmutablePOCache<String,MCurrency>(Table_Name, "C_CurrencyISO", 50);
/**
* Get Currency using ISO code from cache (immutable)
* @param ISOcode Iso code
* @return MCurrency
*/
public static MCurrency get (String ISOcode)
{
return get(Env.getCtx(), ISOcode);
}
/**
* Get Currency using ISO code from cache (immutable)
* @param ctx Context
* @param ISOcode Iso code
* @return MCurrency
@ -100,24 +143,34 @@ public class MCurrency extends X_C_Currency
public static MCurrency get (Properties ctx, String ISOcode)
{
// Try Cache
MCurrency retValue = (MCurrency)s_currenciesISO.get(ISOcode);
MCurrency retValue = (MCurrency)s_currenciesISO.get(ctx, ISOcode, e -> new MCurrency(ctx, e));
if (retValue != null)
return retValue;
// Try database
Query query = new Query(ctx, I_C_Currency.Table_Name, "ISO_Code=?", null);
Query query = new Query(ctx, I_C_Currency.Table_Name, "ISO_Code=?", (String)null);
query.setParameters(ISOcode);
retValue = (MCurrency)query.firstOnly();
// Save
if (retValue!=null)
s_currenciesISO.put(ISOcode, retValue);
if (retValue!=null) {
s_currenciesISO.put(ISOcode, retValue, e -> new MCurrency(Env.getCtx(), e));
}
return retValue;
}
/**
* Get Currency
* Get Currency (immutable)
* @param C_Currency_ID currency
* @return ISO Code
*/
public static MCurrency get (int C_Currency_ID)
{
return get(Env.getCtx(), C_Currency_ID);
}
/**
* Get Currency (immutable)
* @param ctx Context
* @param C_Currency_ID currency
* @return ISO Code
@ -126,16 +179,20 @@ public class MCurrency extends X_C_Currency
{
// Try Cache
Integer key = Integer.valueOf(C_Currency_ID);
MCurrency retValue = (MCurrency)s_currencies.get(key);
MCurrency retValue = s_currencies.get(ctx, key, e -> new MCurrency(ctx, e));
if (retValue != null)
return retValue;
// Create it
retValue = new MCurrency(ctx, C_Currency_ID, null);
retValue = new MCurrency(ctx, C_Currency_ID, (String)null);
// Save in System
if (retValue.getAD_Client_ID() == 0)
s_currencies.put(key, retValue);
return retValue;
if (retValue.get_ID() == C_Currency_ID)
{
if (retValue.getAD_Client_ID() == 0)
s_currencies.put(key, retValue, e -> new MCurrency(Env.getCtx(), e));
return (MCurrency) retValue.markImmutable();
}
return null;
} // get
/**
@ -194,6 +251,15 @@ public class MCurrency extends X_C_Currency
return c.getCostingPrecision();
}
@Override
public MCurrency markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
/*************************************************************************/

View File

@ -7,10 +7,12 @@ import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.compiere.util.CCache;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.cache.IntPOCopyCache;
import org.idempiere.cache.POCopyCache;
import org.idempiere.fa.exceptions.AssetNotImplementedException;
import org.idempiere.fa.exceptions.AssetNotSupportedException;
import org.idempiere.fa.service.api.DepreciationDTO;
@ -21,13 +23,12 @@ import org.idempiere.fa.service.api.IDepreciationMethod;
* Depreciation Engine (eg. SL, ARH_VAR ...)
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*/
public class MDepreciation extends X_A_Depreciation
public class MDepreciation extends X_A_Depreciation implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -632058079835100100L;
private static final long serialVersionUID = -4366354698409595086L;
/** Standard Constructor */
public MDepreciation (Properties ctx, int A_Depreciation_ID, String trxName)
@ -45,12 +46,43 @@ public class MDepreciation extends X_A_Depreciation
super (ctx, rs, trxName);
} // MDepreciation
/**
*
* @param copy
*/
public MDepreciation(MDepreciation copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDepreciation(Properties ctx, MDepreciation copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDepreciation(Properties ctx, MDepreciation copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** Cache */
private static CCache<Integer,MDepreciation>
s_cache = new CCache<Integer,MDepreciation>(Table_Name, 5);
private static IntPOCopyCache<Integer,MDepreciation>
s_cache = new IntPOCopyCache<Integer,MDepreciation>(Table_Name, 5);
/** Cache for type */
private static CCache<String,MDepreciation>
s_cache_forType = new CCache<String,MDepreciation>(Table_Name, Table_Name+"_DepreciationType", 5);
private static POCopyCache<String,MDepreciation>
s_cache_forType = new POCopyCache<String,MDepreciation>(Table_Name, Table_Name+"_DepreciationType", 5);
/** Static logger */
private static Logger s_log = CLogger.getCLogger(MDepreciation.class);
/** The accuracy of calculation on depreciation */
@ -66,37 +98,51 @@ public class MDepreciation extends X_A_Depreciation
return ;
}
s_cache.put(depr.get_ID(), depr);
s_cache.put(depr.get_ID(), depr, e -> new MDepreciation(Env.getCtx(), e));
String key = "" + depr.getAD_Client_ID() + "_" + depr.getDepreciationType();
s_cache_forType.put(key, depr);
s_cache_forType.put(key, depr, e -> new MDepreciation(Env.getCtx(), e));
}
/**
* Get Depreciation method
* Get Depreciation method from cache
* @param A_Depreciation_ID depreciation id
*/
public static MDepreciation get(int A_Depreciation_ID)
{
return get(Env.getCtx(), A_Depreciation_ID);
}
/**
* Get Depreciation method from cache
* @param ctx
* @param A_Depreciation_ID depreciation id
*/
public static MDepreciation get(Properties ctx, int A_Depreciation_ID)
{
MDepreciation depr = s_cache.get(A_Depreciation_ID);
MDepreciation depr = s_cache.get(A_Depreciation_ID, e -> new MDepreciation(ctx, e));
if (depr != null)
{
return depr;
}
depr = new MDepreciation(ctx, A_Depreciation_ID, null);
if (depr.get_ID() > 0)
depr = new MDepreciation(ctx, A_Depreciation_ID, (String)null);
if (depr.get_ID() == A_Depreciation_ID)
{
addToCache(depr);
return depr;
}
else
{
depr = null;
}
return depr;
return null;
} // get
/**
* Get Depreciation method
* @param depreciationType depreciation type (e.g. SL)
*/
public static MDepreciation get(String depreciationType)
{
return get(Env.getCtx(), depreciationType);
}
/**
* Get Depreciation method (immutable)
* @param ctx
* @param depreciationType depreciation type (e.g. SL)
*/
@ -104,11 +150,9 @@ public class MDepreciation extends X_A_Depreciation
{
int AD_Client_ID = Env.getAD_Client_ID(ctx);
String key = "" + AD_Client_ID + "_" + depreciationType;
MDepreciation depr = s_cache_forType.get(key);
MDepreciation depr = s_cache_forType.get(key, e -> new MDepreciation(ctx, e));
if (depr != null)
{
return depr;
}
final String whereClause = COLUMNNAME_DepreciationType+"=?"
+" AND AD_Client_ID IN (0,?)";
@ -117,7 +161,7 @@ public class MDepreciation extends X_A_Depreciation
.setParameters(new Object[]{depreciationType, AD_Client_ID})
.firstOnly();
addToCache(depr);
return depr;
return (MDepreciation) depr.markImmutable();
} // get
/**
@ -482,4 +526,14 @@ public class MDepreciation extends X_A_Depreciation
// TODO: Adding this method to compile correctly and future research
return 0;
}
@Override
public MDepreciation markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
}

View File

@ -5,20 +5,22 @@ import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/** Convention for the first year of depreciation (ex. FMCON, FYCON ...)
* @author Teo Sarca, SC Arhipac SRL
* @version $Id$
*/
public class MDepreciationConvention extends X_A_Depreciation_Convention
public class MDepreciationConvention extends X_A_Depreciation_Convention implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 2274629486216430723L;
private static final long serialVersionUID = -3735111030292424391L;
/**
* Default Constructor
* @param ctx context
@ -43,24 +45,69 @@ public class MDepreciationConvention extends X_A_Depreciation_Convention
super (ctx, rs, trxName);
} // MDepreciationConvention
/**
*
* @param copy
*/
public MDepreciationConvention(MDepreciationConvention copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDepreciationConvention(Properties ctx, MDepreciationConvention copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDepreciationConvention(Properties ctx, MDepreciationConvention copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** Cache */
private static CCache<Integer,MDepreciationConvention> s_cache = new CCache<Integer,MDepreciationConvention>(Table_Name, 5);
private static ImmutableIntPOCache<Integer,MDepreciationConvention> s_cache = new ImmutableIntPOCache<Integer,MDepreciationConvention>(Table_Name, 5);
//~ /** Static logger */
//~ private static Logger s_log = CLogger.getCLogger(MDepreciationConvention.class);
/**
* Get MDepreciationConvention from cache (immutable)
* @param A_Depreciation_Convention_ID
* @return MDepreciationConvention
*/
public static MDepreciationConvention get(int A_Depreciation_Convention_ID) {
return get(Env.getCtx(), A_Depreciation_Convention_ID);
}
/**
* Get MDepreciationConvention from cache (immutable)
* @param ctx context
* @param A_Depreciation_Convention_ID
* @return MDepreciationConvention
*/
public static MDepreciationConvention get(Properties ctx, int A_Depreciation_Convention_ID) {
Integer key = Integer.valueOf(A_Depreciation_Convention_ID);
MDepreciationConvention conv = s_cache.get(key);
if (conv != null) {
MDepreciationConvention conv = s_cache.get(ctx, key, e -> new MDepreciationConvention(ctx, e));
if (conv != null)
return conv;
conv = new MDepreciationConvention(ctx, A_Depreciation_Convention_ID, (String)null);
if (conv.get_ID() == A_Depreciation_Convention_ID) {
s_cache.put(key, conv, e -> new MDepreciationConvention(Env.getCtx(), e));
return conv;
}
conv = new MDepreciationConvention(ctx, A_Depreciation_Convention_ID, null);
if (conv.get_ID() > 0) {
s_cache.put(key, conv);
} else {
conv = null;
}
return conv;
return null;
} // get
/** */
@ -114,4 +161,14 @@ public class MDepreciationConvention extends X_A_Depreciation_Convention
public BigDecimal apply_FMCON(int A_Asset_ID, String PostingType, int A_Asset_Acct_ID, int Flag, int Period) {
return BigDecimal.ONE;
}
@Override
public MDepreciationConvention markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
}

View File

@ -8,21 +8,24 @@ import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.compiere.util.CCache;
import org.compiere.util.CLogMgt;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.cache.ImmutablePOCache;
/**
* Method of adjusting the difference between depreciation (Calculated) and registered as (booked).
* ex. MDI, LDI, YDI ...
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*/
public class MDepreciationMethod extends X_A_Depreciation_Method
public class MDepreciationMethod extends X_A_Depreciation_Method implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 4622027905888469713L;
private static final long serialVersionUID = -7477974832683140825L;
/** Standard Constructor */
public MDepreciationMethod (Properties ctx, int A_Depreciation_Method_ID, String trxName)
@ -40,12 +43,43 @@ public class MDepreciationMethod extends X_A_Depreciation_Method
super (ctx, rs, trxName);
} // MDepreciationMethod
/**
*
* @param copy
*/
public MDepreciationMethod(MDepreciationMethod copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDepreciationMethod(Properties ctx, MDepreciationMethod copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDepreciationMethod(Properties ctx, MDepreciationMethod copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** Cache */
private static CCache<Integer,MDepreciationMethod>
s_cache = new CCache<Integer,MDepreciationMethod>(Table_Name, 5);
private static ImmutableIntPOCache<Integer,MDepreciationMethod>
s_cache = new ImmutableIntPOCache<Integer,MDepreciationMethod>(Table_Name, 5);
/** Cache for type */
private static CCache<String,MDepreciationMethod>
s_cache_forType = new CCache<String,MDepreciationMethod>(Table_Name, Table_Name+"_DepreciationType", 5);
private static ImmutablePOCache<String,MDepreciationMethod>
s_cache_forType = new ImmutablePOCache<String,MDepreciationMethod>(Table_Name, Table_Name+"_DepreciationType", 5);
/**
*
@ -56,8 +90,8 @@ public class MDepreciationMethod extends X_A_Depreciation_Method
{
return;
}
s_cache.put(depr.get_ID(), depr);
s_cache_forType.put(depr.getDepreciationType(), depr);
s_cache.put(depr.get_ID(), depr, e -> new MDepreciationMethod(Env.getCtx(), e));
s_cache_forType.put(depr.getDepreciationType(), depr, e -> new MDepreciationMethod(Env.getCtx(), e));
}
/**
@ -67,45 +101,66 @@ public class MDepreciationMethod extends X_A_Depreciation_Method
{
return 2;
}
/**
*
* Get MDepreciationMethod from cache (immutable)
* @param A_Depreciation_Method_ID
* @return MDepreciationMethod
*/
public static MDepreciationMethod get(int A_Depreciation_Method_ID)
{
return get(Env.getCtx(), A_Depreciation_Method_ID);
}
/**
* Get MDepreciationMethod from cache (immutable)
* @param ctx
* @param A_Depreciation_Method_ID
* @return MDepreciationMethod
*/
public static MDepreciationMethod get(Properties ctx, int A_Depreciation_Method_ID)
{
MDepreciationMethod depr = s_cache.get(A_Depreciation_Method_ID);
MDepreciationMethod depr = s_cache.get(ctx, A_Depreciation_Method_ID, e -> new MDepreciationMethod(ctx, e));
if (depr != null)
{
return depr;
}
depr = new MDepreciationMethod(ctx, A_Depreciation_Method_ID, null);
if (depr.get_ID() > 0)
depr = new MDepreciationMethod(ctx, A_Depreciation_Method_ID, (String)null);
if (depr.get_ID() == A_Depreciation_Method_ID)
{
addToCache(depr);
return depr;
}
else
{
depr = null;
}
return depr;
return null;
} // get
/**
*
* Get MDepreciationMethod from cache
* @param depreciationType
* @return MDepreciationMethod
*/
public static MDepreciationMethod get(String depreciationType)
{
return get(Env.getCtx(), depreciationType);
}
/**
* Get MDepreciationMethod from cache (immutable)
* @param ctx
* @param depreciationType
* @return MDepreciationMethod
*/
public static MDepreciationMethod get(Properties ctx, String depreciationType)
{
String key = depreciationType;
MDepreciationMethod depr = s_cache_forType.get(key);
MDepreciationMethod depr = s_cache_forType.get(ctx, key, e -> new MDepreciationMethod(ctx, e));
if (depr != null)
{
return depr;
}
depr = new Query(ctx, Table_Name, COLUMNNAME_DepreciationType+"=?", null)
.setParameters(new Object[]{depreciationType})
.firstOnly();
addToCache(depr);
return depr;
return (MDepreciationMethod) depr.markImmutable();
}
@ -246,4 +301,14 @@ public class MDepreciationMethod extends X_A_Depreciation_Method
}
return periodAdjustment;
}
@Override
public MDepreciationMethod markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
}

View File

@ -9,8 +9,6 @@ import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.base.Core;
import org.apache.commons.collections.keyvalue.MultiKey;
import org.compiere.util.CCache;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -276,6 +274,38 @@ public class MDepreciationWorkfile extends X_A_Depreciation_Workfile
dump();
}
/**
*
* @param copy
*/
public MDepreciationWorkfile(MDepreciationWorkfile copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDepreciationWorkfile(Properties ctx, MDepreciationWorkfile copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDepreciationWorkfile(Properties ctx, MDepreciationWorkfile copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_asset = copy.m_asset != null ? new MAsset(ctx, copy.m_asset, trxName) : null;
}
/** Logger */
private CLogger log = CLogger.getCLogger(getClass());
@ -316,20 +346,6 @@ public class MDepreciationWorkfile extends X_A_Depreciation_Workfile
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+"=? AND " + COLUMNNAME_C_AcctSchema_ID + "=?" ;
@ -337,12 +353,7 @@ public class MDepreciationWorkfile extends X_A_Depreciation_Workfile
MDepreciationWorkfile wk = new Query(ctx, MDepreciationWorkfile.Table_Name, whereClause, trxName)
.setParameters(new Object[]{A_Asset_ID, postingType,acctSchemaId})
.firstOnly();
if (trxName == null && wk != null)
{
s_cacheAsset.put(key, wk);
}
return wk;
}
@ -358,9 +369,6 @@ public class MDepreciationWorkfile extends X_A_Depreciation_Workfile
{
return get(ctx, A_Asset_ID, postingType, trxName, 0);
}
/** Static cache: Asset/PostingType -> Workfile */
private static CCache<MultiKey, MDepreciationWorkfile>
s_cacheAsset = new CCache<MultiKey, MDepreciationWorkfile>(Table_Name, Table_Name+"_Asset", 10);
/** Returns the date of the last action
*/

View File

@ -21,13 +21,15 @@ import java.math.RoundingMode;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Discount Schema Model
@ -35,35 +37,47 @@ import org.compiere.util.TimeUtil;
* @author Jorg Janke
* @version $Id: MDiscountSchema.java,v 1.3 2006/07/30 00:51:04 jjanke Exp $
*/
public class MDiscountSchema extends X_M_DiscountSchema
public class MDiscountSchema extends X_M_DiscountSchema implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -3314884382853756019L;
private static final long serialVersionUID = 4916780751688051566L;
/**
* Get Discount Schema from Cache
* @param ctx context
* Get Discount Schema from Cache (immutable)
* @param M_DiscountSchema_ID id
* @return MDiscountSchema
*/
public static MDiscountSchema get (int M_DiscountSchema_ID)
{
return get(Env.getCtx(), M_DiscountSchema_ID);
}
/**
* Get Discount Schema from Cache (immutable)
* @param ctx context
* @param M_DiscountSchema_ID id
* @return MDiscountSchema
*/
public static MDiscountSchema get (Properties ctx, int M_DiscountSchema_ID)
{
Integer key = Integer.valueOf(M_DiscountSchema_ID);
MDiscountSchema retValue = (MDiscountSchema) s_cache.get (key);
MDiscountSchema retValue = s_cache.get (ctx, key, e -> new MDiscountSchema(ctx, e));
if (retValue != null)
return retValue;
retValue = new MDiscountSchema (ctx, M_DiscountSchema_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MDiscountSchema (ctx, M_DiscountSchema_ID, (String)null);
if (retValue.get_ID () == M_DiscountSchema_ID)
{
s_cache.put (key, retValue, e -> new MDiscountSchema(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer,MDiscountSchema> s_cache
= new CCache<Integer,MDiscountSchema>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MDiscountSchema> s_cache
= new ImmutableIntPOCache<Integer,MDiscountSchema>(Table_Name, 20);
/**************************************************************************
@ -98,6 +112,39 @@ public class MDiscountSchema extends X_M_DiscountSchema
super(ctx, rs, trxName);
} // MDiscountSchema
/**
*
* @param copy
*/
public MDiscountSchema(MDiscountSchema copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDiscountSchema(Properties ctx, MDiscountSchema copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDiscountSchema(Properties ctx, MDiscountSchema copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_breaks = copy.m_breaks != null ? Arrays.stream(copy.m_breaks).map(e -> {return new MDiscountSchemaBreak(ctx, e, trxName);}).toArray(MDiscountSchemaBreak[]::new) : null;
this.m_lines = copy.m_lines != null ? Arrays.stream(copy.m_lines).map(e -> {return new MDiscountSchemaLine(ctx, e, trxName);}).toArray(MDiscountSchemaLine[]::new) : null;
}
/** Breaks */
private MDiscountSchemaBreak[] m_breaks = null;
/** Lines */
@ -123,7 +170,12 @@ public class MDiscountSchema extends X_M_DiscountSchema
pstmt.setInt (1, getM_DiscountSchema_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
list.add(new MDiscountSchemaBreak(getCtx(), rs, get_TrxName()));
{
MDiscountSchemaBreak dsb = new MDiscountSchemaBreak(getCtx(), rs, get_TrxName());
if (is_Immutable())
dsb.markImmutable();
list.add(dsb);
}
}
catch (Exception e)
{
@ -162,7 +214,12 @@ public class MDiscountSchema extends X_M_DiscountSchema
pstmt.setInt (1, getM_DiscountSchema_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
list.add(new MDiscountSchemaLine(getCtx(), rs, get_TrxName()));
{
MDiscountSchemaLine dsl = new MDiscountSchemaLine(getCtx(), rs, get_TrxName());
if (is_Immutable())
dsl.markImmutable();
list.add(dsl);
}
}
catch (Exception e)
{
@ -337,5 +394,17 @@ public class MDiscountSchema extends X_M_DiscountSchema
m_breaks = null;
return count;
} // reSeq
@Override
public MDiscountSchema markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
if (m_lines != null)
Arrays.stream(m_lines).forEach(e -> {e.markImmutable();});
if (m_breaks != null)
Arrays.stream(m_breaks).forEach(e -> {e.markImmutable();});
return this;
}
} // MDiscountSchema

View File

@ -20,6 +20,9 @@ import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Discount Break Schema (Model)
@ -30,13 +33,13 @@ import java.util.Properties;
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 2012439 ] DiscountSchemaBreak: setting product & category is allowed
*/
public class MDiscountSchemaBreak extends X_M_DiscountSchemaBreak
public class MDiscountSchemaBreak extends X_M_DiscountSchemaBreak implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 6413962940750128351L;
private static final long serialVersionUID = -5405425697628869517L;
/**
* Standard Constructor
@ -60,6 +63,36 @@ public class MDiscountSchemaBreak extends X_M_DiscountSchemaBreak
super(ctx, rs, trxName);
} // MDiscountSchemaBreak
/**
*
* @param copy
*/
public MDiscountSchemaBreak(MDiscountSchemaBreak copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDiscountSchemaBreak(Properties ctx, MDiscountSchemaBreak copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDiscountSchemaBreak(Properties ctx, MDiscountSchemaBreak copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Criteria apply
@ -123,5 +156,14 @@ public class MDiscountSchemaBreak extends X_M_DiscountSchemaBreak
sb.append ("]");
return sb.toString ();
} // toString
@Override
public MDiscountSchemaBreak markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MDiscountSchemaBreak

View File

@ -19,6 +19,9 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Discount Schema Line (Price List) Model
@ -26,13 +29,12 @@ import java.util.Properties;
* @author Jorg Janke
* @version $Id: MDiscountSchemaLine.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
*/
public class MDiscountSchemaLine extends X_M_DiscountSchemaLine
public class MDiscountSchemaLine extends X_M_DiscountSchemaLine implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 1632154004024021493L;
private static final long serialVersionUID = 5145958821951855437L;
/**
* Standard Constructor
@ -56,4 +58,44 @@ public class MDiscountSchemaLine extends X_M_DiscountSchemaLine
super(ctx, rs, trxName);
} // MDiscountSchemaLine
/**
*
* @param copy
*/
public MDiscountSchemaLine(MDiscountSchemaLine copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDiscountSchemaLine(Properties ctx, MDiscountSchemaLine copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDiscountSchemaLine(Properties ctx, MDiscountSchemaLine copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
public MDiscountSchemaLine markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MDiscountSchemaLine

View File

@ -20,6 +20,7 @@ import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -65,7 +66,6 @@ public class MDistribution extends X_GL_Distribution
/**
* Get Distributions for combination
* @param ctx context
* @param C_AcctSchema_ID schema
* @param PostingType posting type
* @param C_DocType_ID document type
@ -85,6 +85,39 @@ public class MDistribution extends X_GL_Distribution
* @param User2_ID user 2
* @return array of distributions or null
*/
public static MDistribution[] get (int C_AcctSchema_ID,
String PostingType, int C_DocType_ID, Timestamp dateAcct,
int AD_Org_ID, int Account_ID,
int M_Product_ID, int C_BPartner_ID, int C_Project_ID,
int C_Campaign_ID, int C_Activity_ID, int AD_OrgTrx_ID,
int C_SalesRegion_ID, int C_LocTo_ID, int C_LocFrom_ID,
int User1_ID, int User2_ID)
{
return get(Env.getCtx(), C_AcctSchema_ID, PostingType, C_DocType_ID, dateAcct, AD_Org_ID, Account_ID, M_Product_ID, C_BPartner_ID,
C_Project_ID, C_Campaign_ID, C_Activity_ID, AD_OrgTrx_ID, C_SalesRegion_ID, C_LocTo_ID, C_LocFrom_ID, User1_ID, User2_ID);
}
/**
* Get Distributions for combination
* @param ctx context
* @param C_AcctSchema_ID schema
* @param PostingType posting type
* @param C_DocType_ID document type
* @param AD_Org_ID org
* @param Account_ID account
* @param M_Product_ID product
* @param C_BPartner_ID partner
* @param C_Project_ID project
* @param C_Campaign_ID campaign
* @param C_Activity_ID activity
* @param AD_OrgTrx_ID trx org
* @param C_SalesRegion_ID
* @param C_LocTo_ID location to
* @param C_LocFrom_ID location from
* @param User1_ID user 1
* @param User2_ID user 2
* @return array of distributions or null
*/
public static MDistribution[] get (Properties ctx, int C_AcctSchema_ID,
String PostingType, int C_DocType_ID, Timestamp dateAcct,
int AD_Org_ID, int Account_ID,
@ -93,7 +126,7 @@ public class MDistribution extends X_GL_Distribution
int C_SalesRegion_ID, int C_LocTo_ID, int C_LocFrom_ID,
int User1_ID, int User2_ID)
{
MDistribution[] acctList = getAll(ctx);
MDistribution[] acctList = getAll();
if (acctList == null || acctList.length == 0)
return null;
//
@ -154,12 +187,23 @@ public class MDistribution extends X_GL_Distribution
/**
* Get Distributions for Account
* @param ctx context
* @param ctx ignore
* @param Account_ID id
* @return array of distributions
*/
public static MDistribution[] get (Properties ctx, int Account_ID)
{
return get(Account_ID);
}
/**
* Get Distributions for Account
* @param Account_ID id
* @return array of distributions
*/
public static MDistribution[] get (int Account_ID)
{
Properties ctx = Env.getCtx();
Integer key = Integer.valueOf(Account_ID);
MDistribution[] retValue = (MDistribution[])s_accounts.get(key);
if (retValue != null)
@ -177,20 +221,31 @@ public class MDistribution extends X_GL_Distribution
.list();
//
retValue = new MDistribution[list.size ()];
list.toArray (retValue);
retValue = list.toArray (retValue);
s_accounts.put(key, retValue);
return retValue;
} // get
/**
* Get All Distributions
* @param ctx context
* @param ctx ignore
* @param Account_ID id
* @return array of distributions
* @deprecated
*/
public static MDistribution[] getAll (Properties ctx)
{
return get(ctx, -1);
return getAll();
}
/**
* Get All Distributions
* @param Account_ID id
* @return array of distributions
*/
public static MDistribution[] getAll ()
{
return get(-1);
} // get
/** Static Logger */
@ -245,6 +300,38 @@ public class MDistribution extends X_GL_Distribution
super(ctx, rs, trxName);
} // MDistribution
/**
*
* @param copy
*/
public MDistribution(MDistribution copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDistribution(Properties ctx, MDistribution copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDistribution(Properties ctx, MDistribution copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_lines = copy.m_lines != null ? Arrays.stream(copy.m_lines).map(e -> {var v = new MDistributionLine(ctx, e, trxName); v.setParent(this); return v;}).toArray(MDistributionLine[]::new) : null;
}
/** The Lines */
private MDistributionLine[] m_lines = null;
@ -449,5 +536,5 @@ public class MDistribution extends X_GL_Distribution
setUser2_ID(0);
return true;
} // beforeSave
} // MDistribution

View File

@ -81,6 +81,41 @@ public class MDistributionLine extends X_GL_DistributionLine
super(ctx, rs, trxName);
} // MDistributionLine
/**
*
* @param copy
*/
public MDistributionLine(MDistributionLine copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDistributionLine(Properties ctx, MDistributionLine copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDistributionLine(Properties ctx, MDistributionLine copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_parent = null;
this.m_amt = copy.m_amt;
this.m_qty = copy.m_qty;
this.m_account = copy.m_account != null ? new MAccount(ctx, copy.m_account, trxName) : null;
}
/** The Parent */
private MDistribution m_parent = null;
/** The Amount */

View File

@ -215,7 +215,7 @@ public class MDistributionRunLine extends X_M_DistributionRunLine
public MProduct getProduct()
{
if (m_product == null)
m_product = MProduct.get(getCtx(), getM_Product_ID());
m_product = MProduct.getCopy(getCtx(), getM_Product_ID(), get_TrxName());
return m_product;
} // getProduct

View File

@ -21,9 +21,10 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Document Type Model
@ -36,12 +37,12 @@ import org.compiere.util.Env;
* See https://sourceforge.net/forum/message.php?msg_id=6499893
* @version $Id: MDocType.java,v 1.3 2006/07/30 00:54:54 jjanke Exp $
*/
public class MDocType extends X_C_DocType
public class MDocType extends X_C_DocType implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -6556521509479670059L;
private static final long serialVersionUID = -7313617271586412889L;
/**
* Return the first Doc Type for this BaseType
@ -86,24 +87,38 @@ public class MDocType extends X_C_DocType
} // getOfClient
/**
* Get Document Type (cached)
* Get Document Type (cached) (immutable)
* @param C_DocType_ID id
* @return document type
*/
static public MDocType get (int C_DocType_ID)
{
return get(Env.getCtx(), C_DocType_ID);
}
/**
* Get Document Type (cached) (immutable)
* @param ctx context
* @param C_DocType_ID id
* @return document type
*/
static public MDocType get (Properties ctx, int C_DocType_ID)
{
MDocType retValue = (MDocType)s_cache.get(C_DocType_ID);
if (retValue == null)
MDocType retValue = s_cache.get(ctx, C_DocType_ID, e -> new MDocType(ctx, e));
if (retValue != null)
return retValue;
retValue = new MDocType (ctx, C_DocType_ID, (String)null);
if (retValue.getC_DocType_ID() == C_DocType_ID)
{
retValue = new MDocType (ctx, C_DocType_ID, null);
s_cache.put(C_DocType_ID, retValue);
s_cache.put(C_DocType_ID, retValue, e -> new MDocType(Env.getCtx(), e));
return retValue;
}
return retValue;
return null;
} // get
/** Cache */
static private CCache<Integer,MDocType> s_cache = new CCache<Integer,MDocType>(Table_Name, 20);
static private ImmutableIntPOCache<Integer,MDocType> s_cache = new ImmutableIntPOCache<Integer,MDocType>(Table_Name, 20);
/**************************************************************************
* Standard Constructor
@ -163,6 +178,37 @@ public class MDocType extends X_C_DocType
setGL_Category_ID ();
} // MDocType
/**
*
* @param copy
*/
public MDocType(MDocType copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDocType(Properties ctx, MDocType copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDocType(Properties ctx, MDocType copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Set Default GL Category
*/
@ -314,7 +360,7 @@ public class MDocType extends X_C_DocType
int relatedDocTypeId = 0;
if (docTypeId != 0)
{
MDocType docType = MDocType.get(Env.getCtx(), docTypeId);
MDocType docType = MDocType.get(docTypeId);
// FIXME: Should refactor code and remove the hard coded name
// Should change document type to allow query the value
if ("Return Material".equals(docType.getName()) ||
@ -368,4 +414,13 @@ public class MDocType extends X_C_DocType
return get_Translation (COLUMNNAME_Name, Env.getAD_Language(getCtx()));
} // getNameTrl
@Override
public MDocType markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MDocType

View File

@ -21,9 +21,11 @@ import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
@ -32,13 +34,12 @@ import org.compiere.util.DB;
* @author Jorg Janke
* @version $Id: MDocTypeCounter.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
*/
public class MDocTypeCounter extends X_C_DocTypeCounter
public class MDocTypeCounter extends X_C_DocTypeCounter implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 3469046560457430527L;
private static final long serialVersionUID = 3999273279386464393L;
/**
* Get Counter document for document type
@ -59,7 +60,7 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
// Indirect Relationship
int Counter_C_DocType_ID = 0;
MDocType dt = MDocType.get(ctx, C_DocType_ID);
MDocType dt = MDocType.get(C_DocType_ID);
if (!dt.isCreateCounter())
return -1;
String cDocBaseType = getCounterDocBaseType(dt.getDocBaseType());
@ -82,15 +83,23 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
return Counter_C_DocType_ID;
} // getCounterDocType_ID
/**
* Get (first) valid Counter document for document type
* @param ctx context
* @param ctx ignore
* @param C_DocType_ID base document
* @return counter document (may be invalid) or null
*/
public static MDocTypeCounter getCounterDocType (Properties ctx, int C_DocType_ID)
{
return getCounterDocType(C_DocType_ID);
}
/**
* Get (first) valid Counter document for document type
* @param C_DocType_ID base document
* @return counter document (may be invalid) or null
*/
public static MDocTypeCounter getCounterDocType (int C_DocType_ID)
{
Integer key = Integer.valueOf(C_DocType_ID);
MDocTypeCounter retValue = (MDocTypeCounter)s_counter.get(key);
@ -109,12 +118,16 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
rs = pstmt.executeQuery ();
while (rs.next () && retValue == null)
{
retValue = new MDocTypeCounter (ctx, rs, null);
retValue = new MDocTypeCounter (Env.getCtx(), rs, null);
if (!retValue.isCreateCounter() || !retValue.isValid())
{
temp = retValue;
retValue = null;
}
else
{
s_counter.put(key, retValue);
}
}
}
catch (Exception e)
@ -136,21 +149,46 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
/**
* Get MDocTypeCounter from Cache
* @param ctx context
* @param C_DocTypeCounter_ID id
* @return MDocTypeCounter
* @param trxName transaction
*/
public static MDocTypeCounter get (int C_DocTypeCounter_ID)
{
return get(C_DocTypeCounter_ID, (String)null);
}
/**
* Get MDocTypeCounter from Cache
* @param C_DocTypeCounter_ID id
* @param trxName transaction
* @return MDocTypeCounter
*/
public static MDocTypeCounter get (int C_DocTypeCounter_ID, String trxName)
{
return get(Env.getCtx(), C_DocTypeCounter_ID, trxName);
}
/**
* Get MDocTypeCounter from Cache
* @param ctx context
* @param C_DocTypeCounter_ID id
* @param trxName
* @return MDocTypeCounter
*/
public static MDocTypeCounter get (Properties ctx, int C_DocTypeCounter_ID, String trxName)
{
Integer key = Integer.valueOf(C_DocTypeCounter_ID);
MDocTypeCounter retValue = (MDocTypeCounter) s_cache.get (key);
MDocTypeCounter retValue = (MDocTypeCounter) s_cache.get (ctx, key, e -> new MDocTypeCounter(ctx, e));
if (retValue != null)
return retValue;
return retValue;
retValue = new MDocTypeCounter (ctx, C_DocTypeCounter_ID, trxName);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
if (retValue.get_ID () == C_DocTypeCounter_ID)
{
s_cache.put(key, retValue, e -> new MDocTypeCounter(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
@ -196,9 +234,9 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
/** Object Cache */
private static CCache<Integer,MDocTypeCounter> s_cache = new CCache<Integer,MDocTypeCounter>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MDocTypeCounter> s_cache = new ImmutableIntPOCache<Integer,MDocTypeCounter>(Table_Name, 20);
/** Counter Relationship Cache */
private static CCache<Integer,MDocTypeCounter> s_counter = new CCache<Integer,MDocTypeCounter>(Table_Name, "C_DocTypeCounter_Relation", 20);
private static ImmutableIntPOCache<Integer,MDocTypeCounter> s_counter = new ImmutableIntPOCache<Integer,MDocTypeCounter>(Table_Name, "C_DocTypeCounter_Relation", 20);
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MDocTypeCounter.class);
@ -230,6 +268,36 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
super(ctx, rs, trxName);
} // MDocTypeCounter
/**
*
* @param copy
*/
public MDocTypeCounter(MDocTypeCounter copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MDocTypeCounter(Properties ctx, MDocTypeCounter copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MDocTypeCounter(Properties ctx, MDocTypeCounter copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Set C_DocType_ID
@ -255,7 +323,7 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
} // setCounter_C_DocType_ID
/**
* Get Doc Type
* Get Doc Type (immutable)
* @return doc type or null if not existing
*/
public MDocType getDocType()
@ -271,7 +339,7 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
} // getDocType
/**
* Get Counter Doc Type
* Get Counter Doc Type (immutable)
* @return counter doc type or null if not existing
*/
public MDocType getCounterDocType()
@ -379,5 +447,14 @@ public class MDocTypeCounter extends X_C_DocTypeCounter
validate();
return true;
} // beforeSave
@Override
public MDocTypeCounter markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MDocTypeCounter

View File

@ -32,13 +32,17 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.cache.POCopyCache;
/**
* @author Trifon N. Trifonov
@ -50,18 +54,19 @@ import org.compiere.util.CLogger;
* <li>https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2936561&group_id=176962
*
*/
public class MEXPFormat extends X_EXP_Format {
public class MEXPFormat extends X_EXP_Format implements ImmutablePOSupport {
/**
*
*/
private static final long serialVersionUID = -5011042965945626099L;
private static final long serialVersionUID = -2749091471654364602L;
/** Static Logger */
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger (MEXPFormat.class);
private static CCache<String,MEXPFormat> s_cache = new CCache<String,MEXPFormat>(MEXPFormat.Table_Name, 50 );
private static CCache<Integer,MEXPFormat> exp_format_by_id_cache = new CCache<Integer,MEXPFormat>(MEXPFormat.Table_Name, 50);
private static POCopyCache<String,MEXPFormat> s_cache = new POCopyCache<String,MEXPFormat>(MEXPFormat.Table_Name, 50 );
private static ImmutableIntPOCache<Integer,MEXPFormat> exp_format_by_id_cache = new ImmutableIntPOCache<Integer,MEXPFormat>(MEXPFormat.Table_Name, 50);
private List<MEXPFormatLine> m_lines = null;
private List<MEXPFormatLine> m_lines_unique = null;
@ -75,6 +80,36 @@ public class MEXPFormat extends X_EXP_Format {
super (ctx, rs, trxName);
}
/**
*
* @param copy
*/
public MEXPFormat(MEXPFormat copy) {
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MEXPFormat(Properties ctx, MEXPFormat copy) {
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MEXPFormat(Properties ctx, MEXPFormat copy, String trxName) {
this(ctx, 0, trxName);
copyPO(copy);
this.m_lines = copy.m_lines != null ? copy.m_lines.stream().map(e -> {return new MEXPFormatLine(ctx, e, trxName);}).collect(Collectors.toCollection(ArrayList::new)) : null;
this.m_lines_unique = copy.m_lines_unique != null ? copy.m_lines_unique.stream().map(e -> {return new MEXPFormatLine(ctx, e, trxName);}).collect(Collectors.toCollection(ArrayList::new)) : null;
}
public List<MEXPFormatLine> getFormatLines() {
return getFormatLinesOrderedBy(X_EXP_FormatLine.COLUMNNAME_Position);
}
@ -92,6 +127,8 @@ public class MEXPFormat extends X_EXP_Format {
.setParameters(getEXP_Format_ID())
.setOrderBy(orderBy)
.list();
if (is_Immutable() && m_lines.size() > 0)
m_lines.stream().forEach(e -> e.markImmutable());
return m_lines;
}
@ -107,30 +144,62 @@ public class MEXPFormat extends X_EXP_Format {
.setParameters(getEXP_Format_ID(), "Y")
.setOrderBy(X_EXP_FormatLine.COLUMNNAME_Position)
.list();
if (is_Immutable() && m_lines_unique.size() > 0)
m_lines_unique.stream().forEach(e -> e.markImmutable());
return m_lines_unique;
}
/**
* Get MEXPFormat from cache (immutable)
* @param EXP_Format_ID
* @return MEXPFormat
*/
public static MEXPFormat get(int EXP_Format_ID)
{
return get(EXP_Format_ID, (String)null);
}
/**
* Get MEXPFormat from cache (immutable)
* @param EXP_Format_ID
* @param trxName
* @return MEXPFormat
*/
public static MEXPFormat get(int EXP_Format_ID, String trxName)
{
return get(Env.getCtx(), EXP_Format_ID, trxName);
}
/**
* Get MEXPFormat from cache (immutable)
* @param ctx
* @param EXP_Format_ID
* @param trxName
* @return MEXPFormat
*/
public static MEXPFormat get(Properties ctx, int EXP_Format_ID, String trxName)
{
MEXPFormat exp_format = exp_format_by_id_cache.get(EXP_Format_ID);
MEXPFormat exp_format = exp_format_by_id_cache.get(ctx, EXP_Format_ID, e -> new MEXPFormat(ctx, e));
if(exp_format != null)
return exp_format;
exp_format = new MEXPFormat(ctx, EXP_Format_ID , trxName);
if(exp_format!=null)
if(exp_format.getEXP_Format_ID() == EXP_Format_ID)
{
exp_format.getFormatLines();
exp_format_by_id_cache.put(EXP_Format_ID, exp_format);
exp_format.getFormatLines();
exp_format_by_id_cache.put(EXP_Format_ID, exp_format, e -> new MEXPFormat(Env.getCtx(), e));
return exp_format;
}
return exp_format;
return null;
}
public static MEXPFormat getFormatByValueAD_Client_IDAndVersion(Properties ctx, String value, int AD_Client_ID, String version, String trxName)
throws SQLException
{
String key = new String(value+version);
MEXPFormat retValue=null;
//if(retValue!=null)
// return retValue;
MEXPFormat retValue=s_cache.get(key, e -> new MEXPFormat(ctx, e, trxName));
if (retValue != null)
return retValue;
StringBuilder whereClause = new StringBuilder(X_EXP_Format.COLUMNNAME_Value).append("=?")
.append(" AND AD_Client_ID = ?")
@ -139,22 +208,21 @@ public class MEXPFormat extends X_EXP_Format {
retValue = (MEXPFormat) new Query(ctx,X_EXP_Format.Table_Name,whereClause.toString(),trxName)
.setParameters(value,AD_Client_ID,version).first();
if(retValue != null)
if (retValue != null)
{
retValue.getFormatLines();
s_cache.put (key, retValue);
exp_format_by_id_cache.put(retValue.getEXP_Format_ID(), retValue);
s_cache.put (key, retValue, e -> new MEXPFormat(Env.getCtx(), e));
exp_format_by_id_cache.put(retValue.getEXP_Format_ID(), new MEXPFormat(Env.getCtx(), retValue));
return retValue;
}
return retValue;
return null;
}
public static MEXPFormat getFormatByAD_Client_IDAD_Table_IDAndVersion(Properties ctx, int AD_Client_ID, int AD_Table_ID, String version, String trxName) throws SQLException
{
String key = new String(MTable.getTableName(ctx, AD_Table_ID)+version);
MEXPFormat retValue=null;
retValue = (MEXPFormat)s_cache.get(key);
MEXPFormat retValue = s_cache.get(key, e -> new MEXPFormat(ctx, e, trxName));
if(retValue!=null)
return retValue;
@ -168,11 +236,12 @@ public class MEXPFormat extends X_EXP_Format {
if(retValue!=null)
{
retValue.getFormatLines();
s_cache.put (key, retValue);
exp_format_by_id_cache.put(retValue.getEXP_Format_ID(), retValue);
s_cache.put (key, retValue, e -> new MEXPFormat(Env.getCtx(), e));
exp_format_by_id_cache.put(retValue.getEXP_Format_ID(), new MEXPFormat(Env.getCtx(), retValue));
return retValue.markImmutable();
}
return retValue;
return null;
}
@Override
@ -196,4 +265,19 @@ public class MEXPFormat extends X_EXP_Format {
}
return true;
} // beforeDelete
@Override
public MEXPFormat markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
if (m_lines != null && m_lines.size() > 0)
m_lines.stream().forEach(e -> e.markImmutable());
if (m_lines_unique != null && m_lines_unique.size() > 0)
m_lines_unique.stream().forEach(e -> e.markImmutable());
return this;
}
}

View File

@ -37,15 +37,17 @@ import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
/**
* @author Trifon N. Trifonov
*/
public class MEXPFormatLine extends X_EXP_FormatLine {
public class MEXPFormatLine extends X_EXP_FormatLine implements ImmutablePOSupport {
/**
*
*/
private static final long serialVersionUID = 1855089248134520749L;
private static final long serialVersionUID = 2125885766063286714L;
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (X_EXP_FormatLine.class);
@ -59,6 +61,34 @@ public class MEXPFormatLine extends X_EXP_FormatLine {
super (ctx, rs, trxName);
}
/**
*
* @param copy
*/
public MEXPFormatLine(MEXPFormatLine copy) {
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MEXPFormatLine(Properties ctx, MEXPFormatLine copy) {
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MEXPFormatLine(Properties ctx, MEXPFormatLine copy, String trxName) {
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder ("X_EXP_FormatLine[ID=").append(get_ID()).append("; Value=").append(getValue()).append("; Type=").append(getType()).append("]");
@ -98,4 +128,14 @@ public class MEXPFormatLine extends X_EXP_FormatLine {
return result;
}
@Override
public MEXPFormatLine markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
}

View File

@ -22,6 +22,7 @@ import java.util.Properties;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Natural Account
@ -33,12 +34,12 @@ import org.compiere.util.Env;
* BF [ 1883533 ] Change to summary - valid combination issue
* BF [ 2320411 ] Translate "Already posted to" message
*/
public class MElementValue extends X_C_ElementValue
public class MElementValue extends X_C_ElementValue implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 4765839867934329276L;
private static final long serialVersionUID = 6352667759697380460L;
/**
* Standard Constructor
@ -116,6 +117,37 @@ public class MElementValue extends X_C_ElementValue
set(imp);
} // MElementValue
/**
*
* @param copy
*/
public MElementValue(MElementValue copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MElementValue(Properties ctx, MElementValue copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MElementValue(Properties ctx, MElementValue copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Set/Update Settings from import
* @param imp import
@ -279,4 +311,13 @@ public class MElementValue extends X_C_ElementValue
return success;
} // afterDelete
@Override
public MElementValue markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MElementValue

View File

@ -22,8 +22,10 @@ import static org.compiere.model.SystemIDs.ENTITYTYPE_DICTIONARY;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.cache.ImmutablePOCache;
/**
* Enitity Type Model
@ -39,34 +41,47 @@ import org.compiere.util.CLogger;
* <li>BF [ 2861194 ] EntityType is not using normal PO framework for getting IDs
* https://sourceforge.net/tracker/?func=detail&aid=2861194&group_id=176962&atid=879332
*/
public class MEntityType extends X_AD_EntityType
public class MEntityType extends X_AD_EntityType implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -8449015496292546851L;
private static final long serialVersionUID = -7160389442572466581L;
/**
* Get EntityType object by name
* Get EntityType object by name (immutable)
* @param entityType
* @return entity type
*/
public static MEntityType get(String entityType)
{
return get(Env.getCtx(), entityType);
}
/**
* Get EntityType object by name (immutable)
* @param ctx
* @param entityType
* @return
* @return entity type
*/
public static MEntityType get(Properties ctx, String entityType)
{
MEntityType retValue = (MEntityType) s_cache.get (entityType);
MEntityType retValue = s_cache.get (ctx, entityType, e -> new MEntityType(ctx, e));
if (retValue != null)
return retValue;
retValue = new Query(ctx, Table_Name, "EntityType=?", null)
.setParameters(entityType)
.firstOnly();
if (retValue != null)
s_cache.put (entityType, retValue);
s_cache.put (entityType, retValue, e -> new MEntityType(Env.getCtx(), e));
return retValue;
}
/** Cached EntityTypes */
private static CCache<String,MEntityType> s_cache = new CCache<String,MEntityType>(Table_Name, 20);
private static ImmutablePOCache<String,MEntityType> s_cache = new ImmutablePOCache<String,MEntityType>(Table_Name, 20);
/** Logger */
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger (MEntityType.class);
@ -93,6 +108,37 @@ public class MEntityType extends X_AD_EntityType
super (ctx, rs, trxName);
} // MEntityType
/**
*
* @param copy
*/
public MEntityType(MEntityType copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MEntityType(Properties ctx, MEntityType copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MEntityType(Properties ctx, MEntityType copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* First Not System Entity ID
* 10=D, 20=C, 100=U, 110=CUST, 200=A, 210=EXT, 220=XX etc
@ -183,4 +229,13 @@ public class MEntityType extends X_AD_EntityType
return true;
} // beforeDelete
@Override
public MEntityType markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MEntityType

View File

@ -19,7 +19,9 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
@ -28,35 +30,44 @@ import org.compiere.util.CCache;
* @author Jorg Janke
* @version $Id: MField.java,v 1.2 2006/07/30 00:58:04 jjanke Exp $
*/
public class MField extends X_AD_Field
public class MField extends X_AD_Field implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 7243492167390659946L;
private static final long serialVersionUID = -7382459987895129752L;
/** Cache */
private static CCache<Integer,MField> s_cache = new CCache<Integer,MField>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MField> s_cache = new ImmutableIntPOCache<Integer,MField>(Table_Name, 20);
/**
*
* @param ctx
* @param AD_Field_ID
* @return MField
* @return MField (immutable)
*/
public static MField get(int AD_Field_ID)
{
return get(Env.getCtx(), AD_Field_ID);
}
/**
* @param ctx context
* @param AD_Field_ID
* @return Immutable instance of MField
*/
public static MField get(Properties ctx, int AD_Field_ID)
{
Integer key = Integer.valueOf(AD_Field_ID);
MField retValue = s_cache.get (key);
if (retValue != null && retValue.getCtx() == ctx) {
MField retValue = s_cache.get (ctx, key, e -> new MField(ctx, e));
if (retValue != null)
return retValue;
retValue = new MField (ctx, AD_Field_ID, (String)null);
if (retValue.get_ID () == AD_Field_ID) {
s_cache.put (key, retValue, e -> new MField(Env.getCtx(), e));
return retValue;
}
retValue = new MField (ctx, AD_Field_ID, null);
if (retValue.get_ID () == AD_Field_ID) {
s_cache.put (key, retValue);
}
return retValue;
return null;
}
/**
@ -122,6 +133,37 @@ public class MField extends X_AD_Field
setEntityType(parent.getEntityType());
} // M_Field
/**
*
* @param copy
*/
public MField(MField copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MField(Properties ctx, MField copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MField(Properties ctx, MField copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Set Column Values
* @param column column
@ -185,4 +227,13 @@ public class MField extends X_AD_Field
return true;
} // beforeSave
@Override
public MField markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MField

View File

@ -21,10 +21,11 @@ import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* GL Category
@ -32,30 +33,42 @@ import org.compiere.util.Env;
* @author Jorg Janke
* @version $Id: MGLCategory.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
*/
public class MGLCategory extends X_GL_Category
public class MGLCategory extends X_GL_Category implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -272365151811522531L;
private static final long serialVersionUID = 7294511214194057235L;
/**
* Get MGLCategory from Cache
* @param ctx context
* Get MGLCategory from Cache (immutable)
* @param GL_Category_ID id
* @return MGLCategory
*/
public static MGLCategory get (int GL_Category_ID)
{
return get(Env.getCtx(), GL_Category_ID);
}
/**
* Get MGLCategory from Cache (immutable)
* @param ctx context
* @param GL_Category_ID id
* @return immutable instance of MGLCategory
*/
public static MGLCategory get (Properties ctx, int GL_Category_ID)
{
Integer key = Integer.valueOf(GL_Category_ID);
MGLCategory retValue = (MGLCategory)s_cache.get (key);
MGLCategory retValue = s_cache.get (ctx, key, e -> new MGLCategory(ctx, e));
if (retValue != null)
return retValue;
retValue = new MGLCategory (ctx, GL_Category_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MGLCategory (ctx, GL_Category_ID, (String)null);
if (retValue.get_ID () == GL_Category_ID)
{
s_cache.put (key, retValue, e -> new MGLCategory(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
@ -126,8 +139,8 @@ public class MGLCategory extends X_GL_Category
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MGLCategory.class);
/** Cache */
private static CCache<Integer, MGLCategory> s_cache
= new CCache<Integer, MGLCategory> (Table_Name, 5);
private static ImmutableIntPOCache<Integer, MGLCategory> s_cache
= new ImmutableIntPOCache<Integer, MGLCategory> (Table_Name, 5);
/**************************************************************************
@ -158,6 +171,37 @@ public class MGLCategory extends X_GL_Category
super(ctx, rs, trxName);
} // MGLCategory
/**
*
* @param copy
*/
public MGLCategory(MGLCategory copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MGLCategory(Properties ctx, MGLCategory copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MGLCategory(Properties ctx, MGLCategory copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
public String toString()
{
@ -169,4 +213,14 @@ public class MGLCategory extends X_GL_Category
.append("]");
return msgreturn.toString();
}
@Override
public MGLCategory markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MGLCategory

View File

@ -359,7 +359,7 @@ public class MGoal extends X_PA_Goal
public MMeasure getMeasure()
{
if (getPA_Measure_ID() != 0)
return MMeasure.get(getCtx(), getPA_Measure_ID());
return MMeasure.get(getPA_Measure_ID());
return null;
} // getMeasure
@ -372,7 +372,7 @@ public class MGoal extends X_PA_Goal
public boolean updateGoal(boolean force)
{
if (log.isLoggable(Level.CONFIG)) log.config("Force=" + force);
MMeasure measure = MMeasure.get(getCtx(), getPA_Measure_ID());
MMeasure measure = MMeasure.get(getPA_Measure_ID());
boolean isUpdateByInterfal = false;
if (getDateLastRun() != null){
@ -385,7 +385,7 @@ public class MGoal extends X_PA_Goal
|| getDateLastRun() == null
|| isUpdateByInterfal)
{
measure.set_TrxName(get_TrxName());
measure = new MMeasure(Env.getCtx(), measure, get_TrxName());
if (measure.updateGoals()) // saves
{
load(get_ID(), get_TrxName());
@ -464,7 +464,7 @@ public class MGoal extends X_PA_Goal
*/
public MColorSchema getColorSchema()
{
return MColorSchema.get(getCtx(), getPA_ColorSchema_ID());
return MColorSchema.getCopy(getCtx(), getPA_ColorSchema_ID(), get_TrxName());
}
/**

View File

@ -19,41 +19,70 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Request Group Model
* @author Jorg Janke
* @version $Id: MGroup.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
*/
public class MGroup extends X_R_Group
public class MGroup extends X_R_Group implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 3218102715154328611L;
private static final long serialVersionUID = 9013217403211341916L;
/**
* Get MGroup from Cache
* @param ctx context
* Get MGroup from Cache (immutable)
* @param R_Group_ID id
* @return MGroup
* @return MGroup
*/
public static MGroup get (int R_Group_ID)
{
return get(Env.getCtx(), R_Group_ID);
}
/**
* Get MGroup from Cache (immutable)
* @param ctx context
* @param R_Group_ID id
* @return Immutable instance of MGroup
*/
public static MGroup get (Properties ctx, int R_Group_ID)
{
Integer key = Integer.valueOf(R_Group_ID);
MGroup retValue = (MGroup) s_cache.get (key);
MGroup retValue = s_cache.get (ctx, key, e -> new MGroup(ctx, e));
if (retValue != null)
return retValue;
retValue = new MGroup (ctx, R_Group_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MGroup (ctx, R_Group_ID, (String)null);
if (retValue.get_ID () == R_Group_ID)
{
s_cache.put (key, retValue, e -> new MGroup(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MGroup from cache
* @param ctx
* @param R_Group_ID
* @param trxName
* @return MGroup
*/
public static MGroup getCopy(Properties ctx, int R_Group_ID, String trxName)
{
MGroup grp = get(ctx, R_Group_ID);
if (grp != null)
grp = new MGroup(ctx, grp, trxName);
return grp;
}
/** Cache */
private static CCache<Integer,MGroup> s_cache = new CCache<Integer,MGroup>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MGroup> s_cache = new ImmutableIntPOCache<Integer,MGroup>(Table_Name, 20);
/**************************************************************************
@ -78,4 +107,44 @@ public class MGroup extends X_R_Group
super (ctx, rs, trxName);
} // MGroup
/**
*
* @param copy
*/
public MGroup(MGroup copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MGroup(Properties ctx, MGroup copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MGroup(Properties ctx, MGroup copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
public MGroup markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MGroup

View File

@ -19,7 +19,9 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Reporting Hierarchy Model
@ -27,34 +29,47 @@ import org.compiere.util.CCache;
* @author Jorg Janke
* @version $Id: MHierarchy.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
*/
public class MHierarchy extends X_PA_Hierarchy
public class MHierarchy extends X_PA_Hierarchy implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 3278979908976853690L;
private static final long serialVersionUID = 7862096742442159952L;
/**
* Get MHierarchy from Cache
* @param ctx context
* Get MHierarchy from Cache (immutable)
* @param PA_Hierarchy_ID id
* @return MHierarchy
*/
public static MHierarchy get (int PA_Hierarchy_ID)
{
return get(Env.getCtx(), PA_Hierarchy_ID);
}
/**
* Get MHierarchy (Immutable) from Cache
* @param ctx context
* @param PA_Hierarchy_ID id
* @return MHierarchy
*/
public static MHierarchy get (Properties ctx, int PA_Hierarchy_ID)
{
Integer key = Integer.valueOf(PA_Hierarchy_ID);
MHierarchy retValue = (MHierarchy)s_cache.get (key);
MHierarchy retValue = (MHierarchy)s_cache.get (ctx, key, e -> new MHierarchy(ctx, e));
if (retValue != null)
return retValue;
retValue = new MHierarchy (ctx, PA_Hierarchy_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MHierarchy (ctx, PA_Hierarchy_ID, (String)null);
if (retValue.get_ID () == PA_Hierarchy_ID)
{
s_cache.put (key, retValue, e -> new MHierarchy(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer, MHierarchy> s_cache
= new CCache<Integer, MHierarchy> (Table_Name, 20);
private static ImmutableIntPOCache<Integer, MHierarchy> s_cache
= new ImmutableIntPOCache<Integer, MHierarchy> (Table_Name, 20);
/**
* Default Constructor
@ -78,6 +93,37 @@ public class MHierarchy extends X_PA_Hierarchy
super (ctx, rs, trxName);
} // MHierarchy
/**
*
* @param copy
*/
public MHierarchy(MHierarchy copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MHierarchy(Properties ctx, MHierarchy copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MHierarchy(Properties ctx, MHierarchy copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get AD_Tree_ID based on tree type
* @param TreeType Tree Type
@ -106,4 +152,13 @@ public class MHierarchy extends X_PA_Hierarchy
return 0;
} // getAD_Tree_ID
@Override
public MHierarchy markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MHierarchy

View File

@ -33,8 +33,9 @@ import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.adempiere.base.Core;
import org.compiere.util.CCache;
import org.compiere.util.Ini;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Image Model
@ -43,17 +44,27 @@ import org.compiere.util.Ini;
* @author Jorg Janke
* @version $Id: MImage.java,v 1.5 2006/07/30 00:51:02 jjanke Exp $
*/
public class MImage extends X_AD_Image
public class MImage extends X_AD_Image implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -7361463683427300715L;
private static final long serialVersionUID = 1850627989276185947L;
private MStorageProvider provider;
/**
* Get MImage from Cache
* Get MImage from Cache (immutable)
* @param AD_Image_ID id
* @return MImage
*/
public static MImage get (int AD_Image_ID)
{
return get(Env.getCtx(), AD_Image_ID);
}
/**
* Get MImage (Immutable) from Cache
* @param ctx context
* @param AD_Image_ID id
* @return MImage
@ -64,17 +75,36 @@ public class MImage extends X_AD_Image
return new MImage (ctx, AD_Image_ID, null);
//
Integer key = Integer.valueOf(AD_Image_ID);
MImage retValue = (MImage) s_cache.get (key);
MImage retValue = s_cache.get (ctx, key, e -> new MImage(ctx, e));
if (retValue != null)
return retValue;
retValue = new MImage (ctx, AD_Image_ID, null);
if (retValue.get_ID () != 0 && Ini.isClient())
s_cache.put (key, retValue);
return retValue;
retValue = new MImage (ctx, AD_Image_ID, (String)null);
if (retValue.get_ID () == AD_Image_ID)
{
s_cache.put (key, retValue, e -> new MImage(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MImage from cache
* @param ctx context
* @param AD_Image_ID
* @param trxName transaction name
* @return MImage
*/
public static MImage getCopy(Properties ctx, int AD_Image_ID, String trxName)
{
MImage img = get(AD_Image_ID);
if (img != null && img.getAD_Image_ID() > 0)
img = new MImage(ctx, img, trxName);
return img;
}
/** Cache */
private static CCache<Integer,MImage> s_cache = new CCache<Integer,MImage>(Table_Name, 20, 10);
private static ImmutableIntPOCache<Integer,MImage> s_cache = new ImmutableIntPOCache<Integer,MImage>(Table_Name, 20, 10);
/**
* Constructor
@ -102,6 +132,36 @@ public class MImage extends X_AD_Image
initImageStoreDetails(ctx, trxName);
} // MImage
/**
*
* @param copy
*/
public MImage(MImage copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MImage(Properties ctx, MImage copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MImage(Properties ctx, MImage copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/** The Image */
private Image m_image = null;
@ -375,4 +435,14 @@ public class MImage extends X_AD_Image
if (prov != null && prov.isPendingFlush())
prov.flush(this, provider);
}
@Override
public MImage markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MImage

View File

@ -32,19 +32,20 @@ import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Import Template Model
*
* @author Carlos Ruiz - GlobalQSS
*/
public class MImportTemplate extends X_AD_ImportTemplate
public class MImportTemplate extends X_AD_ImportTemplate implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -1207697938690504067L;
private static final long serialVersionUID = -4681075469110529774L;
/** Logger */
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger(MImportTemplate.class);
@ -71,6 +72,37 @@ public class MImportTemplate extends X_AD_ImportTemplate
super(ctx, rs, trxName);
} // MImportTemplate
/**
*
* @param copy
*/
public MImportTemplate(MImportTemplate copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MImportTemplate(Properties ctx, MImportTemplate copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MImportTemplate(Properties ctx, MImportTemplate copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
protected boolean beforeSave(boolean newRecord) {
// Validate character set vs supported
@ -112,6 +144,8 @@ public class MImportTemplate extends X_AD_ImportTemplate
.setParameters(Env.getAD_Client_ID(Env.getCtx()), tabid, roleid, roleid)
.setOrderBy("Name")
.list();
if (retValue.size() > 0)
retValue.stream().forEach(e -> e.markImmutable());
s_cacheRoleTab.put(key, retValue);
return retValue;
}
@ -202,4 +236,13 @@ public class MImportTemplate extends X_AD_ImportTemplate
return is;
}
@Override
public MImportTemplate markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MImportTemplate

View File

@ -363,7 +363,7 @@ public class MInOutLine extends X_M_InOutLine
public MProduct getProduct()
{
if (m_product == null && getM_Product_ID() != 0)
m_product = MProduct.get (getCtx(), getM_Product_ID());
m_product = MProduct.getCopy(getCtx(), getM_Product_ID(), get_TrxName());
return m_product;
} // getProduct

View File

@ -224,9 +224,6 @@ public class MInfoColumn extends X_AD_InfoColumn implements IInfoColumn
@Override
public I_AD_Val_Rule getAD_Val_Rule() throws RuntimeException {
if (get_TrxName() != null)
return new MValRule(getCtx(), getAD_Val_Rule_ID(), get_TrxName());
else
return MValRule.get(getCtx(), getAD_Val_Rule_ID());
return MValRule.getCopy(getCtx(), getAD_Val_Rule_ID(), get_TrxName());
}
} // MInfoColumn

View File

@ -23,9 +23,11 @@ import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Interest Area.
@ -35,14 +37,13 @@ import org.compiere.util.DB;
*
* @author Jorg Janke
* @version $Id: MInterestArea.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
*/
public class MInterestArea extends X_R_InterestArea
*/
public class MInterestArea extends X_R_InterestArea implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -6910076559329764930L;
private static final long serialVersionUID = -8171678779149295978L;
/**
* Get all active interest areas
@ -80,28 +81,40 @@ public class MInterestArea extends X_R_InterestArea
return retValue;
} // getAll
/**
* Get MInterestArea from Cache (immutable)
* @param R_InterestArea_ID id
* @return MInterestArea
*/
public static MInterestArea get (int R_InterestArea_ID)
{
return get(Env.getCtx(), R_InterestArea_ID);
}
/**
* Get MInterestArea from Cache
* @param ctx context
* Get MInterestArea from Cache (immutable)
* @param ctx context
* @param R_InterestArea_ID id
* @return MInterestArea
*/
public static MInterestArea get (Properties ctx, int R_InterestArea_ID)
{
Integer key = Integer.valueOf(R_InterestArea_ID);
MInterestArea retValue = (MInterestArea) s_cache.get (key);
MInterestArea retValue = s_cache.get (ctx, key, e -> new MInterestArea(ctx, e));
if (retValue != null)
return retValue;
retValue = new MInterestArea (ctx, R_InterestArea_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MInterestArea (Env.getCtx(), R_InterestArea_ID, (String)null);
if (retValue.get_ID () == R_InterestArea_ID)
{
s_cache.put (key, retValue, e -> new MInterestArea(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer,MInterestArea> s_cache =
new CCache<Integer,MInterestArea>(Table_Name, 5);
private static ImmutableIntPOCache<Integer,MInterestArea> s_cache =
new ImmutableIntPOCache<Integer,MInterestArea>(Table_Name, 5);
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MInterestArea.class);
@ -134,7 +147,40 @@ public class MInterestArea extends X_R_InterestArea
super(ctx, rs, trxName);
} // MInterestArea
/**
*
* @param copy
*/
public MInterestArea(MInterestArea copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MInterestArea(Properties ctx, MInterestArea copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MInterestArea(Properties ctx, MInterestArea copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_AD_User_ID = copy.m_AD_User_ID;
this.m_ci = copy.m_ci != null ? new MContactInterest(ctx, copy.m_ci, trxName) : null;
}
/**
* Get Value
* @return value
@ -228,4 +274,13 @@ public class MInterestArea extends X_R_InterestArea
return m_ci.isSubscribed();
} // isSubscribed
@Override
public MInterestArea markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MInterestArea

View File

@ -20,6 +20,7 @@ import java.io.File;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -28,7 +29,6 @@ import org.adempiere.exceptions.NegativeInventoryDisallowedException;
import org.adempiere.exceptions.PeriodClosedException;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -54,32 +54,36 @@ public class MInventory extends X_M_Inventory implements DocAction
/**
*
*/
private static final long serialVersionUID = 4395759120481570701L;
private static final long serialVersionUID = 3877357565525655884L;
/** Reversal Indicator */
public static String REVERSE_INDICATOR = "^";
/**
* Get Inventory from Cache
* Get Inventory
* @param M_Inventory_ID id
* @return MInventory
*/
public static MInventory get (int M_Inventory_ID)
{
return get(Env.getCtx(), M_Inventory_ID);
}
/**
* Get Inventory
* @param ctx context
* @param M_Inventory_ID id
* @return MInventory
*/
public static MInventory get (Properties ctx, int M_Inventory_ID)
{
Integer key = Integer.valueOf(M_Inventory_ID);
MInventory retValue = (MInventory) s_cache.get (key);
if (retValue != null)
return retValue;
retValue = new MInventory (ctx, M_Inventory_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
MInventory inventory = new MInventory(ctx, M_Inventory_ID, (String)null);
if (inventory.get_ID() == M_Inventory_ID)
return inventory;
else
return null;
} // get
/** Cache */
protected static CCache<Integer,MInventory> s_cache = new CCache<Integer,MInventory>(Table_Name, 5, 5);
/**
* Standard Constructor
* @param ctx context
@ -136,7 +140,38 @@ public class MInventory extends X_M_Inventory implements DocAction
setM_Warehouse_ID(wh.getM_Warehouse_ID());
}
/**
*
* @param copy
*/
public MInventory(MInventory copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MInventory(Properties ctx, MInventory copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MInventory(Properties ctx, MInventory copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_lines = copy.m_lines != null ? Arrays.stream(copy.m_lines).map(e -> {var v = new MInventoryLine(ctx, e, trxName); v.setParent(this); return v;}).toArray(MInventoryLine[]::new) : null;
}
/** Lines */
protected MInventoryLine[] m_lines = null;
@ -205,7 +240,7 @@ public class MInventory extends X_M_Inventory implements DocAction
*/
public String getDocumentInfo()
{
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
MDocType dt = MDocType.get(getC_DocType_ID());
StringBuilder msgreturn = new StringBuilder().append(dt.getNameTrl()).append(" ").append(getDocumentNo());
return msgreturn.toString();
} // getDocumentInfo
@ -353,7 +388,7 @@ public class MInventory extends X_M_Inventory implements DocAction
if (product != null && product.isASIMandatory(line.isSOTrx()))
{
if (product.getAttributeSet() != null && !product.getAttributeSet().excludeTableEntry(MInventoryLine.Table_ID, line.isSOTrx())) {
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
MDocType dt = MDocType.get(getC_DocType_ID());
String docSubTypeInv = dt.getDocSubTypeInv();
BigDecimal qtyDiff = line.getQtyInternalUse();
if (MDocType.DOCSUBTYPEINV_PhysicalInventory.equals(docSubTypeInv))
@ -417,7 +452,7 @@ public class MInventory extends X_M_Inventory implements DocAction
*/
public String completeIt()
{
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
MDocType dt = MDocType.get(getC_DocType_ID());
String docSubTypeInv = dt.getDocSubTypeInv();
if (Util.isEmpty(docSubTypeInv)) {
m_processMsg = "Document inventory subtype not configured, cannot complete";
@ -665,7 +700,7 @@ public class MInventory extends X_M_Inventory implements DocAction
* Set the definite document number after completed
*/
protected void setDefiniteDocumentNo() {
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
MDocType dt = MDocType.get(getC_DocType_ID());
if (dt.isOverwriteDateOnComplete()) {
setMovementDate(TimeUtil.getDay(0));
MPeriod.testPeriodOpen(getCtx(), getMovementDate(), MDocType.DOCBASETYPE_MaterialPhysicalInventory, getAD_Org_ID());
@ -958,7 +993,7 @@ public class MInventory extends X_M_Inventory implements DocAction
reversalDate = new Timestamp(System.currentTimeMillis());
}
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
MDocType dt = MDocType.get(getC_DocType_ID());
MPeriod.testPeriodOpen(getCtx(), reversalDate, dt.getDocBaseType(), getAD_Org_ID());
// Deep Copy
@ -1151,5 +1186,5 @@ public class MInventory extends X_M_Inventory implements DocAction
|| DOCSTATUS_Closed.equals(ds)
|| DOCSTATUS_Reversed.equals(ds);
} // isComplete
} // MInventory

View File

@ -36,12 +36,12 @@ import org.compiere.util.Msg;
* <li>BF [ 1817757 ] Error on saving MInventoryLine in a custom environment
* <li>BF [ 1722982 ] Error with inventory when you enter count qty in negative
*/
public class MInventoryLine extends X_M_InventoryLine
public class MInventoryLine extends X_M_InventoryLine
{
/**
*
*/
private static final long serialVersionUID = 7083622834698840042L;
private static final long serialVersionUID = 3973418005721380194L;
/**
* Get Inventory Line with parameters
@ -137,6 +137,39 @@ public class MInventoryLine extends X_M_InventoryLine
this(inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, QtyBook, QtyCount, null);
}
/**
*
* @param copy
*/
public MInventoryLine(MInventoryLine copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MInventoryLine(Properties ctx, MInventoryLine copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MInventoryLine(Properties ctx, MInventoryLine copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_parent = null;
this.m_product = copy.m_product != null ? new MProduct(ctx, copy.m_product, trxName) : null;
}
/** Manually created */
//protected boolean m_isManualEntry = true;
/** Parent */
@ -156,7 +189,9 @@ public class MInventoryLine extends X_M_InventoryLine
if (m_product != null && m_product.getM_Product_ID() != M_Product_ID)
m_product = null; // reset
if (m_product == null)
m_product = MProduct.get(getCtx(), M_Product_ID);
{
m_product = MProduct.getCopy(getCtx(), M_Product_ID, get_TrxName());
}
return m_product;
} // getProduct
@ -461,4 +496,5 @@ public class MInventoryLine extends X_M_InventoryLine
public boolean isSOTrx() {
return getMovementQty().signum() < 0;
}
} // MInventoryLine

View File

@ -24,6 +24,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;
@ -41,7 +42,6 @@ import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ServerProcessCtl;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -69,7 +69,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
/**
*
*/
private static final long serialVersionUID = 5581441980246794522L;
private static final long serialVersionUID = -261338363319970683L;
/**
* Get Payments Of BPartner
@ -163,7 +163,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
if (counter)
{
to.setRef_Invoice_ID(from.getC_Invoice_ID());
MOrg org = MOrg.get(from.getCtx(), from.getAD_Org_ID());
MOrg org = MOrg.get(from.getAD_Org_ID());
int counterC_BPartner_ID = org.getLinkedC_BPartner_ID(trxName);
if (counterC_BPartner_ID == 0)
return null;
@ -239,29 +239,31 @@ public class MInvoice extends X_C_Invoice implements DocAction
return sb.toString();
} // getPDFFileName
/**
* Get MInvoice from Cache
* @param ctx context
* Get MInvoice from db
* @param C_Invoice_ID id
* @return MInvoice
*/
public static MInvoice get (int C_Invoice_ID)
{
return get(Env.getCtx(), C_Invoice_ID);
}
/**
* Get MInvoice from db
* @param C_Invoice_ID id
* @return MInvoice
*/
public static MInvoice get (Properties ctx, int C_Invoice_ID)
{
Integer key = Integer.valueOf(C_Invoice_ID);
MInvoice retValue = (MInvoice) s_cache.get (key);
if (retValue != null)
MInvoice retValue = new MInvoice(ctx, C_Invoice_ID, (String)null);
if (retValue.get_ID () == C_Invoice_ID)
{
return retValue;
retValue = new MInvoice (ctx, C_Invoice_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer,MInvoice> s_cache = new CCache<Integer,MInvoice>(Table_Name, 20, 2); // 2 minutes
/**************************************************************************
* Invoice Constructor
* @param ctx context
@ -327,7 +329,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
//
if (C_DocTypeTarget_ID <= 0)
{
MDocType odt = MDocType.get(order.getCtx(), order.getC_DocType_ID());
MDocType odt = MDocType.get(order.getC_DocType_ID());
if (odt != null)
{
C_DocTypeTarget_ID = odt.getC_DocTypeInvoice_ID();
@ -410,6 +412,40 @@ public class MInvoice extends X_C_Invoice implements DocAction
setAD_User_ID(line.getAD_User_ID());
} // MInvoice
/**
*
* @param copy
*/
public MInvoice(MInvoice copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MInvoice(Properties ctx, MInvoice copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MInvoice(Properties ctx, MInvoice copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_openAmt = copy.m_openAmt;
this.m_lines = copy.m_lines != null ? Arrays.stream(copy.m_lines).map(e -> {var v = new MInvoiceLine(ctx, e, trxName); v.m_parent=this; return v;}).toArray(MInvoiceLine[]::new) : null;
this.m_taxes = copy.m_taxes != null ? Arrays.stream(copy.m_taxes).map(e -> {return new MInvoiceTax(ctx, e, trxName);}).toArray(MInvoiceTax[]::new) : null;
}
/** Open Amount */
private BigDecimal m_openAmt = null;
@ -559,7 +595,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
setPaymentRule(order.getPaymentRule());
setC_PaymentTerm_ID(order.getC_PaymentTerm_ID());
//
MDocType dt = MDocType.get(getCtx(), order.getC_DocType_ID());
MDocType dt = MDocType.get(order.getC_DocType_ID());
if (dt.getC_DocTypeInvoice_ID() != 0)
setC_DocTypeTarget_ID(dt.getC_DocTypeInvoice_ID());
// Overwrite Invoice BPartner
@ -577,7 +613,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
MRMA rma = new MRMA(getCtx(), ship.getM_RMA_ID(), get_TrxName());
// Retrieves the invoice DocType
MDocType dt = MDocType.get(getCtx(), rma.getC_DocType_ID());
MDocType dt = MDocType.get(rma.getC_DocType_ID());
if (dt.getC_DocTypeInvoice_ID() != 0)
{
setC_DocTypeTarget_ID(dt.getC_DocTypeInvoice_ID());
@ -682,7 +718,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
List<MInvoiceLine> list = new Query(getCtx(), I_C_InvoiceLine.Table_Name, whereClauseFinal, get_TrxName())
.setParameters(getC_Invoice_ID())
.setOrderBy("Line, C_InvoiceLine_ID")
.list();
.list();
return list.toArray(new MInvoiceLine[list.size()]);
} // getLines
@ -694,7 +730,9 @@ public class MInvoice extends X_C_Invoice implements DocAction
public MInvoiceLine[] getLines (boolean requery)
{
if (m_lines == null || m_lines.length == 0 || requery)
{
m_lines = getLines(null);
}
set_TrxName(m_lines, get_TrxName());
return m_lines;
} // getLines
@ -873,8 +911,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
*/
public boolean isCreditMemo()
{
MDocType dt = MDocType.get(getCtx(),
getC_DocType_ID()==0 ? getC_DocTypeTarget_ID() : getC_DocType_ID());
MDocType dt = MDocType.get(getC_DocType_ID()==0 ? getC_DocTypeTarget_ID() : getC_DocType_ID());
return MDocType.DOCBASETYPE_APCreditMemo.equals(dt.getDocBaseType())
|| MDocType.DOCBASETYPE_ARCreditMemo.equals(dt.getDocBaseType());
} // isCreditMemo
@ -2236,7 +2273,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
private void setDefiniteDocumentNo() {
if (isReversal() && ! MSysConfig.getBooleanValue(MSysConfig.Invoice_ReverseUseNewNumber, true, getAD_Client_ID())) // IDEMPIERE-1771
return;
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
MDocType dt = MDocType.get(getC_DocType_ID());
if (dt.isOverwriteDateOnComplete()) {
setDateInvoiced(TimeUtil.getDay(0));
if (getDateAcct().before(getDateInvoiced())) {
@ -2262,7 +2299,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
return null;
// Org Must be linked to BPartner
MOrg org = MOrg.get(getCtx(), getAD_Org_ID());
MOrg org = MOrg.get(getAD_Org_ID());
int counterC_BPartner_ID = org.getLinkedC_BPartner_ID(get_TrxName());
if (counterC_BPartner_ID == 0)
return null;

View File

@ -162,6 +162,49 @@ public class MInvoiceLine extends X_C_InvoiceLine
super(ctx, rs, trxName);
} // MInvoiceLine
/**
*
* @param copy
*/
public MInvoiceLine(MInvoiceLine copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MInvoiceLine(Properties ctx, MInvoiceLine copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MInvoiceLine(Properties ctx, MInvoiceLine copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_tax = copy.m_tax != null ? new MTax(ctx, copy.m_tax, trxName) : null;
this.m_M_PriceList_ID = copy.m_M_PriceList_ID;
this.m_DateInvoiced = copy.m_DateInvoiced;
this.m_C_BPartner_ID = copy.m_C_BPartner_ID;
this.m_C_BPartner_Location_ID = copy.m_C_BPartner_Location_ID;
this.m_IsSOTrx = copy.m_IsSOTrx;
this.m_product = copy.m_product != null ? new MProduct(ctx, copy.m_product, trxName) : null;
this.m_charge = copy.m_charge != null ? new MCharge(ctx, copy.m_charge, trxName) : null;
this.m_name = copy.m_name;
this.m_precision = copy.m_precision;
this.m_parent = null;
this.m_priceSet = copy.m_priceSet;
}
protected int m_M_PriceList_ID = 0;
protected Timestamp m_DateInvoiced = null;
protected int m_C_BPartner_ID = 0;
@ -489,17 +532,17 @@ public class MInvoiceLine extends X_C_InvoiceLine
public MCharge getCharge()
{
if (m_charge == null && getC_Charge_ID() != 0)
m_charge = MCharge.get (getCtx(), getC_Charge_ID());
m_charge = MCharge.getCopy(getCtx(), getC_Charge_ID(), get_TrxName());
return m_charge;
}
/**
* Get Tax
* Get Tax (immutable)
* @return tax
*/
protected MTax getTax()
{
if (m_tax == null)
m_tax = MTax.get(getCtx(), getC_Tax_ID());
m_tax = MTax.get(getCtx(), getC_Tax_ID());
return m_tax;
} // getTax
@ -605,7 +648,7 @@ public class MInvoiceLine extends X_C_InvoiceLine
public MProduct getProduct()
{
if (m_product == null && getM_Product_ID() != 0)
m_product = MProduct.get (getCtx(), getM_Product_ID());
m_product = MProduct.getCopy(getCtx(), getM_Product_ID(), get_TrxName());
return m_product;
} // getProduct

View File

@ -23,8 +23,10 @@ import java.util.Calendar;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Invoice Schedule Model
@ -32,17 +34,37 @@ import org.compiere.util.TimeUtil;
* @author Jorg Janke
* @version $Id: MInvoiceSchedule.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
*/
public class MInvoiceSchedule extends X_C_InvoiceSchedule
public class MInvoiceSchedule extends X_C_InvoiceSchedule implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -1750020695983938895L;
private static final long serialVersionUID = -2480759794244343907L;
/**
* Get MInvoiceSchedule from Cache
* @param ctx context
* Get MInvoiceSchedule (Immutable) from Cache
* @param C_InvoiceSchedule_ID id
* @param trxName transaction
* @return MInvoiceSchedule
*/
public static MInvoiceSchedule get (int C_InvoiceSchedule_ID, String trxName)
{
return get(Env.getCtx(), C_InvoiceSchedule_ID, trxName);
}
/**
* Get MInvoiceSchedule (Immutable) from Cache
* @param C_InvoiceSchedule_ID id
* @return MInvoiceSchedule
*/
public static MInvoiceSchedule get (int C_InvoiceSchedule_ID)
{
return get(C_InvoiceSchedule_ID, (String)null);
}
/**
* Get MInvoiceSchedule (Immutable) from Cache
* @param ctx context
* @param C_InvoiceSchedule_ID id
* @param trxName transaction
* @return MInvoiceSchedule
@ -50,17 +72,20 @@ public class MInvoiceSchedule extends X_C_InvoiceSchedule
public static MInvoiceSchedule get (Properties ctx, int C_InvoiceSchedule_ID, String trxName)
{
Integer key = Integer.valueOf(C_InvoiceSchedule_ID);
MInvoiceSchedule retValue = (MInvoiceSchedule) s_cache.get (key);
MInvoiceSchedule retValue = (MInvoiceSchedule) s_cache.get (ctx, key, e -> new MInvoiceSchedule(ctx, e));
if (retValue != null)
return retValue;
retValue = new MInvoiceSchedule (ctx, C_InvoiceSchedule_ID, trxName);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MInvoiceSchedule (Env.getCtx(), C_InvoiceSchedule_ID, trxName);
if (retValue.get_ID () == C_InvoiceSchedule_ID)
{
s_cache.put (key, retValue, e -> new MInvoiceSchedule(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer,MInvoiceSchedule> s_cache = new CCache<Integer,MInvoiceSchedule>(Table_Name, 5);
private static ImmutableIntPOCache<Integer,MInvoiceSchedule> s_cache = new ImmutableIntPOCache<Integer,MInvoiceSchedule>(Table_Name, 5);
/**************************************************************************
@ -85,6 +110,37 @@ public class MInvoiceSchedule extends X_C_InvoiceSchedule
super(ctx, rs, trxName);
} // MInvoiceSchedule
/**
*
* @param copy
*/
public MInvoiceSchedule(MInvoiceSchedule copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MInvoiceSchedule(Properties ctx, MInvoiceSchedule copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MInvoiceSchedule(Properties ctx, MInvoiceSchedule copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Can I send Invoice
* @param xDate date
@ -219,5 +275,14 @@ public class MInvoiceSchedule extends X_C_InvoiceSchedule
// if (INVOICEWEEKDAY_Thursday.equals(day))
return Calendar.THURSDAY;
} // getCalendarDay
@Override
public MInvoiceSchedule markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MInvoiceSchedule

View File

@ -136,6 +136,39 @@ public class MInvoiceTax extends X_C_InvoiceTax
super(ctx, rs, trxName);
} // MInvoiceTax
/**
*
* @param copy
*/
public MInvoiceTax(MInvoiceTax copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MInvoiceTax(Properties ctx, MInvoiceTax copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MInvoiceTax(Properties ctx, MInvoiceTax copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_precision = copy.m_precision;
this.m_tax = copy.m_tax != null ? new MTax(ctx, copy.m_tax, trxName) : null;
}
/** Tax */
private MTax m_tax = null;
/** Cached Precision */
@ -163,7 +196,7 @@ public class MInvoiceTax extends X_C_InvoiceTax
} // setPrecision
/**
* Get Tax
* Get Tax (immutable)
* @return tax
*/
protected MTax getTax()
@ -257,5 +290,4 @@ public class MInvoiceTax extends X_C_InvoiceTax
.append ("]");
return sb.toString ();
} // toString
} // MInvoiceTax

View File

@ -23,13 +23,14 @@ import java.util.Comparator;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Trx;
import org.compiere.util.Util;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Location (Address)
@ -45,12 +46,13 @@ import org.compiere.util.Util;
* <li>BF [ 3002736 ] MLocation.get cache all MLocations
* https://sourceforge.net/tracker/?func=detail&aid=3002736&group_id=176962&atid=879332
*/
public class MLocation extends X_C_Location implements Comparator<Object>
public class MLocation extends X_C_Location implements Comparator<Object>, ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -4100591609253985073L;
private static final long serialVersionUID = -3421958100626539835L;
// http://jira.idempiere.com/browse/IDEMPIERE-147
public static String LOCATION_MAPS_URL_PREFIX = MSysConfig.getValue(MSysConfig.LOCATION_MAPS_URL_PREFIX);
public static String LOCATION_MAPS_ROUTE_PREFIX = MSysConfig.getValue(MSysConfig.LOCATION_MAPS_ROUTE_PREFIX);
@ -59,7 +61,28 @@ public class MLocation extends X_C_Location implements Comparator<Object>
/**
* Get Location from Cache
* @param ctx context
* @param C_Location_ID id
* @param trxName transaction
* @return MLocation
*/
public static MLocation get (int C_Location_ID, String trxName)
{
return get(Env.getCtx(), C_Location_ID, trxName);
}
/**
* Get Location from Cache (immutable)
* @param C_Location_ID id
* @return MLocation
*/
public static MLocation get (int C_Location_ID)
{
return get(C_Location_ID, (String)null);
}
/**
* Get Location from Cache (immutable)
* @param ctx context
* @param C_Location_ID id
* @param trxName transaction
* @return MLocation
@ -68,24 +91,36 @@ public class MLocation extends X_C_Location implements Comparator<Object>
{
// New
if (C_Location_ID == 0)
return new MLocation(ctx, C_Location_ID, trxName);
return new MLocation(Env.getCtx(), C_Location_ID, trxName);
//
Integer key = Integer.valueOf(C_Location_ID);
MLocation retValue = null;
if (trxName == null)
retValue = (MLocation) s_cache.get (key);
MLocation retValue = s_cache.get (ctx, key, e -> new MLocation(ctx, e));
if (retValue != null)
return retValue;
retValue = new MLocation (ctx, C_Location_ID, trxName);
if (retValue.get_ID () != 0) // found
if (retValue.get_ID () == C_Location_ID) // found
{
if (trxName == null)
s_cache.put (key, retValue);
s_cache.put (key, retValue, e -> new MLocation(Env.getCtx(), e));
return retValue;
}
return null; // not found
} // get
/**
* Get updateable copy of MLocation from cache
* @param ctx context
* @param C_Location_ID
* @param trxName
* @return MLocation
*/
public static MLocation getCopy(Properties ctx, int C_Location_ID, String trxName)
{
MLocation loc = get(C_Location_ID, trxName);
if (loc != null && loc.getC_Location_ID() > 0)
loc = new MLocation(ctx, loc, trxName);
return loc;
}
/**
* Load Location with ID if Business Partner Location
* @param ctx context
@ -126,7 +161,7 @@ public class MLocation extends X_C_Location implements Comparator<Object>
} // getBPLocation
/** Cache */
private static CCache<Integer,MLocation> s_cache = new CCache<Integer,MLocation>(Table_Name, 100, 30);
private static ImmutableIntPOCache<Integer,MLocation> s_cache = new ImmutableIntPOCache<Integer,MLocation>(Table_Name, 100, 30);
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger(MLocation.class);
@ -142,9 +177,9 @@ public class MLocation extends X_C_Location implements Comparator<Object>
super (ctx, C_Location_ID, trxName);
if (C_Location_ID == 0)
{
MCountry defaultCountry = MCountry.getDefault(getCtx());
MCountry defaultCountry = MCountry.getDefault();
setCountry(defaultCountry);
MRegion defaultRegion = MRegion.getDefault(getCtx());
MRegion defaultRegion = MRegion.getDefault();
if (defaultRegion != null
&& defaultRegion.getC_Country_ID() == defaultCountry.getC_Country_ID())
setRegion(defaultRegion);
@ -190,6 +225,39 @@ public class MLocation extends X_C_Location implements Comparator<Object>
super(ctx, rs, trxName);
} // MLocation
/**
*
* @param copy
*/
public MLocation(MLocation copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MLocation(Properties ctx, MLocation copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MLocation(Properties ctx, MLocation copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_c = copy.m_c != null ? new MCountry(ctx, copy.m_c, trxName) : null;
this.m_r = copy.m_r != null ? new MRegion(ctx, copy.m_r, trxName) : null;
}
private MCountry m_c = null;
private MRegion m_r = null;
@ -202,7 +270,7 @@ public class MLocation extends X_C_Location implements Comparator<Object>
if (country != null)
m_c = country;
else
m_c = MCountry.getDefault(getCtx());
m_c = MCountry.getDefault();
super.setC_Country_ID (m_c.getC_Country_ID());
} // setCountry
@ -214,11 +282,11 @@ public class MLocation extends X_C_Location implements Comparator<Object>
{
if (getC_Country_ID() != C_Country_ID)
setRegion(null);
setCountry (MCountry.get(getCtx(), C_Country_ID));
setCountry (MCountry.get(C_Country_ID));
} // setCountry
/**
* Get Country
* Get Country (immutable)
* @return country
*/
public MCountry getCountry()
@ -230,9 +298,9 @@ public class MLocation extends X_C_Location implements Comparator<Object>
if (m_c == null)
{
if (getC_Country_ID() != 0)
m_c = MCountry.get(getCtx(), getC_Country_ID());
m_c = MCountry.get(getC_Country_ID());
else
m_c = MCountry.getDefault(getCtx());
m_c = MCountry.getDefault();
}
return m_c;
} // getCountry
@ -254,7 +322,7 @@ public class MLocation extends X_C_Location implements Comparator<Object>
public String getCountry (boolean local)
{
if (local
&& getC_Country_ID() == MCountry.getDefault(getCtx()).getC_Country_ID())
&& getC_Country_ID() == MCountry.getDefault().getC_Country_ID())
return null;
return getCountryName();
} // getCountry
@ -266,7 +334,7 @@ public class MLocation extends X_C_Location implements Comparator<Object>
public String getCountry (boolean local, String language)
{
if (local
&& getC_Country_ID() == MCountry.getDefault(getCtx()).getC_Country_ID())
&& getC_Country_ID() == MCountry.getDefault().getC_Country_ID())
return null;
MCountry mc = getCountry();
return mc.getTrlName(language);
@ -316,7 +384,7 @@ public class MLocation extends X_C_Location implements Comparator<Object>
setRegion(null);
}
else
setRegion (MRegion.get(getCtx(), C_Region_ID));
setRegion (MRegion.get(C_Region_ID));
} // setC_Region_ID
/**
@ -330,7 +398,7 @@ public class MLocation extends X_C_Location implements Comparator<Object>
m_r = null;
//
if (m_r == null && getC_Region_ID() != 0)
m_r = MRegion.get(getCtx(), getC_Region_ID());
m_r = MRegion.get(getC_Region_ID());
return m_r;
} // getRegion
@ -438,7 +506,7 @@ public class MLocation extends X_C_Location implements Comparator<Object>
public boolean isAddressLinesReverse()
{
// Local
if (MCountry.getDefault(getCtx()) != null && getC_Country_ID() == MCountry.getDefault(getCtx()).getC_Country_ID())
if (MCountry.getDefault() != null && getC_Country_ID() == MCountry.getDefault().getC_Country_ID())
return getCountry().isAddressLinesLocalReverse();
return getCountry().isAddressLinesReverse();
} // isAddressLinesReverse
@ -464,7 +532,7 @@ public class MLocation extends X_C_Location implements Comparator<Object>
if (c == null)
return "CountryNotFound";
boolean local = MCountry.getDefault(getCtx()) != null && getC_Country_ID() == MCountry.getDefault(getCtx()).getC_Country_ID();
boolean local = MCountry.getDefault() != null && getC_Country_ID() == MCountry.getDefault().getC_Country_ID();
String inStr = local ? c.getDisplaySequenceLocal() : c.getDisplaySequence();
StringBuilder outStr = new StringBuilder();
@ -821,6 +889,15 @@ public class MLocation extends X_C_Location implements Comparator<Object>
return ok;
}
@Override
public MLocation markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
/**
* Create address transaction instance
* @param ctx

View File

@ -127,7 +127,7 @@ public final class MLocationLookup extends Lookup
*/
public MLocation getLocation (int C_Location_ID, String trxName)
{
return MLocation.get(m_ctx, C_Location_ID, trxName);
return MLocation.getCopy(m_ctx, C_Location_ID, trxName);
} // getC_Location_ID
/**

View File

@ -22,9 +22,11 @@ import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Warehouse Locator Object
@ -34,12 +36,12 @@ import org.compiere.util.DB;
* @see [ 1966333 ] New Method to get the Default Locator based in Warehouse http://sourceforge.net/tracker/index.php?func=detail&aid=1966333&group_id=176962&atid=879335
* @version $Id: MLocator.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
*/
public class MLocator extends X_M_Locator
public class MLocator extends X_M_Locator implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -4502919527066173270L;
private static final long serialVersionUID = 539879105479299988L;
/**
* Get oldest Default Locator of warehouse with locator
@ -168,30 +170,56 @@ public class MLocator extends X_M_Locator
retValue.saveEx();
}
return retValue;
} // get
} // get
/**
* Get Locator from Cache
* @param ctx context
* Get Locator from Cache (immutable)
* @param M_Locator_ID id
* @return MLocator
*/
public static MLocator get (int M_Locator_ID)
{
return get(Env.getCtx(), M_Locator_ID);
}
/**
* Get Locator from Cache (immutable)
* @param ctx context
* @param M_Locator_ID id
* @return MLocator
*/
public static MLocator get (Properties ctx, int M_Locator_ID)
{
if (s_cache == null)
s_cache = new CCache<Integer,MLocator>(Table_Name, 20);
Integer key = Integer.valueOf(M_Locator_ID);
MLocator retValue = (MLocator) s_cache.get (key);
MLocator retValue = s_cache.get (ctx, key, e -> new MLocator(ctx, e));
if (retValue != null)
return retValue;
retValue = new MLocator (ctx, M_Locator_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MLocator (ctx, M_Locator_ID, (String)null);
if (retValue.get_ID () == M_Locator_ID)
{
s_cache.put (key, retValue, e -> new MLocator(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
* Get updateable copy of MLocator from cache
* @param ctx
* @param M_Locator_ID
* @param trxName
* @return MLocator
*/
public static MLocator getCopy(Properties ctx, int M_Locator_ID, String trxName)
{
MLocator locator = get(M_Locator_ID);
if (locator != null)
locator = new MLocator(ctx, locator, trxName);
return locator;
}
/** Cache */
protected volatile static CCache<Integer,MLocator> s_cache;
private final static ImmutableIntPOCache<Integer,MLocator> s_cache = new ImmutableIntPOCache<Integer,MLocator>(Table_Name, 20);
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MLocator.class);
@ -244,6 +272,37 @@ public class MLocator extends X_M_Locator
super(ctx, rs, trxName);
} // MLocator
/**
*
* @param copy
*/
public MLocator(MLocator copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MLocator(Properties ctx, MLocator copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MLocator(Properties ctx, MLocator copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get String Representation
* @return Value
@ -358,4 +417,13 @@ public class MLocator extends X_M_Locator
*/
} // isCanStoreProduct
@Override
public MLocator markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MLocator

View File

@ -272,7 +272,7 @@ public final class MLocatorLookup extends Lookup implements Serializable
return null;
}
//
return Util.isEmpty(trxName) ? MLocator.get(m_ctx, M_Locator_ID) : new MLocator (m_ctx, M_Locator_ID, trxName);
return MLocator.getCopy(m_ctx, M_Locator_ID, trxName);
} // getMLocator
/**

View File

@ -27,41 +27,52 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Warehouse Locator Type Object
*
* @author Carlos Ruiz - Quality Systems & Solutions - globalqss
*/
public class MLocatorType extends X_M_LocatorType {
public class MLocatorType extends X_M_LocatorType implements ImmutablePOSupport {
/**
*
*/
private static final long serialVersionUID = -7567584133468332781L;
private static final long serialVersionUID = 3021833597380696668L;
/**
* Get Locator Type from Cache
* @param ctx context
* Get Locator Type from Cache (immutable)
* @param M_LocatorType_ID id
* @return MLocator
*/
public static MLocatorType get (int M_LocatorType_ID) {
return get(Env.getCtx(), M_LocatorType_ID);
}
/**
* Get Locator Type from Cache (immutable)
* @param ctx context
* @param M_LocatorType_ID id
* @return MLocator
*/
public static MLocatorType get (Properties ctx, int M_LocatorType_ID) {
if (s_cache == null)
s_cache = new CCache<Integer,MLocatorType>(Table_Name, 20);
Integer key = Integer.valueOf(M_LocatorType_ID);
MLocatorType retValue = (MLocatorType) s_cache.get (key);
MLocatorType retValue = s_cache.get (ctx, key, e -> new MLocatorType(ctx, e));
if (retValue != null)
return retValue;
retValue = new MLocatorType (ctx, M_LocatorType_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MLocatorType (ctx, M_LocatorType_ID, (String)null);
if (retValue.get_ID () == M_LocatorType_ID) {
s_cache.put (key, retValue, e -> new MLocatorType(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private volatile static CCache<Integer,MLocatorType> s_cache;
private final static ImmutableIntPOCache<Integer,MLocatorType> s_cache = new ImmutableIntPOCache<Integer,MLocatorType>(Table_Name, 20);
/** Logger */
@SuppressWarnings("unused")
@ -92,6 +103,34 @@ public class MLocatorType extends X_M_LocatorType {
super(ctx, rs, trxName);
} // MLocatorType
/**
*
* @param copy
*/
public MLocatorType(MLocatorType copy) {
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MLocatorType(Properties ctx, MLocatorType copy) {
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MLocatorType(Properties ctx, MLocatorType copy, String trxName) {
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get String Representation
* @return Name
@ -100,4 +139,13 @@ public class MLocatorType extends X_M_LocatorType {
return getName();
} // toString
@Override
public MLocatorType markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MLocatorType

View File

@ -0,0 +1,89 @@
/**********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Trek Global Corporation *
* - Heng Sin Low *
**********************************************************************/
package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.Env;
/**
* @author hengsin
*
*/
public class MLotCtlExclude extends X_M_LotCtlExclude {
/**
*
*/
private static final long serialVersionUID = -7189245472896373850L;
/**
* @param ctx
* @param M_LotCtlExclude_ID
* @param trxName
*/
public MLotCtlExclude(Properties ctx, int M_LotCtlExclude_ID, String trxName) {
super(ctx, M_LotCtlExclude_ID, trxName);
}
/**
* @param ctx
* @param rs
* @param trxName
*/
public MLotCtlExclude(Properties ctx, ResultSet rs, String trxName) {
super(ctx, rs, trxName);
}
/**
*
* @param copy
*/
public MLotCtlExclude(MLotCtlExclude copy) {
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MLotCtlExclude(Properties ctx, MLotCtlExclude copy) {
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MLotCtlExclude(Properties ctx, MLotCtlExclude copy, String trxName) {
this(ctx, 0, trxName);
copyPO(copy);
}
}

View File

@ -30,12 +30,13 @@ import javax.script.ScriptEngine;
import org.adempiere.apps.graph.GraphColumn;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.MeasureInterface;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
import org.compiere.util.Util;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
@ -50,34 +51,47 @@ import org.compiere.util.Util;
* <li>FR [ 2905227 ] Calculate Measure based on the script to PA
* <li>https://sourceforge.net/tracker/?func=detail&aid=2905227&group_id=176962&atid=879335
*/
public class MMeasure extends X_PA_Measure
public class MMeasure extends X_PA_Measure implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 6274990637485210675L;
private static final long serialVersionUID = -3584012092877837973L;
/**
* Get MMeasure from Cache
* @param ctx context
* Get MMeasure from Cache (immutable)
* @param PA_Measure_ID id
* @return MMeasure
*/
public static MMeasure get (int PA_Measure_ID)
{
return get(Env.getCtx(), PA_Measure_ID);
}
/**
* Get MMeasure from Cache (immutable)
* @param ctx context
* @param PA_Measure_ID id
* @return MMeasure
*/
public static MMeasure get (Properties ctx, int PA_Measure_ID)
{
Integer key = Integer.valueOf(PA_Measure_ID);
MMeasure retValue = (MMeasure)s_cache.get (key);
MMeasure retValue = s_cache.get (ctx, key, e -> new MMeasure(ctx, e));
if (retValue != null)
return retValue;
retValue = new MMeasure (ctx, PA_Measure_ID, null);
if (retValue.get_ID() != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MMeasure (ctx, PA_Measure_ID, (String)null);
if (retValue.get_ID() == PA_Measure_ID)
{
s_cache.put (key, retValue, e -> new MMeasure(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer, MMeasure> s_cache
= new CCache<Integer, MMeasure> (Table_Name, 10);
private static ImmutableIntPOCache<Integer, MMeasure> s_cache
= new ImmutableIntPOCache<Integer, MMeasure> (Table_Name, 10);
/**
* Standard Constructor
@ -101,12 +115,43 @@ public class MMeasure extends X_PA_Measure
super (ctx, rs, trxName);
} // MMeasure
/**
*
* @param copy
*/
public MMeasure(MMeasure copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MMeasure(Properties ctx, MMeasure copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MMeasure(Properties ctx, MMeasure copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
public ArrayList<GraphColumn> getGraphColumnList(MGoal goal)
{
ArrayList<GraphColumn> list = new ArrayList<GraphColumn>();
if (MMeasure.MEASURETYPE_Calculated.equals(getMeasureType()))
{
MMeasureCalc mc = MMeasureCalc.get(getCtx(), getPA_MeasureCalc_ID());
MMeasureCalc mc = MMeasureCalc.get(getPA_MeasureCalc_ID());
String sql = mc.getSqlBarChart(goal.getRestrictions(false),
goal.getMeasureDisplay(), goal.getDateFrom(),
MRole.getDefault()); // logged in role
@ -465,7 +510,7 @@ public class MMeasure extends X_PA_Measure
if (role == null)
role = MRole.getDefault(getCtx(), false); // could result in wrong data
//
MMeasureCalc mc = MMeasureCalc.get(getCtx(), getPA_MeasureCalc_ID());
MMeasureCalc mc = MMeasureCalc.get(getPA_MeasureCalc_ID());
if (mc == null || mc.get_ID() == 0 || mc.get_ID() != getPA_MeasureCalc_ID())
{
log.log(Level.SEVERE, "Not found PA_MeasureCalc_ID=" + getPA_MeasureCalc_ID());
@ -669,4 +714,14 @@ public class MMeasure extends X_PA_Measure
}
return true;
} // updateUserDefinedGoals
@Override
public MMeasure markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MMeasure

View File

@ -23,9 +23,10 @@ import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Performance Measure Calculation
@ -33,34 +34,47 @@ import org.compiere.util.Env;
* @author Jorg Janke
* @version $Id: MMeasureCalc.java,v 1.4 2006/09/25 00:59:41 jjanke Exp $
*/
public class MMeasureCalc extends X_PA_MeasureCalc
public class MMeasureCalc extends X_PA_MeasureCalc implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 4720674127987683534L;
private static final long serialVersionUID = 3143013490477454559L;
/**
* Get MMeasureCalc from Cache
* @param ctx context
* Get MMeasureCalc from Cache (immutable)
* @param PA_MeasureCalc_ID id
* @return MMeasureCalc
*/
public static MMeasureCalc get (int PA_MeasureCalc_ID)
{
return get(Env.getCtx(), PA_MeasureCalc_ID);
}
/**
* Get MMeasureCalc from Cache (immutable)
* @param ctx context
* @param PA_MeasureCalc_ID id
* @return MMeasureCalc
*/
public static MMeasureCalc get (Properties ctx, int PA_MeasureCalc_ID)
{
Integer key = Integer.valueOf(PA_MeasureCalc_ID);
MMeasureCalc retValue = (MMeasureCalc)s_cache.get (key);
MMeasureCalc retValue = s_cache.get (ctx, key, e -> new MMeasureCalc(ctx, e));
if (retValue != null)
return retValue;
retValue = new MMeasureCalc (ctx, PA_MeasureCalc_ID, null);
if (retValue.get_ID() != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MMeasureCalc (ctx, PA_MeasureCalc_ID, (String)null);
if (retValue.get_ID() == PA_MeasureCalc_ID)
{
s_cache.put (key, retValue, e -> new MMeasureCalc(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer, MMeasureCalc> s_cache
= new CCache<Integer, MMeasureCalc> (Table_Name, 10);
private static ImmutableIntPOCache<Integer, MMeasureCalc> s_cache
= new ImmutableIntPOCache<Integer, MMeasureCalc> (Table_Name, 10);
/**************************************************************************
* Standard Constructor
@ -84,6 +98,36 @@ public class MMeasureCalc extends X_PA_MeasureCalc
super (ctx, rs, trxName);
} // MMeasureCalc
/**
*
* @param copy
*/
public MMeasureCalc(MMeasureCalc copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MMeasureCalc(Properties ctx, MMeasureCalc copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MMeasureCalc(Properties ctx, MMeasureCalc copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
/**
* Get Sql to return single value for the Performance Indicator
@ -465,5 +509,13 @@ public class MMeasureCalc extends X_PA_MeasureCalc
return sb.toString ();
} // toString
@Override
public MMeasureCalc markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MMeasureCalc

View File

@ -21,9 +21,11 @@ import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutablePOSupport;
import org.idempiere.cache.ImmutablePOCache;
/**
* Message Model
@ -31,16 +33,26 @@ import org.compiere.util.DB;
* @author Jorg Janke
* @version $Id: MMessage.java,v 1.3 2006/07/30 00:54:54 jjanke Exp $
*/
public class MMessage extends X_AD_Message
public class MMessage extends X_AD_Message implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -7362947218094337783L;
private static final long serialVersionUID = -7983736322524189608L;
/**
* Get Message (cached)
* @param ctx context
* Get Message (cached) (immutable)
* @param Value message value
* @return message
*/
public static MMessage get (String Value)
{
return get(Env.getCtx(), Value);
}
/**
* Get Message (cached) (immutable)
* @param ctx context
* @param Value message value
* @return message
*/
@ -48,7 +60,7 @@ public class MMessage extends X_AD_Message
{
if (Value == null || Value.length() == 0)
return null;
MMessage retValue = (MMessage)s_cache.get(Value);
MMessage retValue = (MMessage)s_cache.get(ctx, Value, e -> new MMessage(ctx, e));
//
if (retValue == null)
{
@ -61,7 +73,7 @@ public class MMessage extends X_AD_Message
pstmt.setString(1, Value);
rs = pstmt.executeQuery();
if (rs.next())
retValue = new MMessage (ctx, rs, null);
retValue = new MMessage (Env.getCtx(), rs, null);
}
catch (Exception e)
{
@ -74,13 +86,20 @@ public class MMessage extends X_AD_Message
pstmt = null;
}
if (retValue != null)
s_cache.put(Value, retValue);
{
s_cache.put(Value, retValue, e -> new MMessage(Env.getCtx(), e));
}
return retValue;
}
return retValue;
else
{
return retValue;
}
} // get
/**
* Get Message (cached)
* Get Message (cached) (immutable)
* @param ctx context
* @param AD_Message_ID id
* @return message
@ -88,18 +107,28 @@ public class MMessage extends X_AD_Message
public static MMessage get (Properties ctx, int AD_Message_ID)
{
String key = String.valueOf(AD_Message_ID);
MMessage retValue = (MMessage)s_cache.get(key);
MMessage retValue = s_cache.get(ctx, key, e -> new MMessage(ctx, e));
if (retValue == null)
{
retValue = new MMessage (ctx, AD_Message_ID, null);
s_cache.put(key, retValue);
s_cache.put(key, retValue, e -> new MMessage(Env.getCtx(), e));
}
return retValue;
} // get
/**
* Get Message ID (cached)
* @param ctx context
* @param Value message value
* @return AD_Message_ID
*/
public static int getAD_Message_ID (String Value)
{
return getAD_Message_ID(Env.getCtx(), Value);
}
/**
* Get Message ID (cached)
* @param ctx context
* @param Value message value
* @return AD_Message_ID
*/
@ -112,7 +141,7 @@ public class MMessage extends X_AD_Message
} // getAD_Message_ID
/** Cache */
static private CCache<String,MMessage> s_cache = new CCache<String,MMessage>(Table_Name, 100);
static private ImmutablePOCache<String,MMessage> s_cache = new ImmutablePOCache<String,MMessage>(Table_Name, 100);
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger(MMessage.class);
@ -138,4 +167,44 @@ public class MMessage extends X_AD_Message
super(ctx, rs, trxName);
} // MMessage
/**
*
* @param copy
*/
public MMessage(MMessage copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MMessage(Properties ctx, MMessage copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MMessage(Properties ctx, MMessage copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
}
@Override
public MMessage markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MMessage

View File

@ -121,7 +121,7 @@ public class MMovementLine extends X_M_MovementLine
public MProduct getProduct()
{
if (getM_Product_ID() != 0)
return MProduct.get(getCtx(), getM_Product_ID());
return MProduct.getCopy(getCtx(), getM_Product_ID(), get_TrxName());
return null;
} // getProduct

View File

@ -369,11 +369,11 @@ public class MOrderLine extends X_C_OrderLine
public MCharge getCharge()
{
if (m_charge == null && getC_Charge_ID() != 0)
m_charge = MCharge.get (getCtx(), getC_Charge_ID());
m_charge = MCharge.getCopy(getCtx(), getC_Charge_ID(), get_TrxName());
return m_charge;
}
/**
* Get Tax
* Get Tax (immutable)
* @return tax
*/
protected MTax getTax()
@ -472,7 +472,7 @@ public class MOrderLine extends X_C_OrderLine
public MProduct getProduct()
{
if (m_product == null && getM_Product_ID() != 0)
m_product = MProduct.get (getCtx(), getM_Product_ID());
m_product = MProduct.getCopy(getCtx(), getM_Product_ID(), get_TrxName());
return m_product;
} // getProduct

View File

@ -182,7 +182,7 @@ public class MOrderTax extends X_C_OrderTax
} // setPrecision
/**
* Get Tax
* Get Tax (immutable)
* @return tax
*/
protected MTax getTax()
@ -266,5 +266,5 @@ public class MOrderTax extends X_C_OrderTax
.append ("]");
return sb.toString ();
} // toString
} // MOrderTax

View File

@ -20,9 +20,10 @@ import java.sql.ResultSet;
import java.util.List;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Organization Model
@ -30,13 +31,12 @@ import org.compiere.util.Env;
* @author Jorg Janke
* @version $Id: MOrg.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
*/
public class MOrg extends X_AD_Org
public class MOrg extends X_AD_Org implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -5604686137606338725L;
private static final long serialVersionUID = -696173265471741122L;
/**
* Get Active Organizations Of Client
@ -58,24 +58,36 @@ public class MOrg extends X_AD_Org
} // getOfClient
/**
* Get Org from Cache
* @param ctx context
* Get Org from Cache (immutable)
* @param AD_Org_ID id
* @return MOrg
*/
public static MOrg get (int AD_Org_ID)
{
return get(Env.getCtx(), AD_Org_ID);
}
/**
* Get Org from Cache (immutable)
* @param AD_Org_ID id
* @return MOrg
*/
public static MOrg get (Properties ctx, int AD_Org_ID)
{
MOrg retValue = s_cache.get (AD_Org_ID);
MOrg retValue = s_cache.get (ctx, AD_Org_ID, e -> new MOrg(ctx, e));
if (retValue != null)
return retValue;
retValue = new MOrg (ctx, AD_Org_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (AD_Org_ID, retValue);
return retValue;
retValue = new MOrg (ctx, AD_Org_ID, (String)null);
if (retValue.get_ID () == AD_Org_ID)
{
s_cache.put (AD_Org_ID, retValue, e -> new MOrg(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/** Cache */
private static CCache<Integer,MOrg> s_cache = new CCache<Integer,MOrg>(Table_Name, 50);
private static ImmutableIntPOCache<Integer,MOrg> s_cache = new ImmutableIntPOCache<Integer,MOrg>(Table_Name, 50);
/**************************************************************************
@ -119,6 +131,38 @@ public class MOrg extends X_AD_Org
setName (name);
} // MOrg
/**
*
* @param copy
*/
public MOrg(MOrg copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MOrg(Properties ctx, MOrg copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MOrg(Properties ctx, MOrg copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_linkedBPartner = copy.m_linkedBPartner;
}
/** Linked Business Partner */
private Integer m_linkedBPartner = null;
@ -128,7 +172,8 @@ public class MOrg extends X_AD_Org
*/
public MOrgInfo getInfo()
{
return MOrgInfo.get(getCtx(), getAD_Org_ID(), get_TrxName());
MOrgInfo orgInfo = MOrgInfo.getCopy(Env.getCtx(), getAD_Org_ID(), get_TrxName());
return orgInfo;
} // getMOrgInfo
@ -151,7 +196,7 @@ public class MOrg extends X_AD_Org
// Access
MRoleOrgAccess.createForOrg (this);
MRole role = MRole.getDefault(getCtx(), true); // reload
role.set_TrxName(get_TrxName());
role = new MRole(getCtx(), role, get_TrxName());
role.loadAccess(true); // reload org access within transaction
// TreeNode
insert_Tree(MTree_Base.TREETYPE_Organization);
@ -199,5 +244,14 @@ public class MOrg extends X_AD_Org
}
return m_linkedBPartner.intValue();
} // getLinkedC_BPartner_ID
@Override
public MOrg markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
} // MOrg

View File

@ -19,7 +19,9 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
* Organization Info Model
@ -30,51 +32,86 @@ import org.compiere.util.CCache;
* @author Teo Sarca, www.arhipac.ro
* <li>BF [ 2107083 ] Caching of MOrgInfo issue
*/
public class MOrgInfo extends X_AD_OrgInfo
public class MOrgInfo extends X_AD_OrgInfo implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = 2496591466841600079L;
private static final long serialVersionUID = -6257741576762100779L;
/**
* Load Constructor
* @param ctx context
* Get MOrgInfo from cache (immutable)
* @param AD_Org_ID id
* @return Org Info
* @deprecated
*/
public static MOrgInfo get (Properties ctx, int AD_Org_ID)
{
return get(ctx, AD_Org_ID, null);
return get(ctx, AD_Org_ID, (String)null);
} // get
/**
* Load Constructor
* @param ctx context
* Get MOrgInfo from cache (immutable)
* @param AD_Org_ID id
* @param trxName
* @return Org Info
*/
public static MOrgInfo get (int AD_Org_ID, String trxName)
{
return get(Env.getCtx(), AD_Org_ID, trxName);
}
/**
* Get MOrgInfo from cache (immutable)
* @param AD_Org_ID id
* @return Org Info
*/
public static MOrgInfo get (int AD_Org_ID)
{
return get(AD_Org_ID, (String)null);
}
/**
* Get MOrgInfo from cache (immutable)
* @param ctx context
* @param AD_Org_ID id
* @param trxName
* @return Org Info
*/
public static MOrgInfo get (Properties ctx, int AD_Org_ID, String trxName)
{
MOrgInfo retValue = s_cache.get(AD_Org_ID);
MOrgInfo retValue = s_cache.get(ctx, AD_Org_ID, e -> new MOrgInfo(ctx, e));
if (retValue != null)
{
return retValue;
}
retValue = new Query(ctx, Table_Name, "AD_Org_ID=?", trxName)
retValue = new Query(Env.getCtx(), Table_Name, "AD_Org_ID=?", trxName)
.setParameters(AD_Org_ID)
.firstOnly();
if (retValue != null)
{
s_cache.put(AD_Org_ID, retValue);
s_cache.put(AD_Org_ID, retValue, e -> new MOrgInfo(Env.getCtx(), e));
return retValue;
}
return retValue;
return null;
} // get
/**
* Get updateable copy of MOrgInfo from cache
* @param ctx
* @param AD_Org_ID
* @param trxName
* @return MOrgInfo
*/
public static MOrgInfo getCopy(Properties ctx, int AD_Org_ID, String trxName)
{
MOrgInfo oi = get(ctx, AD_Org_ID, trxName);
if (oi != null)
oi = new MOrgInfo(ctx, oi, trxName);
return oi;
}
/** Cache */
private static CCache<Integer,MOrgInfo> s_cache = new CCache<Integer, MOrgInfo>(Table_Name, 50);
private static ImmutableIntPOCache<Integer,MOrgInfo> s_cache = new ImmutableIntPOCache<Integer, MOrgInfo>(Table_Name, 50);
/**************************************************************************
@ -100,4 +137,44 @@ public class MOrgInfo extends X_AD_OrgInfo
setTaxID ("?");
} // MOrgInfo
/**
*
* @param copy
*/
public MOrgInfo(MOrgInfo copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MOrgInfo(Properties ctx, MOrgInfo copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MOrgInfo(Properties ctx, MOrgInfo copy, String trxName)
{
super(ctx, 0, trxName);
copyPO(copy);
}
@Override
public MOrgInfo markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
return this;
}
}

View File

@ -21,8 +21,10 @@ import java.util.Properties;
import java.util.List;
import java.util.logging.Level;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.idempiere.cache.ImmutableIntPOCache;
import org.idempiere.cache.ImmutablePOSupport;
/**
@ -31,15 +33,25 @@ import org.compiere.util.Msg;
* @author Jorg Janke
* @version $Id: MPOS.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
*/
public class MPOS extends X_C_POS
public class MPOS extends X_C_POS implements ImmutablePOSupport
{
/**
*
*/
private static final long serialVersionUID = -1568195843844720536L;
private static final long serialVersionUID = 2499679269059812831L;
/**
* Get POS from Cache
* Get POS from Cache (immutable)
* @param C_POS_ID id
* @return MPOS
*/
public static MPOS get (int C_POS_ID)
{
return get(Env.getCtx(), C_POS_ID);
}
/**
* Get POS from Cache (immutable)
* @param ctx context
* @param C_POS_ID id
* @return MPOS
@ -47,13 +59,16 @@ public class MPOS extends X_C_POS
public static MPOS get (Properties ctx, int C_POS_ID)
{
Integer key = Integer.valueOf(C_POS_ID);
MPOS retValue = (MPOS) s_cache.get (key);
MPOS retValue = (MPOS) s_cache.get (ctx, key, e -> new MPOS(ctx, e));
if (retValue != null)
return retValue;
retValue = new MPOS (ctx, C_POS_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
retValue = new MPOS (ctx, C_POS_ID, (String)null);
if (retValue.get_ID () == C_POS_ID)
{
s_cache.put (key, retValue, e -> new MPOS(Env.getCtx(), e));
return retValue;
}
return null;
} // get
/**
@ -74,7 +89,7 @@ public class MPOS extends X_C_POS
} // get
/** Cache */
private static CCache<Integer,MPOS> s_cache = new CCache<Integer,MPOS>(Table_Name, 20);
private static ImmutableIntPOCache<Integer,MPOS> s_cache = new ImmutableIntPOCache<Integer,MPOS>(Table_Name, 20);
/**
* Standard Constructor
@ -107,6 +122,38 @@ public class MPOS extends X_C_POS
super(ctx, rs, trxName);
} // MPOS
/**
*
* @param copy
*/
public MPOS(MPOS copy)
{
this(Env.getCtx(), copy);
}
/**
*
* @param ctx
* @param copy
*/
public MPOS(Properties ctx, MPOS copy)
{
this(ctx, copy, (String) null);
}
/**
*
* @param ctx
* @param copy
* @param trxName
*/
public MPOS(Properties ctx, MPOS copy, String trxName)
{
this(ctx, 0, trxName);
copyPO(copy);
this.m_template = copy.m_template != null ? new MBPartner(ctx, copy.m_template, trxName) : null;
}
/** Cash Business Partner */
private MBPartner m_template = null;
@ -154,14 +201,27 @@ public class MPOS extends X_C_POS
m_template = MBPartner.getBPartnerCashTrx (getCtx(), getAD_Client_ID());
else
m_template = new MBPartner(getCtx(), getC_BPartnerCashTrx_ID(), get_TrxName());
if (is_Immutable() && m_template != null)
m_template.markImmutable();
if (log.isLoggable(Level.FINE)) log.fine("getBPartner - " + m_template);
}
return m_template;
} // getBPartner
@Override
public MPOS markImmutable() {
if (is_Immutable())
return this;
makeImmutable();
if (m_template != null)
m_template.markImmutable();
return this;
}
@Override
public String toString() {
return super.getName();
}
}
} // MPOS

Some files were not shown because too many files have changed in this diff Show More