BF [ 2107083 ] Caching of MOrgInfo issue
BF [ 2107088 ] MOrg.getOfClient should return ONLY active records
This commit is contained in:
parent
732bba1e20
commit
0e10da320a
|
@ -16,10 +16,13 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.ResultSet;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
import java.util.logging.*;
|
import java.util.Properties;
|
||||||
import org.compiere.util.*;
|
|
||||||
|
import org.compiere.util.CCache;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Organization Model
|
* Organization Model
|
||||||
|
@ -29,45 +32,26 @@ import org.compiere.util.*;
|
||||||
*/
|
*/
|
||||||
public class MOrg extends X_AD_Org
|
public class MOrg extends X_AD_Org
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Organizations Of Client
|
* Get Active Organizations Of Client
|
||||||
* @param po persistent object
|
* @param po persistent object
|
||||||
* @return array of orgs
|
* @return array of orgs
|
||||||
*/
|
*/
|
||||||
public static MOrg[] getOfClient (PO po)
|
public static MOrg[] getOfClient (PO po)
|
||||||
{
|
{
|
||||||
ArrayList<MOrg> list = new ArrayList<MOrg>();
|
List<MOrg> list = new Query(po.getCtx(), Table_Name, "AD_Client_ID=?", null)
|
||||||
String sql = "SELECT * FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value";
|
.setOrderBy(COLUMNNAME_Value)
|
||||||
PreparedStatement pstmt = null;
|
.setOnlyActiveRecords(true)
|
||||||
try
|
.setParameters(new Object[]{po.getAD_Client_ID()})
|
||||||
|
.list();
|
||||||
|
for (MOrg org : list)
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement (sql, null);
|
s_cache.put(org.get_ID(), org);
|
||||||
pstmt.setInt (1, po.getAD_Client_ID());
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MOrg (po.getCtx(), rs, null));
|
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
return list.toArray(new MOrg[list.size()]);
|
||||||
{
|
|
||||||
s_log.log (Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOrg[] retValue = new MOrg[list.size ()];
|
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
|
||||||
} // getOfClient
|
} // getOfClient
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,18 +62,15 @@ public class MOrg extends X_AD_Org
|
||||||
*/
|
*/
|
||||||
public static MOrg get (Properties ctx, int AD_Org_ID)
|
public static MOrg get (Properties ctx, int AD_Org_ID)
|
||||||
{
|
{
|
||||||
Integer key = new Integer (AD_Org_ID);
|
MOrg retValue = s_cache.get (AD_Org_ID);
|
||||||
MOrg retValue = (MOrg) s_cache.get (key);
|
|
||||||
if (retValue != null)
|
if (retValue != null)
|
||||||
return retValue;
|
return retValue;
|
||||||
retValue = new MOrg (ctx, AD_Org_ID, null);
|
retValue = new MOrg (ctx, AD_Org_ID, null);
|
||||||
if (retValue.get_ID () != 0)
|
if (retValue.get_ID () != 0)
|
||||||
s_cache.put (key, retValue);
|
s_cache.put (AD_Org_ID, retValue);
|
||||||
return retValue;
|
return retValue;
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
/** Logger */
|
|
||||||
private static CLogger s_log = CLogger.getCLogger (MOrg.class);
|
|
||||||
/** Cache */
|
/** Cache */
|
||||||
private static CCache<Integer,MOrg> s_cache = new CCache<Integer,MOrg>(Table_Name, 50);
|
private static CCache<Integer,MOrg> s_cache = new CCache<Integer,MOrg>(Table_Name, 50);
|
||||||
|
|
||||||
|
@ -135,8 +116,6 @@ public class MOrg extends X_AD_Org
|
||||||
setName (name);
|
setName (name);
|
||||||
} // MOrg
|
} // MOrg
|
||||||
|
|
||||||
/** Org Info */
|
|
||||||
private MOrgInfo m_info = null;
|
|
||||||
/** Linked Business Partner */
|
/** Linked Business Partner */
|
||||||
private Integer m_linkedBPartner = null;
|
private Integer m_linkedBPartner = null;
|
||||||
|
|
||||||
|
@ -146,9 +125,7 @@ public class MOrg extends X_AD_Org
|
||||||
*/
|
*/
|
||||||
public MOrgInfo getInfo()
|
public MOrgInfo getInfo()
|
||||||
{
|
{
|
||||||
if (m_info == null)
|
return MOrgInfo.get(getCtx(), getAD_Org_ID());
|
||||||
m_info = MOrgInfo.get (getCtx(), getAD_Org_ID());
|
|
||||||
return m_info;
|
|
||||||
} // getMOrgInfo
|
} // getMOrgInfo
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,8 +143,8 @@ public class MOrg extends X_AD_Org
|
||||||
if (newRecord)
|
if (newRecord)
|
||||||
{
|
{
|
||||||
// Info
|
// Info
|
||||||
m_info = new MOrgInfo (this);
|
MOrgInfo info = new MOrgInfo (this);
|
||||||
m_info.save();
|
info.saveEx();
|
||||||
// Access
|
// Access
|
||||||
MRoleOrgAccess.createForOrg (this);
|
MRoleOrgAccess.createForOrg (this);
|
||||||
MRole.getDefault(getCtx(), true); // reload
|
MRole.getDefault(getCtx(), true); // reload
|
||||||
|
|
|
@ -15,20 +15,25 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.ResultSet;
|
||||||
import java.util.*;
|
import java.util.Properties;
|
||||||
|
|
||||||
import java.util.logging.*;
|
import org.compiere.util.CCache;
|
||||||
import org.compiere.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Organization Info Model
|
* Organization Info Model
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: MOrgInfo.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
|
* @version $Id: MOrgInfo.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
|
||||||
|
*
|
||||||
|
* @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
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Constructor
|
* Load Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -37,39 +42,23 @@ public class MOrgInfo extends X_AD_OrgInfo
|
||||||
*/
|
*/
|
||||||
public static MOrgInfo get (Properties ctx, int AD_Org_ID)
|
public static MOrgInfo get (Properties ctx, int AD_Org_ID)
|
||||||
{
|
{
|
||||||
MOrgInfo retValue = null;
|
MOrgInfo retValue = s_cache.get(AD_Org_ID);
|
||||||
String sql = "SELECT * FROM AD_OrgInfo WHERE AD_Org_ID=?";
|
if (retValue != null)
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
return retValue;
|
||||||
pstmt.setInt(1, AD_Org_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
retValue = new MOrgInfo (ctx, rs, null);
|
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
retValue = new Query(ctx, Table_Name, "AD_Org_ID=?", null)
|
||||||
|
.setParameters(new Object[]{AD_Org_ID})
|
||||||
|
.first();
|
||||||
|
if (retValue != null)
|
||||||
{
|
{
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
s_cache.put(AD_Org_ID, retValue);
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
return retValue;
|
return retValue;
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
/** Static Logger */
|
/** Cache */
|
||||||
private static CLogger s_log = CLogger.getCLogger (MOrgInfo.class);
|
private static CCache<Integer,MOrgInfo> s_cache = new CCache<Integer,MOrgInfo>(Table_Name, 50);
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue