MWarehouse:
* BF [ 1874419 ] JDBC Statement not close in a finally block * organized imports * exception handling improvements (use saveEx instead of save)
This commit is contained in:
parent
b27cf2b2e5
commit
7c0e11a051
|
@ -16,10 +16,11 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warehouse Model
|
* Warehouse Model
|
||||||
|
@ -27,10 +28,14 @@ import org.compiere.util.*;
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @author victor.perez@e-evolution.com
|
* @author victor.perez@e-evolution.com
|
||||||
* @see FR [ 1966337 ] New Method to get the Transit Warehouse based in ID Org http://sourceforge.net/tracker/index.php?func=detail&aid=1966337&group_id=176962&atid=879335
|
* @see FR [ 1966337 ] New Method to get the Transit Warehouse based in ID Org http://sourceforge.net/tracker/index.php?func=detail&aid=1966337&group_id=176962&atid=879335
|
||||||
|
* @author Teo Sarca, http://www.arhipac.ro
|
||||||
|
* <li>BF [ 1874419 ] JDBC Statement not close in a finally block
|
||||||
* @version $Id: MWarehouse.java,v 1.3 2006/07/30 00:58:05 jjanke Exp $
|
* @version $Id: MWarehouse.java,v 1.3 2006/07/30 00:58:05 jjanke Exp $
|
||||||
*/
|
*/
|
||||||
public class MWarehouse extends X_M_Warehouse
|
public class MWarehouse extends X_M_Warehouse
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get from Cache
|
* Get from Cache
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -57,37 +62,12 @@ public class MWarehouse extends X_M_Warehouse
|
||||||
*/
|
*/
|
||||||
public static MWarehouse[] getForOrg (Properties ctx, int AD_Org_ID)
|
public static MWarehouse[] getForOrg (Properties ctx, int AD_Org_ID)
|
||||||
{
|
{
|
||||||
ArrayList<MWarehouse> list = new ArrayList<MWarehouse>();
|
String whereClause = "IsActive=? AND AD_Org_ID=?";
|
||||||
String sql = "SELECT * FROM M_Warehouse WHERE IsActive = 'Y' AND AD_Org_ID=? ORDER BY Created";
|
List<MWarehouse> list = new Query(ctx, Table_Name, whereClause, null)
|
||||||
PreparedStatement pstmt = null;
|
.setParameters(new Object[]{"Y", AD_Org_ID})
|
||||||
try
|
.setOrderBy(COLUMNNAME_M_Warehouse_ID)
|
||||||
{
|
.list();
|
||||||
pstmt = DB.prepareStatement (sql, null);
|
return list.toArray(new MWarehouse[list.size()]);
|
||||||
pstmt.setInt (1, AD_Org_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MWarehouse (ctx, rs, null));
|
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
MWarehouse[] retValue = new MWarehouse[list.size ()];
|
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,43 +79,16 @@ public class MWarehouse extends X_M_Warehouse
|
||||||
*/
|
*/
|
||||||
public static MWarehouse[] getInTransitForOrg (Properties ctx, int AD_Org_ID)
|
public static MWarehouse[] getInTransitForOrg (Properties ctx, int AD_Org_ID)
|
||||||
{
|
{
|
||||||
ArrayList<MWarehouse> list = new ArrayList<MWarehouse>();
|
String whereClause = "IsActive=? AND IsInTransit=? AND AD_Org_ID=?";
|
||||||
String sql = "SELECT * FROM M_Warehouse WHERE IsActive = 'Y' AND IsInTransit = 'Y' AND AD_Org_ID=? ORDER BY Created";
|
List<MWarehouse> list = new Query(ctx, Table_Name, whereClause, null)
|
||||||
PreparedStatement pstmt = null;
|
.setParameters(new Object[]{"Y", "Y", AD_Org_ID})
|
||||||
try
|
.setOrderBy(COLUMNNAME_M_Warehouse_ID)
|
||||||
{
|
.list();
|
||||||
pstmt = DB.prepareStatement (sql, null);
|
return list.toArray(new MWarehouse[list.size()]);
|
||||||
pstmt.setInt (1, AD_Org_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add (new MWarehouse (ctx, rs, null));
|
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
MWarehouse[] retValue = new MWarehouse[list.size ()];
|
|
||||||
list.toArray (retValue);
|
|
||||||
return retValue;
|
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
/** Cache */
|
/** Cache */
|
||||||
private static CCache<Integer,MWarehouse> s_cache = new CCache<Integer,MWarehouse>("M_Warehouse", 5);
|
private static CCache<Integer,MWarehouse> s_cache = new CCache<Integer,MWarehouse>("M_Warehouse", 5);
|
||||||
/** Static Logger */
|
|
||||||
private static CLogger s_log = CLogger.getCLogger (MWarehouse.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard Constructor
|
* Standard Constructor
|
||||||
|
@ -193,37 +146,12 @@ public class MWarehouse extends X_M_Warehouse
|
||||||
if (!reload && m_locators != null)
|
if (!reload && m_locators != null)
|
||||||
return m_locators;
|
return m_locators;
|
||||||
//
|
//
|
||||||
String sql = "SELECT * FROM M_Locator WHERE IsActive = 'Y' AND M_Warehouse_ID=? ORDER BY X,Y,Z";
|
final String whereClause = "IsActive=? AND M_Warehouse_ID=?";
|
||||||
ArrayList<MLocator> list = new ArrayList<MLocator>();
|
List<MLocator> list = new Query(getCtx(), MLocator.Table_Name, whereClause, null)
|
||||||
PreparedStatement pstmt = null;
|
.setParameters(new Object[]{"Y", getM_Warehouse_ID()})
|
||||||
try
|
.setOrderBy("X,Y,Z")
|
||||||
{
|
.list();
|
||||||
pstmt = DB.prepareStatement (sql, null);
|
m_locators = list.toArray(new MLocator[list.size()]);
|
||||||
pstmt.setInt (1, getM_Warehouse_ID());
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add(new MLocator (getCtx(), rs, null));
|
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
m_locators = new MLocator[list.size()];
|
|
||||||
list.toArray (m_locators);
|
|
||||||
return m_locators;
|
return m_locators;
|
||||||
} // getLocators
|
} // getLocators
|
||||||
|
|
||||||
|
@ -248,7 +176,7 @@ public class MWarehouse extends X_M_Warehouse
|
||||||
// No Locator - create one
|
// No Locator - create one
|
||||||
MLocator loc = new MLocator (this, "Standard");
|
MLocator loc = new MLocator (this, "Standard");
|
||||||
loc.setIsDefault(true);
|
loc.setIsDefault(true);
|
||||||
loc.save();
|
loc.saveEx();
|
||||||
log.info("Created default locator for " + getName());
|
log.info("Created default locator for " + getName());
|
||||||
return loc;
|
return loc;
|
||||||
} // getLocators
|
} // getLocators
|
||||||
|
|
Loading…
Reference in New Issue