Adempiere 3.1.2

This commit is contained in:
vpj-cd 2006-12-07 03:21:41 +00:00
parent 6c5fa90281
commit ee46d9e792
24 changed files with 9257 additions and 8777 deletions

View File

@ -42,7 +42,7 @@ public final class Adempiere
/** Timestamp */
static public final String ID = "$Id: Adempiere.java,v 1.8 2006/08/11 02:58:14 jjanke Exp $";
/** Main Version String */
static public final String MAIN_VERSION = "Release 3.1.1";
static public final String MAIN_VERSION = "Release 3.1.2";
/** Detail Version as date Used for Client/Server */
static public final String DATE_VERSION = "2006-11-02";
/** Database Version as date Compared with AD_System */
@ -72,7 +72,7 @@ public final class Adempiere
static private String s_supportEmail = "";
/** Subtitle */
static public final String SUB_TITLE = "The Open Source Profesional ERP,CRM and SCM ";
static public final String SUB_TITLE = "Smart Suite ERP,CRM and SCM ";
/** Adempiere is a wordwide registered Trademark
* - Don't modify this - Program will someday fail unexpectedly */
static public final String ADEMPIERE_R = "Adempiere\u00AE";

View File

@ -27,7 +27,7 @@ import org.compiere.interfaces.*;
import org.compiere.util.*;
/**
* Adempiere Connection Descriptor
* Compiere Connection Descriptor
*
* @author Jorg Janke
* @author Marek Mosiewicz<marek.mosiewicz@jotel.com.pl> - support for RMI over HTTP
@ -138,7 +138,7 @@ public class CConnection implements Serializable
/**************************************************************************
* Adempiere Connection
* Compiere Connection
* @param host optional application/db host
*/
private CConnection (String host)
@ -182,9 +182,9 @@ public class CConnection implements Serializable
private int m_fw_port = 0;
/** DB User name */
private String m_db_uid = "adempiere";
private String m_db_uid = "compiere";
/** DB User password */
private String m_db_pwd = "adempiere";
private String m_db_pwd = "compiere";
/** Database */
private AdempiereDatabase m_db = null;
@ -209,9 +209,6 @@ public class CConnection implements Serializable
private Server m_server = null;
/** DB Info */
private String m_dbInfo = null;
/** Had application server been query **/
private boolean m_queryAppsServer = false;
/*************************************************************************
@ -259,7 +256,6 @@ public class CConnection implements Serializable
m_apps_host = apps_host;
m_name = toString ();
m_okApps = false;
m_queryAppsServer = false;
}
/**
@ -279,7 +275,6 @@ public class CConnection implements Serializable
{
m_apps_port = apps_port;
m_okApps = false;
m_queryAppsServer = false;
}
/**
@ -308,11 +303,9 @@ public class CConnection implements Serializable
*/
public boolean isAppsServerOK (boolean tryContactAgain)
{
if (!tryContactAgain && m_queryAppsServer)
if (!tryContactAgain)
return m_okApps;
m_queryAppsServer = true;
// Get Context
if (m_iContext == null)
{
@ -347,9 +340,8 @@ public class CConnection implements Serializable
*/
public Exception testAppsServer ()
{
//if (queryAppsServerInfo ())
// testDatabase (false);
queryAppsServerInfo ();
if (queryAppsServerInfo ())
testDatabase (false);
return getAppsServerException ();
} // testAppsServer
@ -809,24 +801,11 @@ public class CConnection implements Serializable
if (getDbPort () != DB_DB2.DEFAULT_PORT)
setDbPort (DB_DB2.DEFAULT_PORT);
}
else if (isDerby())
/*else if (isDerby())
{
// if (getDbPort () != DB_Derby.DEFAULT_PORT)
// setDbPort (DB_Derby.DEFAULT_PORT);
}
// begin vpj-cd e-evolution 09 ene 2006
// PostgreSQL
if (isPostgreSQL ())
{
if (getDbPort () != DB_PostgreSQL.DEFAULT_PORT)
setDbPort (DB_PostgreSQL.DEFAULT_PORT);
}
//end vpj-cd e-evolution 09 ene 2006
if (isFyracle())
{
if (getDbPort () != DB_Fyracle.DEFAULT_PORT)
setDbPort (DB_Fyracle.DEFAULT_PORT);
}
if (getDbPort () != DB_Derby.DEFAULT_PORT)
setDbPort (DB_Derby.DEFAULT_PORT);
}*/
} // setType
/**
@ -875,16 +854,7 @@ public class CConnection implements Serializable
return Database.DB_MSSQLServer.equals (m_type);
} // isMSSQLServer
//begin e-evolution vpj-cd 30 nov 2005
/**
* Is PostgreSQL DB
* @return true if PostgreSQL
*/
// public boolean isEDB ()
// {
// return Database.DB_EDB.equals (m_type);
// } // isPostgreSQL
/**
/**
* Is PostgreSQL DB
* @return true if PostgreSQL
*/
@ -902,6 +872,7 @@ public class CConnection implements Serializable
return Database.DB_FYRACLE.equals (m_type);
} // isPostgreSQL
//end
/**
* Is Database Connection OK
* @return true if database connection is OK
@ -987,9 +958,18 @@ public class CConnection implements Serializable
Connection.TRANSACTION_READ_COMMITTED);
if (conn != null)
{
try
try
{
readInfo(conn);
DatabaseMetaData dbmd = conn.getMetaData ();
m_info[0] = "Database=" + dbmd.getDatabaseProductName ()
+ " - " + dbmd.getDatabaseProductVersion ();
m_info[0] = m_info[0].replace ('\n', ' ');
m_info[1] = "Driver =" + dbmd.getDriverName ()
+ " - " + dbmd.getDriverVersion ();
if (isDataSource())
m_info[1] += " - via DataSource";
m_info[1] = m_info[1].replace ('\n', ' ');
log.config(m_info[0] + " - " + m_info[1]);
conn.close ();
}
catch (Exception e)
@ -1000,19 +980,20 @@ public class CConnection implements Serializable
}
return m_dbException; // from opening
} // testDatabase
public void readInfo(Connection conn) throws SQLException {
DatabaseMetaData dbmd = conn.getMetaData ();
m_info[0] = "Database=" + dbmd.getDatabaseProductName ()
+ " - " + dbmd.getDatabaseProductVersion ();
m_info[0] = m_info[0].replace ('\n', ' ');
public void readInfo(Connection conn) throws SQLException {
DatabaseMetaData dbmd = conn.getMetaData ();
m_info[0] = "Database=" + dbmd.getDatabaseProductName ()
+ " - " + dbmd.getDatabaseProductVersion ();
m_info[0] = m_info[0].replace ('\n', ' ');
m_info[1] = "Driver =" + dbmd.getDriverName ()
+ " - " + dbmd.getDriverVersion ();
if (isDataSource())
m_info[1] += " - via DataSource";
m_info[1] = m_info[1].replace ('\n', ' ');
log.config(m_info[0] + " - " + m_info[1]);
}
+ " - " + dbmd.getDriverVersion ();
if (isDataSource())
m_info[1] += " - via DataSource";
m_info[1] = m_info[1].replace ('\n', ' ');
log.config(m_info[0] + " - " + m_info[1]);
}
/*************************************************************************
* Short String representation
@ -1224,7 +1205,15 @@ public class CConnection implements Serializable
{
try
{
m_db = Database.getDatabase(m_type);
for (int i = 0; i < Database.DB_NAMES.length; i++)
{
if (Database.DB_NAMES[i].equals (m_type))
{
m_db = (AdempiereDatabase)Database.DB_CLASSES[i].
newInstance ();
break;
}
}
}
catch (Exception e)
{
@ -1507,19 +1496,12 @@ public class CConnection implements Serializable
log.finer(getAppsHost());
long start = System.currentTimeMillis();
m_okApps = false;
m_queryAppsServer = true;
m_appsException = null;
//
getInitialContext (false);
if (m_iContext == null)
return m_okApps; // false
// Carlos Ruiz - globalqss - speed up when jnp://MyAppsServer:1099 is set
if (getAppsHost().equalsIgnoreCase("MyAppsServer")) {
log.warning (getAppsHost() + " ignored");
return m_okApps; // false
}
// Prevent error trace
// CLogMgtLog4J.enable(false);
try
@ -1642,6 +1624,7 @@ public class CConnection implements Serializable
return "<?" + transactionIsolation + "?>";
} // getTransactionIsolationInfo
/**************************************************************************
* Testing
@ -1664,7 +1647,7 @@ public class CConnection implements Serializable
Adempiere.startup(true);
//
System.out.println ("Connection = ");
// CConnection[name=localhost{dev-dev1-adempiere},AppsHost=localhost,AppsPort=1099,type=Oracle,DBhost=dev,DBport=1521,DBname=dev1,BQ=false,FW=false,FWhost=,FWport=1630,UID=adempiere,PWD=adempiere]
// CConnection[name=localhost{dev-dev1-compiere},AppsHost=localhost,AppsPort=1099,type=Oracle,DBhost=dev,DBport=1521,DBname=dev1,BQ=false,FW=false,FWhost=,FWport=1630,UID=compiere,PWD=compiere]
System.out.println (Ini.getProperty (Ini.P_CONNECTION));
CConnection cc = CConnection.get ();

View File

@ -3,21 +3,21 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.db;
import java.awt.*;
import java.awt.event.*;
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.db;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
@ -26,23 +26,23 @@ import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Connection Dialog.
*
* @author Jorg Janke
* @author Marek Mosiewicz<marek.mosiewicz@jotel.com.pl> - support for RMI over HTTP
* @version $Id: CConnectionDialog.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
*/
public class CConnectionDialog extends CDialog implements ActionListener
{
/**
* Connection Dialog using current Connection
*/
public CConnectionDialog()
{
this (null);
} // CConnectionDialog
/**
* Connection Dialog.
*
* @author Jorg Janke
* @author Marek Mosiewicz<marek.mosiewicz@jotel.com.pl> - support for RMI over HTTP
* @version $Id: CConnectionDialog.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
*/
public class CConnectionDialog extends CDialog implements ActionListener
{
/**
* Connection Dialog using current Connection
*/
public CConnectionDialog()
{
this (null);
} // CConnectionDialog
/**
* Connection Dialog
@ -50,13 +50,13 @@ public class CConnectionDialog extends CDialog implements ActionListener
*/
public CConnectionDialog(CConnection cc)
{
super((Frame)null, true);
try
{
jbInit();
setConnection (cc);
}
catch(Exception e)
super((Frame)null, true);
try
{
jbInit();
setConnection (cc);
}
catch(Exception e)
{
log.log(Level.SEVERE, "", e);
}
@ -64,33 +64,33 @@ public class CConnectionDialog extends CDialog implements ActionListener
} // CConnection
/** Resources */
private static ResourceBundle res = ResourceBundle.getBundle("org.compiere.db.DBRes");
static
{
/** Connection Profiles */
CConnection.CONNECTIONProfiles = new ValueNamePair[]{
new ValueNamePair("L", res.getString("LAN")),
new ValueNamePair("T", res.getString("TerminalServer")),
new ValueNamePair("V", res.getString("VPN")),
new ValueNamePair("W", res.getString("WAN"))
};
}
/** Default HTTP Port */
public static final String APPS_PORT_HTTP = "80";
/** Default RMI Port */
public static final String APPS_PORT_JNP = "1099";
/** Connection */
private CConnection m_cc = null;
private CConnection m_ccResult = null;
private boolean m_updating = false;
private boolean m_saved = false;
/** Logger */
private static CLogger log = CLogger.getCLogger (CConnectionDialog.class);
private CPanel mainPanel = new CPanel();
private static ResourceBundle res = ResourceBundle.getBundle("org.compiere.db.DBRes");
static
{
/** Connection Profiles */
CConnection.CONNECTIONProfiles = new ValueNamePair[]{
new ValueNamePair("L", res.getString("LAN")),
new ValueNamePair("T", res.getString("TerminalServer")),
new ValueNamePair("V", res.getString("VPN")),
new ValueNamePair("W", res.getString("WAN"))
};
}
/** Default HTTP Port */
public static final String APPS_PORT_HTTP = "80";
/** Default RMI Port */
public static final String APPS_PORT_JNP = "1099";
/** Connection */
private CConnection m_cc = null;
private CConnection m_ccResult = null;
private boolean m_updating = false;
private boolean m_saved = false;
/** Logger */
private static CLogger log = CLogger.getCLogger (CConnectionDialog.class);
private CPanel mainPanel = new CPanel();
private BorderLayout mainLayout = new BorderLayout();
private CPanel centerPanel = new CPanel();
private CPanel southPanel = new CPanel();
@ -99,156 +99,156 @@ public class CConnectionDialog extends CDialog implements ActionListener
private FlowLayout southLayout = new FlowLayout();
private GridBagLayout centerLayout = new GridBagLayout();
private CLabel nameLabel = new CLabel();
private CTextField nameField = new CTextField();
private CLabel hostLabel = new CLabel();
private CTextField hostField = new CTextField();
private CLabel portLabel = new CLabel();
private CTextField dbPortField = new CTextField();
private CLabel sidLabel = new CLabel();
private CTextField sidField = new CTextField();
private CCheckBox cbFirewall = new CCheckBox();
private CLabel fwHostLabel = new CLabel();
private CTextField fwHostField = new CTextField();
private CLabel fwPortLabel = new CLabel();
private CTextField fwPortField = new CTextField();
private CButton bTestDB = new CButton();
private CLabel dbTypeLabel = new CLabel();
private CComboBox dbTypeField = new CComboBox(Database.DB_NAMES);
private CCheckBox cbBequeath = new CCheckBox();
private CLabel appsHostLabel = new CLabel();
private CTextField appsHostField = new CTextField();
private CLabel appsPortLabel = new CLabel();
private CTextField appsPortField = new CTextField();
private CButton bTestApps = new CButton();
private CCheckBox cbOverwrite = new CCheckBox();
private CLabel dbUidLabel = new CLabel();
private CTextField dbUidField = new CTextField();
private JPasswordField dbPwdField = new JPasswordField();
private CLabel connectionProfileLabel = new CLabel();
private CComboBox connectionProfileField = new CComboBox(CConnection.CONNECTIONProfiles);
/**
* Static Layout
* @throws Exception
*/
private void jbInit() throws Exception
{
this.setTitle(res.getString("CConnectionDialog"));
mainPanel.setLayout(mainLayout);
southPanel.setLayout(southLayout);
southLayout.setAlignment(FlowLayout.RIGHT);
centerPanel.setLayout(centerLayout);
nameLabel.setText(res.getString("Name"));
nameField.setColumns(30);
nameField.setReadWrite(false);
hostLabel.setText(res.getString("DBHost"));
hostField.setColumns(30);
portLabel.setText(res.getString("DBPort"));
dbPortField.setColumns(10);
sidLabel.setText(res.getString("DBName"));
cbFirewall.setToolTipText("");
cbFirewall.setText(res.getString("ViaFirewall"));
fwHostLabel.setText(res.getString("FWHost"));
fwHostField.setColumns(30);
fwPortLabel.setText(res.getString("FWPort"));
bTestDB.setText(res.getString("TestConnection"));
bTestDB.setHorizontalAlignment(JLabel.LEFT);
dbTypeLabel.setText(res.getString("Type"));
sidField.setColumns(30);
fwPortField.setColumns(10);
cbBequeath.setText(res.getString("BequeathConnection"));
appsHostLabel.setText(res.getString("AppsHost"));
appsHostField.setColumns(30);
appsPortLabel.setText(res.getString("AppsPort"));
appsPortField.setColumns(10);
bTestApps.setText(res.getString("TestApps"));
bTestApps.setHorizontalAlignment(JLabel.LEFT);
cbOverwrite.setText(res.getString("Overwrite"));
dbUidLabel.setText(res.getString("DBUidPwd"));
dbUidField.setColumns(10);
connectionProfileLabel.setText(res.getString("ConnectionProfile"));
connectionProfileField.addActionListener(this);
this.getContentPane().add(mainPanel, BorderLayout.CENTER);
mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(southPanel, BorderLayout.SOUTH);
southPanel.add(bCancel, null);
southPanel.add(bOK, null);
//
centerPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(12, 12, 5, 5), 0, 0));
centerPanel.add(nameField, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(12, 0, 5, 12), 0, 0));
centerPanel.add(appsHostLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(appsHostField, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
centerPanel.add(appsPortLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(appsPortField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
centerPanel.add(connectionProfileLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(connectionProfileField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
//
centerPanel.add(bTestApps, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 12, 0), 0, 0));
centerPanel.add(cbOverwrite, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 5, 0, 12), 0, 0));
// DB
centerPanel.add(dbTypeLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(dbTypeField, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 0, 0));
centerPanel.add(cbBequeath, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 12), 0, 0));
centerPanel.add(hostLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(hostField, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
centerPanel.add(portLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(dbPortField, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
centerPanel.add(sidLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(sidField, new GridBagConstraints(1, 8, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
centerPanel.add(dbUidLabel, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0
private CTextField nameField = new CTextField();
private CLabel hostLabel = new CLabel();
private CTextField hostField = new CTextField();
private CLabel portLabel = new CLabel();
private CTextField dbPortField = new CTextField();
private CLabel sidLabel = new CLabel();
private CTextField sidField = new CTextField();
private CCheckBox cbFirewall = new CCheckBox();
private CLabel fwHostLabel = new CLabel();
private CTextField fwHostField = new CTextField();
private CLabel fwPortLabel = new CLabel();
private CTextField fwPortField = new CTextField();
private CButton bTestDB = new CButton();
private CLabel dbTypeLabel = new CLabel();
private CComboBox dbTypeField = new CComboBox(Database.DB_NAMES);
private CCheckBox cbBequeath = new CCheckBox();
private CLabel appsHostLabel = new CLabel();
private CTextField appsHostField = new CTextField();
private CLabel appsPortLabel = new CLabel();
private CTextField appsPortField = new CTextField();
private CButton bTestApps = new CButton();
private CCheckBox cbOverwrite = new CCheckBox();
private CLabel dbUidLabel = new CLabel();
private CTextField dbUidField = new CTextField();
private JPasswordField dbPwdField = new JPasswordField();
private CLabel connectionProfileLabel = new CLabel();
private CComboBox connectionProfileField = new CComboBox(CConnection.CONNECTIONProfiles);
/**
* Static Layout
* @throws Exception
*/
private void jbInit() throws Exception
{
this.setTitle(res.getString("CConnectionDialog"));
mainPanel.setLayout(mainLayout);
southPanel.setLayout(southLayout);
southLayout.setAlignment(FlowLayout.RIGHT);
centerPanel.setLayout(centerLayout);
nameLabel.setText(res.getString("Name"));
nameField.setColumns(30);
nameField.setReadWrite(false);
hostLabel.setText(res.getString("DBHost"));
hostField.setColumns(30);
portLabel.setText(res.getString("DBPort"));
dbPortField.setColumns(10);
sidLabel.setText(res.getString("DBName"));
cbFirewall.setToolTipText("");
cbFirewall.setText(res.getString("ViaFirewall"));
fwHostLabel.setText(res.getString("FWHost"));
fwHostField.setColumns(30);
fwPortLabel.setText(res.getString("FWPort"));
bTestDB.setText(res.getString("TestConnection"));
bTestDB.setHorizontalAlignment(JLabel.LEFT);
dbTypeLabel.setText(res.getString("Type"));
sidField.setColumns(30);
fwPortField.setColumns(10);
cbBequeath.setText(res.getString("BequeathConnection"));
appsHostLabel.setText(res.getString("AppsHost"));
appsHostField.setColumns(30);
appsPortLabel.setText(res.getString("AppsPort"));
appsPortField.setColumns(10);
bTestApps.setText(res.getString("TestApps"));
bTestApps.setHorizontalAlignment(JLabel.LEFT);
cbOverwrite.setText(res.getString("Overwrite"));
dbUidLabel.setText(res.getString("DBUidPwd"));
dbUidField.setColumns(10);
connectionProfileLabel.setText(res.getString("ConnectionProfile"));
connectionProfileField.addActionListener(this);
this.getContentPane().add(mainPanel, BorderLayout.CENTER);
mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(southPanel, BorderLayout.SOUTH);
southPanel.add(bCancel, null);
southPanel.add(bOK, null);
//
centerPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(12, 12, 5, 5), 0, 0));
centerPanel.add(nameField, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(12, 0, 5, 12), 0, 0));
centerPanel.add(appsHostLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(appsHostField, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
centerPanel.add(appsPortLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(appsPortField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
centerPanel.add(connectionProfileLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(connectionProfileField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
//
centerPanel.add(bTestApps, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 12, 0), 0, 0));
centerPanel.add(cbOverwrite, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 5, 0, 12), 0, 0));
// DB
centerPanel.add(dbTypeLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(dbTypeField, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 0, 0));
centerPanel.add(cbBequeath, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 12), 0, 0));
centerPanel.add(hostLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(hostField, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
centerPanel.add(portLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(dbPortField, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
centerPanel.add(sidLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(sidField, new GridBagConstraints(1, 8, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
centerPanel.add(dbUidLabel, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(dbUidField, new GridBagConstraints(1, 9, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
centerPanel.add(dbPwdField, new GridBagConstraints(2, 9, 1, 1, 1.0, 0.0
centerPanel.add(dbPwdField, new GridBagConstraints(2, 9, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 12), 0, 0));
centerPanel.add(cbFirewall, new GridBagConstraints(1, 10, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 12), 0, 0));
centerPanel.add(fwHostLabel, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(fwHostField, new GridBagConstraints(1, 11, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
centerPanel.add(fwPortLabel, new GridBagConstraints(0, 12, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(fwPortField, new GridBagConstraints(1, 12, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
centerPanel.add(bTestDB, new GridBagConstraints(1, 13, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 12, 0), 0, 0));
//
nameField.addActionListener(this);
appsHostField.addActionListener(this);
appsPortField.addActionListener(this);
cbOverwrite.addActionListener(this);
bTestApps.addActionListener(this);
//
dbTypeField.addActionListener(this);
hostField.addActionListener(this);
dbPortField.addActionListener(this);
sidField.addActionListener(this);
cbBequeath.addActionListener(this);
cbFirewall.addActionListener(this);
fwHostField.addActionListener(this);
fwPortField.addActionListener(this);
centerPanel.add(fwHostLabel, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(fwHostField, new GridBagConstraints(1, 11, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
centerPanel.add(fwPortLabel, new GridBagConstraints(0, 12, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(fwPortField, new GridBagConstraints(1, 12, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
centerPanel.add(bTestDB, new GridBagConstraints(1, 13, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 12, 0), 0, 0));
//
nameField.addActionListener(this);
appsHostField.addActionListener(this);
appsPortField.addActionListener(this);
cbOverwrite.addActionListener(this);
bTestApps.addActionListener(this);
//
dbTypeField.addActionListener(this);
hostField.addActionListener(this);
dbPortField.addActionListener(this);
sidField.addActionListener(this);
cbBequeath.addActionListener(this);
cbFirewall.addActionListener(this);
fwHostField.addActionListener(this);
fwPortField.addActionListener(this);
bTestDB.addActionListener(this);
bOK.addActionListener(this);
bCancel.addActionListener(this);
@ -256,260 +256,260 @@ public class CConnectionDialog extends CDialog implements ActionListener
// Server
if (!Ini.isClient())
{
appsHostLabel.setVisible(false);
appsHostField.setVisible(false);
appsPortLabel.setVisible(false);
appsPortField.setVisible(false);
bTestApps.setVisible(false);
connectionProfileLabel.setVisible(false);
connectionProfileField.setVisible(false);
}
else // Client
cbBequeath.setVisible(false);
} // jbInit
/**
* Set Busy - lock UI
* @param busy busy
*/
private void setBusy (boolean busy)
{
if (busy)
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
else
this.setCursor(Cursor.getDefaultCursor());
m_updating = busy;
} // setBusy
/**
* Set Connection
* @param cc - if null use current connection
*/
public void setConnection (CConnection cc)
{
m_cc = cc;
if (m_cc == null)
{
m_cc = CConnection.get();
m_cc.setName();
}
// Should copy values
m_ccResult = m_cc;
//
String type = m_cc.getType();
if (type == null || type.length() == 0)
dbTypeField.setSelectedItem(null);
else
m_cc.setType(m_cc.getType()); // sets defaults
updateInfo();
} // setConnection
/**
* Get Connection
* @return CConnection
*/
public CConnection getConnection()
{
return m_ccResult;
} // getConnection;
/**
* ActionListener
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
if (m_updating)
return;
Object src = e.getSource();
if (src == bOK)
{
m_cc.setName();
m_ccResult = m_cc;
dispose();
return;
}
else if (src == bCancel)
{
m_cc.setName();
dispose();
return;
}
else if (src == connectionProfileField)
{
ValueNamePair pp = (ValueNamePair)connectionProfileField.getSelectedItem();
m_cc.setConnectionProfile(pp.getValue());
if (m_cc.isRMIoverHTTP())
appsPortField.setText(APPS_PORT_HTTP);
else
appsPortField.setText(APPS_PORT_JNP);
return;
}
else if (src == dbTypeField)
{
if (dbTypeField.getSelectedItem() == null)
return;
}
if (Ini.isClient())
{
m_cc.setAppsHost(appsHostField.getText());
m_cc.setAppsPort(appsPortField.getText());
}
else
m_cc.setAppsHost("localhost");
//
ValueNamePair pp = (ValueNamePair)connectionProfileField.getSelectedItem();
m_cc.setConnectionProfile(pp.getValue());
//
m_cc.setType((String)dbTypeField.getSelectedItem());
m_cc.setDbHost(hostField.getText());
m_cc.setDbPort(dbPortField.getText());
m_cc.setDbName(sidField.getText());
m_cc.setDbUid(dbUidField.getText());
m_cc.setDbPwd(String.valueOf(dbPwdField.getPassword()));
m_cc.setBequeath(cbBequeath.isSelected());
m_cc.setViaFirewall(cbFirewall.isSelected());
m_cc.setFwHost(fwHostField.getText());
m_cc.setFwPort(fwPortField.getText());
//
if (src == bTestApps)
cmd_testApps();
// Database Selection Changed
else if (src == dbTypeField)
{
m_cc.setType((String)dbTypeField.getSelectedItem());
dbPortField.setText(String.valueOf(m_cc.getDbPort()));
cbBequeath.setSelected(m_cc.isBequeath());
fwPortField.setText(String.valueOf(m_cc.getFwPort()));
}
//
else if (src == bTestDB)
cmd_testDB();
// Name
if (src == nameField)
m_cc.setName(nameField.getText());
updateInfo();
} // actionPerformed
/**
* Update Fields from Connection
*/
private void updateInfo()
{
m_updating = true;
nameField.setText(m_cc.getName());
appsHostField.setText(m_cc.getAppsHost());
appsPortField.setText(String.valueOf(m_cc.getAppsPort()));
//
String cp = m_cc.getConnectionProfile();
ValueNamePair cpPP = null;
for (int i = 0; i < CConnection.CONNECTIONProfiles.length; i++)
{
if (cp.equals(CConnection.CONNECTIONProfiles[i].getValue()))
{
cpPP = CConnection.CONNECTIONProfiles[i];
break;
}
}
if (cpPP == null) // LAN
cpPP = CConnection.CONNECTIONProfiles[0];
connectionProfileField.setSelectedItem(cpPP);
bTestApps.setIcon(getStatusIcon(m_cc.isAppsServerOK(false)));
// bTestApps.setToolTipText(m_cc.getRmiUri());
cbOverwrite.setVisible(m_cc.isAppsServerOK(false));
boolean rw = cbOverwrite.isSelected() || !m_cc.isAppsServerOK(false);
//
dbTypeLabel.setReadWrite(rw);
dbTypeField.setReadWrite(rw);
dbTypeField.setSelectedItem(m_cc.getType());
//
hostLabel.setReadWrite(rw);
hostField.setReadWrite(rw);
hostField.setText(m_cc.getDbHost());
portLabel.setReadWrite(rw);
dbPortField.setReadWrite(rw);
dbPortField.setText(String.valueOf(m_cc.getDbPort()));
sidLabel.setReadWrite(rw);
sidField.setReadWrite(rw);
sidField.setText(m_cc.getDbName());
//
dbUidLabel.setReadWrite(rw);
dbUidField.setReadWrite(rw);
dbUidField.setText(m_cc.getDbUid());
dbPwdField.setEditable(rw);
dbPwdField.setText(m_cc.getDbPwd());
//
cbBequeath.setReadWrite(rw);
cbBequeath.setEnabled(m_cc.isOracle());
cbBequeath.setSelected(m_cc.isBequeath());
//
boolean fwEnabled = rw && m_cc.isViaFirewall() && m_cc.isOracle();
cbFirewall.setReadWrite(rw && m_cc.isOracle());
cbFirewall.setSelected(m_cc.isViaFirewall());
fwHostLabel.setReadWrite(fwEnabled);
fwHostField.setReadWrite(fwEnabled);
fwHostField.setText(m_cc.getFwHost());
fwPortLabel.setReadWrite(fwEnabled);
fwPortField.setReadWrite(fwEnabled);
fwPortField.setText(String.valueOf(m_cc.getFwPort()));
//
bTestDB.setToolTipText(m_cc.getConnectionURL());
bTestDB.setIcon(getStatusIcon(m_cc.isDatabaseOK()));
m_updating = false;
} // updateInfo
/**
* Get Status Icon - ok or not
* @param ok ok
* @return Icon
*/
private Icon getStatusIcon (boolean ok)
{
if (ok)
return bOK.getIcon();
else
return bCancel.getIcon();
} // getStatusIcon
/**
* Test Database connection
*/
private void cmd_testDB()
{
setBusy (true);
Exception e = m_cc.testDatabase(true);
if (e != null)
{
JOptionPane.showMessageDialog(this,
e, // message
res.getString("ConnectionError") + ": " + m_cc.getConnectionURL(),
JOptionPane.ERROR_MESSAGE);
}
setBusy (false);
} // cmd_testDB
/**
* Test Application connection
*/
private void cmd_testApps()
{
setBusy (true);
Exception e = m_cc.testAppsServer();
if (e != null)
{
JOptionPane.showMessageDialog(this,
e.getLocalizedMessage(),
res.getString("ServerNotActive") + " - " + m_cc.getAppsHost(),
JOptionPane.ERROR_MESSAGE);
}
setBusy (false);
} // cmd_testApps
} // CConnectionDialog
appsHostLabel.setVisible(false);
appsHostField.setVisible(false);
appsPortLabel.setVisible(false);
appsPortField.setVisible(false);
bTestApps.setVisible(false);
connectionProfileLabel.setVisible(false);
connectionProfileField.setVisible(false);
}
else // Client
cbBequeath.setVisible(false);
} // jbInit
/**
* Set Busy - lock UI
* @param busy busy
*/
private void setBusy (boolean busy)
{
if (busy)
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
else
this.setCursor(Cursor.getDefaultCursor());
m_updating = busy;
} // setBusy
/**
* Set Connection
* @param cc - if null use current connection
*/
public void setConnection (CConnection cc)
{
m_cc = cc;
if (m_cc == null)
{
m_cc = CConnection.get();
m_cc.setName();
}
// Should copy values
m_ccResult = m_cc;
//
String type = m_cc.getType();
if (type == null || type.length() == 0)
dbTypeField.setSelectedItem(null);
else
m_cc.setType(m_cc.getType()); // sets defaults
updateInfo();
} // setConnection
/**
* Get Connection
* @return CConnection
*/
public CConnection getConnection()
{
return m_ccResult;
} // getConnection;
/**
* ActionListener
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
if (m_updating)
return;
Object src = e.getSource();
if (src == bOK)
{
m_cc.setName();
m_ccResult = m_cc;
dispose();
return;
}
else if (src == bCancel)
{
m_cc.setName();
dispose();
return;
}
else if (src == connectionProfileField)
{
ValueNamePair pp = (ValueNamePair)connectionProfileField.getSelectedItem();
m_cc.setConnectionProfile(pp.getValue());
if (m_cc.isRMIoverHTTP())
appsPortField.setText(APPS_PORT_HTTP);
else
appsPortField.setText(APPS_PORT_JNP);
return;
}
else if (src == dbTypeField)
{
if (dbTypeField.getSelectedItem() == null)
return;
}
if (Ini.isClient())
{
m_cc.setAppsHost(appsHostField.getText());
m_cc.setAppsPort(appsPortField.getText());
}
else
m_cc.setAppsHost("localhost");
//
ValueNamePair pp = (ValueNamePair)connectionProfileField.getSelectedItem();
m_cc.setConnectionProfile(pp.getValue());
//
m_cc.setType((String)dbTypeField.getSelectedItem());
m_cc.setDbHost(hostField.getText());
m_cc.setDbPort(dbPortField.getText());
m_cc.setDbName(sidField.getText());
m_cc.setDbUid(dbUidField.getText());
m_cc.setDbPwd(String.valueOf(dbPwdField.getPassword()));
m_cc.setBequeath(cbBequeath.isSelected());
m_cc.setViaFirewall(cbFirewall.isSelected());
m_cc.setFwHost(fwHostField.getText());
m_cc.setFwPort(fwPortField.getText());
//
if (src == bTestApps)
cmd_testApps();
// Database Selection Changed
else if (src == dbTypeField)
{
m_cc.setType((String)dbTypeField.getSelectedItem());
dbPortField.setText(String.valueOf(m_cc.getDbPort()));
cbBequeath.setSelected(m_cc.isBequeath());
fwPortField.setText(String.valueOf(m_cc.getFwPort()));
}
//
else if (src == bTestDB)
cmd_testDB();
// Name
if (src == nameField)
m_cc.setName(nameField.getText());
updateInfo();
} // actionPerformed
/**
* Update Fields from Connection
*/
private void updateInfo()
{
m_updating = true;
nameField.setText(m_cc.getName());
appsHostField.setText(m_cc.getAppsHost());
appsPortField.setText(String.valueOf(m_cc.getAppsPort()));
//
String cp = m_cc.getConnectionProfile();
ValueNamePair cpPP = null;
for (int i = 0; i < CConnection.CONNECTIONProfiles.length; i++)
{
if (cp.equals(CConnection.CONNECTIONProfiles[i].getValue()))
{
cpPP = CConnection.CONNECTIONProfiles[i];
break;
}
}
if (cpPP == null) // LAN
cpPP = CConnection.CONNECTIONProfiles[0];
connectionProfileField.setSelectedItem(cpPP);
bTestApps.setIcon(getStatusIcon(m_cc.isAppsServerOK(false)));
// bTestApps.setToolTipText(m_cc.getRmiUri());
cbOverwrite.setVisible(m_cc.isAppsServerOK(false));
boolean rw = cbOverwrite.isSelected() || !m_cc.isAppsServerOK(false);
//
dbTypeLabel.setReadWrite(rw);
dbTypeField.setReadWrite(rw);
dbTypeField.setSelectedItem(m_cc.getType());
//
hostLabel.setReadWrite(rw);
hostField.setReadWrite(rw);
hostField.setText(m_cc.getDbHost());
portLabel.setReadWrite(rw);
dbPortField.setReadWrite(rw);
dbPortField.setText(String.valueOf(m_cc.getDbPort()));
sidLabel.setReadWrite(rw);
sidField.setReadWrite(rw);
sidField.setText(m_cc.getDbName());
//
dbUidLabel.setReadWrite(rw);
dbUidField.setReadWrite(rw);
dbUidField.setText(m_cc.getDbUid());
dbPwdField.setEditable(rw);
dbPwdField.setText(m_cc.getDbPwd());
//
cbBequeath.setReadWrite(rw);
cbBequeath.setEnabled(m_cc.isOracle());
cbBequeath.setSelected(m_cc.isBequeath());
//
boolean fwEnabled = rw && m_cc.isViaFirewall() && m_cc.isOracle();
cbFirewall.setReadWrite(rw && m_cc.isOracle());
cbFirewall.setSelected(m_cc.isViaFirewall());
fwHostLabel.setReadWrite(fwEnabled);
fwHostField.setReadWrite(fwEnabled);
fwHostField.setText(m_cc.getFwHost());
fwPortLabel.setReadWrite(fwEnabled);
fwPortField.setReadWrite(fwEnabled);
fwPortField.setText(String.valueOf(m_cc.getFwPort()));
//
bTestDB.setToolTipText(m_cc.getConnectionURL());
bTestDB.setIcon(getStatusIcon(m_cc.isDatabaseOK()));
m_updating = false;
} // updateInfo
/**
* Get Status Icon - ok or not
* @param ok ok
* @return Icon
*/
private Icon getStatusIcon (boolean ok)
{
if (ok)
return bOK.getIcon();
else
return bCancel.getIcon();
} // getStatusIcon
/**
* Test Database connection
*/
private void cmd_testDB()
{
setBusy (true);
Exception e = m_cc.testDatabase(true);
if (e != null)
{
JOptionPane.showMessageDialog(this,
e, // message
res.getString("ConnectionError") + ": " + m_cc.getConnectionURL(),
JOptionPane.ERROR_MESSAGE);
}
setBusy (false);
} // cmd_testDB
/**
* Test Application connection
*/
private void cmd_testApps()
{
setBusy (true);
Exception e = m_cc.testAppsServer();
if (e != null)
{
JOptionPane.showMessageDialog(this,
e.getLocalizedMessage(),
res.getString("ServerNotActive") + " - " + m_cc.getAppsHost(),
JOptionPane.ERROR_MESSAGE);
}
setBusy (false);
} // cmd_testApps
} // CConnectionDialog

View File

@ -624,4 +624,10 @@ class DataSourceImpl implements DataSource {
return impl.toString();
}
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
{
return false;
}
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException{return null;}
}

View File

@ -1,16 +1,17 @@
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Portions created by Victor Perez are Copyright (C) 1999-2005 e-Evolution,S.C
* Contributor(s): Victor Perez
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
*****************************************************************************/
package org.compiere.db;

View File

@ -0,0 +1,426 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
*****************************************************************************/
package org.compiere.db;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.apache.derby.drda.*;
import org.apache.derby.impl.drda.*;
import org.apache.derby.jdbc.*;
import org.compiere.util.*;
/**
* Derby DB Server
*
* @author Jorg Janke
* @version $Id: DerbyServer.java,v 1.5 2006/07/30 00:55:13 jjanke Exp $
*/
public class DerbyServer extends Thread
{
/**
* Get/Create Derby Server
* @return server
*/
public static synchronized DerbyServer get()
{
if (s_server == null)
{
InetAddress address = null;
int port = PORT;
try
{
address = InetAddress.getByAddress(new byte[] {0,0,0,0}); // all ports
s_server = new DerbyServer(address, port);
s_server.start();
}
catch (Exception e)
{
String msg = null;
if (address == null)
msg = "";
else
msg = address.toString();
msg += ":" + port;
log.log(Level.SEVERE, msg, e);
}
}
return s_server;
} // get
/**
* Start Server
* @return true if started
*/
public static boolean startServer()
{
if (get() == null)
return false;
return s_server.isServerStarted();
} // startServer
/**
* Stop Server
* @return true if stopped / not running
*/
public static boolean stopServer()
{
if (s_server == null)
return true;
try
{
s_server.shutdown();
s_server = null;
return true;
}
catch (Exception e)
{
log.log(Level.SEVERE, e.getMessage(), e);
}
return false;
} // stopServer
/** Singleton */
private static DerbyServer s_server = null;
/** Default Port 1527 */
public static final int PORT = NetworkServerControl.DEFAULT_PORTNUMBER;
/** Logger */
private static CLogger log = CLogger.getCLogger (DerbyServer.class);
/**************************************************************************
* Derby Server
* @param address server address
* @param port port
* @throws Exception
*/
private DerbyServer (InetAddress address, int port) throws Exception
{
super("CompiereDerby");
if (s_impl != null)
throw new IllegalStateException("Derby Server already started");
//
String compiereHome = Ini.getAdempiereHome();
s_derbyHome = compiereHome + File.separator + "derby";
File dir = new File(s_derbyHome);
if (!dir.exists())
dir.mkdir();
//
System.setProperty("derby.system.home", s_derbyHome);
System.setProperty("derby.drda.traceDirectory", s_derbyHome);
//
String logIt = "false";
if (CLogMgt.isLevelFiner())
logIt = "true";
System.setProperty("derby.drda.logConnections", logIt);
System.setProperty("derby.drda.traceAll", logIt);
//
System.setProperty("derby.connection.requireAuthentication", "true");
System.setProperty("derby.authentication.provider", "BUILTIN");
addUser("compiere", "compiere");
//
s_address = address;
s_port = port;
s_impl = new NetworkServerControlImpl (s_address, s_port);
} // DerbyServer
/** Singleton */
private static NetworkServerControlImpl s_impl = null;
/** Derby Home */
private static String s_derbyHome = "";
/** Address */
private static InetAddress s_address = null;
/** Port */
private static int s_port = 0;
/**
* Run
*/
public void run()
{
log.info("starting ...");
PrintWriter consoleWriter = new PrintWriter(System.out, true); // flush
try
{
s_impl.blockingStart(consoleWriter);
}
catch (Exception e)
{
log.log(Level.SEVERE, e.getMessage(), e);
s_impl = null;
}
log.info("done");
} // run
/**
* Interrupt - shutdown
*/
public void interrupt ()
{
super.interrupt ();
shutdown();
} // interrupt
/**
* Is Server Started
* @return server started
*/
public boolean isServerStarted()
{
if (s_impl == null)
return false;
try
{
s_impl.ping();
}
catch (Exception e)
{
return false;
}
return true;
} // isServerStarted
/**
* Shutdown
* @return true if shut down
*/
public boolean shutdown()
{
if (s_impl != null)
{
try
{
log.info("shutting down ...");
s_impl.shutdown();
log.info("shutdown");
return true;
}
catch (Exception e)
{
return false;
}
}
return true;
} // shutdown
/**
* String Representation
* @return info
*/
public String toString ()
{
StringBuffer sb = new StringBuffer ("DerbyServer[");
sb.append (s_derbyHome)
.append(";").append(s_address)
.append(":").append(s_port)
.append(";Alive=").append(isAlive())
.append(";Started=").append(isServerStarted());
sb.append ("]");
return sb.toString ();
} // toString
/**
* Get Derby Home
* @return home
*/
public String getDerbyHome()
{
return s_derbyHome;
} // getDerbyHome
/**
* Get Runtime Info
* @return info
*/
public String getRuntimeInfo()
{
try
{
if (s_impl != null)
return s_impl.runtimeInfo();
}
catch (Exception e)
{
return e.getMessage();
}
return "";
} // getRuntimeInfo
/**
* Get System Info
* @return info
*/
public String getSysInfo()
{
try
{
if (s_impl != null)
return s_impl.sysinfo();
}
catch (Exception e)
{
return e.getMessage();
}
return "";
} // getSysInfo
/**
* Get current Network server properties.
* @return Properties object containing Network server properties
* @exception Exception throws an exception if an error occurs
*/
public Properties getCurrentProperties() throws Exception
{
return s_impl.getCurrentProperties();
} // getCurrentProperties
/**
* Add User
* @param dbUid user id
* @param dbPwd user password
*/
public void addUser (String dbUid, String dbPwd)
{
System.setProperty("derby.user." + dbUid, dbPwd);
Properties dp = new Properties();
} // addUser
/**
* Create Database
* @param dbName database name
* @param dbUid user id
* @param dbPwd user password
* @return true if exists or created
*/
public boolean createDatabase (String dbName,
String dbUid, String dbPwd)
{
addUser (dbUid, dbPwd);
// Embedded Driver
try
{
EmbeddedDriver driver = new EmbeddedDriver();
DriverManager.registerDriver (driver);
}
catch (Exception e)
{
log.log(Level.SEVERE, "DriverIssue", e);
return false;
}
// Connection
String dbUrl = "jdbc:derby:" + dbName;
Connection conn = null;
try
{
String urlAttributes = ";create=true"
// + "dataEncryption=true;bootPassword=cLo4u922sc23aPe"
// + ";territory=en_US"
+ ";user=" + dbUid
+ ";password=" + dbPwd;
conn = DriverManager.getConnection(dbUrl + urlAttributes);
log.info("Created DB: " + dbName);
// new JDBCInfo(conn);
}
catch (Exception e)
{
log.severe(e.getMessage());
}
try
{
if (conn != null)
conn.close();
conn = null;
}
catch (Exception e)
{
}
// Connection test
try
{
conn = DriverManager.getConnection(dbUrl, dbUid, dbPwd);
log.info("Connected to DB: " + dbName);
// new JDBCInfo(conn);
}
catch (Exception e)
{
log.severe(e.getMessage());
conn = null;
return false;
}
// Connection test
Statement stmt = null;
try
{
stmt = conn.createStatement();
stmt.executeUpdate("CREATE TABLE XX (XX VARCHAR(5))");
stmt.executeUpdate("INSERT INTO XX (XX) VALUES ('A')");
}
catch (Exception e)
{
log.info(e.getMessage());
}
try
{
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
conn = null;
}
catch (Exception e)
{
}
return true;
} // createDatabase
/**************************************************************************
* Start Derby Server
* @param args
*/
public static void main (String[] args)
{
CLogMgt.setLevel(Level.FINE);
DerbyServer server = DerbyServer.get();
startServer();
server.createDatabase("compiere", "compiere", "compiere");
// log.info(server.getRuntimeInfo());
// log.info(server.getSysInfo());
try
{
// log.info(server.getCurrentProperties().toString());
//
log.info("Sleeping " + get());
Thread.sleep(5000);
}
catch (Exception e)
{
}
// stopServer();
} // main
} // DerbyServer

View File

@ -1,200 +1,200 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.db;
import java.util.*;
import java.util.logging.*;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.naming.directory.*;
import org.compiere.util.*;
/**
* LDAP Management Interface
*
* @author Jorg Janke
* @version $Id: LDAP.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
*/
public class LDAP
{
/**
* Validate User
* @param ldapURL provider url - e.g. ldap://dc.adempiere.org
* @param domain domain name = e.g. adempiere.org
* @param userName user name - e.g. jjanke
* @param password password
* @return true if validated with ldap
*/
public static boolean validate (String ldapURL, String domain, String userName, String password)
{
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
// ldap://dc.adempiere.org
env.put(Context.PROVIDER_URL, ldapURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
// jjanke@adempiere.org
StringBuffer principal = new StringBuffer (userName)
.append("@").append(domain);
env.put(Context.SECURITY_PRINCIPAL, principal.toString());
env.put(Context.SECURITY_CREDENTIALS, password);
//
try
{
// Create the initial context
InitialLdapContext ctx = new InitialLdapContext(env, null);
// DirContext ctx = new InitialDirContext(env);
// Test - Get the attributes
Attributes answer = ctx.getAttributes("");
// Print the answer
// dump (answer);
}
catch (AuthenticationException e)
{
log.info("Error: " + principal + " - " + e.getLocalizedMessage());
return false;
}
catch (Exception e)
{
log.log (Level.SEVERE, ldapURL + " - " + principal, e);
return false;
}
log.info("OK: " + principal);
return true;
} // validate
/** Logger */
private static CLogger log = CLogger.getCLogger (LDAP.class);
/**
* Test NT
* @throws LoginException
*
private static void testNT () throws LoginException
{
try
{
System.out.println ("NT system ----------------------------");
NTSystem ntsystem = new NTSystem ();
System.out.println (ntsystem);
System.out.println (ntsystem.getDomain ());
System.out.println (ntsystem.getDomainSID ());
System.out.println (ntsystem.getName ());
System.out.println (ntsystem.getUserSID ());
System.out.println ("NT login ----------------------------");
NTLoginModule ntlogin = new NTLoginModule ();
System.out.println (ntlogin);
Map<String,String> map = new HashMap<String,String>();
map.put ("debug", "true");
ntlogin.initialize (null, null, null, map);
System.out.println (ntlogin.login ());
}
catch (LoginException le)
{
System.err.println ("Authentication attempt failed" + le);
}
} // testNT
/**
* testKerberos
* @throws LoginException
*
private static void testKerberos ()
throws LoginException
{
System.out.println ("Krb login ----------------------------");
Map<String,String> map = new HashMap<String,String>();
// map.put("debug", "true");
// map.put("debugNative", "true");
Krb5LoginModule klogin = new Krb5LoginModule ();
System.out.println (klogin);
map.put ("principal", "username@adempiere.org");
map.put ("credential", "pass");
klogin.initialize (null, null, null, map);
System.out.println (klogin.login ());
/***********************************************************************
* ** No krb5.ini file found in entire system Debug is true storeKey
* false useTicketCache false useKeyTab false doNotPrompt false
* ticketCache is null KeyTab is null refreshKrb5Config is false
* principal is jjanke tryFirstPass is false useFirstPass is false
* storePass is false clearPass is false [Krb5LoginModule]
* authentication failed Could not load configuration file
* c:\winnt\krb5.ini (The system cannot find the file specified)
* javax.security.auth.login.LoginException: Could not load
* configuration file c:\winnt\krb5.ini (The system cannot find the file
* specified)
*
} // testKerbos
/**/
/**
* Print Attributes to System.out
* @param attrs
*/
private static void dump (Attributes attrs)
{
if (attrs == null)
{
System.out.println ("No attributes");
}
else
{
/* Print each attribute */
try
{
for (NamingEnumeration ae = attrs.getAll (); ae.hasMore ();)
{
Attribute attr = (Attribute) ae.next ();
System.out.println ("attribute: " + attr.getID ());
/* print each value */
for (NamingEnumeration e = attr.getAll();
e.hasMore ();
System.out.println (" value: " + e.next()))
;
}
}
catch (NamingException e)
{
e.printStackTrace ();
}
}
} // dump
/**
* Test
* @param args ignored
*/
public static void main (String[] args)
{
try
{
validate("ldap://dc.adempiere.org", "adempiere.org", "red1", "ikeepforgetting");
}
catch (Exception e)
{
e.printStackTrace();
}
} // main
} // LDAP
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
*****************************************************************************/
package org.compiere.db;
import java.util.*;
import java.util.logging.*;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.naming.directory.*;
import org.compiere.util.*;
/**
* LDAP Management Interface
*
* @author Jorg Janke
* @version $Id: LDAP.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
*/
public class LDAP
{
/**
* Validate User
* @param ldapURL provider url - e.g. ldap://dc.compiere.org
* @param domain domain name = e.g. compiere.org
* @param userName user name - e.g. jjanke
* @param password password
* @return true if validated with ldap
*/
public static boolean validate (String ldapURL, String domain, String userName, String password)
{
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
// ldap://dc.compiere.org
env.put(Context.PROVIDER_URL, ldapURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
// jjanke@compiere.org
StringBuffer principal = new StringBuffer (userName)
.append("@").append(domain);
env.put(Context.SECURITY_PRINCIPAL, principal.toString());
env.put(Context.SECURITY_CREDENTIALS, password);
//
try
{
// Create the initial context
InitialLdapContext ctx = new InitialLdapContext(env, null);
// DirContext ctx = new InitialDirContext(env);
// Test - Get the attributes
Attributes answer = ctx.getAttributes("");
// Print the answer
if (false)
dump (answer);
}
catch (AuthenticationException e)
{
log.info("Error: " + principal + " - " + e.getLocalizedMessage());
return false;
}
catch (Exception e)
{
log.log (Level.SEVERE, ldapURL + " - " + principal, e);
return false;
}
log.info("OK: " + principal);
return true;
} // validate
/** Logger */
private static CLogger log = CLogger.getCLogger (LDAP.class);
/**
* Test NT
* @throws LoginException
*
private static void testNT () throws LoginException
{
try
{
System.out.println ("NT system ----------------------------");
NTSystem ntsystem = new NTSystem ();
System.out.println (ntsystem);
System.out.println (ntsystem.getDomain ());
System.out.println (ntsystem.getDomainSID ());
System.out.println (ntsystem.getName ());
System.out.println (ntsystem.getUserSID ());
System.out.println ("NT login ----------------------------");
NTLoginModule ntlogin = new NTLoginModule ();
System.out.println (ntlogin);
Map<String,String> map = new HashMap<String,String>();
map.put ("debug", "true");
ntlogin.initialize (null, null, null, map);
System.out.println (ntlogin.login ());
}
catch (LoginException le)
{
System.err.println ("Authentication attempt failed" + le);
}
} // testNT
/**
* testKerberos
* @throws LoginException
*
private static void testKerberos ()
throws LoginException
{
System.out.println ("Krb login ----------------------------");
Map<String,String> map = new HashMap<String,String>();
// map.put("debug", "true");
// map.put("debugNative", "true");
Krb5LoginModule klogin = new Krb5LoginModule ();
System.out.println (klogin);
map.put ("principal", "username@compiere.org");
map.put ("credential", "pass");
klogin.initialize (null, null, null, map);
System.out.println (klogin.login ());
/***********************************************************************
* ** No krb5.ini file found in entire system Debug is true storeKey
* false useTicketCache false useKeyTab false doNotPrompt false
* ticketCache is null KeyTab is null refreshKrb5Config is false
* principal is jjanke tryFirstPass is false useFirstPass is false
* storePass is false clearPass is false [Krb5LoginModule]
* authentication failed Could not load configuration file
* c:\winnt\krb5.ini (The system cannot find the file specified)
* javax.security.auth.login.LoginException: Could not load
* configuration file c:\winnt\krb5.ini (The system cannot find the file
* specified)
*
} // testKerbos
/**/
/**
* Print Attributes to System.out
* @param attrs
*/
private static void dump (Attributes attrs)
{
if (attrs == null)
{
System.out.println ("No attributes");
}
else
{
/* Print each attribute */
try
{
for (NamingEnumeration ae = attrs.getAll (); ae.hasMore ();)
{
Attribute attr = (Attribute) ae.next ();
System.out.println ("attribute: " + attr.getID ());
/* print each value */
for (NamingEnumeration e = attr.getAll();
e.hasMore ();
System.out.println (" value: " + e.next()))
;
}
}
catch (NamingException e)
{
e.printStackTrace ();
}
}
} // dump
/**
* Test
* @param args ignored
*/
public static void main (String[] args)
{
try
{
validate("ldap://dc.compiere.org", "compiere.org", "jjanke", "ikeepforgetting");
}
catch (Exception e)
{
e.printStackTrace();
}
} // main
} // LDAP

View File

@ -1,15 +1,17 @@
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
*****************************************************************************/
package org.compiere.dbPort;

View File

@ -1,15 +1,17 @@
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
*****************************************************************************/
package org.compiere.dbPort;

View File

@ -3,58 +3,58 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import junit.framework.*;
import org.compiere.*;
/**
* AccessSqlParserTest tests the class
* AccessSqlParser
*
* @author Jorg Janke
* @version $Id: AccessSqlParserTest.java,v 1.2 2006/07/30 00:58:04 jjanke Exp $
*/
public class AccessSqlParserTest extends TestCase
{
/**
* Construct new test instance
*
* @param name the test name
*/
public AccessSqlParserTest(String name)
{
super(name);
}
/**
* Launch the test.
*
* @param args String[]
*/
public static void main(String[] args)
{
junit.swingui.TestRunner.run(AccessSqlParserTest.class);
}
/**
* Perform pre-test initialization
*
* @throws Exception
*
* @see TestCase#setUp()
*/
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import junit.framework.*;
import org.compiere.*;
/**
* AccessSqlParserTest tests the class
* AccessSqlParser
*
* @author Jorg Janke
* @version $Id: AccessSqlParserTest.java,v 1.2 2006/07/30 00:58:04 jjanke Exp $
*/
public class AccessSqlParserTest extends TestCase
{
/**
* Construct new test instance
*
* @param name the test name
*/
public AccessSqlParserTest(String name)
{
super(name);
}
/**
* Launch the test.
*
* @param args String[]
*/
public static void main(String[] args)
{
junit.swingui.TestRunner.run(AccessSqlParserTest.class);
}
/**
* Perform pre-test initialization
*
* @throws Exception
*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
@ -62,170 +62,170 @@ public class AccessSqlParserTest extends TestCase
}
/**
* Run the oneTable test
*/
public void testOneTable()
{
String sql = "SELECT AD_Table_ID, TableName FROM AD_Table WHERE IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table|0]", fixture.toString());
}
/**
* Run the oneTableSyn test
*/
public void testOneTableSyn()
{
String sql = "SELECT t.AD_Table_ID, t.TableName FROM AD_Table t WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t|0]", fixture.toString());
}
/**
* Run the oneTableSyn test
*/
public void testOneTableSynAS()
{
String sql = "SELECT t.AD_Table_ID, t.TableName FROM AD_Table AS t WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t|0]", fixture.toString());
}
/**
* Run the twoTable test
*/
public void testTwoTable()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName FROM AD_Table t, AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID AND t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString());
}
/**
* Run the twoTableSyn test
*/
public void testTwoTableSyn()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName FROM AD_Table as t, AD_Column AS c WHERE t.AD_Table_ID=c.AD_Table_ID AND t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString());
}
/**
* Run the joinInner test
*/
public void testJoinInner()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName "
+ "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString());
}
/**
* Run the joinOuter test
*/
public void testJoinOuter()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName "
+ "FROM AD_Table t LEFT OUTER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString());
}
/**
* Run the exists test
*/
public void testExists()
{
String sql = "SELECT AD_Table.AD_Table_ID, AD_Table.TableName "
+ "FROM AD_Table "
+ "WHERE EXISTS (SELECT * FROM AD_Column c WHERE AD_Table.AD_Table_ID=c.AD_Table_ID)";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Column=c|AD_Table|1]", fixture.toString());
}
/**
* Run the exists test with syn
*/
public void testExistsSyn()
{
String sql = "SELECT t.AD_Table_ID, t.TableName "
+ "FROM AD_Table t "
+ "WHERE EXISTS (SELECT * FROM AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID)";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Column=c|AD_Table=t|1]", fixture.toString());
}
/**
* Run the embeddedSelect test
*/
public void testEmbeddedSelect()
{
String sql = "SELECT t.AD_Table_ID, t.TableName,"
+ "(SELECT COUNT(c.ColumnName) FROM AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID) "
+ "FROM AD_Table t WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Column=c|AD_Table=t|1]", fixture.toString());
}
/**
* Run the embeddedFrom test
*/
public void testEmbeddedFrom()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, cc.CCount "
+ "FROM AD_Table t,"
+ "(SELECT COUNT(ColumnName) AS CCount FROM AD_Column) cc "
+ "WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Column|AD_Table=t,(##)=cc|1]", fixture.toString());
}
/**
* Run the Product & Instance Attribute Query
* Run the oneTable test
*/
public void testOneTable()
{
String sql = "SELECT AD_Table_ID, TableName FROM AD_Table WHERE IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table|0]", fixture.toString());
}
/**
* Run the oneTableSyn test
*/
public void testOneTableSyn()
{
String sql = "SELECT t.AD_Table_ID, t.TableName FROM AD_Table t WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t|0]", fixture.toString());
}
/**
* Run the oneTableSyn test
*/
public void testOneTableSynAS()
{
String sql = "SELECT t.AD_Table_ID, t.TableName FROM AD_Table AS t WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t|0]", fixture.toString());
}
/**
* Run the twoTable test
*/
public void testTwoTable()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName FROM AD_Table t, AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID AND t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString());
}
/**
* Run the twoTableSyn test
*/
public void testTwoTableSyn()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName FROM AD_Table as t, AD_Column AS c WHERE t.AD_Table_ID=c.AD_Table_ID AND t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString());
}
/**
* Run the joinInner test
*/
public void testJoinInner()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName "
+ "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString());
}
/**
* Run the joinOuter test
*/
public void testJoinOuter()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, c.AD_Column_ID, c.ColumnName "
+ "FROM AD_Table t LEFT OUTER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Table=t,AD_Column=c|0]", fixture.toString());
}
/**
* Run the exists test
*/
public void testExists()
{
String sql = "SELECT AD_Table.AD_Table_ID, AD_Table.TableName "
+ "FROM AD_Table "
+ "WHERE EXISTS (SELECT * FROM AD_Column c WHERE AD_Table.AD_Table_ID=c.AD_Table_ID)";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Column=c|AD_Table|1]", fixture.toString());
}
/**
* Run the exists test with syn
*/
public void testExistsSyn()
{
String sql = "SELECT t.AD_Table_ID, t.TableName "
+ "FROM AD_Table t "
+ "WHERE EXISTS (SELECT * FROM AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID)";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Column=c|AD_Table=t|1]", fixture.toString());
}
/**
* Run the embeddedSelect test
*/
public void testEmbeddedSelect()
{
String sql = "SELECT t.AD_Table_ID, t.TableName,"
+ "(SELECT COUNT(c.ColumnName) FROM AD_Column c WHERE t.AD_Table_ID=c.AD_Table_ID) "
+ "FROM AD_Table t WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Column=c|AD_Table=t|1]", fixture.toString());
}
/**
* Run the embeddedFrom test
*/
public void testEmbeddedFrom()
{
String sql = "SELECT t.AD_Table_ID, t.TableName, cc.CCount "
+ "FROM AD_Table t,"
+ "(SELECT COUNT(ColumnName) AS CCount FROM AD_Column) cc "
+ "WHERE t.IsActive='Y'";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[AD_Column|AD_Table=t,(##)=cc|1]", fixture.toString());
}
/**
* Run the Product & Instance Attribute Query
*/
public void testProductInstanceAttributeQuery()
{
String sql = "SELECT p.M_Product_ID, p.Discontinued, p.Value, p.Name, BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable, bomQtyList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd, BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand, BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved, BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin, bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit, pa.IsInstanceAttribute FROM M_Product p INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID) LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID) WHERE p.IsSummary='N' AND p.IsActive='Y' AND pr.IsActive='Y' AND pr.M_PriceList_Version_ID=? AND EXISTS (SELECT * FROM M_Storage s INNER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) WHERE s.M_Product_ID=p.M_Product_ID AND asi.SerNo LIKE '33' AND asi.Lot LIKE '33' AND asi.M_Lot_ID=101 AND TRUNC(asi.GuaranteeDate,'DD')<TO_DATE('2003-10-16','YYYY-MM-DD') AND asi.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=103 AND Value LIKE '33') AND (M_Attribute_ID=102 AND M_AttributeValue_ID=106))) AND p.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=101 AND M_AttributeValue_ID=105) AND (M_Attribute_ID=100 AND M_AttributeValue_ID=102)) AND p.AD_Client_ID IN(0,11) AND p.AD_Org_ID IN(0,11,12) ORDER BY QtyAvailable DESC, Margin DESC";
String sql = "SELECT p.M_Product_ID, p.Discontinued, p.Value, p.Name, BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable, bomQtyList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd, BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand, BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved, BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin, bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit, pa.IsInstanceAttribute FROM M_Product p INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID) LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID) WHERE p.IsSummary='N' AND p.IsActive='Y' AND pr.IsActive='Y' AND pr.M_PriceList_Version_ID=? AND EXISTS (SELECT * FROM M_Storage s INNER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) WHERE s.M_Product_ID=p.M_Product_ID AND asi.SerNo LIKE '33' AND asi.Lot LIKE '33' AND asi.M_Lot_ID=101 AND TRUNC(asi.GuaranteeDate)<TO_DATE('2003-10-16','YYYY-MM-DD') AND asi.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=103 AND Value LIKE '33') AND (M_Attribute_ID=102 AND M_AttributeValue_ID=106))) AND p.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=101 AND M_AttributeValue_ID=105) AND (M_Attribute_ID=100 AND M_AttributeValue_ID=102)) AND p.AD_Client_ID IN(0,11) AND p.AD_Org_ID IN(0,11,12) ORDER BY QtyAvailable DESC, Margin DESC";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[M_AttributeInstance|M_Storage=s,M_AttributeSetInstance=asi|M_AttributeInstance|M_Product=p,M_ProductPrice=pr,M_AttributeSet=pa|3]", fixture.toString());
}
/**
* Run the Product Attribute Query
*/
public void testProductAttributeQuery()
{
String sql = "SELECT p.M_Product_ID, p.Discontinued, p.Value, p.Name, BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable, bomQtyList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd, BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand, BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved, BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin, bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit, pa.IsInstanceAttribute FROM M_Product p INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID) LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID) WHERE p.IsSummary='N' AND p.IsActive='Y' AND pr.IsActive='Y' AND pr.M_PriceList_Version_ID=? AND p.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=100 AND M_AttributeValue_ID=101)) ORDER BY QtyAvailable DESC, Margin DESC";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[M_AttributeInstance|M_Product=p,M_ProductPrice=pr,M_AttributeSet=pa|1]", fixture.toString());
}
/** **/
public void testHinttech()
{
String sql = "SELECT XX_HTC1_EMPLOYEE_V.C_BPartner_ID,NULL,XX_HTC1_EMPLOYEE_V.C_BPARTNER_NAME,XX_HTC1_EMPLOYEE_V.IsActive FROM XX_HTC1_EMPLOYEE_V WHERE XX_HTC1_EMPLOYEE_V.AD_User_ID IN (SELECT ur.AD_User_ID FROM AD_User_Roles ur INNER JOIN AD_Role r ON (ur.AD_Role_ID=r.AD_Role_ID) WHERE r.Name like '%Field Manager%')";
AccessSqlParser fixture = new AccessSqlParser(sql);
}
}
/*$CPS$ This comment was generated by CodePro. Do not edit it.
* patternId = com.instantiations.assist.eclipse.pattern.testCasePattern
* strategyId = com.instantiations.assist.eclipse.pattern.testCasePattern.junitTestCase
* additionalTestNames = oneTable, oneTableSyn, twoTable, twoTableSyn, joinInner, joinOuter, embeddedSelect, embeddedFrom
* assertTrue = false
* callTestMethod = true
* createMain = true
* createSetUp = true
* createTearDown = false
* createTestFixture = false
* createTestStubs = false
* methods = getSql(),parse()
* package = org.compiere.model
* package.sourceFolder = dbPort/src
* superclassType = junit.framework.TestCase
* testCase = AccessSqlParserTest
* testClassType = org.compiere.model.AccessSqlParser
*/
/**
* Run the Product Attribute Query
*/
public void testProductAttributeQuery()
{
String sql = "SELECT p.M_Product_ID, p.Discontinued, p.Value, p.Name, BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable, bomQtyList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd, BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand, BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved, BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered, bomQtyStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin, bomQtyLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit, pa.IsInstanceAttribute FROM M_Product p INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID) LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID) WHERE p.IsSummary='N' AND p.IsActive='Y' AND pr.IsActive='Y' AND pr.M_PriceList_Version_ID=? AND p.M_AttributeSetInstance_ID IN (SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance WHERE (M_Attribute_ID=100 AND M_AttributeValue_ID=101)) ORDER BY QtyAvailable DESC, Margin DESC";
AccessSqlParser fixture = new AccessSqlParser(sql);
assertEquals("AccessSqlParser[M_AttributeInstance|M_Product=p,M_ProductPrice=pr,M_AttributeSet=pa|1]", fixture.toString());
}
/** **/
public void testHinttech()
{
String sql = "SELECT XX_HTC1_EMPLOYEE_V.C_BPartner_ID,NULL,XX_HTC1_EMPLOYEE_V.C_BPARTNER_NAME,XX_HTC1_EMPLOYEE_V.IsActive FROM XX_HTC1_EMPLOYEE_V WHERE XX_HTC1_EMPLOYEE_V.AD_User_ID IN (SELECT ur.AD_User_ID FROM AD_User_Roles ur INNER JOIN AD_Role r ON (ur.AD_Role_ID=r.AD_Role_ID) WHERE r.Name like '%Field Manager%')";
AccessSqlParser fixture = new AccessSqlParser(sql);
}
}
/*$CPS$ This comment was generated by CodePro. Do not edit it.
* patternId = com.instantiations.assist.eclipse.pattern.testCasePattern
* strategyId = com.instantiations.assist.eclipse.pattern.testCasePattern.junitTestCase
* additionalTestNames = oneTable, oneTableSyn, twoTable, twoTableSyn, joinInner, joinOuter, embeddedSelect, embeddedFrom
* assertTrue = false
* callTestMethod = true
* createMain = true
* createSetUp = true
* createTearDown = false
* createTestFixture = false
* createTestStubs = false
* methods = getSql(),parse()
* package = org.compiere.model
* package.sourceFolder = dbPort/src
* superclassType = junit.framework.TestCase
* testCase = AccessSqlParserTest
* testClassType = org.compiere.model.AccessSqlParser
*/

