Heng Sin Low 2009-05-20 04:14:17 +00:00
parent 7f02b4f4e9
commit c7a5b83f6e
1 changed files with 159 additions and 159 deletions

View File

@ -53,35 +53,35 @@ import org.compiere.util.Trx;
public class MSequence extends X_AD_Sequence public class MSequence extends X_AD_Sequence
{ {
/** /**
* *
*/ */
private static final long serialVersionUID = 8830129847511432980L; private static final long serialVersionUID = 8830129847511432980L;
/** Use SQL procedure to get next id */ /** Use SQL procedure to get next id */
//begin vpj-cd e-evolution 02/11/2005 PostgreSQL //begin vpj-cd e-evolution 02/11/2005 PostgreSQL
//private static final boolean USE_PROCEDURE = true; //private static final boolean USE_PROCEDURE = true;
private static boolean USE_PROCEDURE = false; private static boolean USE_PROCEDURE = false;
//end vpj-cd e-evolution 02/11/2005 //end vpj-cd e-evolution 02/11/2005
/** Log Level for Next ID Call */ /** Log Level for Next ID Call */
private static final Level LOGLEVEL = Level.ALL; private static final Level LOGLEVEL = Level.ALL;
public static synchronized int getNextID (int AD_Client_ID, String TableName) public static int getNextID (int AD_Client_ID, String TableName)
{ {
return getNextID(AD_Client_ID, TableName, null); return getNextID(AD_Client_ID, TableName, null);
} }
/** /**
* *
* Get next number for Key column = 0 is Error. * Get next number for Key column = 0 is Error.
* @param AD_Client_ID client * @param AD_Client_ID client
* @param TableName table name * @param TableName table name
* @param trxName deprecated. * @param trxName deprecated.
* @return next no or (-1=not found, -2=error) * @return next no or (-1=not found, -2=error)
*/ */
public static synchronized int getNextID (int AD_Client_ID, String TableName, String trxName) public static int getNextID (int AD_Client_ID, String TableName, String trxName)
{ {
if (TableName == null || TableName.length() == 0) if (TableName == null || TableName.length() == 0)
throw new IllegalArgumentException("TableName missing"); throw new IllegalArgumentException("TableName missing");
int retValue = -1; int retValue = -1;
// Check AdempiereSys // Check AdempiereSys
@ -94,26 +94,26 @@ public class MSequence extends X_AD_Sequence
//begin vpj-cd e-evolution 09/02/2005 PostgreSQL //begin vpj-cd e-evolution 09/02/2005 PostgreSQL
String selectSQL = null; String selectSQL = null;
if (DB.isOracle() == false) if (DB.isOracle() == false)
{ {
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, AD_Sequence_ID " selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, AD_Sequence_ID "
+ "FROM AD_Sequence " + "FROM AD_Sequence "
+ "WHERE Name=?" + "WHERE Name=?"
+ " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' " + " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' "
+ " FOR UPDATE OF AD_Sequence "; + " FOR UPDATE OF AD_Sequence ";
USE_PROCEDURE=false; USE_PROCEDURE=false;
} }
else else
{ {
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, AD_Sequence_ID " selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, AD_Sequence_ID "
+ "FROM AD_Sequence " + "FROM AD_Sequence "
+ "WHERE Name=?" + "WHERE Name=?"
+ " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' " + " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' "
+ "FOR UPDATE"; // jz derby needs expicitly said it//OF CurrentNext, CurrentNextSys"; + "FOR UPDATE"; // jz derby needs expicitly said it//OF CurrentNext, CurrentNextSys";
USE_PROCEDURE = true; USE_PROCEDURE = true;
} }
//hengsin: executing getNextID in transaction create huge performance and locking issue //hengsin: executing getNextID in transaction create huge performance and locking issue
//Trx trx = trxName == null ? null : Trx.get(trxName, true); //Trx trx = trxName == null ? null : Trx.get(trxName, true);
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -135,18 +135,18 @@ public class MSequence extends X_AD_Sequence
if (CLogMgt.isLevelFinest()) if (CLogMgt.isLevelFinest())
s_log.finest("AC=" + conn.getAutoCommit() + ", RO=" + conn.isReadOnly() s_log.finest("AC=" + conn.getAutoCommit() + ", RO=" + conn.isReadOnly()
+ " - Isolation=" + conn.getTransactionIsolation() + "(" + Connection.TRANSACTION_READ_COMMITTED + " - Isolation=" + conn.getTransactionIsolation() + "(" + Connection.TRANSACTION_READ_COMMITTED
+ ") - RSType=" + pstmt.getResultSetType() + "(" + ResultSet.TYPE_SCROLL_SENSITIVE + ") - RSType=" + pstmt.getResultSetType() + "(" + ResultSet.TYPE_SCROLL_SENSITIVE
+ "), RSConcur=" + pstmt.getResultSetConcurrency() + "(" + ResultSet.CONCUR_UPDATABLE + "), RSConcur=" + pstmt.getResultSetConcurrency() + "(" + ResultSet.CONCUR_UPDATABLE
+ ")"); + ")");
if (rs.next()) if (rs.next())
{ {
// Get the table // Get the table
MTable table = MTable.get(Env.getCtx(), TableName); MTable table = MTable.get(Env.getCtx(), TableName);
boolean hasEntityType = false; boolean hasEntityType = false;
if (table.getColumn("EntityType") != null) if (table.getColumn("EntityType") != null)
hasEntityType = true; hasEntityType = true;
int AD_Sequence_ID = rs.getInt(4); int AD_Sequence_ID = rs.getInt(4);
boolean gotFromHTTP = false; boolean gotFromHTTP = false;
@ -195,7 +195,7 @@ public class MSequence extends X_AD_Sequence
} }
} }
if (! gotFromHTTP) { if (! gotFromHTTP) {
// //
if (USE_PROCEDURE) if (USE_PROCEDURE)
@ -222,22 +222,22 @@ public class MSequence extends X_AD_Sequence
} finally { } finally {
updateSQL.close(); updateSQL.close();
} }
} }
} }
//if (trx == null) //if (trx == null)
conn.commit(); conn.commit();
} }
else else
s_log.severe ("No record found - " + TableName); s_log.severe ("No record found - " + TableName);
// //
break; // EXIT break; // EXIT
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, TableName + " - " + e.getMessage(), e); s_log.log(Level.SEVERE, TableName + " - " + e.getMessage(), e);
try try
{ {
if (conn != null) if (conn != null)
conn.rollback(); conn.rollback();
@ -254,12 +254,12 @@ public class MSequence extends X_AD_Sequence
conn.close(); conn.close();
} catch (SQLException e) {} } catch (SQLException e) {}
conn = null; conn = null;
} }
} }
Thread.yield(); // give it time Thread.yield(); // give it time
} }
//s_log.finest (retValue + " - Table=" + TableName + " [" + trx + "]"); //s_log.finest (retValue + " - Table=" + TableName + " [" + trx + "]");
return retValue; return retValue;
} // getNextID } // getNextID
@ -299,7 +299,7 @@ public class MSequence extends X_AD_Sequence
} }
return retValue; return retValue;
} // nextID } // nextID
/** /**
* Get next id by year * Get next id by year
* @param conn * @param conn
@ -333,7 +333,7 @@ public class MSequence extends X_AD_Sequence
} }
return retValue; return retValue;
} // nextID } // nextID
/************************************************************************** /**************************************************************************
* Get Document No from table * Get Document No from table
* @param AD_Client_ID client * @param AD_Client_ID client
@ -341,10 +341,10 @@ public class MSequence extends X_AD_Sequence
* @param trxName optional Transaction Name * @param trxName optional Transaction Name
* @return document no or null * @return document no or null
*/ */
public static synchronized String getDocumentNo (int AD_Client_ID, String TableName, String trxName) public static String getDocumentNo (int AD_Client_ID, String TableName, String trxName)
{ {
return getDocumentNo(AD_Client_ID, TableName, trxName, null); return getDocumentNo(AD_Client_ID, TableName, trxName, null);
} }
/************************************************************************** /**************************************************************************
* Get Document No from table * Get Document No from table
@ -354,7 +354,7 @@ public class MSequence extends X_AD_Sequence
* @param PO * @param PO
* @return document no or null * @return document no or null
*/ */
public static synchronized String getDocumentNo (int AD_Client_ID, String TableName, String trxName, PO po) public static String getDocumentNo (int AD_Client_ID, String TableName, String trxName, PO po)
{ {
if (TableName == null || TableName.length() == 0) if (TableName == null || TableName.length() == 0)
throw new IllegalArgumentException("TableName missing"); throw new IllegalArgumentException("TableName missing");
@ -366,18 +366,18 @@ public class MSequence extends X_AD_Sequence
// //
if (CLogMgt.isLevel(LOGLEVEL)) if (CLogMgt.isLevel(LOGLEVEL))
s_log.log(LOGLEVEL, TableName + " - AdempiereSys=" + adempiereSys + " [" + trxName + "]"); s_log.log(LOGLEVEL, TableName + " - AdempiereSys=" + adempiereSys + " [" + trxName + "]");
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
boolean isStartNewYear = false; boolean isStartNewYear = false;
String dateColumn = null; String dateColumn = null;
if (!adempiereSys) if (!adempiereSys)
{ {
// Get the Start New Year flag // Get the Start New Year flag
String startNewYearSQL = "SELECT StartNewYear, DateColumn FROM AD_Sequence " String startNewYearSQL = "SELECT StartNewYear, DateColumn FROM AD_Sequence "
+ "WHERE Name = ? AND IsActive = 'Y' AND IsTableID = 'N' AND IsAutoSequence='Y' AND AD_Client_ID = ?"; + "WHERE Name = ? AND IsActive = 'Y' AND IsTableID = 'N' AND IsAutoSequence='Y' AND AD_Client_ID = ?";
try try
{ {
pstmt = DB.prepareStatement(startNewYearSQL, trxName); pstmt = DB.prepareStatement(startNewYearSQL, trxName);
pstmt.setString(1, PREFIX_DOCSEQ + TableName); pstmt.setString(1, PREFIX_DOCSEQ + TableName);
@ -387,8 +387,8 @@ public class MSequence extends X_AD_Sequence
isStartNewYear = "Y".equals(rs.getString(1)); isStartNewYear = "Y".equals(rs.getString(1));
dateColumn = rs.getString(2); dateColumn = rs.getString(2);
} }
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e); s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e);
} }
@ -397,22 +397,22 @@ public class MSequence extends X_AD_Sequence
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
} }
String selectSQL = null; String selectSQL = null;
if (DB.isOracle() == false) if (DB.isOracle() == false)
{ {
if (isStartNewYear) { if (isStartNewYear) {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Sequence_ID " selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Sequence_ID "
+ "FROM AD_Sequence_No y, AD_Sequence s " + "FROM AD_Sequence_No y, AD_Sequence s "
+ "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID " + "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID "
+ "AND s.Name = ? " + "AND s.Name = ? "
+ "AND s.AD_Client_ID = ? " + "AND s.AD_Client_ID = ? "
+ "AND y.CalendarYear = ? " + "AND y.CalendarYear = ? "
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' " + "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' "
+ "ORDER BY s.AD_Client_ID DESC " + "ORDER BY s.AD_Client_ID DESC "
+ "FOR UPDATE OF y"; + "FOR UPDATE OF y";
} else { } else {
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Sequence_ID " selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Sequence_ID "
+ "FROM AD_Sequence " + "FROM AD_Sequence "
+ "WHERE Name = ? " + "WHERE Name = ? "
@ -422,13 +422,13 @@ public class MSequence extends X_AD_Sequence
+ "FOR UPDATE OF AD_Sequence"; + "FOR UPDATE OF AD_Sequence";
} }
USE_PROCEDURE=false; USE_PROCEDURE=false;
} }
else else
{ {
if (isStartNewYear) { if (isStartNewYear) {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, Prefix, Suffix, DecimalPattern, s.AD_Sequence_ID " selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, Prefix, Suffix, DecimalPattern, s.AD_Sequence_ID "
+ "FROM AD_Sequence_No y, AD_Sequence s " + "FROM AD_Sequence_No y, AD_Sequence s "
+ "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID " + "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID "
+ "AND s.Name = ? " + "AND s.Name = ? "
+ "AND s.AD_Client_ID = ? " + "AND s.AD_Client_ID = ? "
+ "AND y.CalendarYear = ? " + "AND y.CalendarYear = ? "
@ -463,8 +463,8 @@ public class MSequence extends X_AD_Sequence
// Error // Error
if (conn == null) if (conn == null)
return null; return null;
if (isStartNewYear) if (isStartNewYear)
{ {
if (po != null && dateColumn != null && dateColumn.length() > 0) if (po != null && dateColumn != null && dateColumn.length() > 0)
{ {
@ -478,18 +478,18 @@ public class MSequence extends X_AD_Sequence
calendarYear = sdf.format(new Date()); calendarYear = sdf.format(new Date());
} }
} }
// //
pstmt = conn.prepareStatement(selectSQL, pstmt = conn.prepareStatement(selectSQL,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1, PREFIX_DOCSEQ + TableName); pstmt.setString(1, PREFIX_DOCSEQ + TableName);
pstmt.setInt(2, AD_Client_ID); pstmt.setInt(2, AD_Client_ID);
if (isStartNewYear) if (isStartNewYear)
pstmt.setString(3, calendarYear); pstmt.setString(3, calendarYear);
// //
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
// s_log.fine("AC=" + conn.getAutoCommit() + " -Iso=" + conn.getTransactionIsolation() // s_log.fine("AC=" + conn.getAutoCommit() + " -Iso=" + conn.getTransactionIsolation()
// + " - Type=" + pstmt.getResultSetType() + " - Concur=" + pstmt.getResultSetConcurrency()); // + " - Type=" + pstmt.getResultSetType() + " - Concur=" + pstmt.getResultSetConcurrency());
if (rs.next()) if (rs.next())
{ {
@ -500,21 +500,21 @@ public class MSequence extends X_AD_Sequence
incrementNo = rs.getInt(3); incrementNo = rs.getInt(3);
if (USE_PROCEDURE) if (USE_PROCEDURE)
{ {
next = isStartNewYear next = isStartNewYear
? nextIDByYear(conn, AD_Sequence_ID, incrementNo, calendarYear) ? nextIDByYear(conn, AD_Sequence_ID, incrementNo, calendarYear)
: nextID(conn, AD_Sequence_ID, adempiereSys); : nextID(conn, AD_Sequence_ID, adempiereSys);
} }
else else
{ {
PreparedStatement updateSQL = null; PreparedStatement updateSQL = null;
try try
{ {
if (adempiereSys) { if (adempiereSys) {
updateSQL = conn updateSQL = conn
.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?"); .prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
next = rs.getInt(2); next = rs.getInt(2);
} else { } else {
String sql = isStartNewYear String sql = isStartNewYear
? "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ? AND CalendarYear = ?" ? "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ? AND CalendarYear = ?"
: "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?"; : "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?";
updateSQL = conn updateSQL = conn
@ -531,7 +531,7 @@ public class MSequence extends X_AD_Sequence
{ {
DB.close(updateSQL); DB.close(updateSQL);
} }
} }
} }
else else
{ {
@ -554,7 +554,7 @@ public class MSequence extends X_AD_Sequence
finally finally
{ {
//Finish //Finish
DB.close(rs, pstmt); DB.close(rs, pstmt);
try try
{ {
if (trx == null && conn != null) { if (trx == null && conn != null) {
@ -567,11 +567,11 @@ public class MSequence extends X_AD_Sequence
s_log.log(Level.SEVERE, "(Table) - finish", e); s_log.log(Level.SEVERE, "(Table) - finish", e);
} }
} }
// Error // Error
if (next < 0) if (next < 0)
return null; return null;
// create DocumentNo // create DocumentNo
StringBuffer doc = new StringBuffer(); StringBuffer doc = new StringBuffer();
if (prefix != null && prefix.length() > 0) if (prefix != null && prefix.length() > 0)
@ -583,11 +583,11 @@ public class MSequence extends X_AD_Sequence
if (suffix != null && suffix.length() > 0) if (suffix != null && suffix.length() > 0)
doc.append(Env.parseVariable(suffix, po, trxName, false)); doc.append(Env.parseVariable(suffix, po, trxName, false));
String documentNo = doc.toString(); String documentNo = doc.toString();
s_log.finer (documentNo + " (" + incrementNo + ")" s_log.finer (documentNo + " (" + incrementNo + ")"
+ " - Table=" + TableName + " [" + trx + "]"); + " - Table=" + TableName + " [" + trx + "]");
return documentNo; return documentNo;
} // getDocumentNo } // getDocumentNo
/** /**
* Get Document No based on Document Type * Get Document No based on Document Type
* @param C_DocType_ID document type * @param C_DocType_ID document type
@ -604,30 +604,30 @@ public class MSequence extends X_AD_Sequence
* Get Document No based on Document Type * Get Document No based on Document Type
* @param C_DocType_ID document type * @param C_DocType_ID document type
* @param trxName optional Transaction Name * @param trxName optional Transaction Name
* @param definite asking for a definitive or temporary sequence * @param definite asking for a definitive or temporary sequence
* @return document no or null * @return document no or null
*/ */
public static synchronized String getDocumentNo (int C_DocType_ID, String trxName, boolean definite) public static String getDocumentNo (int C_DocType_ID, String trxName, boolean definite)
{ {
return getDocumentNo(C_DocType_ID, trxName, definite, null); return getDocumentNo(C_DocType_ID, trxName, definite, null);
} }
/** /**
* Get Document No based on Document Type * Get Document No based on Document Type
* @param C_DocType_ID document type * @param C_DocType_ID document type
* @param trxName optional Transaction Name * @param trxName optional Transaction Name
* @param definite asking for a definitive or temporary sequence * @param definite asking for a definitive or temporary sequence
* @param po * @param po
* @return document no or null * @return document no or null
*/ */
public static synchronized String getDocumentNo (int C_DocType_ID, String trxName, boolean definite, PO po) public static String getDocumentNo (int C_DocType_ID, String trxName, boolean definite, PO po)
{ {
if (C_DocType_ID == 0) if (C_DocType_ID == 0)
{ {
s_log.severe ("C_DocType_ID=0"); s_log.severe ("C_DocType_ID=0");
return null; return null;
} }
MDocType dt = MDocType.get (Env.getCtx(), C_DocType_ID); // wrong for SERVER, but r/o MDocType dt = MDocType.get (Env.getCtx(), C_DocType_ID); // wrong for SERVER, but r/o
if (dt != null && !dt.isDocNoControlled()) if (dt != null && !dt.isDocNoControlled())
{ {
@ -648,17 +648,17 @@ public class MSequence extends X_AD_Sequence
s_log.warning ("No Definite Sequence for DocType - " + dt); s_log.warning ("No Definite Sequence for DocType - " + dt);
return null; return null;
} }
// Check AdempiereSys // Check AdempiereSys
boolean adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS); boolean adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS);
if (CLogMgt.isLevel(LOGLEVEL)) if (CLogMgt.isLevel(LOGLEVEL))
s_log.log(LOGLEVEL, "DocType_ID=" + C_DocType_ID + " [" + trxName + "]"); s_log.log(LOGLEVEL, "DocType_ID=" + C_DocType_ID + " [" + trxName + "]");
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
boolean isStartNewYear = false; boolean isStartNewYear = false;
String dateColumn = null; String dateColumn = null;
if (!adempiereSys) if (!adempiereSys)
{ {
// Get the Start New Year & Sequence Type // Get the Start New Year & Sequence Type
@ -681,22 +681,22 @@ public class MSequence extends X_AD_Sequence
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
} }
String selectSQL = null; String selectSQL = null;
if (DB.isOracle() == false) if (DB.isOracle() == false)
{ {
if (isStartNewYear) if (isStartNewYear)
{ {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Client_ID, s.AD_Sequence_ID " selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Client_ID, s.AD_Sequence_ID "
+ "FROM AD_Sequence_No y, AD_Sequence s " + "FROM AD_Sequence_No y, AD_Sequence s "
+ "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID " + "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID "
+ "AND s.AD_Sequence_ID = ? " + "AND s.AD_Sequence_ID = ? "
+ "AND y.CalendarYear = ? " + "AND y.CalendarYear = ? "
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' " + "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' "
+ "FOR UPDATE OF y"; + "FOR UPDATE OF y";
} }
else else
{ {
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Client_ID, AD_Sequence_ID " selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Client_ID, AD_Sequence_ID "
+ "FROM AD_Sequence " + "FROM AD_Sequence "
+ "WHERE AD_Sequence_ID = ? " + "WHERE AD_Sequence_ID = ? "
@ -704,13 +704,13 @@ public class MSequence extends X_AD_Sequence
+ "FOR UPDATE OF AD_Sequence"; + "FOR UPDATE OF AD_Sequence";
} }
USE_PROCEDURE=false; USE_PROCEDURE=false;
} }
else else
{ {
if (isStartNewYear) { if (isStartNewYear) {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Client_ID, s.AD_Sequence_ID " selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Client_ID, s.AD_Sequence_ID "
+ "FROM AD_Sequence_No y, AD_Sequence s " + "FROM AD_Sequence_No y, AD_Sequence s "
+ "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID " + "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID "
+ "AND s.AD_Sequence_ID = ? " + "AND s.AD_Sequence_ID = ? "
+ "AND y.CalendarYear = ? " + "AND y.CalendarYear = ? "
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' "; + "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' ";
@ -741,8 +741,8 @@ public class MSequence extends X_AD_Sequence
// Error // Error
if (conn == null) if (conn == null)
return null; return null;
if (isStartNewYear) if (isStartNewYear)
{ {
if (po != null && dateColumn != null && dateColumn.length() > 0) if (po != null && dateColumn != null && dateColumn.length() > 0)
{ {
@ -756,7 +756,7 @@ public class MSequence extends X_AD_Sequence
calendarYear = sdf.format(new Date()); calendarYear = sdf.format(new Date());
} }
} }
pstmt = conn.prepareStatement(selectSQL, pstmt = conn.prepareStatement(selectSQL,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
if (definite) if (definite)
@ -765,10 +765,10 @@ public class MSequence extends X_AD_Sequence
pstmt.setInt(1, dt.getDocNoSequence_ID()); pstmt.setInt(1, dt.getDocNoSequence_ID());
if (isStartNewYear) if (isStartNewYear)
pstmt.setString(2, calendarYear); pstmt.setString(2, calendarYear);
// //
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
// s_log.fine("AC=" + conn.getAutoCommit() + " -Iso=" + conn.getTransactionIsolation() // s_log.fine("AC=" + conn.getAutoCommit() + " -Iso=" + conn.getTransactionIsolation()
// + " - Type=" + pstmt.getResultSetType() + " - Concur=" + pstmt.getResultSetConcurrency()); // + " - Type=" + pstmt.getResultSetType() + " - Concur=" + pstmt.getResultSetConcurrency());
if (rs.next()) if (rs.next())
{ {
@ -780,24 +780,24 @@ public class MSequence extends X_AD_Sequence
if (adempiereSys && AD_Client_ID > 11) if (adempiereSys && AD_Client_ID > 11)
adempiereSys = false; adempiereSys = false;
AD_Sequence_ID = rs.getInt(8); AD_Sequence_ID = rs.getInt(8);
if (USE_PROCEDURE) if (USE_PROCEDURE)
{ {
next = isStartNewYear next = isStartNewYear
? nextIDByYear(conn, AD_Sequence_ID, incrementNo, calendarYear) ? nextIDByYear(conn, AD_Sequence_ID, incrementNo, calendarYear)
: nextID(conn, AD_Sequence_ID, adempiereSys); : nextID(conn, AD_Sequence_ID, adempiereSys);
} }
else else
{ {
PreparedStatement updateSQL = null; PreparedStatement updateSQL = null;
try try
{ {
if (adempiereSys) { if (adempiereSys) {
updateSQL = conn updateSQL = conn
.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?"); .prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
next = rs.getInt(2); next = rs.getInt(2);
} else { } else {
String sql = isStartNewYear String sql = isStartNewYear
? "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ? AND CalendarYear = ?" ? "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ? AND CalendarYear = ?"
: "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?"; : "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?";
updateSQL = conn.prepareStatement(sql); updateSQL = conn.prepareStatement(sql);
@ -809,7 +809,7 @@ public class MSequence extends X_AD_Sequence
updateSQL.setString(3, calendarYear); updateSQL.setString(3, calendarYear);
updateSQL.executeUpdate(); updateSQL.executeUpdate();
} }
finally finally
{ {
DB.close(updateSQL); DB.close(updateSQL);
} }
@ -862,14 +862,14 @@ public class MSequence extends X_AD_Sequence
if (suffix != null && suffix.length() > 0) if (suffix != null && suffix.length() > 0)
doc.append(Env.parseVariable(suffix, po, trxName, false)); doc.append(Env.parseVariable(suffix, po, trxName, false));
String documentNo = doc.toString(); String documentNo = doc.toString();
s_log.finer (documentNo + " (" + incrementNo + ")" s_log.finer (documentNo + " (" + incrementNo + ")"
+ " - C_DocType_ID=" + C_DocType_ID + " [" + trx + "]"); + " - C_DocType_ID=" + C_DocType_ID + " [" + trx + "]");
return documentNo; return documentNo;
} // getDocumentNo } // getDocumentNo
/************************************************************************** /**************************************************************************
* Check/Initialize Client DocumentNo/Value Sequences * Check/Initialize Client DocumentNo/Value Sequences
* @param ctx context * @param ctx context
* @param AD_Client_ID client * @param AD_Client_ID client
* @param trxName transaction * @param trxName transaction
@ -923,12 +923,12 @@ public class MSequence extends X_AD_Sequence
rs = null; rs = null;
pstmt = null; pstmt = null;
} }
s_log.info ("AD_Client_ID=" + AD_Client_ID s_log.info ("AD_Client_ID=" + AD_Client_ID
+ " - created #" + counter + " - created #" + counter
+ " - success=" + success); + " - success=" + success);
return success; return success;
} // checkClientSequences } // checkClientSequences
/** /**
* Create Table ID Sequence * Create Table ID Sequence
@ -940,7 +940,7 @@ public class MSequence extends X_AD_Sequence
public static boolean createTableSequence (Properties ctx, String TableName, String trxName) public static boolean createTableSequence (Properties ctx, String TableName, String trxName)
{ {
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE",false); boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE",false);
if(SYSTEM_NATIVE_SEQUENCE) if(SYSTEM_NATIVE_SEQUENCE)
{ {
int next_id = MSequence.getNextID(Env.getAD_Client_ID(ctx), TableName, trxName); int next_id = MSequence.getNextID(Env.getAD_Client_ID(ctx), TableName, trxName);
@ -954,13 +954,13 @@ public class MSequence extends X_AD_Sequence
seq.saveEx(); seq.saveEx();
next_id = 1000000; next_id = 1000000;
} }
if(CConnection.get().getDatabase().createSequence(TableName+"_SEQ", 1, 0 , 99999999, next_id, trxName)) if(CConnection.get().getDatabase().createSequence(TableName+"_SEQ", 1, 0 , 99999999, next_id, trxName))
return true; return true;
return false; return false;
} }
MSequence seq = new MSequence (ctx, 0, trxName); MSequence seq = new MSequence (ctx, 0, trxName);
seq.setClientOrg(0, 0); seq.setClientOrg(0, 0);
seq.setName(TableName); seq.setName(TableName);
@ -968,7 +968,7 @@ public class MSequence extends X_AD_Sequence
seq.setIsTableID(true); seq.setIsTableID(true);
return seq.save(); return seq.save();
} // createTableSequence } // createTableSequence
/** /**
* Get Sequence * Get Sequence
@ -976,11 +976,11 @@ public class MSequence extends X_AD_Sequence
* @param tableName table name * @param tableName table name
* @return Sequence * @return Sequence
*/ */
public static MSequence get (Properties ctx, String tableName) public static MSequence get (Properties ctx, String tableName)
{ {
return get(ctx, tableName, null); return get(ctx, tableName, null);
} }
/** /**
* Get Sequence * Get Sequence
* @param ctx context * @param ctx context
@ -1018,19 +1018,19 @@ public class MSequence extends X_AD_Sequence
} }
return retValue; return retValue;
} // get } // get
/** Sequence for Table Document No's */ /** Sequence for Table Document No's */
private static final String PREFIX_DOCSEQ = "DocumentNo_"; private static final String PREFIX_DOCSEQ = "DocumentNo_";
/** Start Number */ /** Start Number */
public static final int INIT_NO = 1000000; // 1 Mio public static final int INIT_NO = 1000000; // 1 Mio
/** Start System Number */ /** Start System Number */
// public static final int INIT_SYS_NO = 100; // start number for Compiere // public static final int INIT_SYS_NO = 100; // start number for Compiere
public static final int INIT_SYS_NO = 50000; // start number for Adempiere public static final int INIT_SYS_NO = 50000; // start number for Adempiere
/** Static Logger */ /** Static Logger */
private static CLogger s_log = CLogger.getCLogger(MSequence.class); private static CLogger s_log = CLogger.getCLogger(MSequence.class);
/************************************************************************** /**************************************************************************
* Standard Constructor * Standard Constructor
* @param ctx context * @param ctx context
@ -1080,7 +1080,7 @@ public class MSequence extends X_AD_Sequence
setName(PREFIX_DOCSEQ + tableName); setName(PREFIX_DOCSEQ + tableName);
setDescription("DocumentNo/Value for Table " + tableName); setDescription("DocumentNo/Value for Table " + tableName);
} // MSequence; } // MSequence;
/** /**
* New Document Sequence Constructor * New Document Sequence Constructor
* @param ctx context * @param ctx context
@ -1099,8 +1099,8 @@ public class MSequence extends X_AD_Sequence
setCurrentNext(StartNo); setCurrentNext(StartNo);
setCurrentNextSys(StartNo/10); setCurrentNextSys(StartNo/10);
} // MSequence; } // MSequence;
/************************************************************************** /**************************************************************************
* Get Next No and increase current next * Get Next No and increase current next
* @return next no to use * @return next no to use
@ -1111,7 +1111,7 @@ public class MSequence extends X_AD_Sequence
setCurrentNext(retValue + getIncrementNo()); setCurrentNext(retValue + getIncrementNo());
return retValue; return retValue;
} // getNextNo } // getNextNo
/** /**
* Validate Table Sequence Values * Validate Table Sequence Values
* @return true if updated * @return true if updated
@ -1135,7 +1135,7 @@ public class MSequence extends X_AD_Sequence
IDRangeEnd = system.getIDRangeEnd().intValue(); IDRangeEnd = system.getIDRangeEnd().intValue();
boolean change = false; boolean change = false;
String info = null; String info = null;
// Current Next // Current Next
String sql = "SELECT MAX(" + tableName + "_ID) FROM " + tableName; String sql = "SELECT MAX(" + tableName + "_ID) FROM " + tableName;
if (IDRangeEnd > 0) if (IDRangeEnd > 0)
@ -1147,7 +1147,7 @@ public class MSequence extends X_AD_Sequence
if (getCurrentNext() < maxTableID) if (getCurrentNext() < maxTableID)
{ {
setCurrentNext(maxTableID); setCurrentNext(maxTableID);
info = "CurrentNext=" + maxTableID; info = "CurrentNext=" + maxTableID;
change = true; change = true;
} }
@ -1171,8 +1171,8 @@ public class MSequence extends X_AD_Sequence
log.fine(getName() + " - " + info); log.fine(getName() + " - " + info);
return change; return change;
} // validate } // validate
/************************************************************************** /**************************************************************************
* Test * Test
* @param args ignored * @param args ignored
@ -1181,7 +1181,7 @@ public class MSequence extends X_AD_Sequence
{ {
// int id = getNextID_HTTP("AD_Column"); // int id = getNextID_HTTP("AD_Column");
// if (true) return; // if (true) return;
org.compiere.Adempiere.startup(true); org.compiere.Adempiere.startup(true);
CLogMgt.setLevel(Level.SEVERE); CLogMgt.setLevel(Level.SEVERE);
CLogMgt.setLoggerLevel(Level.SEVERE, null); CLogMgt.setLoggerLevel(Level.SEVERE, null);
@ -1195,25 +1195,25 @@ public class MSequence extends X_AD_Sequence
System.out.println(DB.getDocumentNo(118, trxName)); System.out.println(DB.getDocumentNo(118, trxName));
System.out.println(DB.getDocumentNo(118, trxName)); System.out.println(DB.getDocumentNo(118, trxName));
System.out.println(DB.getDocumentNo(117, trxName)); System.out.println(DB.getDocumentNo(117, trxName));
trxName = "test1"; trxName = "test1";
System.out.println(DB.getDocumentNo(115, trxName)); // hangs here as supposed System.out.println(DB.getDocumentNo(115, trxName)); // hangs here as supposed
System.out.println(DB.getDocumentNo(116, trxName)); System.out.println(DB.getDocumentNo(116, trxName));
System.out.println(DB.getDocumentNo(117, trxName)); System.out.println(DB.getDocumentNo(117, trxName));
System.out.println(DB.getDocumentNo(118, trxName)); System.out.println(DB.getDocumentNo(118, trxName));
/** **/ /** **/
/** Time Test */ /** Time Test */
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
Thread[] threads = new Thread[10]; Thread[] threads = new Thread[10];
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
Runnable r = new GetIDs(i); Runnable r = new GetIDs(i);
threads[i] = new Thread(r); threads[i] = new Thread(r);
threads[i].start(); threads[i].start();
} }
@ -1228,7 +1228,7 @@ public class MSequence extends X_AD_Sequence
} }
} }
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
System.out.println("-------------------------------------------"); System.out.println("-------------------------------------------");
System.out.println("Size=" + s_list.size() + " (should be 1000)"); System.out.println("Size=" + s_list.size() + " (should be 1000)");
Integer[] ia = new Integer[s_list.size()]; Integer[] ia = new Integer[s_list.size()];
@ -1253,9 +1253,9 @@ public class MSequence extends X_AD_Sequence
System.out.println("Duplicates=" + duplicates); System.out.println("Duplicates=" + duplicates);
System.out.println("Time (ms)=" + time + " - " + ((float)time/s_list.size()) + " each" ); System.out.println("Time (ms)=" + time + " - " + ((float)time/s_list.size()) + " each" );
System.out.println("-------------------------------------------"); System.out.println("-------------------------------------------");
/** ** /** **
try try
{ {
@ -1271,17 +1271,17 @@ public class MSequence extends X_AD_Sequence
sql += "FOR UPDATE"; sql += "FOR UPDATE";
// creates ORA-00907: missing right parenthesis // creates ORA-00907: missing right parenthesis
// sql += "FOR UPDATE OF CurrentNext, CurrentNextSys"; // sql += "FOR UPDATE OF CurrentNext, CurrentNextSys";
PreparedStatement pstmt = conn.prepareStatement(sql, PreparedStatement pstmt = conn.prepareStatement(sql,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
System.out.println("AC=" + conn.getAutoCommit() + ", RO=" + conn.isReadOnly() System.out.println("AC=" + conn.getAutoCommit() + ", RO=" + conn.isReadOnly()
+ " - Isolation=" + conn.getTransactionIsolation() + "(" + Connection.TRANSACTION_READ_COMMITTED + " - Isolation=" + conn.getTransactionIsolation() + "(" + Connection.TRANSACTION_READ_COMMITTED
+ ") - RSType=" + pstmt.getResultSetType() + "(" + ResultSet.TYPE_SCROLL_SENSITIVE + ") - RSType=" + pstmt.getResultSetType() + "(" + ResultSet.TYPE_SCROLL_SENSITIVE
+ "), RSConcur=" + pstmt.getResultSetConcurrency() + "(" + ResultSet.CONCUR_UPDATABLE + "), RSConcur=" + pstmt.getResultSetConcurrency() + "(" + ResultSet.CONCUR_UPDATABLE
+ ")"); + ")");
if (rs.next()) if (rs.next())
{ {
int IncrementNo = rs.getInt(3); int IncrementNo = rs.getInt(3);
@ -1297,23 +1297,23 @@ public class MSequence extends X_AD_Sequence
conn.close(); conn.close();
// //
System.out.println("Next=" + retValue); System.out.println("Next=" + retValue);
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace (); e.printStackTrace ();
} }
System.exit(0); System.exit(0);
/** ** /** **
int AD_Client_ID = 0; int AD_Client_ID = 0;
int C_DocType_ID = 115; // GL int C_DocType_ID = 115; // GL
String TableName = "C_Invoice"; String TableName = "C_Invoice";
String trxName = "x"; String trxName = "x";
Trx trx = Trx.get(trxName, true); Trx trx = Trx.get(trxName, true);
System.out.println ("none " + getNextID (0, "Test")); System.out.println ("none " + getNextID (0, "Test"));
System.out.println ("----------------------------------------------"); System.out.println ("----------------------------------------------");
System.out.println ("trx1 " + getNextID (0, "Test")); System.out.println ("trx1 " + getNextID (0, "Test"));
@ -1324,12 +1324,12 @@ public class MSequence extends X_AD_Sequence
System.out.println ("trx4 " + getNextID (0, "Test")); System.out.println ("trx4 " + getNextID (0, "Test"));
// trx.rollback(); // trx.rollback();
// trx.close(); // trx.close();
System.out.println ("----------------------------------------------"); System.out.println ("----------------------------------------------");
System.out.println ("none " + getNextID (0, "Test")); System.out.println ("none " + getNextID (0, "Test"));
System.out.println ("=============================================="); System.out.println ("==============================================");
trx = Trx.get(trxName, true);
trx = Trx.get(trxName, true);
System.out.println ("none " + getDocumentNo(AD_Client_ID, TableName, null)); System.out.println ("none " + getDocumentNo(AD_Client_ID, TableName, null));
System.out.println ("----------------------------------------------"); System.out.println ("----------------------------------------------");
System.out.println ("trx1 " + getDocumentNo(AD_Client_ID, TableName, trxName)); System.out.println ("trx1 " + getDocumentNo(AD_Client_ID, TableName, trxName));
@ -1340,12 +1340,12 @@ public class MSequence extends X_AD_Sequence
System.out.println ("trx4 " + getDocumentNo(AD_Client_ID, TableName, trxName)); System.out.println ("trx4 " + getDocumentNo(AD_Client_ID, TableName, trxName));
trx.rollback(); trx.rollback();
trx.close(); trx.close();
System.out.println ("----------------------------------------------"); System.out.println ("----------------------------------------------");
System.out.println ("none " + getDocumentNo(AD_Client_ID, TableName, null)); System.out.println ("none " + getDocumentNo(AD_Client_ID, TableName, null));
System.out.println ("=============================================="); System.out.println ("==============================================");
trx = Trx.get(trxName, true); trx = Trx.get(trxName, true);
System.out.println ("none " + getDocumentNo(C_DocType_ID, null)); System.out.println ("none " + getDocumentNo(C_DocType_ID, null));
System.out.println ("----------------------------------------------"); System.out.println ("----------------------------------------------");
System.out.println ("trx1 " + getDocumentNo(C_DocType_ID, trxName)); System.out.println ("trx1 " + getDocumentNo(C_DocType_ID, trxName));
@ -1356,18 +1356,18 @@ public class MSequence extends X_AD_Sequence
System.out.println ("trx4 " + getDocumentNo(C_DocType_ID, trxName)); System.out.println ("trx4 " + getDocumentNo(C_DocType_ID, trxName));
trx.rollback(); trx.rollback();
trx.close(); trx.close();
System.out.println ("----------------------------------------------"); System.out.println ("----------------------------------------------");
System.out.println ("none " + getDocumentNo(C_DocType_ID, null)); System.out.println ("none " + getDocumentNo(C_DocType_ID, null));
System.out.println ("=============================================="); System.out.println ("==============================================");
/** **/ /** **/
} // main } // main
/** Test */ /** Test */
private static Vector<Integer> s_list = null; private static Vector<Integer> s_list = null;
/** /**
* Test Sequence - Get IDs * Test Sequence - Get IDs
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MSequence.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $ * @version $Id: MSequence.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
*/ */
@ -1382,7 +1382,7 @@ public class MSequence extends X_AD_Sequence
m_i = i; m_i = i;
} }
private int m_i; private int m_i;
/** /**
* Run * Run
*/ */
@ -1403,7 +1403,7 @@ public class MSequence extends X_AD_Sequence
} }
} }
} // GetIDs } // GetIDs
/** /**
* Get next number for Key column * Get next number for Key column
* @param AD_Client_ID client * @param AD_Client_ID client
@ -1420,11 +1420,11 @@ public class MSequence extends X_AD_Sequence
String prm_ALTKEY = ""; // TODO: generate alt-key based on key of table String prm_ALTKEY = ""; // TODO: generate alt-key based on key of table
String prm_COMMENT = MSysConfig.getValue("DICTIONARY_ID_COMMENTS"); String prm_COMMENT = MSysConfig.getValue("DICTIONARY_ID_COMMENTS");
String prm_PROJECT = new String("Adempiere"); String prm_PROJECT = new String("Adempiere");
return getNextID_HTTP(TableName, website, prm_USER, return getNextID_HTTP(TableName, website, prm_USER,
prm_PASSWORD, prm_TABLE, prm_ALTKEY, prm_COMMENT, prm_PROJECT); prm_PASSWORD, prm_TABLE, prm_ALTKEY, prm_COMMENT, prm_PROJECT);
} }
/** /**
* Get next number for Key column * Get next number for Key column
* @param AD_Client_ID client * @param AD_Client_ID client
@ -1441,7 +1441,7 @@ public class MSequence extends X_AD_Sequence
String prm_ALTKEY = ""; // TODO: generate alt-key based on key of table String prm_ALTKEY = ""; // TODO: generate alt-key based on key of table
String prm_COMMENT = MSysConfig.getValue("PROJECT_ID_COMMENTS"); String prm_COMMENT = MSysConfig.getValue("PROJECT_ID_COMMENTS");
String prm_PROJECT = MSysConfig.getValue("PROJECT_ID_PROJECT"); String prm_PROJECT = MSysConfig.getValue("PROJECT_ID_PROJECT");
return getNextID_HTTP(TableName, website, prm_USER, return getNextID_HTTP(TableName, website, prm_USER,
prm_PASSWORD, prm_TABLE, prm_ALTKEY, prm_COMMENT, prm_PROJECT); prm_PASSWORD, prm_TABLE, prm_ALTKEY, prm_COMMENT, prm_PROJECT);
} }
@ -1460,7 +1460,7 @@ public class MSequence extends X_AD_Sequence
+ URLEncoder.encode(prm_TABLE, "UTF-8") + "&ALTKEY=" + URLEncoder.encode(prm_TABLE, "UTF-8") + "&ALTKEY="
+ URLEncoder.encode(prm_ALTKEY, "UTF-8") + "&COMMENT=" + URLEncoder.encode(prm_ALTKEY, "UTF-8") + "&COMMENT="
+ URLEncoder.encode(prm_COMMENT, "UTF-8"); + URLEncoder.encode(prm_COMMENT, "UTF-8");
// Now use the URL class to parse the user-specified URL into // Now use the URL class to parse the user-specified URL into
// its various parts: protocol, host, port, filename. Check the protocol // its various parts: protocol, host, port, filename. Check the protocol
URL url = new URL(completeUrl); URL url = new URL(completeUrl);
@ -1475,7 +1475,7 @@ public class MSequence extends X_AD_Sequence
Socket socket = new Socket(host, port); Socket socket = new Socket(host, port);
// Get input and output streams for the socket // Get input and output streams for the socket
InputStream from_server = socket.getInputStream(); InputStream from_server = socket.getInputStream();
PrintWriter to_server = PrintWriter to_server =
new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
// Send the HTTP GET command to the Web server, specifying the file. // Send the HTTP GET command to the Web server, specifying the file.
@ -1503,11 +1503,11 @@ public class MSequence extends X_AD_Sequence
System.err.println(e); System.err.println(e);
retValue = -1; retValue = -1;
} }
s_log.log(Level.INFO, "getNextID_HTTP - " + TableName + "=" + read + "(" + retValue + ")"); s_log.log(Level.INFO, "getNextID_HTTP - " + TableName + "=" + read + "(" + retValue + ")");
return retValue; return retValue;
} }
private static boolean isExceptionCentralized(String tableName) { private static boolean isExceptionCentralized(String tableName) {
String [] exceptionTables = new String[] { String [] exceptionTables = new String[] {
"AD_ACCESSLOG", "AD_ACCESSLOG",
@ -1553,7 +1553,7 @@ public class MSequence extends X_AD_Sequence
// don't log selects or insert/update for exception tables (i.e. AD_Issue, AD_ChangeLog) // don't log selects or insert/update for exception tables (i.e. AD_Issue, AD_ChangeLog)
return false; return false;
} }
/** /**
* Get preliminary document no by year * Get preliminary document no by year
* @param tab * @param tab
@ -1563,12 +1563,12 @@ public class MSequence extends X_AD_Sequence
*/ */
public static String getPreliminaryNoByYear(GridTab tab, int AD_Sequence_ID, String dateColumn, String trxName) { public static String getPreliminaryNoByYear(GridTab tab, int AD_Sequence_ID, String dateColumn, String trxName) {
Date d = (Date)tab.getValue(dateColumn); Date d = (Date)tab.getValue(dateColumn);
if (d == null) if (d == null)
d = new Date(); d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
String calendarYear = sdf.format(d); String calendarYear = sdf.format(d);
String sql = "select CurrentNext From AD_Sequence_No Where AD_Sequence_ID = ? and CalendarYear = ?"; String sql = "select CurrentNext From AD_Sequence_No Where AD_Sequence_ID = ? and CalendarYear = ?";
return DB.getSQLValueString(trxName, sql, AD_Sequence_ID, calendarYear); return DB.getSQLValueString(trxName, sql, AD_Sequence_ID, calendarYear);
} }