[ 1949319 ] ReportEngine doesn't work inside transaction

This commit is contained in:
Heng Sin Low 2008-04-23 02:09:14 +00:00
parent 6cf931088b
commit 9e5979268e
3 changed files with 78 additions and 11 deletions

View File

@ -60,8 +60,18 @@ public class DataEngine
*/
public DataEngine (Language language)
{
this(language, null);
} // DataEngine
/**
* Constructor
* @param language Language of the data (for translation)
* @param trxName
*/
public DataEngine (Language language, String trxName){
if (language != null)
m_language = language;
m_trxName = trxName;
} // DataEngine
/** Logger */
@ -80,6 +90,8 @@ public class DataEngine
private int m_runningTotalLines = -1;
/** Print String */
private String m_runningTotalString = null;
/** TrxName String */
private String m_trxName = null;
/** Key Indicator in Report */
public static final String KEY = "*";
@ -110,7 +122,7 @@ public class DataEngine
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, m_trxName);
pstmt.setInt(1, format.getAD_ReportView_ID());
rs = pstmt.executeQuery();
if (rs.next())
@ -213,7 +225,7 @@ public class DataEngine
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, m_trxName);
pstmt.setInt(1, format.get_ID());
rs = pstmt.executeQuery();
@ -715,7 +727,7 @@ public class DataEngine
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(pd.getSQL(), null);
pstmt = DB.prepareStatement(pd.getSQL(), m_trxName);
rs = pstmt.executeQuery();
// Row Loop
while (rs.next())

View File

@ -96,6 +96,19 @@ public class ReportEngine implements PrintServiceAttributeListener
* @param info print info
*/
public ReportEngine (Properties ctx, MPrintFormat pf, MQuery query, PrintInfo info)
{
this(ctx, pf, query, info, null);
} // ReportEngine
/**
* Constructor
* @param ctx context
* @param pf Print Format
* @param query Optional Query
* @param info print info
* @param trxName
*/
public ReportEngine (Properties ctx, MPrintFormat pf, MQuery query, PrintInfo info, String trxName)
{
if (pf == null)
throw new IllegalArgumentException("ReportEngine - no PrintFormat");
@ -104,7 +117,9 @@ public class ReportEngine implements PrintServiceAttributeListener
//
m_printFormat = pf;
m_info = info;
m_trxName = trxName;
setQuery(query); // loads Data
} // ReportEngine
/** Static Logger */
@ -127,7 +142,9 @@ public class ReportEngine implements PrintServiceAttributeListener
private String m_printerName = Ini.getProperty(Ini.P_PRINTER);
/** View */
private View m_view = null;
/** Transaction Name */
private String m_trxName = null;
/**
* Set PrintFormat.
* If Layout was created, re-create layout
@ -145,7 +162,7 @@ public class ReportEngine implements PrintServiceAttributeListener
if (m_view != null)
m_view.revalidate();
} // setPrintFormat
/**
* Set Query and generate PrintData.
* If Layout was created, re-create layout
@ -182,11 +199,13 @@ public class ReportEngine implements PrintServiceAttributeListener
{
if (m_query == null)
return;
DataEngine de = new DataEngine(m_printFormat.getLanguage());
DataEngine de = new DataEngine(m_printFormat.getLanguage(),m_trxName);
setPrintData(de.getPrintData (m_ctx, m_printFormat, m_query));
// m_printData.dump();
} // setPrintData
/**
* Get PrintData
* @return print data
@ -217,7 +236,7 @@ public class ReportEngine implements PrintServiceAttributeListener
throw new IllegalStateException ("No print format");
if (m_printData == null)
throw new IllegalStateException ("No print data (Delete Print Format and restart)");
m_layout = new LayoutEngine (m_printFormat, m_printData, m_query);
m_layout = new LayoutEngine (m_printFormat, m_printData, m_query, m_trxName);
} // layout
/**
@ -1069,7 +1088,6 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
X_C_PaySelectionCheck.Table_ID, X_C_PaySelectionCheck.Table_ID,
X_C_DunningRunEntry.Table_ID };
/**************************************************************************
* Get Document Print Engine for Document Type.
* @param ctx context
@ -1078,6 +1096,19 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
* @return Report Engine or null
*/
public static ReportEngine get (Properties ctx, int type, int Record_ID)
{
return get(ctx, type, Record_ID, null);
}
/**************************************************************************
* Get Document Print Engine for Document Type.
* @param ctx context
* @param type document type
* @param Record_ID id
* @param trxName
* @return Report Engine or null
*/
public static ReportEngine get (Properties ctx, int type, int Record_ID, String trxName)
{
if (Record_ID < 1)
{
@ -1177,7 +1208,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt = DB.prepareStatement(sql, trxName);
pstmt.setInt(1, Record_ID);
rs = pstmt.executeQuery();
if (rs.next()) // first record only
@ -1252,7 +1283,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
info.setPrinterName(format.getPrinterName());
// Engine
ReportEngine re = new ReportEngine(ctx, format, query, info);
ReportEngine re = new ReportEngine(ctx, format, query, info, trxName);
return re;
} // get

View File

@ -56,6 +56,19 @@ public class LayoutEngine implements Pageable, Printable, Doc
*/
public LayoutEngine (MPrintFormat format, PrintData data, MQuery query)
{
this(format, data, query, null);
} // LayoutEngine
/**
* Detail Constructor
* @param format Print Format
* @param data Print Data
* @param query query for parameter info
* @param trxName
*/
public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, String trxName)
{
m_TrxName = trxName;
log.info(format + " - " + data + " - " + query);
// s_FASTDRAW = MClient.get(format.getCtx()).isUseBetaFunctions();
//
@ -85,6 +98,8 @@ public class LayoutEngine implements Pageable, Printable, Doc
private MPrintFont m_printFont;
/** Printed Column Count */
private int m_columnCount = -1;
/** Transaction name */
private String m_TrxName = null;
/** Paper - default: standard portrait */
@ -214,6 +229,15 @@ public class LayoutEngine implements Pageable, Printable, Doc
if (m_hasLayout && doLayout)
layout(); // re-calculate
} // setPrintData
public void setPrintData (PrintData data, MQuery query, boolean doLayout, String trxName)
{
m_data = data;
m_query = query;
m_TrxName = trxName;
if (m_hasLayout && doLayout)
layout(); // re-calculate
} // setPrintData
/**************************************************************************
@ -1109,7 +1133,7 @@ public class LayoutEngine implements Pageable, Printable, Doc
format.setTranslationViewQuery(query);
log.fine(query.toString());
//
DataEngine de = new DataEngine(format.getLanguage());
DataEngine de = new DataEngine(format.getLanguage(),m_TrxName);
PrintData includedData = de.getPrintData(data.getCtx(), format, query);
if (includedData == null)
return null;