View File

@ -3,238 +3,238 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Client Share Info
*
* @author Jorg Janke
* @version $Id: MClientShare.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
*/
public class MClientShare extends X_AD_ClientShare
{
/**
* Is Table Client Level Only
* @param AD_Client_ID client
* @param AD_Table_ID table
* @return true if client level only (default false)
*/
public static boolean isClientLevelOnly (int AD_Client_ID, int AD_Table_ID)
{
Boolean share = isShared(AD_Client_ID, AD_Table_ID);
if (share != null)
return share.booleanValue();
return false;
} // isClientLevel
/**
* Is Table Org Level Only
* @param AD_Client_ID client
* @param AD_Table_ID table
* @return true if Org level only (default false)
*/
public static boolean isOrgLevelOnly (int AD_Client_ID, int AD_Table_ID)
{
Boolean share = isShared(AD_Client_ID, AD_Table_ID);
if (share != null)
return !share.booleanValue();
return false;
} // isOrgLevel
/**
* Is Table Shared for Client
* @param AD_Client_ID client
* @param AD_Table_ID table
* @return info or null
*/
private static Boolean isShared (int AD_Client_ID, int AD_Table_ID)
{
// Load
if (s_shares.isEmpty())
{
String sql = "SELECT AD_Client_ID, AD_Table_ID, ShareType "
+ "FROM AD_ClientShare WHERE ShareType<>'x' AND IsActive='Y'";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
int Client_ID = rs.getInt(1);
int table_ID = rs.getInt(2);
String key = Client_ID + "_" + table_ID;
String ShareType = rs.getString(3);
if (ShareType.equals(SHARETYPE_ClientAllShared))
s_shares.put(key, Boolean.TRUE);
else if (ShareType.equals(SHARETYPE_OrgNotShared))
s_shares.put(key, Boolean.FALSE);
}
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;
}
if (s_shares.isEmpty()) // put in something
s_shares.put("0_0", Boolean.TRUE);
} // load
String key = AD_Client_ID + "_" + AD_Table_ID;
return s_shares.get(key);
} // load
/** Shared Info */
private static CCache<String,Boolean> s_shares
= new CCache<String,Boolean>("AD_ClientShare", 10, 120); // 2h
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MClientShare.class);
/**************************************************************************
* Default Constructor
* @param ctx context
* @param AD_ClientShare_ID id
* @param trxName trx
*/
public MClientShare (Properties ctx, int AD_ClientShare_ID, String trxName)
{
super (ctx, AD_ClientShare_ID, trxName);
} // MClientShare
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName trx
*/
public MClientShare (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
} // MClientShare
/** The Table */
private MTable m_table = null;
/**
* Is Client Level Only
* @return true if client level only (shared)
*/
public boolean isClientLevelOnly()
{
return getShareType().equals(SHARETYPE_ClientAllShared);
} // isClientLevelOnly
/**
* Is Org Level Only
* @return true if org level only (not shared)
*/
public boolean isOrgLevelOnly()
{
return getShareType().equals(SHARETYPE_OrgNotShared);
} // isOrgLevelOnly
/**
* Get Table model
* @return table
*/
public MTable getTable()
{
if (m_table == null)
m_table = MTable.get(getCtx(), getAD_Table_ID());
return m_table;
} // getTable
/**
* Get Table Name
* @return table name
*/
public String getTableName()
{
return getTable().getTableName();
} // getTableName
/**
* After Save
* @param newRecord new
* @param success success
* @return true
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
if (isActive())
{
setDataToLevel();
listChildRecords();
}
return true;
} // afterSave
/**
* Set Data To Level
* @return info
*/
public String setDataToLevel()
{
String info = "-";
if (isClientLevelOnly())
{
StringBuffer sql = new StringBuffer("UPDATE ")
.append(getTableName())
.append(" SET AD_Org_ID=0 WHERE AD_Org_ID<>0 AND AD_Client_ID=?");
int no = DB.executeUpdate(sql.toString(), getAD_Client_ID(), get_TrxName());
info = getTableName() + " set to Shared #" + no;
log.info(info);
}
else if (isOrgLevelOnly())
{
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM ")
.append(getTableName())
.append(" WHERE AD_Org_ID=0 WHERE AD_Client_ID=?");
int no = DB.getSQLValue(get_TrxName(), sql.toString(), getAD_Client_ID());
info = getTableName() + " Shared records #" + no;
log.info(info);
}
return info;
} // setDataToLevel
/**
* List Child Tables
* @return child tables
*/
public String listChildRecords()
{
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Client Share Info
*
* @author Jorg Janke
* @version $Id: MClientShare.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
*/
public class MClientShare extends X_AD_ClientShare
{
/**
* Is Table Client Level Only
* @param AD_Client_ID client
* @param AD_Table_ID table
* @return true if client level only (default false)
*/
public static boolean isClientLevelOnly (int AD_Client_ID, int AD_Table_ID)
{
Boolean share = isShared(AD_Client_ID, AD_Table_ID);
if (share != null)
return share.booleanValue();
return false;
} // isClientLevel
/**
* Is Table Org Level Only
* @param AD_Client_ID client
* @param AD_Table_ID table
* @return true if Org level only (default false)
*/
public static boolean isOrgLevelOnly (int AD_Client_ID, int AD_Table_ID)
{
Boolean share = isShared(AD_Client_ID, AD_Table_ID);
if (share != null)
return !share.booleanValue();
return false;
} // isOrgLevel
/**
* Is Table Shared for Client
* @param AD_Client_ID client
* @param AD_Table_ID table
* @return info or null
*/
private static Boolean isShared (int AD_Client_ID, int AD_Table_ID)
{
// Load
if (s_shares.isEmpty())
{
String sql = "SELECT AD_Client_ID, AD_Table_ID, ShareType "
+ "FROM AD_ClientShare WHERE ShareType<>'x' AND IsActive='Y'";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
int Client_ID = rs.getInt(1);
int table_ID = rs.getInt(2);
String key = Client_ID + "_" + table_ID;
String ShareType = rs.getString(3);
if (ShareType.equals(SHARETYPE_ClientAllShared))
s_shares.put(key, Boolean.TRUE);
else if (ShareType.equals(SHARETYPE_OrgNotShared))
s_shares.put(key, Boolean.FALSE);
}
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;
}
if (s_shares.isEmpty()) // put in something
s_shares.put("0_0", Boolean.TRUE);
} // load
String key = AD_Client_ID + "_" + AD_Table_ID;
return s_shares.get(key);
} // load
/** Shared Info */
private static CCache<String,Boolean> s_shares
= new CCache<String,Boolean>("AD_ClientShare", 10, 120); // 2h
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MClientShare.class);
/**************************************************************************
* Default Constructor
* @param ctx context
* @param AD_ClientShare_ID id
* @param trxName trx
*/
public MClientShare (Properties ctx, int AD_ClientShare_ID, String trxName)
{
super (ctx, AD_ClientShare_ID, trxName);
} // MClientShare
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName trx
*/
public MClientShare (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
} // MClientShare
/** The Table */
private MTable m_table = null;
/**
* Is Client Level Only
* @return true if client level only (shared)
*/
public boolean isClientLevelOnly()
{
return getShareType().equals(SHARETYPE_ClientAllShared);
} // isClientLevelOnly
/**
* Is Org Level Only
* @return true if org level only (not shared)
*/
public boolean isOrgLevelOnly()
{
return getShareType().equals(SHARETYPE_OrgNotShared);
} // isOrgLevelOnly
/**
* Get Table model
* @return table
*/
public MTable getTable()
{
if (m_table == null)
m_table = MTable.get(getCtx(), getAD_Table_ID());
return m_table;
} // getTable
/**
* Get Table Name
* @return table name
*/
public String getTableName()
{
return getTable().getTableName();
} // getTableName
/**
* After Save
* @param newRecord new
* @param success success
* @return true
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
if (isActive())
{
setDataToLevel();
listChildRecords();
}
return true;
} // afterSave
/**
* Set Data To Level
* @return info
*/
public String setDataToLevel()
{
String info = "-";
if (isClientLevelOnly())
{
StringBuffer sql = new StringBuffer("UPDATE ")
.append(getTableName())
.append(" SET AD_Org_ID=0 WHERE AD_Org_ID<>0 AND AD_Client_ID=?");
int no = DB.executeUpdate(sql.toString(), getAD_Client_ID(), get_TrxName());
info = getTableName() + " set to Shared #" + no;
log.info(info);
}
else if (isOrgLevelOnly())
{
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM ")
.append(getTableName())
.append(" WHERE AD_Org_ID=0 WHERE AD_Client_ID=?");
int no = DB.getSQLValue(get_TrxName(), sql.toString(), getAD_Client_ID());
info = getTableName() + " Shared records #" + no;
log.info(info);
}
return info;
} // setDataToLevel
/**
* List Child Tables
* @return child tables
*/
public String listChildRecords()
{
StringBuffer info = new StringBuffer();
String sql = "SELECT AD_Table_ID, TableName "
+ "FROM AD_Table t "
+ "WHERE AccessLevel='3' AND IsView='N'" //jz put quote for typing
+ "WHERE AccessLevel=3 AND IsView='N'"
+ " AND EXISTS (SELECT * FROM AD_Column c "
+ "WHERE t.AD_Table_ID=c.AD_Table_ID"
+ " AND c.IsParent='Y'"
@ -242,50 +242,50 @@ public class MClientShare extends X_AD_ClientShare
+ "WHERE cc.IsKey='Y' AND cc.AD_Table_ID=?))";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_Table_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
int AD_Table_ID = rs.getInt(1);
String TableName = rs.getString(2);
if (info.length() != 0)
info.append(", ");
info.append(TableName);
}
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;
}
log.info(info.toString());
return info.toString();
} // listChildRecords
/**
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
if (getAD_Org_ID() != 0)
setAD_Org_ID(0);
return true;
} // beforeSave
} // MClientShare
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_Table_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
int AD_Table_ID = rs.getInt(1);
String TableName = rs.getString(2);
if (info.length() != 0)
info.append(", ");
info.append(TableName);
}
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;
}
log.info(info.toString());
return info.toString();
} // listChildRecords
/**
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
if (getAD_Org_ID() != 0)
setAD_Org_ID(0);
return true;
} // beforeSave
} // MClientShare

View File

@ -3,52 +3,52 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Cost Element Model
* @author Jorg Janke
* @version $Id: MCostElement.java,v 1.2 2006/07/30 00:58:04 jjanke Exp $
*/
public class MCostElement extends X_M_CostElement
{
/**
* Get Material Cost Element or create it
* @param po parent
* @param CostingMethod method
* @return cost element
*/
public static MCostElement getMaterialCostElement (PO po, String CostingMethod)
{
if (CostingMethod == null || CostingMethod.length() == 0)
{
s_log.severe("No CostingMethod");
return null;
}
//
MCostElement retValue = null;
String sql = "SELECT * FROM M_CostElement WHERE AD_Client_ID=? AND CostingMethod=? ORDER BY AD_Org_ID";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, po.get_TrxName());
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Cost Element Model
* @author Jorg Janke
* @version $Id: MCostElement.java,v 1.2 2006/07/30 00:58:04 jjanke Exp $
*/
public class MCostElement extends X_M_CostElement
{
/**
* Get Material Cost Element or create it
* @param po parent
* @param CostingMethod method
* @return cost element
*/
public static MCostElement getMaterialCostElement (PO po, String CostingMethod)
{
if (CostingMethod == null || CostingMethod.length() == 0)
{
s_log.severe("No CostingMethod");
return null;
}
//
MCostElement retValue = null;
String sql = "SELECT * FROM M_CostElement WHERE AD_Client_ID=? AND CostingMethod=? ORDER BY AD_Org_ID";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, po.get_TrxName());
pstmt.setInt (1, po.getAD_Client_ID());
pstmt.setString(2, CostingMethod);
ResultSet rs = pstmt.executeQuery ();
@ -59,400 +59,400 @@ public class MCostElement extends X_M_CostElement
s_log.warning("More then one Material Cost Element for CostingMethod=" + CostingMethod);
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;
}
if (retValue != null)
return retValue;
// Create New
retValue = new MCostElement (po.getCtx(), 0, po.get_TrxName());
retValue.setClientOrg(po.getAD_Client_ID(), 0);
String name = MRefList.getListName(po.getCtx(), COSTINGMETHOD_AD_Reference_ID, CostingMethod);
if (name == null || name.length() == 0)
name = CostingMethod;
retValue.setName(name);
retValue.setCostElementType(COSTELEMENTTYPE_Material);
retValue.setCostingMethod(CostingMethod);
retValue.save();
//
return retValue;
} // getMaterialCostElement
/**
* Get first Material Cost Element
* @param ctx context
* @param CostingMethod costing method
* @return Cost Element or null
*/
public static MCostElement getMaterialCostElement(Properties ctx, String CostingMethod)
{
MCostElement retValue = null;
String sql = "SELECT * FROM M_CostElement WHERE AD_Client_ID=? AND CostingMethod=? ORDER BY AD_Org_ID";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, Env.getAD_Client_ID(ctx));
pstmt.setString(2, CostingMethod);
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
retValue = new MCostElement (ctx, rs, null);
if (rs.next())
s_log.info("More then one Material Cost Element for CostingMethod=" + CostingMethod);
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;
}
return retValue;
} // getMaterialCostElement
/**
* Get active Material Cost Element for client
* @param po parent
* @return cost element array
*/
public static MCostElement[] getCostingMethods (PO po)
{
ArrayList<MCostElement> list = new ArrayList<MCostElement>();
String sql = "SELECT * FROM M_CostElement "
+ "WHERE AD_Client_ID=?"
+ " AND IsActive='Y' AND CostElementType='M' AND CostingMethod IS NOT NULL";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, po.get_TrxName());
pstmt.setInt (1, po.getAD_Client_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add(new MCostElement (po.getCtx(), rs, po.get_TrxName()));
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;
}
//
MCostElement[] retValue = new MCostElement[list.size ()];
list.toArray (retValue);
return retValue;
} // getMaterialCostElement
/**
* Get Cost Element from Cache
* @param ctx context
* @param M_CostElement_ID id
* @return Cost Element
*/
public static MCostElement get (Properties ctx, int M_CostElement_ID)
{
Integer key = new Integer (M_CostElement_ID);
MCostElement retValue = (MCostElement) s_cache.get (key);
if (retValue != null)
return retValue;
retValue = new MCostElement (ctx, M_CostElement_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
} // get
/** Cache */
private static CCache<Integer,MCostElement> s_cache = new CCache<Integer,MCostElement>("M_CostElement", 20);
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MCostElement.class);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param M_CostElement_ID id
* @param trxName trx
*/
public MCostElement (Properties ctx, int M_CostElement_ID, String trxName)
{
super (ctx, M_CostElement_ID, trxName);
if (M_CostElement_ID == 0)
{
// setName (null);
setCostElementType (COSTELEMENTTYPE_Material);
setIsCalculated (false);
}
} // MCostElement
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName trx
*/
public MCostElement (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
} // MCostElement
/**
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
// Check Unique Costing Method
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;
}
if (retValue != null)
return retValue;
// Create New
retValue = new MCostElement (po.getCtx(), 0, po.get_TrxName());
retValue.setClientOrg(po.getAD_Client_ID(), 0);
String name = MRefList.getListName(po.getCtx(), COSTINGMETHOD_AD_Reference_ID, CostingMethod);
if (name == null || name.length() == 0)
name = CostingMethod;
retValue.setName(name);
retValue.setCostElementType(COSTELEMENTTYPE_Material);
retValue.setCostingMethod(CostingMethod);
retValue.save();
//
return retValue;
} // getMaterialCostElement
/**
* Get first Material Cost Element
* @param ctx context
* @param CostingMethod costing method
* @return Cost Element or null
*/
public static MCostElement getMaterialCostElement(Properties ctx, String CostingMethod)
{
MCostElement retValue = null;
String sql = "SELECT * FROM M_CostElement WHERE AD_Client_ID=? AND CostingMethod=? ORDER BY AD_Org_ID";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, Env.getAD_Client_ID(ctx));
pstmt.setString(2, CostingMethod);
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
retValue = new MCostElement (ctx, rs, null);
if (rs.next())
s_log.info("More then one Material Cost Element for CostingMethod=" + CostingMethod);
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;
}
return retValue;
} // getMaterialCostElement
/**
* Get active Material Cost Element for client
* @param po parent
* @return cost element array
*/
public static MCostElement[] getCostingMethods (PO po)
{
ArrayList<MCostElement> list = new ArrayList<MCostElement>();
String sql = "SELECT * FROM M_CostElement "
+ "WHERE AD_Client_ID=?"
+ " AND IsActive='Y' AND CostElementType='M' AND CostingMethod IS NOT NULL";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, po.get_TrxName());
pstmt.setInt (1, po.getAD_Client_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add(new MCostElement (po.getCtx(), rs, po.get_TrxName()));
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;
}
//
MCostElement[] retValue = new MCostElement[list.size ()];
list.toArray (retValue);
return retValue;
} // getMaterialCostElement
/**
* Get Cost Element from Cache
* @param ctx context
* @param M_CostElement_ID id
* @return Cost Element
*/
public static MCostElement get (Properties ctx, int M_CostElement_ID)
{
Integer key = new Integer (M_CostElement_ID);
MCostElement retValue = (MCostElement) s_cache.get (key);
if (retValue != null)
return retValue;
retValue = new MCostElement (ctx, M_CostElement_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
} // get
/** Cache */
private static CCache<Integer,MCostElement> s_cache = new CCache<Integer,MCostElement>("M_CostElement", 20);
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MCostElement.class);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param M_CostElement_ID id
* @param trxName trx
*/
public MCostElement (Properties ctx, int M_CostElement_ID, String trxName)
{
super (ctx, M_CostElement_ID, trxName);
if (M_CostElement_ID == 0)
{
// setName (null);
setCostElementType (COSTELEMENTTYPE_Material);
setIsCalculated (false);
}
} // MCostElement
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName trx
*/
public MCostElement (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
} // MCostElement
/**
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
// Check Unique Costing Method
if (COSTELEMENTTYPE_Material.equals(getCostElementType())
&& (newRecord || is_ValueChanged("CostingMethod")))
{
String sql = "SELECT MAX(COALESCE(M_CostElement_ID,0)) FROM M_CostElement "
String sql = "SELECT COALESCE(MAX(M_CostElement_ID),0) FROM M_CostElement "
+ "WHERE AD_Client_ID=? AND CostingMethod=?";
int id = DB.getSQLValue(get_TrxName(), sql, getAD_Client_ID(), getCostingMethod());
if (id > 0 && id != get_ID())
{
log.saveError("AlreadyExists", Msg.getElement(getCtx(), "CostingMethod"));
return false;
}
}
// Maintain Calclated
if (COSTELEMENTTYPE_Material.equals(getCostElementType()))
{
String cm = getCostingMethod();
if (cm == null || cm.length() == 0
|| COSTINGMETHOD_StandardCosting.equals(cm))
setIsCalculated(false);
else
setIsCalculated(true);
}
else
{
if (isCalculated())
setIsCalculated(false);
if (getCostingMethod() != null)
setCostingMethod(null);
}
if (getAD_Org_ID() != 0)
setAD_Org_ID(0);
return true;
} // beforeSave
/**
* Before Delete
* @return true if can be deleted
*/
protected boolean beforeDelete ()
{
String cm = getCostingMethod();
if (cm == null
|| !COSTELEMENTTYPE_Material.equals(getCostElementType()))
return true;
// Costing Methods on AS level
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID());
for (int i = 0; i < ass.length; i++)
{
if (ass[i].getCostingMethod().equals(getCostingMethod()))
{
log.saveError("CannotDeleteUsed", Msg.getElement(getCtx(), "C_AcctSchema_ID")
+ " - " + ass[i].getName());
return false;
}
}
// Costing Methods on PC level
String sql = "SELECT M_Product_Category_ID FROM M_Product_Category_Acct WHERE AD_Client_ID=? AND CostingMethod=?";
int M_Product_Category_ID = 0;
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_Client_ID());
pstmt.setString (2, getCostingMethod());
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
{
M_Product_Category_ID = rs.getInt(1);
}
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;
}
if (M_Product_Category_ID != 0)
{
log.saveError("CannotDeleteUsed", Msg.getElement(getCtx(), "M_Product_Category_ID")
+ " (ID=" + M_Product_Category_ID + ")");
return false;
}
return true;
} // beforeDelete
/**
* Is this a Costing Method
* @return true if not Material cost or no costing method.
*/
public boolean isCostingMethod()
{
return COSTELEMENTTYPE_Material.equals(getCostElementType())
&& getCostingMethod() != null;
} // isCostingMethod
/**
* Is Avg Invoice Costing Method
* @return true if AverageInvoice
*/
public boolean isAverageInvoice()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_AverageInvoice)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isAverageInvoice
/**
* Is Avg PO Costing Method
* @return true if AveragePO
*/
public boolean isAveragePO()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_AveragePO)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isAveragePO
/**
* Is FiFo Costing Method
* @return true if Fifo
*/
public boolean isFifo()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_Fifo)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isFifo
/**
* Is Last Invoice Costing Method
* @return true if LastInvoice
*/
public boolean isLastInvoice()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_LastInvoice)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isLastInvoice
/**
* Is Last PO Costing Method
* @return true if LastPOPrice
*/
public boolean isLastPOPrice()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_LastPOPrice)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isLastPOPrice
/**
* Is LiFo Costing Method
* @return true if Lifo
*/
public boolean isLifo()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_Lifo)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isLiFo
/**
* Is Std Costing Method
* @return true if StandardCosting
*/
public boolean isStandardCosting()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_StandardCosting)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isStandardCosting
/**
* Is User Costing Method
* @return true if User Defined
*/
public boolean isUserDefined()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_UserDefined)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isAveragePO
/**
* String Representation
* @return info
*/
public String toString ()
{
StringBuffer sb = new StringBuffer ("MCostElement[");
sb.append (get_ID ())
.append ("-").append (getName())
.append(",Type=").append(getCostElementType())
.append(",Method=").append(getCostingMethod())
.append ("]");
return sb.toString ();
} // toString
} // MCostElement
{
log.saveError("AlreadyExists", Msg.getElement(getCtx(), "CostingMethod"));
return false;
}
}
// Maintain Calclated
if (COSTELEMENTTYPE_Material.equals(getCostElementType()))
{
String cm = getCostingMethod();
if (cm == null || cm.length() == 0
|| COSTINGMETHOD_StandardCosting.equals(cm))
setIsCalculated(false);
else
setIsCalculated(true);
}
else
{
if (isCalculated())
setIsCalculated(false);
if (getCostingMethod() != null)
setCostingMethod(null);
}
if (getAD_Org_ID() != 0)
setAD_Org_ID(0);
return true;
} // beforeSave
/**
* Before Delete
* @return true if can be deleted
*/
protected boolean beforeDelete ()
{
String cm = getCostingMethod();
if (cm == null
|| !COSTELEMENTTYPE_Material.equals(getCostElementType()))
return true;
// Costing Methods on AS level
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID());
for (int i = 0; i < ass.length; i++)
{
if (ass[i].getCostingMethod().equals(getCostingMethod()))
{
log.saveError("CannotDeleteUsed", Msg.getElement(getCtx(), "C_AcctSchema_ID")
+ " - " + ass[i].getName());
return false;
}
}
// Costing Methods on PC level
String sql = "SELECT M_Product_Category_ID FROM M_Product_Category_Acct WHERE AD_Client_ID=? AND CostingMethod=?";
int M_Product_Category_ID = 0;
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getAD_Client_ID());
pstmt.setString (2, getCostingMethod());
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
{
M_Product_Category_ID = rs.getInt(1);
}
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;
}
if (M_Product_Category_ID != 0)
{
log.saveError("CannotDeleteUsed", Msg.getElement(getCtx(), "M_Product_Category_ID")
+ " (ID=" + M_Product_Category_ID + ")");
return false;
}
return true;
} // beforeDelete
/**
* Is this a Costing Method
* @return true if not Material cost or no costing method.
*/
public boolean isCostingMethod()
{
return COSTELEMENTTYPE_Material.equals(getCostElementType())
&& getCostingMethod() != null;
} // isCostingMethod
/**
* Is Avg Invoice Costing Method
* @return true if AverageInvoice
*/
public boolean isAverageInvoice()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_AverageInvoice)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isAverageInvoice
/**
* Is Avg PO Costing Method
* @return true if AveragePO
*/
public boolean isAveragePO()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_AveragePO)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isAveragePO
/**
* Is FiFo Costing Method
* @return true if Fifo
*/
public boolean isFifo()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_Fifo)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isFifo
/**
* Is Last Invoice Costing Method
* @return true if LastInvoice
*/
public boolean isLastInvoice()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_LastInvoice)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isLastInvoice
/**
* Is Last PO Costing Method
* @return true if LastPOPrice
*/
public boolean isLastPOPrice()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_LastPOPrice)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isLastPOPrice
/**
* Is LiFo Costing Method
* @return true if Lifo
*/
public boolean isLifo()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_Lifo)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isLiFo
/**
* Is Std Costing Method
* @return true if StandardCosting
*/
public boolean isStandardCosting()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_StandardCosting)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isStandardCosting
/**
* Is User Costing Method
* @return true if User Defined
*/
public boolean isUserDefined()
{
String cm = getCostingMethod();
return cm != null
&& cm.equals(COSTINGMETHOD_UserDefined)
&& COSTELEMENTTYPE_Material.equals(getCostElementType());
} // isAveragePO
/**
* String Representation
* @return info
*/
public String toString ()
{
StringBuffer sb = new StringBuffer ("MCostElement[");
sb.append (get_ID ())
.append ("-").append (getName())
.append(",Type=").append(getCostElementType())
.append(",Method=").append(getCostingMethod())
.append ("]");
return sb.toString ();
} // toString
} // MCostElement

