diff --git a/base/src/org/adempiere/pipo/AbstractElementHandler.java b/base/src/org/adempiere/pipo/AbstractElementHandler.java index acfd9fd446..eb3ed83e70 100644 --- a/base/src/org/adempiere/pipo/AbstractElementHandler.java +++ b/base/src/org/adempiere/pipo/AbstractElementHandler.java @@ -287,7 +287,7 @@ public abstract class AbstractElementHandler implements ElementHandler { fileTarget = new FileInputStream(filePath); } catch (FileNotFoundException e ) { - System.out.println("Can't find file "); + System.out.println("File not found: " + filePath); return null; } @@ -308,7 +308,7 @@ public abstract class AbstractElementHandler implements ElementHandler { fileTarget = new FileOutputStream(filePath); } catch (FileNotFoundException e ) { - System.out.println("Can't find file "); + System.out.println("File not found: " + filePath); return null; } diff --git a/base/src/org/adempiere/pipo/IDFinder.java b/base/src/org/adempiere/pipo/IDFinder.java index 1d4e6b2e89..6cb0df0b4b 100644 --- a/base/src/org/adempiere/pipo/IDFinder.java +++ b/base/src/org/adempiere/pipo/IDFinder.java @@ -20,6 +20,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.logging.Level; +import org.adempiere.pipo.exception.DatabaseAccessException; import org.compiere.util.CLogger; import org.compiere.util.DB; @@ -66,6 +67,7 @@ public class IDFinder { } catch (Exception e) { log.info ("get_ID:"+e); + throw new DatabaseAccessException(e); } return id; } @@ -113,7 +115,8 @@ public class IDFinder { pstmt = null; } catch (Exception e) { - log.info ("get_ID:"+e); + log.info ("get_IDWithColumn:"+e); + throw new DatabaseAccessException(e); } return id; } @@ -154,6 +157,7 @@ public class IDFinder { } catch (Exception e) { log.info ("get_IDWithMaster:"+e); + throw new DatabaseAccessException(e); } return id; } @@ -196,6 +200,7 @@ public class IDFinder { } catch (Exception e) { log.info ("get_IDWithMasterAndColumn:"+e); + throw new DatabaseAccessException(e); } return id; } @@ -232,6 +237,7 @@ public class IDFinder { } catch (Exception e) { log.info ("get_IDWithMasterID:"+e); + throw new DatabaseAccessException(e); } return id; } @@ -269,7 +275,8 @@ public class IDFinder { pstmt = null; } catch (Exception e) { - log.log(Level.SEVERE, "getID:"+e); + log.log(Level.SEVERE, "getIDbyName:"+e); + throw new DatabaseAccessException(e); } return id; } diff --git a/base/src/org/adempiere/pipo/handler/ColumnElementHandler.java b/base/src/org/adempiere/pipo/handler/ColumnElementHandler.java index 1010a69a66..e38155d422 100644 --- a/base/src/org/adempiere/pipo/handler/ColumnElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/ColumnElementHandler.java @@ -17,6 +17,7 @@ package org.adempiere.pipo.handler; import java.math.BigDecimal; +import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; @@ -36,6 +37,7 @@ import org.compiere.model.X_AD_Column; import org.compiere.model.X_AD_Element; import org.compiere.util.DB; import org.compiere.util.Env; +import org.compiere.util.Trx; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; @@ -219,9 +221,9 @@ public class ColumnElementHandler extends AbstractElementHandler { recreateColumn = false; } - if (tableName.equals("A_Depreciation") && columnName.equals("Processed")) { + /*if (tableName.equals("A_Depreciation") && columnName.equals("Processed")) { System.out.println("A_Depreciation.Processed: " + recreateColumn); - } + }*/ if (m_Column.save(getTrxName(ctx)) == true) { record_log(ctx, 1, m_Column.getName(), "Column", m_Column @@ -281,9 +283,15 @@ public class ColumnElementHandler extends AbstractElementHandler { String sql = null; ResultSet rst = null; ResultSet rsc = null; + Connection conn = null; + Trx trx = Trx.get(getTrxName(ctx), true); + if (!trx.commit()) + return 0; + try { // Find Column in Database - DatabaseMetaData md = DB.getConnectionRO().getMetaData(); + conn = trx.getConnection(); + DatabaseMetaData md = conn.getMetaData(); String catalog = DB.getDatabase().getCatalog(); String schema = DB.getDatabase().getSchema(); String tableName = table.getTableName(); @@ -327,14 +335,16 @@ public class ColumnElementHandler extends AbstractElementHandler { log.info(sql); if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) { - no = DB.executeUpdate(sql, false, getTrxName(ctx)); + System.out.println(sql); + no = DB.executeUpdate(sql, false, trx.getTrxName()); if (no == -1) return 0; } else { String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR); for (int i = 0; i < statements.length; i++) { + System.out.println(statements[i]); int count = DB.executeUpdate(statements[i], false, - getTrxName(ctx)); + trx.getTrxName()); if (count == -1) { return 0; } @@ -342,6 +352,7 @@ public class ColumnElementHandler extends AbstractElementHandler { } } } + trx.commit(true); } catch (SQLException e) { log.log(Level.SEVERE, e.getLocalizedMessage(), e); if (rsc != null) { @@ -358,18 +369,9 @@ public class ColumnElementHandler extends AbstractElementHandler { } rst = null; } + trx.rollback(); return 0; - } - - // postgres requires commit on DDL (ALTER,CREATE) - if (DB.isPostgreSQL()) { - try { - DB.commit(true, getTrxName(ctx)); - } catch (SQLException e) { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - return 0; - } - } + } return 1; } diff --git a/base/src/org/adempiere/pipo/handler/ProcessElementHandler.java b/base/src/org/adempiere/pipo/handler/ProcessElementHandler.java index df388c7f52..50de7f01e4 100644 --- a/base/src/org/adempiere/pipo/handler/ProcessElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/ProcessElementHandler.java @@ -142,6 +142,7 @@ public class ProcessElementHandler extends AbstractElementHandler { .get_ID(), AD_Backup_ID, Object_Status, "AD_Process", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Process")); + element.recordId = m_Process.getAD_Process_ID(); } else { record_log(ctx, 0, m_Process.getName(), "Process", m_Process .get_ID(), AD_Backup_ID, Object_Status, "AD_Process", diff --git a/base/src/org/adempiere/pipo/handler/ProcessParaElementHandler.java b/base/src/org/adempiere/pipo/handler/ProcessParaElementHandler.java index 77d308fa28..9b29e9fe75 100644 --- a/base/src/org/adempiere/pipo/handler/ProcessParaElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/ProcessParaElementHandler.java @@ -41,10 +41,38 @@ public class ProcessParaElementHandler extends AbstractElementHandler { String entitytype = atts.getValue("EntityType"); if (isProcessElement(ctx, entitytype)) { + if (element.parent != null && element.parent.getElementValue().equals("process") && + element.parent.defer) { + element.defer = true; + return; + } + String name = atts.getValue("Name"); - int id = get_IDWithMaster(ctx, "AD_Process_Para", name, - "AD_Process", atts.getValue("ADProcessNameID")); + int id = 0; + int masterId = 0; + String processValue = ""; + if (element.parent != null && element.parent.getElementValue().equals("process") && + element.parent.recordId > 0) { + masterId = element.parent.recordId; + } else { + processValue = atts.getValue("ADProcessValueID"); + if (processValue != null && processValue.trim().length() > 0) { + masterId = get_IDWithColumn(ctx, "AD_Process", "Value", processValue); + } else { + //for backward compatibility + processValue = atts.getValue("ADProcessNameID"); + masterId = get_IDWithColumn(ctx, "AD_Process", "Name", processValue); + } + } + if (masterId <= 0) { + element.defer = true; + element.unresolved = "AD_Process: " + processValue; + return; + } + id = get_IDWithMasterAndColumn(ctx, "AD_Process_Para", "Name", + name, "AD_Process", masterId); + X_AD_Process_Para m_Process_para = new X_AD_Process_Para(ctx, id, getTrxName(ctx)); int AD_Backup_ID = -1; @@ -58,14 +86,8 @@ public class ProcessParaElementHandler extends AbstractElementHandler { AD_Backup_ID = 0; } m_Process_para.setName(atts.getValue("Name")); - name = atts.getValue("ADProcessNameID"); - id = get_IDWithColumn(ctx, "AD_Process", "Name", name); - if (id <= 0) { - element.defer = true; - element.unresolved = "AD_Process: " + name; - return; - } - m_Process_para.setAD_Process_ID(id); + + m_Process_para.setAD_Process_ID(masterId); m_Process_para.setColumnName(atts.getValue("ColumnName")); m_Process_para.setEntityType(atts.getValue("EntityType")); @@ -200,12 +222,12 @@ public class ProcessParaElementHandler extends AbstractElementHandler { (m_Processpara.getName() != null ? m_Processpara .getName() : "")); if (m_Processpara.getAD_Process_ID() > 0) { - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + sql = "SELECT Value FROM AD_Process WHERE AD_Process_ID=?"; name = DB.getSQLValueString(null, sql, m_Processpara .getAD_Process_ID()); - atts.addAttribute("", "", "ADProcessNameID", "CDATA", name); + atts.addAttribute("", "", "ADProcessValueID", "CDATA", name); } else - atts.addAttribute("", "", "ADProcessNameID", "CDATA", ""); + atts.addAttribute("", "", "ADProcessValueID", "CDATA", ""); if (m_Processpara.getAD_Process_Para_ID() > 0) { sql = "SELECT Name FROM AD_Process_Para WHERE AD_Process_Para_ID=?"; name = DB.getSQLValueString(null, sql, m_Processpara diff --git a/base/src/org/adempiere/pipo/handler/ReferenceElementHandler.java b/base/src/org/adempiere/pipo/handler/ReferenceElementHandler.java index e938da02a0..0f3afccb5f 100644 --- a/base/src/org/adempiere/pipo/handler/ReferenceElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/ReferenceElementHandler.java @@ -90,6 +90,7 @@ public class ReferenceElementHandler extends AbstractElementHandler { "AD_Reference", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Reference")); references.add(m_Reference.getAD_Reference_ID()); + element.recordId = m_Reference.getAD_Reference_ID(); } else { record_log(ctx, 0, m_Reference.getName(), "Reference", m_Reference.get_ID(), AD_Backup_ID, Object_Status, diff --git a/base/src/org/adempiere/pipo/handler/ReferenceListElementHandler.java b/base/src/org/adempiere/pipo/handler/ReferenceListElementHandler.java index ea990fcdf0..61fdec5a1a 100644 --- a/base/src/org/adempiere/pipo/handler/ReferenceListElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/ReferenceListElementHandler.java @@ -48,8 +48,15 @@ public class ReferenceListElementHandler extends AbstractElementHandler { } String name = atts.getValue("Name"); String value = atts.getValue("Value"); - int AD_Reference_ID = get_IDWithColumn(ctx, "AD_Reference", "Name", - atts.getValue("ADRefenceNameID")); + int AD_Reference_ID = 0; + if (element.parent != null && element.parent.getElementValue().equals("reference") && + element.parent.recordId > 0) { + AD_Reference_ID = element.parent.recordId; + } else { + AD_Reference_ID = get_IDWithColumn(ctx, "AD_Reference", "Name", + atts.getValue("ADRefenceNameID")); + } + int AD_Ref_List_ID = get_IDWithMasterAndColumn(ctx, "AD_Ref_List", "Value", value, "AD_Reference", AD_Reference_ID); X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID, getTrxName(ctx)); diff --git a/base/src/org/adempiere/pipo/handler/ReferenceTableElementHandler.java b/base/src/org/adempiere/pipo/handler/ReferenceTableElementHandler.java index 8dfdf220a0..ced1a61105 100644 --- a/base/src/org/adempiere/pipo/handler/ReferenceTableElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/ReferenceTableElementHandler.java @@ -54,12 +54,19 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { return; } - StringBuffer sqlB = new StringBuffer( + int AD_Reference_ID = 0; + if (element.parent != null && element.parent.getElementValue().equals("reference") && + element.parent.recordId > 0) { + AD_Reference_ID = element.parent.recordId; + } else { + StringBuffer sqlB = new StringBuffer( "SELECT AD_Reference_ID FROM AD_Reference WHERE Name= ?"); - int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name); - sqlB = new StringBuffer( + AD_Reference_ID = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name); + } + + StringBuffer sqlB = new StringBuffer( "SELECT Count(*) FROM AD_Ref_Table WHERE AD_Reference_ID= ?"); - int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), id); + int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), AD_Reference_ID); int tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts .getValue("ADTableNameID")); if (tableId == 0) { @@ -141,17 +148,17 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { "', OrderByClause = '" + OrderByClause).append( "', EntityType ='" + entityType).append( "', WhereClause = '" + WhereClause).append( - "' WHERE AD_Reference_ID = " + id); + "' WHERE AD_Reference_ID = " + AD_Reference_ID); int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx)); if (no > 0) { record_log(ctx, 1, atts.getValue("ADRefenceNameID"), - "Reference Table", id, 0, "Update", "AD_Ref_Table", + "Reference Table", AD_Reference_ID, 0, "Update", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table")); } else { record_log(ctx, 0, atts.getValue("ADRefenceNameID"), - "Reference Table", id, 0, "Update", "AD_Ref_Table", + "Reference Table", AD_Reference_ID, 0, "Update", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table")); throw new POSaveFailedException("ReferenceTable"); @@ -165,7 +172,7 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { .append( ",entityType, isValueDisplayed, OrderByClause, ") .append(" WhereClause )").append( - "VALUES(0, 0, 0, 0, " + id).append( + "VALUES(0, 0, 0, 0, " + AD_Reference_ID).append( ", " + tableId).append(", " + DisplayId) .append(", " + keyId).append(", '" + entityType) .append("', '" + isValueDisplayed).append( @@ -175,12 +182,12 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx)); if (no > 0) { record_log(ctx, 1, atts.getValue("ADRefenceNameID"), - "Reference Table", id, 0, "New", "AD_Ref_Table", + "Reference Table", AD_Reference_ID, 0, "New", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table")); } else { record_log(ctx, 0, atts.getValue("ADRefenceNameID"), - "Reference Table", id, 0, "New", "AD_Ref_Table", + "Reference Table", AD_Reference_ID, 0, "New", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table")); throw new POSaveFailedException("ReferenceTable"); diff --git a/base/src/org/adempiere/pipo/handler/ReportViewColElementHandler.java b/base/src/org/adempiere/pipo/handler/ReportViewColElementHandler.java index 387ab94573..4fc9c980a6 100644 --- a/base/src/org/adempiere/pipo/handler/ReportViewColElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/ReportViewColElementHandler.java @@ -45,7 +45,13 @@ public class ReportViewColElementHandler extends AbstractElementHandler { if (isProcessElement(ctx, entitytype)) { String name = atts.getValue("ADReportviewNameID"); - int AD_ReportView_ID = get_IDWithColumn(ctx, "AD_ReportView", "Name", name); + int AD_ReportView_ID = 0; + if (element.parent != null && element.parent.getElementValue().equals("reportview") && + element.parent.recordId > 0) { + AD_ReportView_ID = element.parent.recordId; + } else { + AD_ReportView_ID = get_IDWithColumn(ctx, "AD_ReportView", "Name", name); + } if (AD_ReportView_ID <= 0) { element.defer = true; return; diff --git a/base/src/org/adempiere/pipo/handler/ReportViewElementHandler.java b/base/src/org/adempiere/pipo/handler/ReportViewElementHandler.java index d3bea7e20c..a9f9bb3847 100644 --- a/base/src/org/adempiere/pipo/handler/ReportViewElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/ReportViewElementHandler.java @@ -97,6 +97,7 @@ public class ReportViewElementHandler extends AbstractElementHandler { m_Reportview.get_ID(), AD_Backup_ID, Object_Status, "AD_Reportview", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Reportview")); + element.recordId = m_Reportview.getAD_ReportView_ID(); } else { record_log(ctx, 0, m_Reportview.getName(), "Reportview", m_Reportview.get_ID(), AD_Backup_ID, Object_Status, diff --git a/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java b/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java index ce41a34cdf..98466a6757 100644 --- a/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java @@ -60,12 +60,16 @@ public class SQLStatementElementHandler extends AbstractElementHandler { // pstmt.executeUpdate(); // Connection m_con = DB.getConnectionRW(true); - Statement stmt = m_con.createStatement(); - int n = stmt.executeUpdate (atts.getValue("statement")); - log.info("Executed SQL Statement for PostgreSQL: "+ atts.getValue("statement")); - // Postgres needs to commit DDL statements - if (m_con != null && !m_con.getAutoCommit()) - m_con.commit(); + try { + Statement stmt = m_con.createStatement(); + int n = stmt.executeUpdate (atts.getValue("statement")); + log.info("Executed SQL Statement for PostgreSQL: "+ atts.getValue("statement")); + // Postgres needs to commit DDL statements + if (m_con != null && !m_con.getAutoCommit()) + m_con.commit(); + } finally { + m_con.close(); + } } /* else if(DB.isSybase() == true && DBType.equals("Sybase")){ pstmt.executeUpdate(); diff --git a/base/src/org/compiere/db/DB_Oracle.java b/base/src/org/compiere/db/DB_Oracle.java index 1de09108b3..0a89edd62d 100644 --- a/base/src/org/compiere/db/DB_Oracle.java +++ b/base/src/org/compiere/db/DB_Oracle.java @@ -547,6 +547,7 @@ public class DB_Oracle implements AdempiereDatabase try { System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog"); + //System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "ALL"); ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDataSourceName("AdempiereDS"); cpds.setDriverClass(DRIVER); @@ -555,8 +556,10 @@ public class DB_Oracle implements AdempiereDatabase cpds.setUser(connection.getDbUid()); cpds.setPassword(connection.getDbPwd()); cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL); - cpds.setIdleConnectionTestPeriod(120); + cpds.setIdleConnectionTestPeriod(1200); cpds.setAcquireRetryAttempts(5); + //cpds.setTestConnectionOnCheckin(true); + //cpds.setTestConnectionOnCheckout(true); //cpds.setCheckoutTimeout(60); if (Ini.isClient()) @@ -565,7 +568,7 @@ public class DB_Oracle implements AdempiereDatabase cpds.setMinPoolSize(1); cpds.setMaxPoolSize(15); cpds.setMaxIdleTimeExcessConnections(1200); - cpds.setMaxIdleTime(600); + cpds.setMaxIdleTime(900); m_maxbusyconnections = 12; } else @@ -574,12 +577,13 @@ public class DB_Oracle implements AdempiereDatabase cpds.setMinPoolSize(5); cpds.setMaxPoolSize(150); cpds.setMaxIdleTimeExcessConnections(1200); - cpds.setMaxIdleTime(900); + cpds.setMaxIdleTime(1200); m_maxbusyconnections = 120; } - cpds.setUnreturnedConnectionTimeout(1200); - cpds.setDebugUnreturnedConnectionStackTraces(true); + //the following sometimes kill active connection! + //cpds.setUnreturnedConnectionTimeout(1200); + //cpds.setDebugUnreturnedConnectionStackTraces(true); m_ds = cpds; } diff --git a/base/src/org/compiere/db/DB_PostgreSQL.java b/base/src/org/compiere/db/DB_PostgreSQL.java index 34d3569215..606ab7c12b 100755 --- a/base/src/org/compiere/db/DB_PostgreSQL.java +++ b/base/src/org/compiere/db/DB_PostgreSQL.java @@ -504,6 +504,9 @@ public class DB_PostgreSQL implements AdempiereDatabase getDataSource(connection); // Connection conn = m_ds.getConnection(); + ComboPooledDataSource cpds = (ComboPooledDataSource)m_ds; + //System.out.println("Num Connections: " + cpds.getNumConnections() + ", Busy Connections: " + // + cpds.getNumBusyConnections()); // Connection conn = getDriverConnection(connection); // conn.setAutoCommit(autoCommit); @@ -519,13 +522,13 @@ public class DB_PostgreSQL implements AdempiereDatabase */ public DataSource getDataSource(CConnection connection) { - //throw new UnsupportedOperationException("Not supported/implemented"); if (m_ds != null) return m_ds; try { System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog"); + //System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "ALL"); ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDataSourceName("AdempiereDS"); cpds.setDriverClass(DRIVER); @@ -534,7 +537,9 @@ public class DB_PostgreSQL implements AdempiereDatabase cpds.setUser(connection.getDbUid()); cpds.setPassword(connection.getDbPwd()); cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL); - cpds.setIdleConnectionTestPeriod(120); + cpds.setIdleConnectionTestPeriod(1200); + //cpds.setTestConnectionOnCheckin(true); + //cpds.setTestConnectionOnCheckout(true); cpds.setAcquireRetryAttempts(5); //cpds.setCheckoutTimeout(60); @@ -544,7 +549,7 @@ public class DB_PostgreSQL implements AdempiereDatabase cpds.setMinPoolSize(1); cpds.setMaxPoolSize(15); cpds.setMaxIdleTimeExcessConnections(1200); - cpds.setMaxIdleTime(600); + cpds.setMaxIdleTime(900); m_maxbusyconnections = 12; } else @@ -553,12 +558,13 @@ public class DB_PostgreSQL implements AdempiereDatabase cpds.setMinPoolSize(5); cpds.setMaxPoolSize(150); cpds.setMaxIdleTimeExcessConnections(1200); - cpds.setMaxIdleTime(900); + cpds.setMaxIdleTime(1200); m_maxbusyconnections = 120; } - cpds.setUnreturnedConnectionTimeout(1200); - cpds.setDebugUnreturnedConnectionStackTraces(true); + //the following sometimes kill active connection! + //cpds.setUnreturnedConnectionTimeout(1200); + //cpds.setDebugUnreturnedConnectionStackTraces(true); m_ds = cpds; } diff --git a/base/src/org/compiere/model/MChangeLog.java b/base/src/org/compiere/model/MChangeLog.java index 1bafd1956c..cbdf5ed662 100644 --- a/base/src/org/compiere/model/MChangeLog.java +++ b/base/src/org/compiere/model/MChangeLog.java @@ -141,10 +141,10 @@ public class MChangeLog extends X_AD_ChangeLog int AD_Client_ID, int AD_Org_ID, Object OldValue, Object NewValue) { - this (ctx, 0, null); // out of trx + this (ctx, 0, TrxName); if (AD_ChangeLog_ID == 0) { - AD_ChangeLog_ID = DB.getNextID (AD_Client_ID, Table_Name, null); + AD_ChangeLog_ID = DB.getNextID (AD_Client_ID, Table_Name, TrxName); if (AD_ChangeLog_ID <= 0) log.severe("No NextID (" + AD_ChangeLog_ID + ")"); } diff --git a/base/src/org/compiere/model/PO.java b/base/src/org/compiere/model/PO.java index 920768a044..3cc8ee0554 100644 --- a/base/src/org/compiere/model/PO.java +++ b/base/src/org/compiere/model/PO.java @@ -694,7 +694,20 @@ public abstract class PO // although is ID (integer) in database else if (value.getClass() == Integer.class && p_info.getColumnClass(index) == String.class) - m_newValues[index] = value; + m_newValues[index] = value; + else if (value.getClass() == String.class + && p_info.getColumnClass(index) == Integer.class) + try + { + m_newValues[index] = new Integer((String)value); + } + catch (NumberFormatException e) + { + log.log(Level.SEVERE, ColumnName + + " - Class invalid: " + value.getClass().toString() + + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value); + return false; + } else { log.log(Level.SEVERE, ColumnName @@ -1817,12 +1830,24 @@ public abstract class PO setAD_Org_ID(0); } } + + Trx localTrx = null; + if (m_trxName == null) { + m_trxName = Trx.createTrxName("POSave"); + localTrx = Trx.get(m_trxName, true); + } + // Before Save try { if (!beforeSave(newRecord)) { log.warning("beforeSave failed - " + toString()); + if (localTrx != null) { + localTrx.rollback(); + localTrx.close(); + m_trxName = null; + } return false; } } @@ -1830,23 +1855,70 @@ public abstract class PO { log.log(Level.WARNING, "beforeSave - " + toString(), e); log.saveError("Error", e.toString(), false); - // throw new DBException(e); + if (localTrx != null) { + localTrx.rollback(); + localTrx.close(); + m_trxName = null; + } return false; } - // Call ModelValidators TYPE_NEW/TYPE_CHANGE - String errorMsg = ModelValidationEngine.get().fireModelChange - (this, newRecord ? ModelValidator.TYPE_NEW : ModelValidator.TYPE_CHANGE); - if (errorMsg != null) - { - log.warning("Validation failed - " + errorMsg); - log.saveError("Error", errorMsg); - return false; + + try { + // Call ModelValidators TYPE_NEW/TYPE_CHANGE + String errorMsg = ModelValidationEngine.get().fireModelChange + (this, newRecord ? ModelValidator.TYPE_NEW : ModelValidator.TYPE_CHANGE); + if (errorMsg != null) + { + log.warning("Validation failed - " + errorMsg); + log.saveError("Error", errorMsg); + if (localTrx != null) { + localTrx.rollback(); + m_trxName = null; + } + return false; + } + // Save + if (newRecord) + { + boolean b = saveNew(); + if (b) + { + if (localTrx != null) + return localTrx.commit(); + else + return b; + } + else + { + if (localTrx != null) + localTrx.rollback(); + return b; + } + } + else + { + boolean b = saveUpdate(); + if (b) + { + if (localTrx != null) + return localTrx.commit(); + else + return b; + } + else + { + if (localTrx != null) + localTrx.rollback(); + return b; + } + } + } finally { + if (localTrx != null) + { + localTrx.close(); + m_trxName = null; + } } - // Save - if (newRecord) - return saveNew(); - else - return saveUpdate(); } // save /** diff --git a/base/src/org/compiere/process/ColumnSync.java b/base/src/org/compiere/process/ColumnSync.java index 9c66f723e6..0a1901ac62 100644 --- a/base/src/org/compiere/process/ColumnSync.java +++ b/base/src/org/compiere/process/ColumnSync.java @@ -70,71 +70,81 @@ public class ColumnSync extends SvrProcess throw new AdempiereUserError("@NotFound@ @AD_Table_ID@ " + column.getAD_Table_ID()); // Find Column in Database - DatabaseMetaData md = DB.getConnectionRO().getMetaData(); - String catalog = DB.getDatabase().getCatalog(); - String schema = DB.getDatabase().getSchema(); - String tableName = table.getTableName(); - if (DB.isOracle()) - tableName = tableName.toUpperCase(); - - // begin vpj-cd e-evolution 08/01/2005 PostgreSQL - if (DB.isPostgreSQL()) - tableName = tableName.toLowerCase(); - // end vpj-cd e-evolution 08/01/2005 PostgreSQL - - int noColumns = 0; - String sql = null; - // - ResultSet rs = md.getColumns(catalog, schema, tableName, null); - while (rs.next()) - { - noColumns++; - String columnName = rs.getString ("COLUMN_NAME"); - if (!columnName.equalsIgnoreCase(column.getColumnName())) - continue; - - // update existing column - boolean notNull = DatabaseMetaData.columnNoNulls == rs.getInt("NULLABLE"); - sql = column.getSQLModify(table, column.isMandatory() != notNull); - break; - } - rs.close(); - rs = null; - - // No Table - if (noColumns == 0) - sql = table.getSQLCreate (); - // No existing column - else if (sql == null) - sql = column.getSQLAdd(table); - - int no = 0; - if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) - { - no = DB.executeUpdate(sql, false, get_TrxName()); - addLog (0, null, new BigDecimal(no), sql); - } - else - { - String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR); - for (int i = 0; i < statements.length; i++) + Connection conn = null; + try { + conn = DB.getConnectionRO(); + DatabaseMetaData md = conn.getMetaData(); + String catalog = DB.getDatabase().getCatalog(); + String schema = DB.getDatabase().getSchema(); + String tableName = table.getTableName(); + if (DB.isOracle()) + tableName = tableName.toUpperCase(); + + // begin vpj-cd e-evolution 08/01/2005 PostgreSQL + if (DB.isPostgreSQL()) + tableName = tableName.toLowerCase(); + // end vpj-cd e-evolution 08/01/2005 PostgreSQL + + int noColumns = 0; + String sql = null; + // + ResultSet rs = md.getColumns(catalog, schema, tableName, null); + while (rs.next()) { - int count = DB.executeUpdate(statements[i], false, get_TrxName()); - addLog (0, null, new BigDecimal(count), statements[i]); - no += count; + noColumns++; + String columnName = rs.getString ("COLUMN_NAME"); + if (!columnName.equalsIgnoreCase(column.getColumnName())) + continue; + + // update existing column + boolean notNull = DatabaseMetaData.columnNoNulls == rs.getInt("NULLABLE"); + sql = column.getSQLModify(table, column.isMandatory() != notNull); + break; + } + rs.close(); + rs = null; + + // No Table + if (noColumns == 0) + sql = table.getSQLCreate (); + // No existing column + else if (sql == null) + sql = column.getSQLAdd(table); + + int no = 0; + if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) + { + no = DB.executeUpdate(sql, false, get_TrxName()); + addLog (0, null, new BigDecimal(no), sql); + } + else + { + String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR); + for (int i = 0; i < statements.length; i++) + { + int count = DB.executeUpdate(statements[i], false, get_TrxName()); + addLog (0, null, new BigDecimal(count), statements[i]); + no += count; + } + } + + if (no == -1) + { + String msg = "@Error@ "; + ValueNamePair pp = CLogger.retrieveError(); + if (pp != null) + msg = pp.getName() + " - "; + msg += sql; + throw new AdempiereUserError (msg); + } + return sql; + } finally { + if (conn != null) { + try { + conn.close(); + } catch (Exception e) {} } } - - if (no == -1) - { - String msg = "@Error@ "; - ValueNamePair pp = CLogger.retrieveError(); - if (pp != null) - msg = pp.getName() + " - "; - msg += sql; - throw new AdempiereUserError (msg); - } - return sql; } // doIt } // ColumnSync diff --git a/base/src/org/compiere/process/TableCreateColumns.java b/base/src/org/compiere/process/TableCreateColumns.java index 9661c535bd..e84a9553e9 100644 --- a/base/src/org/compiere/process/TableCreateColumns.java +++ b/base/src/org/compiere/process/TableCreateColumns.java @@ -81,32 +81,42 @@ public class TableCreateColumns extends SvrProcess + ", AllTables=" + p_AllTables + ", AD_Table_ID=" + p_AD_Table_ID); // - Connection conn = DB.getConnectionRO(); - AdempiereDatabase db = DB.getDatabase(); - DatabaseMetaData md = conn.getMetaData(); - String catalog = db.getCatalog(); - String schema = db.getSchema(); + Connection conn = null; - if (p_AllTables) - addTable (md, catalog, schema); - else - { - MTable table = new MTable (getCtx(), p_AD_Table_ID, get_TrxName()); - if (table == null || table.get_ID() == 0) - throw new AdempiereSystemError("@NotFound@ @AD_Table_ID@ " + p_AD_Table_ID); - log.info(table.getTableName() + ", EntityType=" + p_EntityType); - String tableName = table.getTableName(); - if (DB.isOracle()) - tableName = tableName.toUpperCase(); - // globalqss 2005-10-24 - if (DB.isPostgreSQL()) - tableName = tableName.toLowerCase(); - // end globalqss 2005-10-24 - ResultSet rs = md.getColumns(catalog, schema, tableName, null); - addTableColumn(rs, table); + try { + conn = DB.getConnectionRO(); + AdempiereDatabase db = DB.getDatabase(); + DatabaseMetaData md = conn.getMetaData(); + String catalog = db.getCatalog(); + String schema = db.getSchema(); + + if (p_AllTables) + addTable (md, catalog, schema); + else + { + MTable table = new MTable (getCtx(), p_AD_Table_ID, get_TrxName()); + if (table == null || table.get_ID() == 0) + throw new AdempiereSystemError("@NotFound@ @AD_Table_ID@ " + p_AD_Table_ID); + log.info(table.getTableName() + ", EntityType=" + p_EntityType); + String tableName = table.getTableName(); + if (DB.isOracle()) + tableName = tableName.toUpperCase(); + // globalqss 2005-10-24 + if (DB.isPostgreSQL()) + tableName = tableName.toLowerCase(); + // end globalqss 2005-10-24 + ResultSet rs = md.getColumns(catalog, schema, tableName, null); + addTableColumn(rs, table); + } + + return "#" + m_count; + } finally { + if (conn != null) { + try { + conn.close(); + } catch (Exception e) {} + } } - - return "#" + m_count; } // doIt /** diff --git a/base/src/org/compiere/util/Login.java b/base/src/org/compiere/util/Login.java index ae56aabace..fc25c49831 100644 --- a/base/src/org/compiere/util/Login.java +++ b/base/src/org/compiere/util/Login.java @@ -151,12 +151,18 @@ public class Login DB.setDBTarget(cc); Env.setContext(m_ctx, "#Host", cc.getAppsHost()); Env.setContext(m_ctx, "#Database", cc.getDbName()); - - if (DB.getConnectionRO() == null) + + Connection conn = DB.getConnectionRO(); + if (conn == null) { log.saveError("NoDatabase", ""); return null; - } + } + try { + conn.close(); + } catch (SQLException e) { + } + if (app_pwd == null) return null; //