File diff suppressed because it is too large Load Diff

View File

@ -3,224 +3,217 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Organization Model
*
* @author Jorg Janke
* @version $Id: MOrg.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
*/
public class MOrg extends X_AD_Org
{
/**
* Get Organizations Of Client
* @param po persistent object
* @return array of orgs
*/
public static MOrg[] getOfClient (PO po)
{
ArrayList<MOrg> list = new ArrayList<MOrg>();
String sql = "SELECT * FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, po.getAD_Client_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MOrg (po.getCtx(), rs, null));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
MOrg[] retValue = new MOrg[list.size ()];
list.toArray (retValue);
return retValue;
} // getOfClient
/**
* Get Org from Cache
* @param ctx context
* @param AD_Org_ID id
* @return MOrg
*/
public static MOrg get (Properties ctx, int AD_Org_ID)
{
Integer key = new Integer (AD_Org_ID);
MOrg retValue = (MOrg) s_cache.get (key);
if (retValue != null)
return retValue;
retValue = new MOrg (ctx, AD_Org_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
} // get
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MOrg.class);
/** Cache */
private static CCache<Integer,MOrg> s_cache = new CCache<Integer,MOrg>("AD_Org", 20);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param AD_Org_ID id
* @param trxName transaction
*/
public MOrg (Properties ctx, int AD_Org_ID, String trxName)
{
super(ctx, AD_Org_ID, trxName);
if (AD_Org_ID == 0)
{
// setValue (null);
// setName (null);
setIsSummary (false);
}
} // MOrg
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName transaction
*/
public MOrg (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MOrg
/**
* Parent Constructor
* @param client client
* @param name name
*/
public MOrg (MClient client, String name)
{
this (client.getCtx(), 0, client.get_TrxName());
setAD_Client_ID (client.getAD_Client_ID());
setValue (name);
setName (name);
} // MOrg
/** Org Info */
private MOrgInfo m_info = null;
/** Linked Business Partner */
private Integer m_linkedBPartner = null;
/**
* Get Org Info
* @return Org Info
*/
public MOrgInfo getInfo()
{
if (m_info == null)
m_info = MOrgInfo.get (getCtx(), getAD_Org_ID());
return m_info;
} // getMOrgInfo
/**
* After Save
* @param newRecord new Record
* @param success save success
* @return success
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
if (!success)
return success;
if (newRecord)
{
// Info
m_info = new MOrgInfo (this);
m_info.save();
// Access
MRoleOrgAccess.createForOrg (this);
MRole.getDefault(getCtx(), true); // reload
// TreeNode
insert_Tree(MTree_Base.TREETYPE_Organization);
}
// Value/Name change
if (!newRecord && (is_ValueChanged("Value") || is_ValueChanged("Name")))
{
MAccount.updateValueDescription(getCtx(), "AD_Org_ID=" + getAD_Org_ID(), get_TrxName());
if ("Y".equals(Env.getContext(getCtx(), "$Element_OT")))
MAccount.updateValueDescription(getCtx(), "AD_OrgTrx_ID=" + getAD_Org_ID(), get_TrxName());
}
return true;
} // afterSave
/**
* After Delete
* @param success
* @return deleted
*/
protected boolean afterDelete (boolean success)
{
if (success)
delete_Tree(MTree_Base.TREETYPE_Organization);
return success;
} // afterDelete
/**
* Get Linked BPartner
* @return C_BPartner_ID
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Organization Model
*
* @author Jorg Janke
* @version $Id: MOrg.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
*/
public class MOrg extends X_AD_Org
{
/**
* Get Organizations Of Client
* @param po persistent object
* @return array of orgs
*/
public static MOrg[] getOfClient (PO po)
{
ArrayList<MOrg> list = new ArrayList<MOrg>();
String sql = "SELECT * FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, po.getAD_Client_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MOrg (po.getCtx(), rs, null));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
MOrg[] retValue = new MOrg[list.size ()];
list.toArray (retValue);
return retValue;
} // getOfClient
/**
* Get Org from Cache
* @param ctx context
* @param AD_Org_ID id
* @return MOrg
*/
public static MOrg get (Properties ctx, int AD_Org_ID)
{
Integer key = new Integer (AD_Org_ID);
MOrg retValue = (MOrg) s_cache.get (key);
if (retValue != null)
return retValue;
retValue = new MOrg (ctx, AD_Org_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
} // get
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MOrg.class);
/** Cache */
private static CCache<Integer,MOrg> s_cache = new CCache<Integer,MOrg>("AD_Org", 20);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param AD_Org_ID id
* @param trxName transaction
*/
public MOrg (Properties ctx, int AD_Org_ID, String trxName)
{
super(ctx, AD_Org_ID, trxName);
if (AD_Org_ID == 0)
{
// setValue (null);
// setName (null);
setIsSummary (false);
}
} // MOrg
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName transaction
*/
public MOrg (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MOrg
/**
* Parent Constructor
* @param client client
* @param name name
*/
public MOrg (MClient client, String name)
{
this (client.getCtx(), 0, client.get_TrxName());
setAD_Client_ID (client.getAD_Client_ID());
setValue (name);
setName (name);
} // MOrg
/** Org Info */
private MOrgInfo m_info = null;
/** Linked Business Partner */
private Integer m_linkedBPartner = null;
/**
* Get Org Info
* @return Org Info
*/
public MOrgInfo getInfo()
{
if (m_info == null)
m_info = MOrgInfo.get (getCtx(), getAD_Org_ID());
return m_info;
} // getMOrgInfo
/**
* After Save
* @param newRecord new Record
* @param success save success
* @return success
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
if (!success)
return success;
if (newRecord)
{
// Info
m_info = new MOrgInfo (this);
m_info.save();
// Access
MRoleOrgAccess.createForOrg (this);
MRole.getDefault(getCtx(), true); // reload
// TreeNode
insert_Tree(MTree_Base.TREETYPE_Organization);
}
// Value/Name change
if (!newRecord && (is_ValueChanged("Value") || is_ValueChanged("Name")))
{
MAccount.updateValueDescription(getCtx(), "AD_Org_ID=" + getAD_Org_ID(), get_TrxName());
if ("Y".equals(Env.getContext(getCtx(), "$Element_OT")))
MAccount.updateValueDescription(getCtx(), "AD_OrgTrx_ID=" + getAD_Org_ID(), get_TrxName());
}
return true;
} // afterSave
/**
* After Delete
* @param success
* @return deleted
*/
protected boolean afterDelete (boolean success)
{
if (success)
delete_Tree(MTree_Base.TREETYPE_Organization);
return success;
} // afterDelete
/**
* Get Linked BPartner
* @return C_BPartner_ID
*/
public int getLinkedC_BPartner_ID()
{
return getLinkedC_BPartner_ID(null);
}
public int getLinkedC_BPartner_ID(String trxName)
{
if (m_linkedBPartner == null)
{
//jz int C_BPartner_ID = DB.getSQLValue(null,
int C_BPartner_ID = DB.getSQLValue(trxName,
int C_BPartner_ID = DB.getSQLValue(null,
"SELECT C_BPartner_ID FROM C_BPartner WHERE AD_OrgBP_ID=?",
getAD_Org_ID());
if (C_BPartner_ID < 0) // not found = -1
C_BPartner_ID = 0;
m_linkedBPartner = new Integer (C_BPartner_ID);
}
return m_linkedBPartner.intValue();
} // getLinkedC_BPartner_ID
} // MOrg
C_BPartner_ID = 0;
m_linkedBPartner = new Integer (C_BPartner_ID);
}
return m_linkedBPartner.intValue();
} // getLinkedC_BPartner_ID
} // MOrg

View File

@ -1,56 +1,55 @@
/******************************************************************************
* Product: Compiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Organization Info Model
*
* @author Jorg Janke
* @version $Id: MOrgInfo.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
*/
public class MOrgInfo extends X_AD_OrgInfo
{
/**
* Load Constructor
* @param ctx context
* @param AD_Org_ID id
* @return Org Info
*/
public static MOrgInfo get (Properties ctx, int AD_Org_ID)
{
MOrgInfo retValue = null;
String sql = "SELECT * FROM AD_OrgInfo WHERE AD_Org_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Org_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
retValue = new MOrgInfo (ctx, rs, null);
rs.close();
pstmt.close();
pstmt = null;
* Product: Adempiere ERP & CRM Smart Business Solution
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* This program is free software; you can redistribute it and/or modify it
* under the terms version 2 of the GNU General Public License as published
* by the Free Software Foundation. This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Organization Info Model
*
* @author Jorg Janke
* @version $Id: MOrgInfo.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
*/
public class MOrgInfo extends X_AD_OrgInfo
{
/**
* Load Constructor
* @param ctx context
* @param AD_Org_ID id
* @return Org Info
*/
public static MOrgInfo get (Properties ctx, int AD_Org_ID)
{
MOrgInfo retValue = null;
String sql = "SELECT * FROM AD_OrgInfo WHERE AD_Org_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Org_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
retValue = new MOrgInfo (ctx, rs, null);
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
@ -58,42 +57,42 @@ public class MOrgInfo extends X_AD_OrgInfo
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
return retValue;
} // get
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MOrgInfo.class);
/**************************************************************************
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName transaction
*/
public MOrgInfo (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MOrgInfo
/**
* Organization constructor
* @param org org
*/
public MOrgInfo (MOrg org)
{
super(org.getCtx(), 0, org.get_TrxName());
setClientOrg(org);
setDUNS ("?");
setTaxID ("?");
} // MOrgInfo
} // MOrgInfo
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
return retValue;
} // get
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MOrgInfo.class);
/**************************************************************************
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName transaction
*/
public MOrgInfo (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MOrgInfo
/**
* Organization constructor
* @param org org
*/
public MOrgInfo (MOrg org)
{
super(org.getCtx(), 0, org.get_TrxName());
setClientOrg(org);
setDUNS ("?");
setTaxID ("?");
} // MOrgInfo
} // MOrgInfo

View File

@ -3,17 +3,18 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.util;
/**
@ -24,225 +25,240 @@ package org.compiere.util;
*/
public class AmtInWords_IN implements AmtInWords
{
/**
* AmtInWords_IN
*/
public AmtInWords_IN ()
{
super ();
} // AmtInWords_IN
private static final String[] basenumbers = new String[]{
"Nol",
"Satu",
"Dua",
"Tiga",
"Empat",
"Lima",
"Enam",
"Tujuh",
"Delapan",
"Sembilan",
/**
* AmtInWords_IN
*/
public AmtInWords_IN ()
{
super ();
} // AmtInWords_IN
private static final String[] basenumbers = new String[]{
"Nol",
"Satu",
"Dua",
"Tiga",
"Empat",
"Lima",
"Enam",
"Tujuh",
"Delapan",
"Sembilan",
"Sepuluh",
"Sebelas",
};
private static final long POWER_THREE = 1000L;
private static final long POWER_SIX = 1000000L;
private static final long POWER_NINE = 1000000000L;
private static final long POWER_TWELVE = 1000000000000L;
private static final long POWER_FIFTEEN = 1000000000000000L;
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (AmtInWords_IN.class);
//-------------------------- STATIC METHODS --------------------------
/**
* Convenient method for {@link #sayNumber(StringBuffer, long)}.
*
/**
* Convenient method for {@link #sayNumber(StringBuffer, long)}.
*
* @param number number to say
* @return said number
*/
public static String sayNumber(long number) {
public static String sayNumber(double number) {
StringBuffer result = new StringBuffer();
sayNumber(result, number);
result.append(" Rupiah");
return result.toString();
}
/**
* Say a number. This method will append the result to the given string buffer.
*
* @param appendTo the string buffer
* @param number number to say
/**
* Say a number. This method will append the result to the given string buffer.
*
* @param appendTo the string buffer
* @param number number to say
* @return said number
* @throws IllegalArgumentException if the number equals to {@link Long#MIN_VALUE}
*/
public static String sayNumber(StringBuffer appendTo, long number)
public static String sayNumber(StringBuffer appendTo, double number)
throws IllegalArgumentException {
if (number == Long.MIN_VALUE) {
if (number == Double.MIN_VALUE) {
throw new IllegalArgumentException("Out of range");
}
if (number < 0) {
appendTo.append("Minus ");
}
long abs = Math.abs(number);
double abs = Math.abs(number);
// s_log.warning("Debug=" + abs);
if (abs < POWER_THREE) {
saySimpleNumber(appendTo, (int) abs);
} else if (abs < 2000) {
int thousand = (int) (abs % POWER_THREE);
appendTo.append("Seribu ");
saySimpleNumber(appendTo, thousand);
} else if (abs < POWER_SIX) {
int thousand = (int) (abs % POWER_SIX / POWER_THREE);
saySimpleNumber(appendTo, thousand);
appendTo.append(" Ribu");
long remainder = abs - thousand * POWER_THREE;
double remainder = abs - thousand * POWER_THREE;
if (remainder > 0) {
appendTo.append(' ');
sayNumber(appendTo, remainder);
}
} else if (abs < POWER_NINE) {
}
} else if (abs < POWER_NINE) {
int million = (int) (abs % POWER_NINE / POWER_SIX);
saySimpleNumber(appendTo, million);
appendTo.append(" Juta");
long remainder = abs - million * POWER_SIX;
double remainder = abs - million * POWER_SIX;
if (remainder > 0) {
appendTo.append(' ');
sayNumber(appendTo, remainder);
}
} else if (abs < POWER_TWELVE) {
}
} else if (abs < POWER_TWELVE) {
int billion = (int) (abs % POWER_TWELVE / POWER_NINE);
saySimpleNumber(appendTo, billion);
appendTo.append(" Milyar");
long remainder = abs - billion * POWER_NINE;
double remainder = abs - billion * POWER_NINE;
if (remainder > 0) {
appendTo.append(' ');
sayNumber(appendTo, remainder);
}
} else if (abs < POWER_FIFTEEN) {
}
} else if (abs < POWER_FIFTEEN) {
int trillion = (int) (abs % POWER_FIFTEEN / POWER_TWELVE);
saySimpleNumber(appendTo, trillion);
appendTo.append(" Trilyun");
long remainder = abs - trillion * POWER_TWELVE;
double remainder = abs - trillion * POWER_TWELVE;
if (remainder > 0) {
appendTo.append(' ');
sayNumber(appendTo, remainder);
}
} else {
int log = (int) Math.floor(Math.log(abs) / Math.log(10));
// we want to break the number to several billions.
int logWhole = log - log % 12;
long powerWhole = (long) Math.pow(10, logWhole);
long part = abs / powerWhole;
sayNumber(appendTo, part);
appendTo.append(" Trilyun");
long remainder = abs - part * powerWhole;
if (remainder > 0) {
appendTo.append(' ');
sayNumber(appendTo, remainder);
}
appendTo.append("Lebih Dari Seribu Triliun");
}
return appendTo.toString();
}
static void saySimpleNumber(StringBuffer appendTo, int number) {
assert number < 1000 && number >= 0: "Must be between 0 and 1000";
if (number < 12) {
assert number < 12 && number >= 0: "Must be between 0 and 11";
appendTo.append(basenumbers[number]);
} else if (number < 20) {
assert number >= 12 && number <= 19: "Must be between 12 and 19";
int belasan = number % 10;
appendTo.append(basenumbers[belasan]);
appendTo.append(" Belas");
} else if (number < 100) {
assert number >= 20 && number <= 99: "Must be between 20 and 99";
int puluhan = number / 10;
appendTo.append(basenumbers[puluhan]);
appendTo.append(" Puluh");
int remainder = number - puluhan * 10;
if (remainder > 0) {
static void saySimpleNumber(StringBuffer appendTo, int number) {
assert number < 1000 && number >= 0: "Must be between 0 and 1000";
if (number < 12) {
assert number < 12 && number >= 0: "Must be between 0 and 11";
appendTo.append(basenumbers[number]);
} else if (number < 20) {
assert number >= 12 && number <= 19: "Must be between 12 and 19";
int belasan = number % 10;
appendTo.append(basenumbers[belasan]);
appendTo.append(" Belas");
} else if (number < 100) {
assert number >= 20 && number <= 99: "Must be between 20 and 99";
int puluhan = number / 10;
appendTo.append(basenumbers[puluhan]);
appendTo.append(" Puluh");
int remainder = number - puluhan * 10;
if (remainder > 0) {
appendTo.append(' ');
saySimpleNumber(appendTo, remainder);
}
} else if (number < 200) {
assert number >= 100 && number <= 199: "Must be between 100 and 199";
appendTo.append("Seratus");
int remainder = number - 100;
if (remainder > 0) {
appendTo.append(' ');
saySimpleNumber(appendTo, remainder);
}
} else if (number != 0) {
assert number >= 200 && number <= 999: "Must be between 200 and 999";
int ratusan = number % 1000 / 100;
assert ratusan > 0 && ratusan < 10 :"1-9";
appendTo.append(basenumbers[ratusan]);
appendTo.append(" Ratus");
int remainder = number - ratusan * 100;
if (remainder > 0) {
appendTo.append(' ');
saySimpleNumber(appendTo, remainder);
}
} else if (number < 200) {
assert number >= 100 && number <= 199: "Must be between 100 and 199";
appendTo.append("Seratus");
int remainder = number - 100;
if (remainder > 0) {
appendTo.append(' ');
saySimpleNumber(appendTo, remainder);
}
} else if (number != 0) {
assert number >= 200 && number <= 999: "Must be between 200 and 999";
int ratusan = number % 1000 / 100;
assert ratusan > 0 && ratusan < 10 :"1-9";
appendTo.append(basenumbers[ratusan]);
appendTo.append(" Ratus");
int remainder = number - ratusan * 100;
if (remainder > 0) {
appendTo.append(' ');
saySimpleNumber(appendTo, remainder);
}
}
}
}
/**************************************************************************
/**************************************************************************
* Get Amount in Words
* @param amount numeric amount (352.80)
* @return amount in words (three*five*two 80/100)
* @throws Exception
*/
public String getAmtInWords (String amount) throws Exception
{
if (amount == null)
return amount;
//
amount = amount.replaceAll (",", "");
float numFloat = Float.parseFloat(amount);
long number = 0L;
number = (long)numFloat;
return AmtInWords_IN.sayNumber(number);
StringBuffer result = new StringBuffer();
int pos = amount.lastIndexOf ('.');
String oldamt = amount;
amount = amount.replaceAll (",", "");
String cents = pos > 0 ? oldamt.substring (pos + 1):null;
double numDouble = Double.parseDouble(amount);
sayNumber(result, numDouble);
if (cents != null)
{
result.append(" Koma ");
numDouble = Double.parseDouble(cents);
sayNumber(result, numDouble);
}
result.append(" Rupiah");
return result.toString();
} // getAmtInWords
/**
* Test Print
* @param amt amount
*/
private void print (String amt)
{
try
{
System.out.println(amt + " = " + getAmtInWords(amt));
}
catch (Exception e)
{
e.printStackTrace();
}
} // print
/**
* Test
* @param args ignored
*/
* Test Print
* @param amt amount
*/
private void print (String amt)
{
try
{
System.out.println(amt + " = " + getAmtInWords(amt));
}
catch (Exception e)
{
e.printStackTrace();
}
} // print
/**
* Test
* @param args ignored
*/
public static void main (String[] args)
{
AmtInWords_IN aiw = new AmtInWords_IN();
// I doubt decimal support for rupiah is still needed ;)
aiw.print (".23");
aiw.print ("948,776,477,778,778,778");
aiw.print ("1.79");
// aiw.print ("12.345");
// aiw.print ("123.45");
// aiw.print ("1234.56");
// aiw.print ("12345.78");
// aiw.print ("123457.89");
aiw.print ("1,234,578.90");
aiw.print ("0.00");
aiw.print ("0.23");
aiw.print ("1.23876787");
aiw.print ("11.45");
aiw.print ("121.45");
aiw.print ("1231.56");
aiw.print ("10341.78");
aiw.print ("12341.78");
aiw.print ("123451.89");
aiw.print ("12234571.90");
aiw.print ("123234571.90");
aiw.print ("1987234571.90");
aiw.print ("11123234571.90");
aiw.print ("123123234571.90");
aiw.print ("2123123234571.90");
aiw.print ("23,123,123,234,571.90");
aiw.print ("100,000,000,000,000.90");
aiw.print ("111,111,111");
aiw.print ("222,222,222,222,222");
aiw.print ("222,222,222,222,222,222,222");
} // main
} // AmtInWords_IN

View File

@ -170,6 +170,9 @@ public class CLogger extends Logger implements Serializable
public boolean saveWarning (String AD_Message, String message)
{
s_lastWarning = new ValueNamePair (AD_Message, message);
// print it
if (true) // issueError
warning(AD_Message + " - " + message);
return true;
} // saveWarning

View File

@ -1066,6 +1066,113 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
throw new RuntimeException (ex);
}
} // remote_executeUpdate
public void setAsciiStream(int parameterIndex, java.io.InputStream x, long length)
throws SQLException
{
}
//vpj-cd add support java 6
public void setBinaryStream(int parameterIndex, java.io.InputStream x,
long length) throws SQLException
{
}
public void setCharacterStream(int parameterIndex,
java.io.Reader reader,
long length) throws SQLException
{
}
public void setAsciiStream(int parameterIndex, java.io.InputStream x)
throws SQLException
{
}
public void setBinaryStream(int parameterIndex, java.io.InputStream x)
throws SQLException
{
}
public void setCharacterStream(int parameterIndex,
java.io.Reader reader) throws SQLException
{
}
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException
{
}
public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException
{
}
public void setClob(int parameterIndex, Reader reader)
throws SQLException
{
}
public void setClob(int parameterIndex, Reader reader, long length)
throws SQLException
{
}
public void setNClob(int parameterIndex, NClob value) throws SQLException
{
}
public void setNClob(int parameterIndex, Reader reader, long length)
throws SQLException
{
}
public void setNClob(int parameterIndex, Reader reader)
throws SQLException
{
}
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException
{
}
public void setBlob(int parameterIndex, InputStream inputStream)
throws SQLException
{
}
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException
{
}
public void setNString(int parameterIndex, String value) throws SQLException
{
}
public void setRowId(int parameterIndex, RowId x) throws SQLException{}
} // CPreparedStatement

View File

@ -905,5 +905,15 @@ public class CStatement implements Statement
}
return rowSet;
} // remote_getRowSet
public boolean isPoolable() throws SQLException{ return false;}
public void setPoolable(boolean a) throws SQLException{};
public boolean isClosed() throws SQLException{ return false;}
public boolean isWrapperFor(java.lang.Class c) throws SQLException{ return false;}
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException{return null;}
} // CStatement

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff