move branch adempire311 to trunk
This commit is contained in:
parent
1fb80939f9
commit
00ed296b49
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="/tools"/>
|
||||
<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/>
|
||||
<classpathentry kind="src" path="/looks"/>
|
||||
<classpathentry kind="src" path="/jboss"/>
|
||||
<classpathentry kind="lib" path="/interfaces/Interfaces.jar"/>
|
||||
<classpathentry kind="lib" path="/tools/lib/jnlp.jar"/>
|
||||
<classpathentry kind="lib" path="/lib/jPDF.jar"/>
|
||||
<classpathentry kind="lib" path="/lib/oracle.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/derby"/>
|
||||
<classpathentry kind="lib" path="/lib/db2.jar"/>
|
||||
<classpathentry kind="lib" path="/tools/lib/postgresql.jar"/>
|
||||
<classpathentry kind="output" path="build"/>
|
||||
</classpath>
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dbPort</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>jboss</project>
|
||||
<project>looks</project>
|
||||
<project>tools</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.compiere.Adempiere"/>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="4"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="dbPort" path="1" type="4"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="base" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="print" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="dbPort" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="tools" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/jstl.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/Verisign.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/standard.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/log4j.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/activation.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/mail.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/j2ee.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/bsh-1.3.0.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/xdoclet-1.2.3.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/jpayment.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="looks" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="jboss" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/jboss/client/jboss-client.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/jboss/client/jboss-common-client.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/jboss/client/jboss-j2ee.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/jboss/client/jbosssx-client.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/jboss/client/jboss-transaction-client.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/jboss/client/jnp-client.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/jboss/client/jmx-invoker-adaptor-client.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="client" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/jnlp.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry path="3" projectName="extend" type="1"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="dbPort"/> </runtimeClasspathEntry> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/jfreechart-1.0.2.jar" path="3" type="2"/> "/>
|
||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/tools/lib/jcommon-1.0.5.jar" path="3" type="2"/> "/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="dbPort"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-DPropertyFile=${workspace_loc:_production}/Adempiere/Adempiere.properties"/>
|
||||
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/dbPort"/>
|
||||
</listAttribute>
|
||||
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
|
||||
</launchConfiguration>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.compiere.util.GenerateModel"/>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="4"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="${workspace_loc:_gen}/ org.compiere.model 'U','A','D','C','CUST'"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="dbPort"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-DPropertyFile=${workspace_loc:_production}/Adempiere/Adempiere.properties"/>
|
||||
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
|
||||
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/dbPort"/>
|
||||
</listAttribute>
|
||||
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
|
||||
</launchConfiguration>
|
|
@ -0,0 +1,19 @@
|
|||
@Title Build dbPort
|
||||
@Rem $Header: /cvsroot/adempiere/dbPort/RUN_build.bat,v 1.10 2005/09/16 00:49:04 jjanke Exp $
|
||||
|
||||
@CALL ..\utils_dev\myDevEnv.bat
|
||||
@IF NOT %ADEMPIERE_ENV%==Y GOTO NOBUILD
|
||||
|
||||
@echo Cleanup ...
|
||||
@"%JAVA_HOME%\bin\java" -Dant.home="." %ANT_PROPERTIES% org.apache.tools.ant.Main clean
|
||||
|
||||
@echo Building ...
|
||||
@"%JAVA_HOME%\bin\java" -Dant.home="." %ANT_PROPERTIES% org.apache.tools.ant.Main dist
|
||||
|
||||
@Echo Done ...
|
||||
@sleep 60
|
||||
@exit
|
||||
|
||||
:NOBUILD
|
||||
@Echo Check myDevEnv.bat (copy from myDevEnvTemplate.bat)
|
||||
@Pause
|
|
@ -0,0 +1,18 @@
|
|||
# Module compiling script
|
||||
# Ported from Windows script Marek Mosiewicz<marek.mosiewicz@jotel.com.pl>
|
||||
|
||||
|
||||
SAVED_DIR=`pwd` #save current dir
|
||||
cd `dirname $0`/../utils_dev #change dir to place where script resides - doesn not work with sym links
|
||||
UTILS_DEV=`pwd` #this is adempiere source
|
||||
cd $SAVED_DIR #back to the saved directory
|
||||
|
||||
. $UTILS_DEV/myDevEnv.sh #call environment
|
||||
echo done
|
||||
if [ ! $ADEMPIERE_ENV==Y ] ; then
|
||||
echo "Can't set developemeent environemnt - check myDevEnv.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo running Ant
|
||||
$JAVA_HOME/bin/java -Dant.home="." $ANT_PROPERTIES org.apache.tools.ant.Main
|
|
@ -0,0 +1,102 @@
|
|||
<!-- ============================================= -->
|
||||
<!-- dbPort -->
|
||||
<!-- ============================================= -->
|
||||
<!-- $Header: /cvs/adempiere/dbPort/build.xml,v 1.3 2006/07/03 23:19:37 jjanke Exp $ -->
|
||||
|
||||
<project name="dbPort" default="dist" basedir=".">
|
||||
|
||||
<description>
|
||||
This buildfile is used to build the dbPort subproject within
|
||||
the Adempiere project.
|
||||
</description>
|
||||
|
||||
<!-- set global properties for this build -->
|
||||
<property environment="env"/>
|
||||
<property name="src" value="src"/>
|
||||
<property name="build.dir" value="build"/>
|
||||
<property name="dist.dir" value="."/>
|
||||
<property name="lib.dir" value="../lib"/>
|
||||
<property name="toolslib.dir" value="../tools/lib"/>
|
||||
|
||||
<!-- set path to include the necessary jar files for javac -->
|
||||
<path id="project.class.path">
|
||||
<pathelement path="${classpath}"/>
|
||||
<pathelement path="${lib.dir}/oracle.jar"/>
|
||||
<pathelement path="${lib.dir}/postgresql.jar"/>
|
||||
<pathelement path="${lib.dir}/sybase.jar"/>
|
||||
<pathelement path="${lib.dir}/sqlServer.jar"/>
|
||||
<pathelement path="${lib.dir}/db2.jar"/>
|
||||
<pathelement path="${lib.dir}/derby.jar"/>
|
||||
<pathelement path="${lib.dir}/postgresql.jar"/>
|
||||
|
||||
<pathelement path="${lib.dir}/jboss.jar"/>
|
||||
|
||||
<pathelement path="${lib.dir}/CCTools.jar"/>
|
||||
<pathelement path="../looks/CLooks.jar"/>
|
||||
<pathelement path="${lib.dir}/freepdf.jar"/>
|
||||
<pathelement path="${toolslib.dir}/junit.jar"/>
|
||||
|
||||
<!-- Recursive relationship: require AppsServer -->
|
||||
<pathelement path="../base/Base.jar"/>
|
||||
<!-- <pathelement path="../interfaces/Interfaces.jar"/> -->
|
||||
<pathelement path="../tools/lib/j2ee.jar"/>
|
||||
</path>
|
||||
|
||||
|
||||
<target name="init" description="initialization target">
|
||||
<echo message="=========== Build dbPort"/>
|
||||
<!-- create the time stamp -->
|
||||
<tstamp/>
|
||||
<!-- create the build directory structure used by compile -->
|
||||
<mkdir dir="${build.dir}"/>
|
||||
<!-- check for the distribution directory -->
|
||||
<available file="${dist.dir}" type="dir" property="dist.dir.exists"/>
|
||||
</target>
|
||||
|
||||
<target name="makedir" depends="init" unless="dist.dir.exists">
|
||||
<!-- create the distribution directory if not available -->
|
||||
<mkdir dir="${dist}/${dist.dir}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="compile" depends="makedir">
|
||||
<property name="src.interfaces" value="../interfaces/src"/>
|
||||
<!-- compile the java code from ${src} into ${build.dir} -->
|
||||
<javac destdir="${build.dir}"
|
||||
deprecation="on" debug="on" encoding="${env.ENCODING}">
|
||||
<src path="${src}"/>
|
||||
<src path="${src.interfaces}"/>
|
||||
<classpath refid="project.class.path"/>
|
||||
</javac>
|
||||
<!-- copy all image & sound files from src to the build directory -->
|
||||
<copy todir="${build.dir}">
|
||||
<fileset dir="${src}">
|
||||
<include name="**/images/*"/>
|
||||
<include name="**/*.gif"/>
|
||||
<include name="**/*.jpg"/>
|
||||
<include name="**/*.wav"/>
|
||||
<include name="**/*.htm"/>
|
||||
<include name="**/*.html"/>
|
||||
<include name="**/*.properties"/>
|
||||
<exclude name="**/package.html"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
|
||||
<!-- =========================================== -->
|
||||
<!-- Distribution -->
|
||||
<!-- =========================================== -->
|
||||
<target name="dist" depends="compile">
|
||||
<!-- put everything from ${build.dir} into the dbPort.jar file -->
|
||||
<jar jarfile="${dist.dir}/dbPort.jar" basedir="${build.dir}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="clean">
|
||||
<!-- Delete the ${build.dir} directory trees -->
|
||||
<delete dir="${build.dir}"/>
|
||||
<delete file="${dist.dir}/dbPort.jar" failonerror="false"/>
|
||||
</target>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,33 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<title>JBuilder Project dbPort.jpx</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Project dbPort Notes</h1>
|
||||
<hr><table border="0">
|
||||
<tr><th align="left" valign="top">Title:</th><td align="left" valign="top">
|
||||
<!-- Type Title below -->
|
||||
|
||||
</td></tr>
|
||||
<tr><th align="left" valign="top">Author:</th><td align="left" valign="top">
|
||||
<!-- Type Author below -->
|
||||
|
||||
</td></tr>
|
||||
<tr><th align="left" valign="top">Company:</th><td align="left" valign="top">
|
||||
<!-- Type Company below -->
|
||||
|
||||
</td></tr>
|
||||
<tr><th align="left" valign="top">Description:</th><td align="left" valign="top">
|
||||
<!-- Type Description below -->
|
||||
|
||||
</td></tr>
|
||||
</table><hr>
|
||||
<h2>Things to do... </h2>
|
||||
<ol>
|
||||
<!-- Edit this section to keep track of your to do items -->
|
||||
<li>First
|
||||
<li>Second
|
||||
</ol>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,5 @@
|
|||
@Rem API Documentation for Base
|
||||
|
||||
call ..\doc\documentation.bat src doc -private
|
||||
|
||||
@pause
|
|
@ -0,0 +1,2 @@
|
|||
org.compiere.db
|
||||
org.compiere.dbPort
|
|
@ -0,0 +1,834 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 Adempiere Fundation. 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., *
|
||||
* or via info@adempiere.org or http://www.adempiere.org/license.html *
|
||||
* Enterprise: e-Evolution,SC
|
||||
* Contributor: Victor Perez Juarez
|
||||
*****************************************************************************/
|
||||
package org.adempiere.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Generate Model Classes extending PO.
|
||||
* Base class for CMP interface - will be extended to create byte code directly
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: GenerateModel.java,v 1.5 2006/07/30 00:54:36 jjanke Exp $
|
||||
*/
|
||||
public class GenerateModelJPA
|
||||
{
|
||||
/**
|
||||
* Generate PO Class
|
||||
* @param AD_Table_ID table id
|
||||
* @param directory directory with \ or / at the end.
|
||||
* @param packageName package name
|
||||
*/
|
||||
public GenerateModelJPA (int AD_Table_ID, String directory, String packageName)
|
||||
{
|
||||
// create column access methods
|
||||
StringBuffer mandatory = new StringBuffer();
|
||||
StringBuffer sb = createColumns(AD_Table_ID, mandatory);
|
||||
// add header stuff
|
||||
String tableName = createHeader(AD_Table_ID, sb, mandatory, packageName);
|
||||
// Save it
|
||||
writeToFile (sb, directory + tableName + ".java");
|
||||
} // GenerateModel
|
||||
|
||||
/** File Header */
|
||||
public static final String COPY =
|
||||
"/******************************************************************************\n"
|
||||
+" * Product: Adempiere ERP & CRM Smart Business Solution *\n"
|
||||
+" * Copyright (C) 1999-2006 Adempiere Fundation. All Rights Reserved. *\n"
|
||||
+" * This program is free software; you can redistribute it and/or modify it *\n"
|
||||
+" * under the terms version 2 of the GNU General Public License as published *\n"
|
||||
+" * by the Free Software Foundation. This program is distributed in the hope *\n"
|
||||
+" * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *\n"
|
||||
+" * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *\n"
|
||||
+" * See the GNU General Public License for more details. *\n"
|
||||
+" * You should have received a copy of the GNU General Public License along *\n"
|
||||
+" * with this program; if not, write to the Free Software Foundation, Inc., *\n"
|
||||
//+" * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *\n"
|
||||
//+" * For the text or an alternative of this public license, you may reach us *\n"
|
||||
+" * or via info@adempiere.org or http://www.adempiere.org/license.html *\n"
|
||||
+" * Enterprise: e-Evolution,SC www.e-evolution.com *\n"
|
||||
+" * Contributor: Victor Perez Juarez *\n"
|
||||
+" *****************************************************************************/\n";
|
||||
|
||||
/** Generated on */
|
||||
private Timestamp s_run = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger (GenerateModelJPA.class);
|
||||
|
||||
/**
|
||||
* Add Header info to buffer
|
||||
* @param AD_Table_ID table
|
||||
* @param sb buffer
|
||||
* @param mandatory init call for mandatory columns
|
||||
* @param packageName package name
|
||||
* @return class name
|
||||
*/
|
||||
private String createHeader (int AD_Table_ID, StringBuffer sb, StringBuffer mandatory, String packageName)
|
||||
{
|
||||
String tableName = "";
|
||||
int accessLevel = 0;
|
||||
String sql = "SELECT TableName, AccessLevel FROM AD_Table WHERE AD_Table_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, AD_Table_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
tableName = rs.getString(1);
|
||||
accessLevel = rs.getInt(2);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
pstmt = null;
|
||||
}
|
||||
if (tableName == null)
|
||||
throw new RuntimeException ("TableName not found for ID=" + AD_Table_ID);
|
||||
//
|
||||
String accessLevelInfo = accessLevel + " ";
|
||||
if (accessLevel >= 4 )
|
||||
accessLevelInfo += "- System ";
|
||||
if (accessLevel == 2 || accessLevel == 3 || accessLevel == 6 || accessLevel == 7)
|
||||
accessLevelInfo += "- Client ";
|
||||
if (accessLevel == 1 || accessLevel == 3 || accessLevel == 5 || accessLevel == 7)
|
||||
accessLevelInfo += "- Org ";
|
||||
|
||||
String keyColumn = tableName + "_ID";
|
||||
//String className = "X_" + tableName;
|
||||
String className = "" + tableName;
|
||||
//
|
||||
StringBuffer start = new StringBuffer ()
|
||||
.append (COPY)
|
||||
.append ("package " + packageName + ";\n"
|
||||
+ "/** Generated Model JPA - DO NOT CHANGE */\n");
|
||||
if (!packageName.equals("org.adempiere.model"))
|
||||
start.append("import org.adempiere.model.*;");
|
||||
start.append("import java.util.*;"
|
||||
+ "import java.sql.*;"
|
||||
+ "import java.math.*;"
|
||||
+ "import javax.persistence.*;"
|
||||
+ "import org.compiere.util.*;"
|
||||
+ "import org.adempiere.util.*;"
|
||||
// Class
|
||||
+ "/** Generated Model for ").append(tableName).append("\n"
|
||||
+ " * @author Victor Perez (generated) \n"
|
||||
+ " * @version ").append(Adempiere.MAIN_VERSION).append(" - ").append(s_run).append(" */\n"
|
||||
+ " @Entity"
|
||||
+ "@Table(name=\""+ tableName +"\")"
|
||||
+ "public class ").append(className).append(" extends PO"
|
||||
+ " implements java.io.Serializable "
|
||||
+ "{"
|
||||
// Standard Constructor
|
||||
+ "/** Standard Constructor\n@param ctx context\n@param "
|
||||
+ keyColumn + " id\n@param trxName transaction\n*/\n"
|
||||
+ "public ").append(className).append(" (Properties ctx, int ").append(keyColumn)
|
||||
.append(", String trxName)"
|
||||
+ "{"
|
||||
+ "super (ctx, ").append(keyColumn).append(", trxName);"
|
||||
+ "/** if (").append(keyColumn).append(" == 0)"
|
||||
+ "{").append(mandatory).append("} */\n"
|
||||
+ "}" // Constructor End
|
||||
// Short Constructor
|
||||
// + "/** Short Constructor */\n"
|
||||
// + "public ").append(className).append(" (Properties ctx, int ").append(keyColumn).append(")"
|
||||
// + "{"
|
||||
// + "this (ctx, ").append(keyColumn).append(", null);"
|
||||
// + "}" // Constructor End
|
||||
|
||||
// Load Constructor
|
||||
+ "/** Load Constructor \n@param ctx context\n@param rs result set \n@param trxName transaction\n*/\n"
|
||||
+ "public ").append(className).append(" (Properties ctx, ResultSet rs, String trxName)"
|
||||
+ "{"
|
||||
+ "super (ctx, rs, trxName);"
|
||||
+ "}" // Load Constructor End
|
||||
//
|
||||
+ "/** AD_Table_ID=").append(AD_Table_ID).append(" */\n"
|
||||
+ "public static final int Table_ID=").append(AD_Table_ID).append(";\n"
|
||||
//
|
||||
+ "/** TableName=").append(tableName).append(" */\n"
|
||||
+ "public static final String Table_Name=\"").append(tableName).append("\";\n"
|
||||
+ "protected static KeyNamePair Model = new KeyNamePair(").append(AD_Table_ID).append(",\"").append(tableName).append("\");\n"
|
||||
//
|
||||
+ "protected BigDecimal accessLevel = new BigDecimal(").append(accessLevel).append(");"
|
||||
+ "/** AccessLevel\n@return ").append(accessLevelInfo).append("\n*/\n"
|
||||
+ "protected int get_AccessLevel()"
|
||||
+ "{"
|
||||
+ "return accessLevel.intValue();"
|
||||
+ "}"
|
||||
//
|
||||
+ "/** Load Meta Data\n@param ctx context\n@return PO Info\n*/\n"
|
||||
+ "protected POInfo initPO (Properties ctx)"
|
||||
+ "{"
|
||||
+ "POInfo poi = POInfo.getPOInfo (ctx, Table_ID);"
|
||||
+ "return poi;"
|
||||
+ "}" // initPO
|
||||
//
|
||||
+ "/** Info\n@return info\n*/\n"
|
||||
+ "public String toString()"
|
||||
+ "{"
|
||||
+ "StringBuffer sb = new StringBuffer (\"").append(className).append("[\")"
|
||||
+ ".append(get_ID()).append(\"]\");"
|
||||
+ "return sb.toString();"
|
||||
+ "}");
|
||||
|
||||
StringBuffer end = new StringBuffer ("}");
|
||||
//
|
||||
sb.insert(0, start);
|
||||
sb.append(end);
|
||||
|
||||
return className;
|
||||
} // createHeader
|
||||
|
||||
|
||||
/**
|
||||
* Create Column access methods
|
||||
* @param AD_Table_ID table
|
||||
* @param mandatory init call for mandatory columns
|
||||
* @return set/get method
|
||||
*/
|
||||
private StringBuffer createColumns (int AD_Table_ID, StringBuffer mandatory)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String sql = "SELECT c.ColumnName, c.IsUpdateable, c.IsMandatory," // 1..3
|
||||
+ " c.AD_Reference_ID, c.AD_Reference_Value_ID, DefaultValue, SeqNo, " // 4..7
|
||||
+ " c.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, " // 8..12
|
||||
+ " c.Name, c.Description, c.ColumnSQL, c.IsEncrypted "
|
||||
+ "FROM AD_Column c "
|
||||
+ "WHERE c.AD_Table_ID=?"
|
||||
+ " AND c.IsActive='Y'"
|
||||
+ " AND c.ColumnName <> 'AD_Client_ID'"
|
||||
+ " AND c.ColumnName <> 'AD_Org_ID'"
|
||||
+ " AND c.ColumnName <> 'IsActive'"
|
||||
+ " AND c.ColumnName NOT LIKE 'Created%'"
|
||||
+ " AND c.ColumnName NOT LIKE 'Updated%' "
|
||||
+ "ORDER BY c.ColumnName";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, AD_Table_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
String columnName = rs.getString(1);
|
||||
boolean isUpdateable = "Y".equals(rs.getString(2));
|
||||
boolean isMandatory = "Y".equals(rs.getString(3));
|
||||
int displayType = rs.getInt(4);
|
||||
int AD_Reference_Value_ID = rs.getInt(5);
|
||||
String defaultValue = rs.getString(6);
|
||||
int seqNo = rs.getInt(7);
|
||||
int fieldLength = rs.getInt(8);
|
||||
String ValueMin = rs.getString(9);
|
||||
String ValueMax = rs.getString(10);
|
||||
String VFormat = rs.getString(11);
|
||||
String Callout = rs.getString(12);
|
||||
String Name = rs.getString(13);
|
||||
String Description = rs.getString(14);
|
||||
String ColumnSQL = rs.getString(15);
|
||||
boolean virtualColumn = ColumnSQL != null && ColumnSQL.length() > 0;
|
||||
boolean IsEncrypted = "Y".equals(rs.getString(16));
|
||||
//
|
||||
sb.append("@Column(name=\"" + Name+"\") ");
|
||||
sb.append(createColumnMethods (mandatory,
|
||||
columnName, isUpdateable, isMandatory,
|
||||
displayType, AD_Reference_Value_ID, fieldLength,
|
||||
defaultValue, ValueMin, ValueMax, VFormat,
|
||||
Callout, Name, Description, virtualColumn, IsEncrypted));
|
||||
//
|
||||
if (seqNo == 1)
|
||||
sb.append(createKeyNamePair(columnName, displayType));
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
pstmt = null;
|
||||
}
|
||||
return sb;
|
||||
} // createColumns
|
||||
|
||||
/**
|
||||
* Create set/get methods for column
|
||||
* @param mandatory init call for mandatory columns
|
||||
* @param columnName column name
|
||||
* @param isUpdateable updateable
|
||||
* @param isMandatory mandatory
|
||||
* @param displayType display type
|
||||
* @param AD_Reference_ID validation reference
|
||||
* @param fieldLength int
|
||||
* @param defaultValue default value
|
||||
* @param ValueMin String
|
||||
* @param ValueMax String
|
||||
* @param VFormat String
|
||||
* @param Callout String
|
||||
* @param Name String
|
||||
* @param Description String
|
||||
* @param virtualColumn virtual column
|
||||
* @param IsEncrypted stored encrypted
|
||||
@return set/get method
|
||||
*/
|
||||
private String createColumnMethods (StringBuffer mandatory,
|
||||
String columnName, boolean isUpdateable, boolean isMandatory,
|
||||
int displayType, int AD_Reference_ID, int fieldLength,
|
||||
String defaultValue, String ValueMin, String ValueMax, String VFormat,
|
||||
String Callout, String Name, String Description,
|
||||
boolean virtualColumn, boolean IsEncrypted)
|
||||
{
|
||||
// Clazz
|
||||
Class clazz = DisplayType.getClass(displayType, true);
|
||||
if (defaultValue == null)
|
||||
defaultValue = "";
|
||||
if (DisplayType.isLOB(displayType)) // No length check for LOBs
|
||||
fieldLength = 0;
|
||||
|
||||
// Handle Posted
|
||||
if (columnName.equalsIgnoreCase("Posted")
|
||||
|| columnName.equalsIgnoreCase("Processed")
|
||||
|| columnName.equalsIgnoreCase("Processing"))
|
||||
{
|
||||
clazz = Boolean.class;
|
||||
AD_Reference_ID = 0;
|
||||
}
|
||||
// Record_ID
|
||||
else if (columnName.equalsIgnoreCase("Record_ID"))
|
||||
{
|
||||
clazz = Integer.class;
|
||||
AD_Reference_ID = 0;
|
||||
}
|
||||
// String Key
|
||||
else if (columnName.equalsIgnoreCase("AD_Language")
|
||||
|| columnName.equalsIgnoreCase("EntityType"))
|
||||
{
|
||||
clazz = String.class;
|
||||
}
|
||||
// Data Type
|
||||
String dataType = clazz.getName();
|
||||
dataType = dataType.substring(dataType.lastIndexOf('.')+1);
|
||||
if (dataType.equals("Boolean"))
|
||||
dataType = "boolean";
|
||||
else if (dataType.equals("Integer"))
|
||||
dataType = "int";
|
||||
else if (displayType == DisplayType.Binary)
|
||||
dataType = "byte[]";
|
||||
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
// ****** Set Comment ******
|
||||
sb.append("/** Set ").append(Name);
|
||||
sb.append(".\n@param ").append(columnName).append(" ");
|
||||
if (Description != null && Description.length() > 0)
|
||||
sb.append(Description);
|
||||
else
|
||||
sb.append(Name);
|
||||
sb.append(" */\n");
|
||||
|
||||
// Set ********
|
||||
String setValue = "set_Value";
|
||||
if (IsEncrypted)
|
||||
setValue = "set_ValueE";
|
||||
// public void setColumn (xxx variable)
|
||||
sb.append("public ");
|
||||
if (!isUpdateable)
|
||||
{
|
||||
setValue = "set_ValueNoCheck";
|
||||
if (IsEncrypted)
|
||||
setValue = "set_ValueNoCheckE";
|
||||
}
|
||||
sb.append("void set").append(columnName).append(" (").append(dataType).append(" ").append(columnName).append(")"
|
||||
+ "{");
|
||||
// List Validation
|
||||
if (AD_Reference_ID != 0)
|
||||
{
|
||||
String staticVar = addListValidation (sb, AD_Reference_ID, columnName, !isMandatory);
|
||||
sb.insert(0, staticVar); // first check
|
||||
}
|
||||
// setValue ("ColumnName", xx);
|
||||
if (virtualColumn)
|
||||
{
|
||||
sb.append ("throw new IllegalArgumentException (\"").append(columnName).append(" is virtual column\");");
|
||||
}
|
||||
else if (clazz.equals(Integer.class))
|
||||
{
|
||||
if (columnName.endsWith("_ID"))
|
||||
{
|
||||
if (isMandatory) // check mandatory ID
|
||||
{
|
||||
int firstOK = 1; // Valid ID 0
|
||||
if (columnName.equals("AD_Client_ID") || columnName.equals("AD_Org_ID")
|
||||
|| columnName.equals("Record_ID") || columnName.equals("C_DocType_ID")
|
||||
|| columnName.equals("Node_ID") || columnName.equals("AD_Role_ID")
|
||||
|| columnName.equals("M_AttributeSet_ID") || columnName.equals("M_AttributeSetInstance_ID"))
|
||||
firstOK = 0;
|
||||
sb.append("if (").append (columnName)
|
||||
.append (" < ").append(firstOK).append(") throw new IllegalArgumentException (\"")
|
||||
.append(columnName).append(" is mandatory.\");");
|
||||
}
|
||||
else // set optional _ID to null if 0
|
||||
sb.append("if (").append (columnName).append (" <= 0) ")
|
||||
.append(setValue).append(" (\"").append(columnName).append("\", null); else \n");
|
||||
}
|
||||
sb.append(setValue).append(" (\"").append(columnName).append("\", new Integer(").append(columnName).append("));");
|
||||
}
|
||||
else if (clazz.equals(Boolean.class))
|
||||
sb.append(setValue).append(" (\"").append(columnName).append("\", new Boolean(").append(columnName).append("));");
|
||||
else
|
||||
{
|
||||
if (isMandatory && AD_Reference_ID == 0) // does not apply to int/boolean
|
||||
{
|
||||
sb.append("if (")
|
||||
.append (columnName).append (" == null)"
|
||||
+ " throw new IllegalArgumentException (\"")
|
||||
.append(columnName).append(" is mandatory.\");");
|
||||
}
|
||||
// String length check
|
||||
if (clazz.equals(String.class) && fieldLength > 0)
|
||||
{
|
||||
sb.append ("if (");
|
||||
if (!isMandatory)
|
||||
sb.append(columnName).append(" != null && ");
|
||||
sb.append(columnName).append(".length() > ").append(fieldLength)
|
||||
.append("){log.warning(\"Length > ")
|
||||
.append(fieldLength).append(" - truncated\");")
|
||||
.append(columnName).append(" = ")
|
||||
.append(columnName).append(".substring(0,").append(fieldLength-1).append(");}");
|
||||
}
|
||||
|
||||
//
|
||||
sb.append (setValue).append(" (\"").append (columnName).append ("\", ")
|
||||
.append (columnName).append (");");
|
||||
}
|
||||
sb.append("}");
|
||||
|
||||
// Mandatory call in constructor
|
||||
if (isMandatory)
|
||||
{
|
||||
mandatory.append("set").append(columnName).append(" (");
|
||||
if (clazz.equals(Integer.class))
|
||||
mandatory.append("0");
|
||||
else if (clazz.equals(Boolean.class))
|
||||
{
|
||||
if (defaultValue.indexOf('Y') != -1)
|
||||
mandatory.append(true);
|
||||
else
|
||||
mandatory.append("false");
|
||||
}
|
||||
else if (clazz.equals(BigDecimal.class))
|
||||
mandatory.append("Env.ZERO");
|
||||
else if (clazz.equals(Timestamp.class))
|
||||
mandatory.append("new Timestamp(System.currentTimeMillis())");
|
||||
else
|
||||
mandatory.append("null");
|
||||
mandatory.append(");");
|
||||
if (defaultValue.length() > 0)
|
||||
mandatory.append("// ").append(defaultValue).append(Env.NL);
|
||||
}
|
||||
|
||||
|
||||
// ****** Get Comment ******
|
||||
sb.append("/** Get ").append(Name);
|
||||
if (Description != null && Description.length() > 0)
|
||||
sb.append(".\n@return ").append(Description);
|
||||
else
|
||||
sb.append(".\n@return ").append(Name);
|
||||
sb.append(" */\n");
|
||||
|
||||
// Get ********
|
||||
String getValue = "get_Value";
|
||||
if (IsEncrypted)
|
||||
getValue = "get_ValueE";
|
||||
sb.append("public ").append(dataType);
|
||||
if (clazz.equals(Boolean.class))
|
||||
{
|
||||
sb.append(" is");
|
||||
if (columnName.toLowerCase().startsWith("is"))
|
||||
sb.append(columnName.substring(2));
|
||||
else
|
||||
sb.append(columnName);
|
||||
}
|
||||
else
|
||||
sb.append(" get").append(columnName);
|
||||
sb.append("() {");
|
||||
if (clazz.equals(Integer.class))
|
||||
sb.append("Integer ii = (Integer)")
|
||||
.append(getValue).append("(\"").append(columnName).append("\");"
|
||||
+ "if (ii == null)"
|
||||
+ " return 0;"
|
||||
+ "return ii.intValue();");
|
||||
else if (clazz.equals(BigDecimal.class))
|
||||
sb.append("BigDecimal bd = (BigDecimal)").append(getValue)
|
||||
.append("(\"").append(columnName).append("\");"
|
||||
+ "if (bd == null)"
|
||||
+ " return Env.ZERO;"
|
||||
+ "return bd;");
|
||||
else if (clazz.equals(Boolean.class))
|
||||
sb.append("Object oo = ").append(getValue)
|
||||
.append("(\"").append(columnName).append("\");"
|
||||
+ "if (oo != null) { if (oo instanceof Boolean) return ((Boolean)oo).booleanValue(); return \"Y\".equals(oo);}"
|
||||
+ "return false;");
|
||||
else if (dataType.equals("Object"))
|
||||
sb.append("return ").append(getValue)
|
||||
.append("(\"").append(columnName).append("\");");
|
||||
else
|
||||
sb.append("return (").append(dataType).append(")").append(getValue)
|
||||
.append("(\"").append(columnName).append("\");");
|
||||
sb.append("}");
|
||||
//
|
||||
return sb.toString();
|
||||
} // createColumnMethods
|
||||
|
||||
|
||||
/**
|
||||
* Add List Validation
|
||||
* @param sb buffer - example:
|
||||
if (NextAction.equals("N") || NextAction.equals("F"));
|
||||
else throw new IllegalArgumentException ("NextAction Invalid value - Reference_ID=219 - N - F");
|
||||
* @param AD_Reference_ID reference
|
||||
* @param columnName column
|
||||
* @param nullable the validation must allow null values
|
||||
* @return static parameter - Example:
|
||||
public static final int NEXTACTION_AD_Reference_ID=219;
|
||||
public static final String NEXTACTION_None = "N";
|
||||
public static final String NEXTACTION_FollowUp = "F";
|
||||
*/
|
||||
private String addListValidation (StringBuffer sb, int AD_Reference_ID,
|
||||
String columnName, boolean nullable)
|
||||
{
|
||||
StringBuffer retValue = new StringBuffer();
|
||||
retValue.append("\n/** ").append(columnName).append(" AD_Reference_ID=").append(AD_Reference_ID) .append(" */\n")
|
||||
.append("public static final int ").append(columnName.toUpperCase())
|
||||
.append("_AD_Reference_ID=").append(AD_Reference_ID).append(";");
|
||||
//
|
||||
boolean found = false;
|
||||
StringBuffer values = new StringBuffer("Reference_ID=")
|
||||
.append(AD_Reference_ID);
|
||||
StringBuffer statement = new StringBuffer();
|
||||
if (nullable)
|
||||
statement.append("if (").append(columnName).append(" == null");
|
||||
//
|
||||
String sql = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, AD_Reference_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
String value = rs.getString(1);
|
||||
values.append(" - ").append(value);
|
||||
if (statement.length() == 0)
|
||||
statement.append("if (").append(columnName)
|
||||
.append(".equals(\"").append(value).append("\")");
|
||||
else
|
||||
statement.append(" || ").append(columnName)
|
||||
.append(".equals(\"").append(value).append("\")");
|
||||
if (!found)
|
||||
{
|
||||
found = true;
|
||||
sb.append("if (")
|
||||
.append (columnName).append (" == null)"
|
||||
+ " throw new IllegalArgumentException (\"")
|
||||
.append(columnName).append(" is mandatory\");");
|
||||
}
|
||||
// Name (SmallTalkNotation)
|
||||
String name = rs.getString(2);
|
||||
char[] nameArray = name.toCharArray();
|
||||
StringBuffer nameClean = new StringBuffer();
|
||||
boolean initCap = true;
|
||||
for (int i = 0; i < nameArray.length; i++)
|
||||
{
|
||||
char c = nameArray[i];
|
||||
if (Character.isJavaIdentifierPart(c))
|
||||
{
|
||||
if (initCap)
|
||||
nameClean.append(Character.toUpperCase(c));
|
||||
else
|
||||
nameClean.append(c);
|
||||
initCap = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == '+')
|
||||
nameClean.append("Plus");
|
||||
else if (c == '-')
|
||||
nameClean.append("_");
|
||||
else if (c == '>')
|
||||
{
|
||||
if (name.indexOf('<') == -1) // ignore <xx>
|
||||
nameClean.append("Gt");
|
||||
}
|
||||
else if (c == '<')
|
||||
{
|
||||
if (name.indexOf('>') == -1) // ignore <xx>
|
||||
nameClean.append("Le");
|
||||
}
|
||||
else if (c == '!')
|
||||
nameClean.append("Not");
|
||||
else if (c == '=')
|
||||
nameClean.append("Eq");
|
||||
else if (c == '~')
|
||||
nameClean.append("Like");
|
||||
initCap = true;
|
||||
}
|
||||
}
|
||||
retValue.append("/** ").append(name).append(" = ").append(value).append(" */\n");
|
||||
retValue.append("public static final String ").append(columnName.toUpperCase())
|
||||
.append("_").append(nameClean)
|
||||
.append(" = \"").append(value).append("\";");
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
found = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
pstmt = null;
|
||||
}
|
||||
statement.append(")"
|
||||
+ "; "
|
||||
+ "else "
|
||||
+ "throw new IllegalArgumentException (\"").append(columnName)
|
||||
.append(" Invalid value - \" + ").append(columnName)
|
||||
.append(" + \" - ").append(values).append("\");");
|
||||
//
|
||||
if (found && !columnName.equals("EntityType"))
|
||||
sb.append (statement);
|
||||
return retValue.toString();
|
||||
} // addListValidation
|
||||
|
||||
/**
|
||||
* Create getKeyNamePair() method with first identifier
|
||||
* @param columnName name
|
||||
* * @param displayType int
|
||||
@return method code
|
||||
*/
|
||||
private StringBuffer createKeyNamePair (String columnName, int displayType)
|
||||
{
|
||||
String method = "get" + columnName + "()";
|
||||
if (displayType != DisplayType.String)
|
||||
method = "String.valueOf(" + method + ")";
|
||||
StringBuffer sb = new StringBuffer("/** Get Record ID/ColumnName\n@return ID/ColumnName pair\n*/"
|
||||
+ "public KeyNamePair getKeyNamePair() "
|
||||
+ "{return new KeyNamePair(get_ID(), ").append(method).append(");}");
|
||||
return sb;
|
||||
} // createKeyNamePair
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Write to file
|
||||
* @param sb string buffer
|
||||
* @param fileName file name
|
||||
*/
|
||||
private void writeToFile (StringBuffer sb, String fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
File out = new File (fileName);
|
||||
FileWriter fw = new FileWriter (out);
|
||||
for (int i = 0; i < sb.length(); i++)
|
||||
{
|
||||
char c = sb.charAt(i);
|
||||
// after
|
||||
if (c == ';' || c == '}')
|
||||
{
|
||||
fw.write (c);
|
||||
if (sb.substring(i+1).startsWith("//"))
|
||||
fw.write('\t');
|
||||
else
|
||||
fw.write(Env.NL);
|
||||
}
|
||||
// before & after
|
||||
else if (c == '{')
|
||||
{
|
||||
fw.write(Env.NL);
|
||||
fw.write (c);
|
||||
fw.write(Env.NL);
|
||||
}
|
||||
else
|
||||
fw.write (c);
|
||||
}
|
||||
fw.flush ();
|
||||
fw.close ();
|
||||
float size = out.length();
|
||||
size /= 1024;
|
||||
log.info(out.getAbsolutePath() + " - " + size + " kB");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.log(Level.SEVERE, fileName, ex);
|
||||
}
|
||||
} // writeToFile
|
||||
|
||||
/**
|
||||
* String representation
|
||||
* @return string representation
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("GenerateModel[")
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Generate PO Model Class.
|
||||
* <pre>
|
||||
* Example: java GenerateModel.class mydirectory myPackage 'U','A'
|
||||
* would generate entity type User and Application classes into mydirectory.
|
||||
* Without parameters, the default is used:
|
||||
* C:\Adempiere\adempiere-all\extend\src\adempiere\model\ adempiere.model 'U','A'
|
||||
* </pre>
|
||||
* @param args directory package entityType
|
||||
* - directory where to save the generated file
|
||||
* - package of the classes to be generated
|
||||
* - entityType to be generated
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
org.compiere.Adempiere.startupEnvironment(true);
|
||||
CLogMgt.setLevel(Level.FINE);
|
||||
// CLogMgt.setLevel(Level.ALL);
|
||||
log.info("Generate Model $Revision: 1.5 $");
|
||||
log.info("----------------------------------");
|
||||
// first parameter
|
||||
String directory = "/app/adempiere/adempiere_branch_3.1.1/dbPort/src/org/adempiere/model/";
|
||||
if (args.length > 0)
|
||||
directory = args[0];
|
||||
if (directory == null || directory.length() == 0)
|
||||
{
|
||||
System.err.println("No Directory");
|
||||
System.exit(1);
|
||||
}
|
||||
log.info("Directory: " + directory);
|
||||
|
||||
// second parameter
|
||||
String packageName = "adempiere.model";
|
||||
if (args.length > 1)
|
||||
packageName = args[1];
|
||||
if (packageName == null || packageName.length() == 0)
|
||||
{
|
||||
System.err.println("No package");
|
||||
System.exit(1);
|
||||
}
|
||||
log.info("Package: " + packageName);
|
||||
|
||||
// third parameter
|
||||
String entityType = "'U','A','D'"; // User, Application
|
||||
if (args.length > 2)
|
||||
entityType = args[2];
|
||||
if (entityType == null || entityType.length() == 0)
|
||||
{
|
||||
System.err.println("No EntityType");
|
||||
System.exit(1);
|
||||
}
|
||||
StringBuffer sql = new StringBuffer("EntityType IN (")
|
||||
.append(entityType).append(")");
|
||||
log.info(sql.toString());
|
||||
log.info("----------------------------------");
|
||||
|
||||
// complete sql
|
||||
sql.insert(0, "SELECT AD_Table_ID "
|
||||
+ "FROM AD_Table "
|
||||
+ "WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')" // special views
|
||||
+ " OR IsView='N')"
|
||||
+ " AND TableName NOT LIKE '%_Trl' AND ");
|
||||
sql.append(" ORDER BY TableName");
|
||||
|
||||
//
|
||||
int count = 0;
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
new GenerateModelJPA(rs.getInt(1), directory, packageName);
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.severe("main - " + e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
pstmt = null;
|
||||
}
|
||||
log.info("Generated = " + count);
|
||||
|
||||
} // main
|
||||
|
||||
} // GenerateModel
|
|
@ -0,0 +1,572 @@
|
|||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.logging.*;
|
||||
import javax.jnlp.*;
|
||||
import javax.swing.*;
|
||||
import org.compiere.db.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.plaf.*;
|
||||
import org.compiere.util.*;
|
||||
import com.qoppa.pdf.*;
|
||||
|
||||
/**
|
||||
* Adempiere Control Class
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: Adempiere.java,v 1.8 2006/08/11 02:58:14 jjanke Exp $
|
||||
*/
|
||||
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";
|
||||
/** Detail Version as date Used for Client/Server */
|
||||
static public final String DATE_VERSION = "2006-08-10";
|
||||
/** Database Version as date Compared with AD_System */
|
||||
static public final String DB_VERSION = "2006-08-10";
|
||||
|
||||
/** Product Name */
|
||||
static public final String NAME = "Adempiere\u00AE";
|
||||
/** URL of Product */
|
||||
static public final String URL = "www.adempiere.org";
|
||||
/** 16*16 Product Image.
|
||||
/** Removing/modifying the Adempiere logo is a violation of the license */
|
||||
static private final String s_File16x16 = "images/AD16.gif";
|
||||
/** 32*32 Product Image.
|
||||
/** Removing/modifying the Adempiere logo is a violation of the license */
|
||||
static private final String s_file32x32 = "images/AD32.gif";
|
||||
/** 100*30 Product Image.
|
||||
/** Removing/modifying the Adempiere logo is a violation of the license */
|
||||
static private final String s_file100x30 = "images/AD10030.png";
|
||||
/** Removing/modifying the Adempiere logo is a violation of the license */
|
||||
static private final String s_file100x30HR = "images/AD10030HR.png";
|
||||
/** 48*15 Product Image.
|
||||
/** Removing/modifying the Adempiere logo is a violation of the license */
|
||||
static private final String s_file48x15 = "images/Adempiere.png";
|
||||
/** Removing/modifying the Adempiere logo is a violation of the license */
|
||||
static private final String s_file48x15HR = "images/AdempiereHR.png";
|
||||
/** Support Email */
|
||||
static private String s_supportEmail = "";
|
||||
|
||||
/** Subtitle */
|
||||
static public final String SUB_TITLE = "The Open Source Profesional 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";
|
||||
/** Copyright Notice - Don't modify this - Program will someday fail unexpectedly
|
||||
* it also violates the license and you'll be held liable for any damage claims */
|
||||
static public final String COPYRIGHT = "\u00A9 1999-2006 Adempiere \u00AE";
|
||||
|
||||
static private String s_ImplementationVersion = null;
|
||||
static private String s_ImplementationVendor = null;
|
||||
|
||||
static private Image s_image16;
|
||||
static private Image s_image48x15;
|
||||
static private Image s_imageLogo;
|
||||
static private ImageIcon s_imageIcon32;
|
||||
static private ImageIcon s_imageIconLogo;
|
||||
|
||||
/** Logging */
|
||||
private static CLogger log = null;
|
||||
|
||||
/**
|
||||
* Get Product Name
|
||||
* @return Application Name
|
||||
*/
|
||||
public static String getName()
|
||||
{
|
||||
return NAME;
|
||||
} // getName
|
||||
|
||||
/**
|
||||
* Get Product Version
|
||||
* @return Application Version
|
||||
*/
|
||||
public static String getVersion()
|
||||
{
|
||||
return MAIN_VERSION + " - " + DATE_VERSION;
|
||||
} // getVersion
|
||||
|
||||
/**
|
||||
* Short Summary (Windows)
|
||||
* @return summary
|
||||
*/
|
||||
public static String getSum()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(NAME).append(" ").append(MAIN_VERSION).append(SUB_TITLE);
|
||||
return sb.toString();
|
||||
} // getSum
|
||||
|
||||
/**
|
||||
* Summary (Windows).
|
||||
* Removing/modifying the Adempiere copyright notice is a violation of the license
|
||||
* Adempiere(tm) Version 2.5.1a_2004-03-15 - Smart ERP & CRM - Copyright (c) 1999-2005 Jorg Janke; Implementation: 2.5.1a 20040417-0243 - (C) 1999-2005 Jorg Janke, Adempiere Inc. USA
|
||||
* @return Summary in Windows character set
|
||||
*/
|
||||
public static String getSummary()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(NAME).append(" ")
|
||||
.append(MAIN_VERSION).append("_").append(DATE_VERSION)
|
||||
.append(" -").append(SUB_TITLE)
|
||||
.append("- ").append(COPYRIGHT)
|
||||
.append("; Implementation: ").append(getImplementationVersion())
|
||||
.append(" - ").append(getImplementationVendor());
|
||||
return sb.toString();
|
||||
} // getSummary
|
||||
|
||||
/**
|
||||
* Set Package Info
|
||||
*/
|
||||
private static void setPackageInfo()
|
||||
{
|
||||
if (s_ImplementationVendor != null)
|
||||
return;
|
||||
|
||||
Package adempierePackage = Package.getPackage("org.compiere");
|
||||
s_ImplementationVendor = adempierePackage.getImplementationVendor();
|
||||
s_ImplementationVersion = adempierePackage.getImplementationVersion();
|
||||
if (s_ImplementationVendor == null)
|
||||
{
|
||||
s_ImplementationVendor = "not supported";
|
||||
s_ImplementationVersion = "unknown";
|
||||
}
|
||||
} // setPackageInfo
|
||||
|
||||
/**
|
||||
* Get Jar Implementation Version
|
||||
* @return Implementation-Version
|
||||
*/
|
||||
public static String getImplementationVersion()
|
||||
{
|
||||
if (s_ImplementationVersion == null)
|
||||
setPackageInfo();
|
||||
return s_ImplementationVersion;
|
||||
} // getImplementationVersion
|
||||
|
||||
/**
|
||||
* Get Jar Implementation Vendor
|
||||
* @return Implementation-Vendor
|
||||
*/
|
||||
public static String getImplementationVendor()
|
||||
{
|
||||
if (s_ImplementationVendor == null)
|
||||
setPackageInfo();
|
||||
return s_ImplementationVendor;
|
||||
} // getImplementationVendor
|
||||
|
||||
/**
|
||||
* Get Checksum
|
||||
* @return checksum
|
||||
*/
|
||||
public static int getCheckSum()
|
||||
{
|
||||
return getSum().hashCode();
|
||||
} // getCheckSum
|
||||
|
||||
/**
|
||||
* Summary in ASCII
|
||||
* @return Summary in ASCII
|
||||
*/
|
||||
public static String getSummaryAscii()
|
||||
{
|
||||
String retValue = getSummary();
|
||||
// Registered Trademark
|
||||
retValue = Util.replace(retValue, "\u00AE", "(r)");
|
||||
// Trademark
|
||||
retValue = Util.replace(retValue, "\u2122", "(tm)");
|
||||
// Copyright
|
||||
retValue = Util.replace(retValue, "\u00A9", "(c)");
|
||||
// Cr
|
||||
retValue = Util.replace(retValue, Env.NL, " ");
|
||||
retValue = Util.replace(retValue, "\n", " ");
|
||||
return retValue;
|
||||
} // getSummaryAscii
|
||||
|
||||
/**
|
||||
* Get Java VM Info
|
||||
* @return VM info
|
||||
*/
|
||||
public static String getJavaInfo()
|
||||
{
|
||||
return System.getProperty("java.vm.name")
|
||||
+ " " + System.getProperty("java.vm.version");
|
||||
} // getJavaInfo
|
||||
|
||||
/**
|
||||
* Get Operating System Info
|
||||
* @return OS info
|
||||
*/
|
||||
public static String getOSInfo()
|
||||
{
|
||||
return System.getProperty("os.name") + " "
|
||||
+ System.getProperty("os.version") + " "
|
||||
+ System.getProperty("sun.os.patch.level");
|
||||
} // getJavaInfo
|
||||
|
||||
/**
|
||||
* Get full URL
|
||||
* @return URL
|
||||
*/
|
||||
public static String getURL()
|
||||
{
|
||||
return "http://" + URL;
|
||||
} // getURL
|
||||
|
||||
/**
|
||||
* Get Sub Title
|
||||
* @return Subtitle
|
||||
*/
|
||||
public static String getSubtitle()
|
||||
{
|
||||
return SUB_TITLE;
|
||||
} // getSubitle
|
||||
|
||||
/**
|
||||
* Get 16x16 Image.
|
||||
* Removing/modifying the Adempiere logo is a violation of the license
|
||||
* @return Image Icon
|
||||
*/
|
||||
public static Image getImage16()
|
||||
{
|
||||
if (s_image16 == null)
|
||||
{
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
URL url = org.compiere.Adempiere.class.getResource(s_File16x16);
|
||||
// System.out.println(url);
|
||||
if (url == null)
|
||||
return null;
|
||||
s_image16 = tk.getImage(url);
|
||||
}
|
||||
return s_image16;
|
||||
} // getImage16
|
||||
|
||||
/**
|
||||
* Get 28*15 Logo Image.
|
||||
* @param hr high resolution
|
||||
* @return Image Icon
|
||||
*/
|
||||
public static Image getImageLogoSmall(boolean hr)
|
||||
{
|
||||
if (s_image48x15 == null)
|
||||
{
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
URL url = null;
|
||||
if (hr)
|
||||
url = org.compiere.Adempiere.class.getResource(s_file48x15HR);
|
||||
else
|
||||
url = org.compiere.Adempiere.class.getResource(s_file48x15);
|
||||
// System.out.println(url);
|
||||
if (url == null)
|
||||
return null;
|
||||
s_image48x15 = tk.getImage(url);
|
||||
}
|
||||
return s_image48x15;
|
||||
} // getImageLogoSmall
|
||||
|
||||
/**
|
||||
* Get Logo Image.
|
||||
* @return Image Logo
|
||||
*/
|
||||
public static Image getImageLogo()
|
||||
{
|
||||
if (s_imageLogo == null)
|
||||
{
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
URL url = org.compiere.Adempiere.class.getResource(s_file100x30);
|
||||
// System.out.println(url);
|
||||
if (url == null)
|
||||
return null;
|
||||
s_imageLogo = tk.getImage(url);
|
||||
}
|
||||
return s_imageLogo;
|
||||
} // getImageLogo
|
||||
|
||||
/**
|
||||
* Get 32x32 ImageIcon.
|
||||
* Removing/modifying the Adempiere logo is a violation of the license
|
||||
* @return Image Icon
|
||||
*/
|
||||
public static ImageIcon getImageIcon32()
|
||||
{
|
||||
if (s_imageIcon32 == null)
|
||||
{
|
||||
URL url = org.compiere.Adempiere.class.getResource(s_file32x32);
|
||||
// System.out.println(url);
|
||||
if (url == null)
|
||||
return null;
|
||||
s_imageIcon32 = new ImageIcon(url);
|
||||
}
|
||||
return s_imageIcon32;
|
||||
} // getImageIcon32
|
||||
|
||||
/**
|
||||
* Get 100x30 ImageIcon.
|
||||
* Removing/modifying the Adempiere logo is a violation of the license
|
||||
* @return Image Icon
|
||||
*/
|
||||
public static ImageIcon getImageIconLogo()
|
||||
{
|
||||
if (s_imageIconLogo == null)
|
||||
{
|
||||
URL url = org.compiere.Adempiere.class.getResource(s_file100x30);
|
||||
// System.out.println(url);
|
||||
if (url == null)
|
||||
return null;
|
||||
s_imageIconLogo = new ImageIcon(url);
|
||||
}
|
||||
return s_imageIconLogo;
|
||||
} // getImageIconLogo
|
||||
|
||||
/**
|
||||
* Get default (Home) directory
|
||||
* @return Home directory
|
||||
*/
|
||||
public static String getAdempiereHome()
|
||||
{
|
||||
// Try Environment
|
||||
String retValue = Ini.getAdempiereHome();
|
||||
// Look in current Directory
|
||||
if (retValue == null && System.getProperty("user.dir").indexOf("Adempiere") != -1)
|
||||
{
|
||||
retValue = System.getProperty("user.dir");
|
||||
int pos = retValue.indexOf("Adempiere");
|
||||
retValue = retValue.substring(pos+9);
|
||||
}
|
||||
if (retValue == null)
|
||||
retValue = File.separator + "Adempiere";
|
||||
return retValue;
|
||||
} // getHome
|
||||
|
||||
/**
|
||||
* Get Support Email
|
||||
* @return Support mail address
|
||||
*/
|
||||
public static String getSupportEMail()
|
||||
{
|
||||
return s_supportEmail;
|
||||
} // getSupportEMail
|
||||
|
||||
/**
|
||||
* Set Support Email
|
||||
* @param email Support mail address
|
||||
*/
|
||||
public static void setSupportEMail(String email)
|
||||
{
|
||||
s_supportEmail = email;
|
||||
} // setSupportEMail
|
||||
|
||||
/**
|
||||
* Get JNLP CodeBase
|
||||
* @return code base or null
|
||||
*/
|
||||
public static URL getCodeBase()
|
||||
{
|
||||
try
|
||||
{
|
||||
BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
|
||||
URL url = bs.getCodeBase();
|
||||
return url;
|
||||
}
|
||||
catch(UnavailableServiceException ue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
} // getCodeBase
|
||||
|
||||
/**
|
||||
* Get JNLP CodeBase Host
|
||||
* @return code base or null
|
||||
*/
|
||||
public static String getCodeBaseHost()
|
||||
{
|
||||
URL url = getCodeBase();
|
||||
if (url == null)
|
||||
return null;
|
||||
return url.getHost();
|
||||
} // getCodeBase
|
||||
|
||||
/*************************************************************************
|
||||
* Startup Client/Server.
|
||||
* - Print greeting,
|
||||
* - Check Java version and
|
||||
* - load ini parameters
|
||||
* If it is a client, load/set PLAF and exit if error.
|
||||
* If Client, you need to call startupEnvironment explicitly!
|
||||
* For testing call method startupEnvironment
|
||||
* @param isClient true for client
|
||||
* @return successful startup
|
||||
*/
|
||||
public static synchronized boolean startup (boolean isClient)
|
||||
{
|
||||
// Already started
|
||||
if (log != null)
|
||||
return true;
|
||||
|
||||
// Check Version
|
||||
if (!Login.isJavaOK(isClient) && isClient)
|
||||
System.exit(1);
|
||||
|
||||
CLogMgt.initialize(isClient);
|
||||
Ini.setClient (isClient); // Ini requires Logging
|
||||
// Init Log
|
||||
log = CLogger.getCLogger(Adempiere.class);
|
||||
// Greeting
|
||||
log.info(getSummaryAscii());
|
||||
// log.info(getAdempiereHome() + " - " + getJavaInfo() + " - " + getOSInfo());
|
||||
|
||||
// Load System environment
|
||||
// EnvLoader.load(Ini.ENV_PREFIX);
|
||||
|
||||
// System properties
|
||||
Ini.loadProperties (false);
|
||||
|
||||
// Set up Log
|
||||
CLogMgt.setLevel(Ini.getProperty(Ini.P_TRACELEVEL));
|
||||
if (isClient && Ini.isPropertyBool(Ini.P_TRACEFILE)
|
||||
&& CLogFile.get(false, null, isClient) == null)
|
||||
CLogMgt.addHandler(CLogFile.get (true, Ini.findAdempiereHome(), isClient));
|
||||
|
||||
// Set UI
|
||||
if (isClient)
|
||||
{
|
||||
if (CLogMgt.isLevelAll())
|
||||
log.log(Level.FINEST, System.getProperties().toString());
|
||||
//
|
||||
//begin vpj-cd e-evolution
|
||||
//CompiereTheme.load();
|
||||
AdempiereThemeInnova.load();
|
||||
//end vpj-cd e-evolution
|
||||
AdempierePLAF.setPLAF (null);
|
||||
}
|
||||
|
||||
// Set Default Database Connection from Ini
|
||||
DB.setDBTarget(CConnection.get(getCodeBaseHost()));
|
||||
|
||||
if (isClient) // don't test connection
|
||||
return false; // need to call
|
||||
|
||||
return startupEnvironment(isClient);
|
||||
} // startup
|
||||
|
||||
/**
|
||||
* Startup Adempiere Environment.
|
||||
* Automatically called for Server connections
|
||||
* For testing call this method.
|
||||
* @param isClient true if client connection
|
||||
* @return successful startup
|
||||
*/
|
||||
public static boolean startupEnvironment (boolean isClient)
|
||||
{
|
||||
startup(isClient); // returns if already initiated
|
||||
if (!DB.isConnected())
|
||||
{
|
||||
log.severe ("No Database");
|
||||
System.exit(1);
|
||||
}
|
||||
// Initialize main cached Singletons
|
||||
ModelValidationEngine.get();
|
||||
try
|
||||
{
|
||||
MSystem system = MSystem.get(Env.getCtx()); // Initializes Base Context too
|
||||
String className = system.getEncryptionKey();
|
||||
if (className == null || className.length() == 0)
|
||||
{
|
||||
className = System.getProperty(SecureInterface.ADEMPIERE_SECURE);
|
||||
if (className != null && className.length() > 0
|
||||
&& !className.equals(SecureInterface.ADEMPIERE_SECURE_DEFAULT))
|
||||
{
|
||||
SecureEngine.init(className); // test it
|
||||
system.setEncryptionKey(className);
|
||||
system.save();
|
||||
}
|
||||
}
|
||||
SecureEngine.init(className);
|
||||
|
||||
//
|
||||
if (isClient)
|
||||
MClient.get(Env.getCtx(),0); // Login Client loaded later
|
||||
else
|
||||
MClient.getAll(Env.getCtx());
|
||||
Document.setKey(system.getSummary());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.warning("Environment problems: " + e.toString());
|
||||
}
|
||||
|
||||
// Start Workflow Document Manager (in other package) for PO
|
||||
String className = null;
|
||||
try
|
||||
{
|
||||
className = "org.compiere.wf.DocWorkflowManager";
|
||||
Class.forName(className);
|
||||
// Initialize Archive Engine
|
||||
className = "org.compiere.print.ArchiveEngine";
|
||||
Class.forName(className);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.warning("Not started: " + className + " - " + e.getMessage());
|
||||
}
|
||||
|
||||
if (!isClient)
|
||||
DB.updateMail();
|
||||
return true;
|
||||
} // startupEnvironment
|
||||
|
||||
|
||||
/**
|
||||
* Main Method
|
||||
*
|
||||
* @param args optional start class
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Splash.getSplash();
|
||||
startup(true); // error exit and initUI
|
||||
|
||||
// Start with class as argument - or if nothing provided with Client
|
||||
String className = "org.compiere.apps.AMenu";
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
if (!args[i].equals("-debug")) // ignore -debug
|
||||
{
|
||||
className = args[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
try
|
||||
{
|
||||
Class startClass = Class.forName(className);
|
||||
startClass.newInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("Adempiere starting: " + className + " - " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} // main
|
||||
} // Adempiere
|
|
@ -0,0 +1 @@
|
|||
build=sometime
|
|
@ -0,0 +1,276 @@
|
|||
/******************************************************************************
|
||||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
|
||||
import javax.sql.*;
|
||||
|
||||
//import org.compiere.util.CPreparedStatement;
|
||||
|
||||
/**
|
||||
* Interface for Adempiere Databases
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: AdempiereDatabase.java,v 1.5 2006/09/22 23:35:19 jjanke Exp $
|
||||
*/
|
||||
public interface AdempiereDatabase
|
||||
{
|
||||
/**
|
||||
* Get Database Name
|
||||
* @return database short name
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Get Database Description
|
||||
* @return database long name and version
|
||||
*/
|
||||
public String getDescription();
|
||||
|
||||
/**
|
||||
* Get and register Database Driver
|
||||
* @return Driver
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Driver getDriver() throws SQLException;
|
||||
|
||||
|
||||
/**
|
||||
* Get Standard JDBC Port
|
||||
* @return standard port
|
||||
*/
|
||||
public int getStandardPort();
|
||||
|
||||
/**
|
||||
* Get Database Connection String
|
||||
* @param connection Connection Descriptor
|
||||
* @return connection String
|
||||
*/
|
||||
public String getConnectionURL (CConnection connection);
|
||||
|
||||
/**
|
||||
* Get Connection URL
|
||||
* @param dbHost db Host
|
||||
* @param dbPort db Port
|
||||
* @param dbName db Name
|
||||
* @param userName user name
|
||||
* @return url
|
||||
*/
|
||||
public String getConnectionURL (String dbHost, int dbPort, String dbName,
|
||||
String userName);
|
||||
|
||||
/**
|
||||
* Get Database Connection String
|
||||
* @param connectionURL Connection URL
|
||||
* @param userName user name
|
||||
* @return connection String
|
||||
*/
|
||||
public String getConnectionURL (String connectionURL, String userName);
|
||||
|
||||
/**
|
||||
* Get JDBC Catalog
|
||||
* @return catalog
|
||||
*/
|
||||
public String getCatalog();
|
||||
|
||||
/**
|
||||
* Get JDBC Schema
|
||||
* @return schema
|
||||
*/
|
||||
public String getSchema();
|
||||
|
||||
/**
|
||||
* Supports BLOB
|
||||
* @return true if BLOB is supported
|
||||
*/
|
||||
public boolean supportsBLOB();
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString();
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Convert an individual Oracle Style statements to target database statement syntax
|
||||
*
|
||||
* @param oraStatement oracle statement
|
||||
* @return converted Statement
|
||||
*/
|
||||
public String convertStatement (String oraStatement);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check if DBMS support the sql statement
|
||||
* @sql SQL statement
|
||||
* @return true: yes
|
||||
*/
|
||||
public boolean isSupported(String sql);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get constraint type associated with the index
|
||||
* @conn connection
|
||||
* @tableName table name
|
||||
* @IXName Index name
|
||||
* @return String[0] = 0: do not know, 1: Primary Key 2: Foreign Key
|
||||
* String[1] - String[n] = Constraint Name
|
||||
*/
|
||||
public String getConstraintType(Connection conn, String tableName, String IXName);
|
||||
|
||||
|
||||
/**
|
||||
* Check and generate an alternative SQL
|
||||
* @reExNo number of re-execution
|
||||
* @msg previous execution error message
|
||||
* @sql previous executed SQL
|
||||
* @return String, the alternative SQL, null if no alternative
|
||||
*/
|
||||
public String getAlternativeSQL(int reExNo, String msg, String sql);
|
||||
|
||||
/**
|
||||
* Get Name of System User
|
||||
* @return e.g. sa, system
|
||||
*/
|
||||
public String getSystemUser();
|
||||
|
||||
/**
|
||||
* Get Name of System Database
|
||||
* @param databaseName database Name
|
||||
* @return e.g. master or database Name
|
||||
*/
|
||||
public String getSystemDatabase(String databaseName);
|
||||
|
||||
|
||||
/**
|
||||
* Create SQL TO Date String from Timestamp
|
||||
*
|
||||
* @param time Date to be converted
|
||||
* @param dayOnly true if time set to 00:00:00
|
||||
* @return date function
|
||||
*/
|
||||
public String TO_DATE (Timestamp time, boolean dayOnly);
|
||||
|
||||
/**
|
||||
* Create SQL for formatted Date, Number
|
||||
*
|
||||
* @param columnName the column name in the SQL
|
||||
* @param displayType Display Type
|
||||
* @param AD_Language 6 character language setting (from Env.LANG_*)
|
||||
*
|
||||
* @return TRIM(TO_CHAR(columnName,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.'''))
|
||||
* or TRIM(TO_CHAR(columnName,'TM9')) depending on DisplayType and Language
|
||||
* @see org.compiere.util.DisplayType
|
||||
* @see org.compiere.util.Env
|
||||
*
|
||||
**/
|
||||
public String TO_CHAR (String columnName, int displayType, String AD_Language);
|
||||
|
||||
|
||||
/**
|
||||
* Return number as string for INSERT statements with correct precision
|
||||
* @param number number
|
||||
* @param displayType display Type
|
||||
* @return number as string
|
||||
*/
|
||||
public String TO_NUMBER (BigDecimal number, int displayType);
|
||||
|
||||
|
||||
/** Create User commands */
|
||||
public static final int CMD_CREATE_USER = 0;
|
||||
/** Create Database/Schema Commands */
|
||||
public static final int CMD_CREATE_DATABASE = 1;
|
||||
/** Drop Database/Schema Commands */
|
||||
public static final int CMD_DROP_DATABASE = 2;
|
||||
|
||||
/**
|
||||
* Get SQL Commands.
|
||||
* <code>
|
||||
* The following variables are resolved:
|
||||
* @SystemPassword@, @AdempiereUser@, @AdempierePassword@
|
||||
* @SystemPassword@, @DatabaseName@, @DatabaseDevice@
|
||||
* </code>
|
||||
* @param cmdType CMD_*
|
||||
* @return array of commands to be executed
|
||||
*/
|
||||
public String[] getCommands (int cmdType);
|
||||
|
||||
|
||||
/**
|
||||
* Get Cached Connection on Server
|
||||
* @param connection info
|
||||
* @param autoCommit true if autocommit connection
|
||||
* @param transactionIsolation Connection transaction level
|
||||
* @return connection or null
|
||||
* @throws Exception
|
||||
*/
|
||||
public Connection getCachedConnection (CConnection connection,
|
||||
boolean autoCommit, int transactionIsolation) throws Exception;
|
||||
|
||||
/**
|
||||
* Get Connection from Driver
|
||||
* @param connection info
|
||||
* @return connection or null
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Connection getDriverConnection (CConnection connection) throws SQLException;
|
||||
|
||||
/**
|
||||
* Get Driver Connection
|
||||
* @param dbUrl URL
|
||||
* @param dbUid user
|
||||
* @param dbPwd password
|
||||
* @return connection
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Connection getDriverConnection (String dbUrl, String dbUid, String dbPwd)
|
||||
throws SQLException;
|
||||
|
||||
/**
|
||||
* Create DataSource
|
||||
* @param connection connection
|
||||
* @return data dource
|
||||
*/
|
||||
public DataSource getDataSource(CConnection connection);
|
||||
|
||||
/**
|
||||
* Get Status
|
||||
* @return status info
|
||||
*/
|
||||
public String getStatus();
|
||||
|
||||
/**
|
||||
* Close
|
||||
*/
|
||||
public void close();
|
||||
|
||||
/**
|
||||
* Get Data Type
|
||||
* @param DisplayType display type
|
||||
* @return data type
|
||||
*/
|
||||
// public String getDataType (int displayType, int precision,
|
||||
// boolean defaultValue)
|
||||
|
||||
} // AdempiereDatabase
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,513 @@
|
|||
/******************************************************************************
|
||||
* 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.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import javax.swing.*;
|
||||
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
|
||||
* @param cc Adempiere Connection
|
||||
*/
|
||||
public CConnectionDialog(CConnection cc)
|
||||
{
|
||||
super((Frame)null, true);
|
||||
try
|
||||
{
|
||||
jbInit();
|
||||
setConnection (cc);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "", e);
|
||||
}
|
||||
AdempierePLAF.showCenterScreen(this);
|
||||
} // 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 BorderLayout mainLayout = new BorderLayout();
|
||||
private CPanel centerPanel = new CPanel();
|
||||
private CPanel southPanel = new CPanel();
|
||||
private CButton bOK = AdempierePLAF.getOKButton();
|
||||
private CButton bCancel = AdempierePLAF.getCancelButton();
|
||||
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
|
||||
,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, 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);
|
||||
bTestDB.addActionListener(this);
|
||||
bOK.addActionListener(this);
|
||||
bCancel.addActionListener(this);
|
||||
|
||||
// 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
|
|
@ -0,0 +1,286 @@
|
|||
/******************************************************************************
|
||||
* 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.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import org.compiere.plaf.*;
|
||||
import org.compiere.swing.*;
|
||||
|
||||
/**
|
||||
* Connection Editor.
|
||||
* A combo box and a button
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: CConnectionEditor.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class CConnectionEditor extends JComponent
|
||||
implements CEditor
|
||||
{
|
||||
/**
|
||||
* Connection Editor creating new Connection
|
||||
*/
|
||||
public CConnectionEditor()
|
||||
{
|
||||
super();
|
||||
setName("ConnectionEditor");
|
||||
CConnectionEditor_MouseListener ml = new CConnectionEditor_MouseListener();
|
||||
// Layout
|
||||
m_text.setEditable(false);
|
||||
m_text.setBorder(null);
|
||||
m_text.addMouseListener(ml);
|
||||
m_server.setIcon(new ImageIcon(getClass().getResource("Server16.gif")));
|
||||
m_server.setFocusable(false);
|
||||
m_server.setBorder(null);
|
||||
m_server.setOpaque(true);
|
||||
m_server.addMouseListener(ml);
|
||||
m_db.setIcon(new ImageIcon(getClass().getResource("Database16.gif")));
|
||||
m_db.setFocusable(false);
|
||||
m_db.setBorder(null);
|
||||
m_db.setOpaque(true);
|
||||
m_db.addMouseListener(ml);
|
||||
LookAndFeel.installBorder(this, "TextField.border");
|
||||
//
|
||||
setLayout(new BorderLayout(0,0));
|
||||
add(m_server, BorderLayout.WEST);
|
||||
add(m_text, BorderLayout.CENTER);
|
||||
add(m_db, BorderLayout.EAST);
|
||||
} // CConnectionEditor
|
||||
|
||||
/** Text Element */
|
||||
private JTextField m_text = new JTextField(10);
|
||||
/** DB Button Element */
|
||||
private JLabel m_db = new JLabel ();
|
||||
/** Host Button Element */
|
||||
private JLabel m_server = new JLabel();
|
||||
/** The Value */
|
||||
private CConnection m_value = null;
|
||||
/** ReadWrite */
|
||||
private boolean m_rw = true;
|
||||
/** Mandatory */
|
||||
private boolean m_mandatory = false;
|
||||
|
||||
/**
|
||||
* Enable Editor
|
||||
* @param rw true, if you can enter/select data
|
||||
*/
|
||||
public void setReadWrite (boolean rw)
|
||||
{
|
||||
m_rw = rw;
|
||||
setBackground(false);
|
||||
} // setReadWrite
|
||||
|
||||
/**
|
||||
* Is it possible to edit
|
||||
* @return true, if editable
|
||||
*/
|
||||
public boolean isReadWrite()
|
||||
{
|
||||
return m_rw;
|
||||
} // isReadWrite
|
||||
|
||||
/**
|
||||
* Set Editor Mandatory
|
||||
* @param mandatory true, if you have to enter data
|
||||
*/
|
||||
public void setMandatory (boolean mandatory)
|
||||
{
|
||||
m_mandatory = mandatory;
|
||||
} // setMandatory
|
||||
|
||||
/**
|
||||
* Is Field mandatory
|
||||
* @return true, if mandatory
|
||||
*/
|
||||
public boolean isMandatory()
|
||||
{
|
||||
return m_mandatory;
|
||||
} // isMandatory
|
||||
|
||||
/**
|
||||
* Set Background based on editable / mandatory / error
|
||||
* @param error if true, set background to error color, otherwise mandatory/editable
|
||||
*/
|
||||
public void setBackground (boolean error)
|
||||
{
|
||||
Color c = null;
|
||||
if (error)
|
||||
c = AdempierePLAF.getFieldBackground_Error();
|
||||
else if (!m_rw)
|
||||
c = AdempierePLAF.getFieldBackground_Inactive();
|
||||
else if (m_mandatory)
|
||||
c = AdempierePLAF.getFieldBackground_Mandatory();
|
||||
else
|
||||
c = AdempierePLAF.getFieldBackground_Normal();
|
||||
setBackground(c);
|
||||
} // setBackground
|
||||
|
||||
/**
|
||||
* Set Background color
|
||||
* @param color
|
||||
*/
|
||||
public void setBackground (Color color)
|
||||
{
|
||||
m_server.setBackground(color);
|
||||
m_text.setBackground(color);
|
||||
m_db.setBackground(color);
|
||||
} // setBackground
|
||||
|
||||
/**
|
||||
* Set Visible
|
||||
* @param visible true if field is to be shown
|
||||
*/
|
||||
public void setVisible (boolean visible)
|
||||
{
|
||||
this.setVisible(visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Editor to value
|
||||
* @param value value of the editor
|
||||
*/
|
||||
public void setValue (Object value)
|
||||
{
|
||||
if (value != null && value instanceof CConnection)
|
||||
m_value = (CConnection)value;
|
||||
setDisplay();
|
||||
} // setValue
|
||||
|
||||
/**
|
||||
* Return Editor value
|
||||
* @return current value
|
||||
*/
|
||||
public Object getValue()
|
||||
{
|
||||
return m_value;
|
||||
} // getValue
|
||||
|
||||
/**
|
||||
* Return Display Value
|
||||
* @return displayed String value
|
||||
*/
|
||||
public String getDisplay()
|
||||
{
|
||||
if (m_value == null)
|
||||
return "";
|
||||
return m_value.getName();
|
||||
} // getDisplay
|
||||
|
||||
/**
|
||||
* Update Display with Connection info
|
||||
*/
|
||||
public void setDisplay()
|
||||
{
|
||||
m_text.setText(getDisplay());
|
||||
if (m_value == null)
|
||||
return;
|
||||
// Text
|
||||
if (m_value.isAppsServerOK(false) || m_value.isDatabaseOK())
|
||||
{
|
||||
m_text.setForeground(AdempierePLAF.getTextColor_OK());
|
||||
setBackground(false);
|
||||
if (!m_value.isAppsServerOK(false))
|
||||
m_server.setBackground(AdempierePLAF.getFieldBackground_Error());
|
||||
if (!m_value.isDatabaseOK())
|
||||
m_db.setBackground(AdempierePLAF.getFieldBackground_Error());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_text.setForeground(AdempierePLAF.getTextColor_Issue());
|
||||
setBackground(true);
|
||||
}
|
||||
} // setDisplay
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Remove Action Listener
|
||||
* @param l
|
||||
*/
|
||||
public synchronized void removeActionListener(ActionListener l)
|
||||
{
|
||||
listenerList.remove(ActionListener.class, l);
|
||||
} // removeActionListener
|
||||
|
||||
/**
|
||||
* Add Action Listener
|
||||
* @param l
|
||||
*/
|
||||
public synchronized void addActionListener(ActionListener l)
|
||||
{
|
||||
listenerList.add(ActionListener.class, l);
|
||||
} // addActionListener
|
||||
|
||||
/**
|
||||
* Fire Action Performed
|
||||
*/
|
||||
private void fireActionPerformed()
|
||||
{
|
||||
ActionEvent e = null;
|
||||
ActionListener[] listeners = listenerList.getListeners(ActionListener.class);
|
||||
for (int i = 0; i < listeners.length; i++)
|
||||
{
|
||||
if (e == null)
|
||||
e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "actionPerformed");
|
||||
listeners[i].actionPerformed(e);
|
||||
}
|
||||
} // fireActionPerformed
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Test Method
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// System.out.println("CConnectionEditor");
|
||||
JFrame frame = new JFrame("CConnectionEditor");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.getRootPane().getContentPane().add(new CConnectionEditor());
|
||||
AdempierePLAF.showCenterScreen(frame);
|
||||
} // main
|
||||
|
||||
|
||||
/**
|
||||
* MouseListener
|
||||
*/
|
||||
public class CConnectionEditor_MouseListener extends MouseAdapter
|
||||
{
|
||||
/**
|
||||
* Mouse Clicked - Open Dialog
|
||||
* @param e
|
||||
*/
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
if (!isEnabled() || !m_rw || m_active)
|
||||
return;
|
||||
m_active = true;
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
//
|
||||
CConnectionDialog cd = new CConnectionDialog(m_value);
|
||||
setValue(cd.getConnection());
|
||||
fireActionPerformed();
|
||||
//
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
m_active = false;
|
||||
} // mouseClicked
|
||||
|
||||
private boolean m_active = false;
|
||||
} // CConnectionExitor_MouseListener
|
||||
|
||||
} // CConnectionEditor
|
|
@ -0,0 +1,846 @@
|
|||
/******************************************************************************
|
||||
* 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.io.*;
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Class to Create a new Adempiere Database from a reference DB.
|
||||
* <pre>
|
||||
* - Create User
|
||||
* - Create DDL (table, procedures, functions, etc.)
|
||||
* </pre>
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: CreateAdempiere.java,v 1.5 2006/09/22 23:35:19 jjanke Exp $
|
||||
*/
|
||||
public class CreateAdempiere
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param databaseType AdempiereDatabase.TYPE_
|
||||
* @param databaseHost database host
|
||||
* @param databasePort database port 0 for default
|
||||
* @param systemPassword system password
|
||||
*/
|
||||
public CreateAdempiere(String databaseType, String databaseHost, int databasePort,
|
||||
String systemPassword)
|
||||
{
|
||||
initDatabase(databaseType);
|
||||
m_databaseHost = databaseHost;
|
||||
if (databasePort == 0)
|
||||
m_databasePort = m_dbTarget.getStandardPort();
|
||||
else
|
||||
m_databasePort = databasePort;
|
||||
m_systemPassword = systemPassword;
|
||||
log.info(m_dbTarget.getName() + " on " + databaseHost);
|
||||
} // create
|
||||
|
||||
/** Adempiere Target Database */
|
||||
private AdempiereDatabase m_dbTarget = null;
|
||||
/** Adempiere Source Database */
|
||||
private AdempiereDatabase m_dbSource = null;
|
||||
//
|
||||
private String m_databaseHost = null;
|
||||
private int m_databasePort = 0;
|
||||
private String m_systemPassword = null;
|
||||
private String m_adempiereUser = null;
|
||||
private String m_adempierePassword = null;
|
||||
private String m_databaseName = null;
|
||||
private String m_databaseDevice = null;
|
||||
//
|
||||
private Properties m_ctx = new Properties ();
|
||||
/** Cached connection */
|
||||
private Connection m_conn = null;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger (CreateAdempiere.class);
|
||||
|
||||
/**
|
||||
* Create Adempiere Database
|
||||
* @param databaseType Database.DB_
|
||||
*/
|
||||
private void initDatabase(String databaseType)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < Database.DB_NAMES.length; i++)
|
||||
{
|
||||
if (Database.DB_NAMES[i].equals (databaseType))
|
||||
{
|
||||
m_dbTarget = (AdempiereDatabase)Database.DB_CLASSES[i].
|
||||
newInstance ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.severe(e.toString ());
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (m_dbTarget == null)
|
||||
throw new IllegalStateException("No database: " + databaseType);
|
||||
|
||||
// Source Database
|
||||
m_dbSource = DB.getDatabase();
|
||||
} // createDatabase
|
||||
|
||||
/**
|
||||
* Clean Start - drop & re-create DB
|
||||
*/
|
||||
public void cleanStart()
|
||||
{
|
||||
Connection conn = getConnection(true, true);
|
||||
if (conn == null)
|
||||
throw new IllegalStateException("No Database");
|
||||
//
|
||||
dropDatabase(conn);
|
||||
createUser(conn);
|
||||
createDatabase(conn);
|
||||
//
|
||||
try
|
||||
{
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
}
|
||||
catch (SQLException e2)
|
||||
{
|
||||
log.log(Level.SEVERE, "close connection", e2);
|
||||
}
|
||||
conn = null;
|
||||
} // cleanStart
|
||||
|
||||
|
||||
/**
|
||||
* Set Adempiere User
|
||||
* @param adempiereUser adempiere id
|
||||
* @param adempierePassword adempiere password
|
||||
*/
|
||||
public void setAdempiereUser (String adempiereUser, String adempierePassword)
|
||||
{
|
||||
m_adempiereUser = adempiereUser;
|
||||
m_adempierePassword = adempierePassword;
|
||||
} // setAdempiereUser
|
||||
|
||||
/**
|
||||
* Set Database Name
|
||||
* @param databaseName db name
|
||||
* @param databaseDevice device or table space
|
||||
*/
|
||||
public void setDatabaseName (String databaseName, String databaseDevice)
|
||||
{
|
||||
m_databaseName = databaseName;
|
||||
m_databaseDevice = databaseDevice;
|
||||
} // createDatabase
|
||||
|
||||
|
||||
/**
|
||||
* Test Connection
|
||||
* @return connection
|
||||
*/
|
||||
public boolean testConnection()
|
||||
{
|
||||
String dbUrl = m_dbTarget.getConnectionURL (m_databaseHost, m_databasePort,
|
||||
m_databaseName, m_dbTarget.getSystemUser()); // adempiere may not be defined yet
|
||||
log.info(dbUrl + " - " + m_dbTarget.getSystemUser() + "/" + m_systemPassword);
|
||||
try
|
||||
{
|
||||
Connection conn = m_dbTarget.getDriverConnection(dbUrl, m_dbTarget.getSystemUser(), m_systemPassword);
|
||||
//
|
||||
JDBCInfo info = new JDBCInfo(conn);
|
||||
if (CLogMgt.isLevelFinest())
|
||||
{
|
||||
info.listCatalogs();
|
||||
info.listSchemas();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "test", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} // testConnection
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Create User
|
||||
* @param sysConn system connection
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean createUser (Connection sysConn)
|
||||
{
|
||||
log.info(m_adempiereUser + "/" + m_adempierePassword);
|
||||
return executeCommands(m_dbTarget.getCommands(AdempiereDatabase.CMD_CREATE_USER),
|
||||
sysConn, true, false);
|
||||
} // createUser
|
||||
|
||||
/**
|
||||
* Create Database (User)
|
||||
* @param sysConn system connection
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean createDatabase (Connection sysConn)
|
||||
{
|
||||
log.info(m_databaseName + "(" + m_databaseDevice + ")");
|
||||
return executeCommands(m_dbTarget.getCommands(AdempiereDatabase.CMD_CREATE_DATABASE),
|
||||
sysConn, true, false);
|
||||
} // createDatabase
|
||||
|
||||
/**
|
||||
* Drop Database (User)
|
||||
* @param sysConn system connection
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean dropDatabase (Connection sysConn)
|
||||
{
|
||||
log.info(m_databaseName);
|
||||
return executeCommands(m_dbTarget.getCommands(AdempiereDatabase.CMD_DROP_DATABASE),
|
||||
sysConn, true, false);
|
||||
} // dropDatabase
|
||||
|
||||
|
||||
/**
|
||||
* Create Tables and copy data
|
||||
* @param whereClause optional where clause
|
||||
* @param dropFirst drop first
|
||||
* @return true if executed
|
||||
*/
|
||||
public boolean copy (String whereClause, boolean dropFirst)
|
||||
{
|
||||
log.info(whereClause);
|
||||
if (getConnection(false, true) == null)
|
||||
return false;
|
||||
//
|
||||
boolean success = true;
|
||||
int count = 0;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
String sql = "SELECT * FROM AD_Table";
|
||||
if (whereClause != null && whereClause.length() > 0)
|
||||
sql += " WHERE " + whereClause;
|
||||
sql += " ORDER BY TableName";
|
||||
//
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
//jz: pstmt.getConnection() could be null
|
||||
Connection conn = pstmt.getConnection();
|
||||
DatabaseMetaData md = null;
|
||||
if (conn != null)
|
||||
md = conn.getMetaData();
|
||||
else
|
||||
{
|
||||
//jz: globalization issue??
|
||||
throw new DBException("No Connection");
|
||||
}
|
||||
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next() && success)
|
||||
{
|
||||
MTable table = new MTable (m_ctx, rs, null);
|
||||
if (table.isView())
|
||||
continue;
|
||||
if (dropFirst)
|
||||
{
|
||||
executeCommands(new String[]
|
||||
{"DROP TABLE " + table.getTableName()},
|
||||
m_conn, false, false);
|
||||
}
|
||||
//
|
||||
if (createTable (table, md))
|
||||
{
|
||||
list.add(table.getTableName());
|
||||
count++;
|
||||
}
|
||||
else
|
||||
success = false;
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log (Level.SEVERE, sql, e);
|
||||
success = false;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
if (!success)
|
||||
return false;
|
||||
|
||||
/** Enable Contraints */
|
||||
enableConstraints(list);
|
||||
|
||||
databaseBuild();
|
||||
|
||||
log.info("#" + count);
|
||||
|
||||
try
|
||||
{
|
||||
if (m_conn != null)
|
||||
m_conn.close();
|
||||
}
|
||||
catch (SQLException e2)
|
||||
{
|
||||
log.log(Level.SEVERE, "close connection", e2);
|
||||
}
|
||||
m_conn = null;
|
||||
return success;
|
||||
} // copy
|
||||
|
||||
/**
|
||||
* Execute Script
|
||||
* @param script file with script
|
||||
* @return true if executed
|
||||
*/
|
||||
public boolean execute (File script)
|
||||
{
|
||||
return false;
|
||||
} // createTables
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create Table
|
||||
* @param mTable table model
|
||||
* @param md meta data
|
||||
* @return true if created
|
||||
*/
|
||||
private boolean createTable (MTable mTable, DatabaseMetaData md)
|
||||
{
|
||||
String tableName = mTable.getTableName();
|
||||
log.info(tableName);
|
||||
String catalog = m_dbSource.getCatalog();
|
||||
String schema = m_dbSource.getSchema();
|
||||
String table = tableName.toUpperCase();
|
||||
//
|
||||
MColumn[] columns = mTable.getColumns(false);
|
||||
|
||||
StringBuffer sb = new StringBuffer("CREATE TABLE ");
|
||||
sb.append(tableName).append(" (");
|
||||
try
|
||||
{
|
||||
// Columns
|
||||
boolean first = true;
|
||||
ResultSet sourceColumns = md.getColumns(catalog, schema, table, null);
|
||||
while (sourceColumns.next())
|
||||
{
|
||||
sb.append(first ? "" : ", ");
|
||||
first = false;
|
||||
// Case sensitive Column Name
|
||||
MColumn column = null;
|
||||
String columnName = sourceColumns.getString("COLUMN_NAME");
|
||||
for (int i = 0; i < columns.length; i++)
|
||||
{
|
||||
String cn = columns[i].getColumnName();
|
||||
if (cn.equalsIgnoreCase(columnName))
|
||||
{
|
||||
columnName = cn;
|
||||
column = columns[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
sb.append(columnName).append(" ");
|
||||
// Data Type & Precision
|
||||
int sqlType = sourceColumns.getInt ("DATA_TYPE"); // sql.Types
|
||||
String typeName = sourceColumns.getString ("TYPE_NAME"); // DB Dependent
|
||||
int size = sourceColumns.getInt ("COLUMN_SIZE");
|
||||
int decDigits = sourceColumns.getInt("DECIMAL_DIGITS");
|
||||
if (sourceColumns.wasNull())
|
||||
decDigits = -1;
|
||||
if (typeName.equals("NUMBER"))
|
||||
{
|
||||
/** Oracle Style *
|
||||
if (decDigits == -1)
|
||||
sb.append(typeName);
|
||||
else
|
||||
sb.append(typeName).append("(")
|
||||
.append(size).append(",").append(decDigits).append(")");
|
||||
/** Other DBs */
|
||||
int dt = column.getAD_Reference_ID();
|
||||
if (DisplayType.isID(dt))
|
||||
sb.append("INTEGER");
|
||||
else
|
||||
{
|
||||
int scale = DisplayType.getDefaultPrecision(dt);
|
||||
sb.append("DECIMAL(")
|
||||
.append(18+scale).append(",").append(scale).append(")");
|
||||
}
|
||||
}
|
||||
else if (typeName.equals("DATE") || typeName.equals("BLOB") || typeName.equals("CLOB"))
|
||||
sb.append(typeName);
|
||||
else if (typeName.equals("CHAR") || typeName.startsWith("VARCHAR"))
|
||||
sb.append(typeName).append("(").append(size).append(")");
|
||||
else if (typeName.startsWith("NCHAR") || typeName.startsWith("NVAR"))
|
||||
sb.append(typeName).append("(").append(size/2).append(")");
|
||||
else if (typeName.startsWith("TIMESTAMP"))
|
||||
sb.append("DATE");
|
||||
else
|
||||
log.severe("Do not support data type " + typeName);
|
||||
// Default
|
||||
String def = sourceColumns.getString("COLUMN_DEF");
|
||||
if (def != null)
|
||||
{
|
||||
//jz: replace '' to \', otherwise exception
|
||||
def.replaceAll("''", "\\'");
|
||||
sb.append(" DEFAULT ").append(def);
|
||||
}
|
||||
// Null
|
||||
if (sourceColumns.getInt("NULLABLE") == DatabaseMetaData.columnNoNulls)
|
||||
sb.append(" NOT NULL");
|
||||
else
|
||||
sb.append(" NULL");
|
||||
|
||||
// Check Contraints
|
||||
|
||||
|
||||
} // for all columns
|
||||
sourceColumns.close();
|
||||
|
||||
// Primary Key
|
||||
ResultSet sourcePK = md.getPrimaryKeys(catalog, schema, table);
|
||||
// TABLE_CAT=null, TABLE_SCHEM=REFERENCE, TABLE_NAME=A_ASSET, COLUMN_NAME=A_ASSET_ID, KEY_SEQ=1, PK_NAME=A_ASSET_KEY
|
||||
first = true;
|
||||
boolean hasPK = false;
|
||||
while (sourcePK.next())
|
||||
{
|
||||
hasPK = true;
|
||||
if (first)
|
||||
sb.append(", CONSTRAINT ").append(sourcePK.getString("PK_NAME")).append(" PRIMARY KEY (");
|
||||
else
|
||||
sb.append(",");
|
||||
first = false;
|
||||
String columnName = sourcePK.getString("COLUMN_NAME");
|
||||
sb.append(checkColumnName(columnName));
|
||||
}
|
||||
if (hasPK) // close constraint
|
||||
sb.append(")"); // USING INDEX TABLESPACE INDX
|
||||
sourcePK.close();
|
||||
//
|
||||
sb.append(")"); // close create table
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.log(Level.SEVERE, "createTable", ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Execute Create Table
|
||||
if (!executeCommands(new String[]{sb.toString()}, m_conn, false, true))
|
||||
return true; // continue
|
||||
|
||||
// Create Inexes
|
||||
createTableIndexes(mTable, md);
|
||||
|
||||
return createTableData(mTable);
|
||||
} // createTable
|
||||
|
||||
/**
|
||||
* Check Column Name
|
||||
* @param columnName column name
|
||||
* @return column name with correct case
|
||||
*/
|
||||
private String checkColumnName (String columnName)
|
||||
{
|
||||
return M_Element.getColumnName (columnName);
|
||||
} // checkColumnName
|
||||
|
||||
/**
|
||||
* Create Table Indexes
|
||||
* @param mTable table
|
||||
* @param md meta data
|
||||
*/
|
||||
private void createTableIndexes(MTable mTable, DatabaseMetaData md)
|
||||
{
|
||||
String tableName = mTable.getTableName();
|
||||
log.info(tableName);
|
||||
String catalog = m_dbSource.getCatalog();
|
||||
String schema = m_dbSource.getSchema();
|
||||
String table = tableName.toUpperCase();
|
||||
try
|
||||
{
|
||||
ResultSet sourceIndex = md.getIndexInfo(catalog, schema, table, false, false);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
} // createTableIndexes
|
||||
|
||||
|
||||
/**
|
||||
* Create/Copy Table Data
|
||||
* @param mTable model table
|
||||
* @return true if data created/copied
|
||||
*/
|
||||
private boolean createTableData (MTable mTable)
|
||||
{
|
||||
boolean success = true;
|
||||
int count = 0;
|
||||
int errors = 0;
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
// Get Table Data
|
||||
String sql = "SELECT * FROM " + mTable.getTableName();
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, mTable.get_TrxName());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
if (createTableDataRow(rs, mTable))
|
||||
count++;
|
||||
else
|
||||
errors++;
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log (Level.SEVERE, sql, e);
|
||||
success = false;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
long elapsed = System.currentTimeMillis() - start;
|
||||
log.config("Inserted=" + count + " - Errors=" + errors
|
||||
+ " - " + elapsed + " ms");
|
||||
return success;
|
||||
} // createTableData
|
||||
|
||||
/**
|
||||
* Create Table Data Row
|
||||
* @param rs result set
|
||||
* @param mTable table
|
||||
* @return true if created
|
||||
*/
|
||||
private boolean createTableDataRow (ResultSet rs, MTable mTable)
|
||||
{
|
||||
StringBuffer insert = new StringBuffer ("INSERT INTO ")
|
||||
.append(mTable.getTableName()).append(" (");
|
||||
StringBuffer values = new StringBuffer ();
|
||||
//
|
||||
MColumn[] columns = mTable.getColumns(false);
|
||||
for (int i = 0; i < columns.length; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
insert.append(",");
|
||||
values.append(",");
|
||||
}
|
||||
MColumn column = columns[i];
|
||||
String columnName = column.getColumnName();
|
||||
insert.append(columnName);
|
||||
//
|
||||
int dt = column.getAD_Reference_ID();
|
||||
try
|
||||
{
|
||||
Object value = rs.getObject(columnName);
|
||||
if (rs.wasNull())
|
||||
{
|
||||
values.append("NULL");
|
||||
}
|
||||
else if (columnName.endsWith("_ID") // Record_ID, C_ProjectType defined as Button
|
||||
|| DisplayType.isNumeric(dt)
|
||||
|| (DisplayType.isID(dt) && !columnName.equals("AD_Language")))
|
||||
{
|
||||
BigDecimal bd = rs.getBigDecimal(columnName);
|
||||
String s = m_dbTarget.TO_NUMBER(bd, dt);
|
||||
values.append(s);
|
||||
}
|
||||
else if (DisplayType.isDate(dt))
|
||||
{
|
||||
Timestamp ts = rs.getTimestamp(columnName);
|
||||
String tsString = m_dbTarget.TO_DATE(ts, dt == DisplayType.Date);
|
||||
values.append(tsString);
|
||||
}
|
||||
else if (DisplayType.isLOB(dt))
|
||||
{
|
||||
// ignored
|
||||
values.append("NULL");
|
||||
}
|
||||
else if (DisplayType.isText(dt) || dt == DisplayType.YesNo
|
||||
|| dt == DisplayType.List || dt == DisplayType.Button
|
||||
|| columnName.equals("AD_Language"))
|
||||
{
|
||||
String s = rs.getString(columnName);
|
||||
values.append(DB.TO_STRING(s));
|
||||
}
|
||||
else
|
||||
{
|
||||
log.warning("Unknown DisplayType=" + dt
|
||||
+ " - " + value + " [" + value.getClass().getName() + "]");
|
||||
values.append("NuLl");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, columnName, e);
|
||||
}
|
||||
} // for all columns
|
||||
|
||||
//
|
||||
insert.append(") VALUES (").append(values).append(")");
|
||||
return executeCommands(new String[]{insert.toString()},
|
||||
m_conn, false, false); // do not convert as text is converted
|
||||
} // createTableDataRow
|
||||
|
||||
|
||||
/**
|
||||
* Enable Constraints
|
||||
* @param list list
|
||||
* @return true if constraints enabled/created
|
||||
*/
|
||||
private boolean enableConstraints (ArrayList list)
|
||||
{
|
||||
log.info("");
|
||||
return false;
|
||||
} // enableConstraints
|
||||
|
||||
|
||||
private void databaseBuild()
|
||||
{
|
||||
// Build Script
|
||||
//jz remove hard coded path later
|
||||
String fileName = "C:\\Adempiere\\adempiere-all2\\db\\database\\DatabaseBuild.sql";
|
||||
File file = new File (fileName);
|
||||
if (!file.exists())
|
||||
log.severe("No file: " + fileName);
|
||||
|
||||
// FileReader reader = new FileReader (file);
|
||||
|
||||
|
||||
|
||||
} // databaseBuild
|
||||
|
||||
/**
|
||||
* Get Connection
|
||||
* @param asSystem if true execute as db system administrator
|
||||
* @param createNew create new connection
|
||||
* @return connection or null
|
||||
*/
|
||||
private Connection getConnection (boolean asSystem, boolean createNew)
|
||||
{
|
||||
if (!createNew && m_conn != null)
|
||||
return m_conn;
|
||||
//
|
||||
String dbUrl = m_dbTarget.getConnectionURL(m_databaseHost, m_databasePort,
|
||||
(asSystem ? m_dbTarget.getSystemDatabase(m_databaseName) : m_databaseName),
|
||||
(asSystem ? m_dbTarget.getSystemUser() : m_adempiereUser));
|
||||
try
|
||||
{
|
||||
if (asSystem)
|
||||
m_conn = m_dbTarget.getDriverConnection(dbUrl, m_dbTarget.getSystemUser(), m_systemPassword);
|
||||
else
|
||||
m_conn = m_dbTarget.getDriverConnection(dbUrl, m_adempiereUser, m_adempierePassword);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, dbUrl, e);
|
||||
}
|
||||
return m_conn;
|
||||
} // getConnection
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Execute Commands
|
||||
* @param cmds array of SQL commands
|
||||
* @param conn connection
|
||||
* @param batch tf true commit as batch
|
||||
* @param doConvert convert to DB specific notation
|
||||
* @return true if success
|
||||
*/
|
||||
private boolean executeCommands (String[] cmds, Connection conn,
|
||||
boolean batch, boolean doConvert)
|
||||
{
|
||||
if (cmds == null || cmds.length == 0)
|
||||
{
|
||||
log.warning("No Commands");
|
||||
return false;
|
||||
}
|
||||
|
||||
Statement stmt = null;
|
||||
String cmd = null;
|
||||
String cmdOriginal = null;
|
||||
try
|
||||
{
|
||||
if (conn == null)
|
||||
{
|
||||
conn = getConnection(false, false);
|
||||
if (conn == null)
|
||||
return false;
|
||||
}
|
||||
if (conn.getAutoCommit() == batch)
|
||||
conn.setAutoCommit(!batch);
|
||||
stmt = conn.createStatement();
|
||||
|
||||
// Commands
|
||||
for (int i = 0; i < cmds.length; i++)
|
||||
{
|
||||
cmd = cmds[i];
|
||||
cmdOriginal = cmds[i];
|
||||
if (cmd == null || cmd.length() == 0)
|
||||
continue;
|
||||
//
|
||||
if (cmd.indexOf('@') != -1)
|
||||
{
|
||||
cmd = Util.replace(cmd, "@SystemPassword@", m_systemPassword);
|
||||
cmd = Util.replace(cmd, "@AdempiereUser@", m_adempiereUser);
|
||||
cmd = Util.replace(cmd, "@AdempierePassword@", m_adempierePassword);
|
||||
cmd = Util.replace(cmd, "@SystemPassword@", m_systemPassword);
|
||||
cmd = Util.replace(cmd, "@DatabaseName@", m_databaseName);
|
||||
if (m_databaseDevice != null)
|
||||
cmd = Util.replace(cmd, "@DatabaseDevice@", m_databaseDevice);
|
||||
}
|
||||
if (doConvert)
|
||||
cmd = m_dbTarget.convertStatement(cmd);
|
||||
writeLog(cmd);
|
||||
log.finer(cmd);
|
||||
int no = stmt.executeUpdate(cmd);
|
||||
log.finest("# " + no);
|
||||
}
|
||||
//
|
||||
stmt.close();
|
||||
stmt = null;
|
||||
//
|
||||
if (batch)
|
||||
conn.commit();
|
||||
//
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String msg = e.getMessage();
|
||||
if (msg == null || msg.length() == 0)
|
||||
msg = e.toString();
|
||||
msg += " (";
|
||||
if (e instanceof SQLException)
|
||||
{
|
||||
msg += "State=" + ((SQLException)e).getSQLState()
|
||||
+ ",ErrorCode=" + ((SQLException)e).getErrorCode();
|
||||
}
|
||||
msg += ")";
|
||||
if (cmdOriginal != null && !cmdOriginal.equals(cmd))
|
||||
msg += " - " + cmdOriginal;
|
||||
msg += "\n=>" + cmd;
|
||||
log.log(Level.SEVERE, msg);
|
||||
}
|
||||
// Error clean up
|
||||
try
|
||||
{
|
||||
if (stmt != null)
|
||||
stmt.close();
|
||||
}
|
||||
catch (SQLException e1)
|
||||
{
|
||||
log.log(Level.SEVERE, "close statement", e1);
|
||||
}
|
||||
stmt = null;
|
||||
return false;
|
||||
} // execureCommands
|
||||
|
||||
|
||||
/**
|
||||
* Write to File Log
|
||||
* @param cmd cmd
|
||||
*/
|
||||
private void writeLog (String cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_writer == null)
|
||||
{
|
||||
File file = File.createTempFile("create", ".log");
|
||||
m_writer = new PrintWriter(new FileWriter(file));
|
||||
log.info(file.toString());
|
||||
}
|
||||
m_writer.println(cmd);
|
||||
m_writer.flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.severe(e.toString());
|
||||
}
|
||||
} // writeLog
|
||||
|
||||
private PrintWriter m_writer = null;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Create DB
|
||||
* @param args
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Adempiere.startup(true);
|
||||
CLogMgt.setLevel(Level.FINE);
|
||||
CLogMgt.setLoggerLevel(Level.FINE,null);
|
||||
|
||||
// C_UOM_Conversion
|
||||
// I_BankStatement
|
||||
//
|
||||
// Derby
|
||||
//jz: changed the password from "" to null
|
||||
//begin vpj-cd e-Evolution 03/03/2005 PostgreSQL
|
||||
//PostgreSQL
|
||||
//CreateCompiere cc = new CreateCompiere (Database.DB_DERBY, "localhost", 1527, null);
|
||||
//cc.setCompiereUser("adempiere", "adempiere");
|
||||
//cc.setDatabaseName("adempiere", "adempiere");
|
||||
CreateAdempiere cc = new CreateAdempiere (Database.DB_POSTGRESQL, "127.0.0.2", 5432 , "adempiere");
|
||||
cc.setAdempiereUser("adempiere", "adempiere");
|
||||
cc.setDatabaseName("adempiere", "adempiere");
|
||||
// end begin vpj-cd e-Evolution 03/03/2005 PostgreSQL
|
||||
if (!cc.testConnection())
|
||||
return;
|
||||
cc.cleanStart();
|
||||
//
|
||||
// cc.copy(null, false);
|
||||
cc.copy("TableName > 'C_RfQResponseLineQty'", false);
|
||||
} // main
|
||||
|
||||
} // CreateAdempiere
|
|
@ -0,0 +1,64 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DBRes.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Adempiere Connection" },
|
||||
{ "Name", "Name" },
|
||||
{ "AppsHost", "Application Host" },
|
||||
{ "AppsPort", "Application Port" },
|
||||
{ "TestApps", "Test Application Server" },
|
||||
{ "DBHost", "Database Host" },
|
||||
{ "DBPort", "Database Port" },
|
||||
{ "DBName", "Database Name" },
|
||||
{ "DBUidPwd", "User / Password" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Firewall Host" },
|
||||
{ "FWPort", "Firewall Port" },
|
||||
{ "TestConnection", "Test Database" },
|
||||
{ "Type", "Database Type" },
|
||||
{ "BequeathConnection", "Bequeath Connection" },
|
||||
{ "Overwrite", "Overwrite" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Connection Error" },
|
||||
{ "ServerNotActive", "Server Not Active" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,61 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DBRes_ar.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_ar extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "\u0631\u0628\u0637 \u0643\u0645\u0628\u064a\u0631" },
|
||||
{ "Name", "\u0627\u0644\u0627\u0650\u0633\u0645" },
|
||||
{ "AppsHost", "\u0645\u0636\u064a\u0641 \u0627\u0644\u062a\u0637\u0628\u064a\u0642\u0627\u062a" },
|
||||
{ "AppsPort", "\u0627\u0644\u062a\u0637\u0628\u064a\u0642\u0627\u062a \u0645\u0646\u0641\u062f" },
|
||||
{ "TestApps", "\u062c\u0631\u0628 \u0645\u0648\u0632\u0639 \u0627\u0644\u062a\u0637\u0628\u064a\u0642\u0627\u062a" },
|
||||
{ "DBHost", "\u0645\u0636\u064a\u0641 \u0642\u0627\u0639\u062f\u0629 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a" },
|
||||
{ "DBPort", "\u0645\u0646\u0641\u0630 \u0642\u0627\u0639\u062f\u0629 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a" },
|
||||
{ "DBName", "\u0627\u0650\u0633\u0645 \u0642\u0627\u0639\u062f\u0629 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a" },
|
||||
{ "DBUidPwd", "\u0627\u0644\u0645\u0633\u062a\u0639\u0645\u0644\\u0643\u0644\u0645\u0629 \u0627\u0644\u0633\u0631" },
|
||||
{ "ViaFirewall", "\u0639\u0628\u0631 \u062c\u062f\u0627\u0631 \u0646\u0627\u0631\u064a" },
|
||||
{ "FWHost", "\u0645\u0636\u064a\u0641 \u0627\u0644\u062c\u062f\u0627\u0631 \u0627\u0644\u0646\u0627\u0631\u064a" },
|
||||
{ "FWPort", "\u0645\u0646\u0641\u0630 \u0627\u0644\u062c\u062f\u0627\u0631 \u0627\u0644\u0646\u0627\u0631\u064a" },
|
||||
{ "TestConnection", "\u0645\u0646\u0641\u0630 \u0628\u0646\u0643 \u0627\u0644\u0645\u0639\u0644\u0648\u0645\u0627\u062a" },
|
||||
{ "Type", "\u0646\u0648\u0639 \u0642\u0627\u0639\u062f\u0629 \u0627\u0644\u0628\u064a\u0627\u0646\u0627\u062a" },
|
||||
{ "BequeathConnection", "\u062a\u0631\u0643\u0629 \u0627\u0644\u0631\u0651\u064e\u0628\u0637" },
|
||||
{ "Overwrite", "\u0627\u0633\u062d\u0642" },
|
||||
{ "RMIoverHTTP", "HTTP \u0645\u0631\u0651\u0631 \u0627\u0644\u0643\u0627\u0626\u0646\u0627\u062a \u0639\u0628\u0631 \u0646\u0641\u0642" },
|
||||
{ "ConnectionError", "\u062e\u0637\u0623 \u0623\u062b\u0646\u0627\u0621 \u0627\u0644\u0631\u0628\u0637" },
|
||||
{ "ServerNotActive", "\u0627\u0644\u0645\u0648\u0632\u0639 \u0644\u0627 \u064a\u0639\u0645\u0644" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
* @uml.property name="contents"
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // DBRes_ar_TN
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Plamen Niikolov
|
||||
* @version $Id: DBRes_bg.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_bg extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "\u0412\u0440\u044a\u0437\u043a\u0430" },
|
||||
{ "Name", "\u0418\u043c\u0435" },
|
||||
{ "AppsHost", "\u0421\u044a\u0440\u0432\u0435\u0440 \u043d\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u0442\u043e" },
|
||||
{ "AppsPort", "\u041f\u043e\u0440\u0442 \u043d\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u0442\u043e" },
|
||||
{ "TestApps", "\u0422\u0435\u0441\u0442 \u043d\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u0442\u043e" },
|
||||
{ "DBHost", "\u0421\u044a\u0440\u0432\u0435\u0440 \u043d\u0430 \u0431\u0430\u0437\u0430\u0442\u0430 \u0434\u0430\u043d\u043d\u0438" },
|
||||
{ "DBPort", "\u041f\u043e\u0440\u0442 \u043d\u0430 \u0431\u0430\u0437\u0430\u0442\u0430 \u0434\u0430\u043d\u043d\u0438" },
|
||||
{ "DBName", "\u0418\u043c\u0435 \u043d\u0430 \u0431\u0430\u0437\u0430\u0442\u0430 \u0434\u0430\u043d\u043d\u0438" },
|
||||
{ "DBUidPwd", "\u041f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b / \u041f\u0430\u0440\u043e\u043b\u0430" },
|
||||
{ "ViaFirewall", "\u0417\u0430\u0434 \u0437\u0430\u0449\u0438\u0442\u043d\u0430 \u0441\u0442\u0435\u043d\u0430" },
|
||||
{ "FWHost", "\u0421\u044a\u0440\u0432\u0435\u0440 \u043d\u0430 \u0437\u0430\u0449\u0438\u0442\u043d\u0430\u0442\u0430 \u0441\u0442\u0435\u043d\u0430" },
|
||||
{ "FWPort", "\u041f\u043e\u0440\u0442 \u043d\u0430 \u0437\u0430\u0449\u0438\u0442\u043d\u0430\u0442\u0430 \u0441\u0442\u0435\u043d\u0430" },
|
||||
{ "TestConnection", "\u0422\u0435\u0441\u0442 \u043d\u0430 \u0431\u0430\u0437\u0430\u0442\u0430 \u0434\u0430\u043d\u043d\u0438" },
|
||||
{ "Type", "\u0412\u0438\u0434 \u043d\u0430 \u0431\u0430\u0437\u0430\u0442\u0430 \u0434\u0430\u043d\u043d\u0438" },
|
||||
{ "BequeathConnection", "\u041b\u043e\u043a\u0430\u043b\u043d\u0430 \u0432\u0440\u044a\u0437\u043a\u0430" },
|
||||
{ "Overwrite", "\u0417\u0430\u043c\u044f\u043d\u0430" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "\u0413\u0440\u0435\u0448\u043a\u0430 \u043f\u0440\u0438 \u0441\u0432\u044a\u0440\u0437\u0432\u0430\u043d\u0435" },
|
||||
{ "ServerNotActive", "\u0421\u044a\u0440\u0432\u0435\u0440\u044a\u0442 \u043d\u0435 \u0435 \u0430\u043a\u0442\u0438\u0432\u0435\u043d" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
}
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Jaume Teixi
|
||||
* @version $Id: DBRes_ca.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_ca extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Connexi<EFBFBD> Adempiere" },
|
||||
{ "Name", "Nom" },
|
||||
{ "AppsHost", "Servidor Aplicaci<63>" },
|
||||
{ "AppsPort", "Port Aplicaci<63>" },
|
||||
{ "TestApps", "Provar Aplicaci<63>" },
|
||||
{ "DBHost", "Servidor Base de Dades" },
|
||||
{ "DBPort", "Port Base de Dades" },
|
||||
{ "DBName", "Nom Base de Dades" },
|
||||
{ "DBUidPwd", "Usuari / Contrasenya" },
|
||||
{ "ViaFirewall", "via Tallafocs" },
|
||||
{ "FWHost", "Servidor Tallafocs" },
|
||||
{ "FWPort", "Port Tallafocs" },
|
||||
{ "TestConnection", "Provar Base de Dades" },
|
||||
{ "Type", "Tipus Base de Dades" },
|
||||
{ "BequeathConnection", "Delegar Connexi<78>" },
|
||||
{ "Overwrite", "Sobrescriure" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Error Connexi<78>" },
|
||||
{ "ServerNotActive", "Servidor No Actiu" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DBRes_da.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_da extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Adempiere forbindelse" },
|
||||
{ "Name", "Navn" },
|
||||
{ "AppsHost", "Programvært" },
|
||||
{ "AppsPort", "Programport" },
|
||||
{ "TestApps", "Test programserver" },
|
||||
{ "DBHost", "Databasevært" },
|
||||
{ "DBPort", "Databaseport" },
|
||||
{ "DBName", "Databasenavn" },
|
||||
{ "DBUidPwd", "Bruger/adgangskode" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Firewall-vært" },
|
||||
{ "FWPort", "Firewall-port" },
|
||||
{ "TestConnection", "Test database" },
|
||||
{ "Type", "Databasetype" },
|
||||
{ "BequeathConnection", "Nedarv forbindelse" },
|
||||
{ "Overwrite", "Overskriv" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Fejl i forbindelse" },
|
||||
{ "ServerNotActive", "Server er ikke aktiv" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings (German)
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DBRes_de.java,v 1.3 2006/08/30 20:30:44 comdivision Exp $
|
||||
*/
|
||||
public class DBRes_de extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Adempiere Verbindung" },
|
||||
{ "Name", "Name" },
|
||||
{ "AppsHost", "Applikationsserver" },
|
||||
{ "AppsPort", "Port Applikationsserver" },
|
||||
{ "TestApps", "Test Applikationsserver" },
|
||||
{ "DBHost", "Datenbank Server" },
|
||||
{ "DBPort", "Datenbank Port" },
|
||||
{ "DBName", "Datenbank Name" },
|
||||
{ "DBUidPwd", "Nutzer / Kennwort" },
|
||||
{ "ViaFirewall", "<EFBFBD>ber Firewall" },
|
||||
{ "FWHost", "Firewall Server" },
|
||||
{ "FWPort", "Firewall Port" },
|
||||
{ "TestConnection", "Teste Datenbankverbindung" },
|
||||
{ "Type", "Datenbank Typ" },
|
||||
{ "BequeathConnection", "Bequeath Connection" },
|
||||
{ "Overwrite", "ueberschreiben" },
|
||||
{ "ConnectionProfile", "Verbindungsprofil" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Verbindungsfehler" },
|
||||
{ "ServerNotActive", "Rechner nicht erreichbar" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contents
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContents
|
||||
} // Res_de
|
|
@ -0,0 +1,59 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Erwin Cortes
|
||||
* @version $Id: DBRes_es.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_es extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Conexión ADempiere" },
|
||||
{ "Name", "Nombre" },
|
||||
{ "AppsHost", "Servidor de Aplicación" },
|
||||
{ "AppsPort", "Puerto de Aplicación" },
|
||||
{ "TestApps", "Test de Aplicación" },
|
||||
{ "DBHost", "Host de Base de Datos" },
|
||||
{ "DBPort", "Puerto de Base de Datos" },
|
||||
{ "DBName", "Nombre de Base de datos" },
|
||||
{ "DBUidPwd", "Usuario / Contraseña" },
|
||||
{ "ViaFirewall", "vía Firewall" },
|
||||
{ "FWHost", "Servidor de Firewall" },
|
||||
{ "FWPort", "Puerto del Firewall" },
|
||||
{ "TestConnection", "Test de Base de datos" },
|
||||
{ "Type", "Tipo de Base de Datos" },
|
||||
{ "BequeathConnection", "Conexión Heredada" },
|
||||
{ "Overwrite", "Sobreescribir" },
|
||||
{ "RMIoverHTTP", "Tunelizar Objetos vía HTTP" },
|
||||
{ "ConnectionError", "Error en conexión" },
|
||||
{ "ServerNotActive", "Servidor inactivo" }};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
}
|
||||
} // Res
|
|
@ -0,0 +1,64 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author .
|
||||
* @version $Id: DBRes_fa.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_fa extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "\u0627\u062a\u0635\u0627\u0644 \u0628\u0647 \u06a9\u0627\u0645\u067e\u064a\u0631\u0647" },
|
||||
{ "Name", "\u0646\u0627\u0645" },
|
||||
{ "AppsHost", "\u0633\u064a\u0633\u062a\u0645 \u0645\u064a\u0632\u0628\u0627\u0646 \u06a9\u0627\u0631\u0628\u0631\u062f" },
|
||||
{ "AppsPort", "\u062f\u0631\u06af\u0627\u0647 \u06a9\u0627\u0631\u0628\u0631\u062f" },
|
||||
{ "TestApps", "\u0633\u0631\u0648\u0631 \u06a9\u0627\u0631\u0628\u0631\u062f \u0622\u0632\u0645\u0627\u064a\u0634\u06cc" },
|
||||
{ "DBHost", "\u0645\u064a\u0632\u0628\u0627\u0646 \u0628\u0627\u0646\u06a9 \u0627\u0637\u0644\u0627\u0639\u0627\u062a\u06cc" },
|
||||
{ "DBPort", "\u062f\u0631\u06af\u0627\u0647 \u0628\u0627\u0646\u06a9 \u0627\u0637\u0644\u0627\u0639\u0627\u062a\u06cc" },
|
||||
{ "DBName", "\u0646\u0627\u0645 \u0628\u0627\u0646\u06a9 \u0627\u0637\u0644\u0627\u0639\u0627\u062a" },
|
||||
{ "DBUidPwd", "\u0645\u0634\u062e\u0635\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u0646\u062f\u0647 \u0648 \u06a9\u0644\u0645\u0647 \u0639\u0628\u0648\u0631" },
|
||||
{ "ViaFirewall", "\u0627\u0632 \u0637\u0631\u0650\u064a\u0642 \u0641\u0627\u064a\u0631\u0648\u0627\u0644" },
|
||||
{ "FWHost", "\u0645\u064a\u0632\u0628\u0627\u0646 \u0641\u0627\u064a\u0631\u0648\u0627\u0644" },
|
||||
{ "FWPort", "\u062f\u0631\u06af\u0627\u0647 \u0641\u0627\u064a\u0631\u0648\u0627\u0644" },
|
||||
{ "TestConnection", "\u0628\u0627\u0646\u06a9 \u0627\u0637\u0644\u0627\u0639\u0627\u062a \u0622\u0632\u0645\u0627\u064a\u0634" },
|
||||
{ "Type", "\u0646\u0648\u0639 \u0628\u0627\u0646\u06a9 \u0627\u0637\u0644\u0627\u0639\u0627\u062a" },
|
||||
{ "BequeathConnection", "\u0627\u062a\u0635\u0627\u0644 \u062a\u062e\u0635\u064a\u0635 \u062f\u0627\u062f\u0647 \u0634\u062f\u0647" },
|
||||
{ "Overwrite", "\u0628\u0627\u0632\u0646\u0648\u064a\u0633\u06cc" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "\u062e\u0637\u0627 \u062f\u0631 \u0627\u062a\u0635\u0627\u0644" },
|
||||
{ "ServerNotActive", "\u0633\u0631\u0648\u0631 \u0641\u0639\u0627\u0644 \u0646\u064a\u0633\u062a" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,67 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings for Finnish language
|
||||
*
|
||||
* @author Petteri Soininen (petteri.soininen@netorek.fi)
|
||||
* @version $Id: DBRes_fi.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_fi extends ListResourceBundle
|
||||
{
|
||||
/**
|
||||
* Data
|
||||
*/
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Adempiere-yhteys" },
|
||||
{ "Name", "Nimi" },
|
||||
{ "AppsHost", "Sovellusverkkoasema" },
|
||||
{ "AppsPort", "Sovellusportti" },
|
||||
{ "TestApps", "Testisovelluspalvelin" },
|
||||
{ "DBHost", "Tietokantaverkkoasema" },
|
||||
{ "DBPort", "Tietokantaportti" },
|
||||
{ "DBName", "Tietokannan nimi" },
|
||||
{ "DBUidPwd", "K<EFBFBD>ytt<EFBFBD>j<EFBFBD>tunnus / Salasana" },
|
||||
{ "ViaFirewall", "Palomuurin l<>pi" },
|
||||
{ "FWHost", "Palomuuriverkkoasema" },
|
||||
{ "FWPort", "Palomuuriportti" },
|
||||
{ "TestConnection", "Testitietokanta" },
|
||||
{ "Type", "Tietokantatyyppi" },
|
||||
{ "BequeathConnection", "Periytyv<EFBFBD> yhteys" },
|
||||
{ "Overwrite", "Korvaa" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Yhteysvirhe" },
|
||||
{ "ServerNotActive", "Palvelin ei aktiivinen" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings (French)
|
||||
*
|
||||
* @author Jean-Luc SCHEIDEGGER
|
||||
* @version $Id: DBRes_fr.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_fr extends ListResourceBundle
|
||||
{
|
||||
/** Translation Content */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Connexion Adempiere" },
|
||||
{ "Name", "Nom" },
|
||||
{ "AppsHost", "Hote d'Application" },
|
||||
{ "AppsPort", "Port de l'Application" },
|
||||
{ "TestApps", "Application de Test" },
|
||||
{ "DBHost", "Hote Base de Donn<6E>es" },
|
||||
{ "DBPort", "Port Base de Donn<6E>es" },
|
||||
{ "DBName", "Nom Base de Donn<6E>es" },
|
||||
{ "DBUidPwd", "Utilisateur / Mot de Passe" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Hote Firewall" },
|
||||
{ "FWPort", "Port Firewall" },
|
||||
{ "TestConnection", "Test Base de Donn<6E>es" },
|
||||
{ "Type", "Type Base de Donn<6E>es" },
|
||||
{ "BequeathConnection", "Connexion d<>di<64>e" },
|
||||
{ "Overwrite", "Ecraser" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Erreur Connexion" },
|
||||
{ "ServerNotActive", "Serveur Non Actif" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContents
|
||||
} // DBRes_fr
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Marko Bubalo
|
||||
* @version $Id: DBRes_hr.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_hr extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Adempiere veza" },
|
||||
{ "Name", "Naziv" },
|
||||
{ "AppsHost", "Host aplikacije" },
|
||||
{ "AppsPort", "Port aplikacije" },
|
||||
{ "TestApps", "Testiranje servera" },
|
||||
{ "DBHost", "Host baze" },
|
||||
{ "DBPort", "Port baze" },
|
||||
{ "DBName", "Naziv baze" },
|
||||
{ "DBUidPwd", "Korisnik / lozinka" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Firewall Host" },
|
||||
{ "FWPort", "Firewall Port" },
|
||||
{ "TestConnection", "Tesiranje baze" },
|
||||
{ "Type", "Tip baze" },
|
||||
{ "BequeathConnection", "Bequeath Connection" },
|
||||
{ "Overwrite", "Prebrisati" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Gre<EFBFBD>ka u vezi" },
|
||||
{ "ServerNotActive", "Server nije aktivan" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Halim Englen
|
||||
* @version $Id: DBRes_in.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_in extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Koneksi Ke Adempiere" },
|
||||
{ "Name", "Nama" },
|
||||
{ "AppsHost", "Pusat Aplikasi" },
|
||||
{ "AppsPort", "Port Aplikasi" },
|
||||
{ "TestApps", "Uji Server Aplikasi" },
|
||||
{ "DBHost", "Pusat Database" },
|
||||
{ "DBPort", "Port Database" },
|
||||
{ "DBName", "Nama Database" },
|
||||
{ "DBUidPwd", "ID Pengguna / Kata Sandi" },
|
||||
{ "ViaFirewall", "lewat Firewall" },
|
||||
{ "FWHost", "Pusat Firewall" },
|
||||
{ "FWPort", "Port Firewall" },
|
||||
{ "TestConnection", "Uji Koneksi" },
|
||||
{ "Type", "Tipe Database" },
|
||||
{ "BequeathConnection", "Koneksi Warisan" },
|
||||
{ "Overwrite", "Timpakan" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Kesalahan Koneksi" },
|
||||
{ "ServerNotActive", "Server tidak aktif" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,63 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Alessandro Riolo
|
||||
* @version $Id: DBRes_it.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_it extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Connessione a Adempiere" },
|
||||
{ "Name", "Nome" },
|
||||
{ "AppsHost", "Host dell'Applicativo" },
|
||||
{ "AppsPort", "Porta dell'Applicativo" },
|
||||
{ "TestApps", "Applicazione di Test" },
|
||||
{ "DBHost", "Host del Database" },
|
||||
{ "DBPort", "Porta del Database" },
|
||||
{ "DBName", "Nome del Database" },
|
||||
{ "DBUidPwd", "Utente / Password" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Host del Firewall" },
|
||||
{ "FWPort", "Porta del Firewall" },
|
||||
{ "TestConnection", "Database di Test" },
|
||||
{ "Type", "Tipo di Database" },
|
||||
{ "BequeathConnection", "Connessione Dedicata" },
|
||||
{ "Overwrite", "Sovrascri" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Errore di Connessione" },
|
||||
{ "ServerNotActive", "Server non Attivo" }};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
}
|
||||
} // Res
|
|
@ -0,0 +1,64 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Stefan Christians
|
||||
* @version $Id: DBRes_ja.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_ja extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "\u30b3\u30f3\u30d4\u30a8\u30fc\u30ec\u306e\u63a5\u7d9a" },
|
||||
{ "Name", "\u540d\u524d" },
|
||||
{ "AppsHost", "\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30fb\u30b5\u30fc\u30d0" },
|
||||
{ "AppsPort", "\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30fb\u30dd\u30fc\u30c8" },
|
||||
{ "TestApps", "\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30fb\u30b5\u30fc\u30d0\u306e\u30c6\u30b9\u30c8" },
|
||||
{ "DBHost", "\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30fb\u30b5\u30fc\u30d0" },
|
||||
{ "DBPort", "\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30fb\u30dd\u30fc\u30c8" },
|
||||
{ "DBName", "\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u540d\u524d" },
|
||||
{ "DBUidPwd", "\u30e6\u30fc\u30b6 / \u30d1\u30b9\u30ef\u30fc\u30c9" },
|
||||
{ "ViaFirewall", "\u30d5\u30a1\u30a4\u30a2\u30a6\u30a9\u30fc\u30eb" },
|
||||
{ "FWHost", "\u30d5\u30a1\u30a4\u30a2\u30a6\u30a9\u30fc\u30eb\u30fb\u30b5\u30fc\u30d0" },
|
||||
{ "FWPort", "\u30d5\u30a1\u30a4\u30a2\u30a6\u30a9\u30fc\u30eb\u30fb\u30dd\u30fc\u30c8" },
|
||||
{ "TestConnection", "\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30fb\u30b5\u30fc\u30d0\u306e\u30c6\u30b9\u30c8" },
|
||||
{ "Type", "\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9" },
|
||||
{ "BequeathConnection", "\u53e4\u63a5\u7d9a" },
|
||||
{ "Overwrite", "\u30aa\u30fc\u30f4\u30a1\u30e9\u30a4\u30c8" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "\u63a5\u7d9a\u306e\u30a8\u30e9\u30fc" },
|
||||
{ "ServerNotActive", "\u30b5\u30fc\u30d0\u3092\u898b\u4ed8\u3051\u308c\u306a\u3044" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author .
|
||||
* @version $Id: DBRes_ml.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_ml extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Adempiere Connection" },
|
||||
{ "Name", "Name" },
|
||||
{ "AppsHost", "Application Host" },
|
||||
{ "AppsPort", "Application Port" },
|
||||
{ "TestApps", "Test Application" },
|
||||
{ "DBHost", "Database Host" },
|
||||
{ "DBPort", "Database Port" },
|
||||
{ "DBName", "Database Name" },
|
||||
{ "DBUidPwd", "User / Password" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Firewall Host" },
|
||||
{ "FWPort", "Firewall Port" },
|
||||
{ "TestConnection", "Test Database" },
|
||||
{ "Type", "Database Type" },
|
||||
{ "BequeathConnection", "Bequeath Connection" },
|
||||
{ "Overwrite", "Overwrite" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Connection Error" },
|
||||
{ "ServerNotActive", "Server Not Active" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Eldir Tomassen
|
||||
* @version $Id: DBRes_nl.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_nl extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Verbinding met Adempiere" },
|
||||
{ "Name", "Naam" },
|
||||
{ "AppsHost", "Applicatie Server" },
|
||||
{ "AppsPort", "Applicatie Poort" },
|
||||
{ "TestApps", "Test Applicatie" },
|
||||
{ "DBHost", "Database Server" },
|
||||
{ "DBPort", "Database Poort" },
|
||||
{ "DBName", "Database Naam" },
|
||||
{ "DBUidPwd", "Gebruikersnaam / Wachtwoord" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Firewall" },
|
||||
{ "FWPort", "Firewall Poort" },
|
||||
{ "TestConnection", "Test Database" },
|
||||
{ "Type", "Database Type" },
|
||||
{ "BequeathConnection", "Lokale Connectie" },
|
||||
{ "Overwrite", "Overschrijven" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Fout bij verbinden" },
|
||||
{ "ServerNotActive", "Server Niet Actief" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Norwegian Connection Resource Strings
|
||||
*
|
||||
* @author Olaf Slazak L<EFBFBD>ken
|
||||
* @version $Id: DBRes_no.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_no extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Adempiere Forbindelse" },
|
||||
{ "Name", "Navn" },
|
||||
{ "AppsHost", "Applikasjon Maskine" },
|
||||
{ "AppsPort", "Applikasjon Port" },
|
||||
{ "TestApps", "Test Applikasjon " },
|
||||
{ "DBHost", "Database Maskin" },
|
||||
{ "DBPort", "Database Port" },
|
||||
{ "DBName", "Database Navn" },
|
||||
{ "DBUidPwd", "Bruker /Passord" },
|
||||
{ "ViaFirewall", "Gjennom Brannmur" },
|
||||
{ "FWHost", "Brannmur Maskin" },
|
||||
{ "FWPort", "Brannmur Port" },
|
||||
{ "TestConnection", "Test Database" },
|
||||
{ "Type", "Database Type" },
|
||||
{ "BequeathConnection", "Bequeath Forbindelse" },
|
||||
{ "Overwrite", "Overskriv" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Feil ved Oppkobling" },
|
||||
{ "ServerNotActive", "Server Ikke Aktivert" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Adam Bodurka
|
||||
* @version $Id: DBRes_pl.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_pl extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Po\u0142\u0105czenie z Adempiere" },
|
||||
{ "Name", "Nazwa" },
|
||||
{ "AppsHost", "Host Aplikacji" },
|
||||
{ "AppsPort", "Port Aplikacji" },
|
||||
{ "TestApps", "Test Aplikacji" },
|
||||
{ "DBHost", "Host Bazy Danych" },
|
||||
{ "DBPort", "Port Bazy Danych" },
|
||||
{ "DBName", "Nazwa Bazy Danych" },
|
||||
{ "DBUidPwd", "U\u017cytkownik / Has\u0142o" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Host Firewall-a" },
|
||||
{ "FWPort", "Port Firewall-a" },
|
||||
{ "TestConnection", "Test Bazy Danych" },
|
||||
{ "Type", "Typ Bazy Danych" },
|
||||
{ "BequeathConnection", "Zapisuj Po\u0142\u0105czenie" },
|
||||
{ "Overwrite", "Nadpisuj" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "B\u0142\u0105d po\u0142\u0105czenia" },
|
||||
{ "ServerNotActive", "Serwer nie jest aktywny" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Jesse Jr
|
||||
* @version $Id: DBRes_pt.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_pt extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Adempiere Conex<65>o" },
|
||||
{ "Name", "Nome" },
|
||||
{ "AppsHost", "Servidor de Aplica<63><61>o" },
|
||||
{ "AppsPort", "Porta TCP da Aplica<63><61>o" },
|
||||
{ "TestApps", "Testar Aplica<63><61>o" },
|
||||
{ "DBHost", "Servidor do Banco de Dado" },
|
||||
{ "DBPort", "Porta TCP do Banco de Dados" },
|
||||
{ "DBName", "Nome do Banco de Dados" },
|
||||
{ "DBUidPwd", "Usu<EFBFBD>rio / Senha" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Servidor de Firewall" },
|
||||
{ "FWPort", "Porta TCP do Firewall" },
|
||||
{ "TestConnection", "Testar Banco de Dados" },
|
||||
{ "Type", "Tipo de Banco de Dados" },
|
||||
{ "BequeathConnection", "Conex<EFBFBD>o Bequeath" },
|
||||
{ "Overwrite", "Sobrescrever" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Erro de Conex<65>o" },
|
||||
{ "ServerNotActive", "Servidor n<>o Ativo" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,64 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DBRes_ro.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_ro extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Conexiune" },
|
||||
{ "Name", "Nume" },
|
||||
{ "AppsHost", "Server de aplica\u0163ie" },
|
||||
{ "AppsPort", "Port de aplica\u0163ie" },
|
||||
{ "TestApps", "Testare a serverului de aplica\u0163ie" },
|
||||
{ "DBHost", "Server de baz\u0103 de date" },
|
||||
{ "DBPort", "Port de baz\u0103 de date" },
|
||||
{ "DBName", "Numele bazei de date" },
|
||||
{ "DBUidPwd", "Utilizator / parol\u0103" },
|
||||
{ "ViaFirewall", "Prin firewall" },
|
||||
{ "FWHost", "Gazd\u0103 de firewall" },
|
||||
{ "FWPort", "Port de firewall" },
|
||||
{ "TestConnection", "Testare a bazei de date" },
|
||||
{ "Type", "Tip al bazei de date" },
|
||||
{ "BequeathConnection", "Cedare de conexiune" },
|
||||
{ "Overwrite", "Suprascriere" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Eroare de conexiune" },
|
||||
{ "ServerNotActive", "Serverul este inactiv" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contents
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Vyacheslav Pedak
|
||||
* @version $Id: DBRes_ru.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_ru extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 Adempiere" },
|
||||
{ "Name", "\u0418\u043c\u044f" },
|
||||
{ "AppsHost", "\u0421\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f" },
|
||||
{ "AppsPort", "\u041f\u043e\u0440\u0442" },
|
||||
{ "TestApps", "\u0422\u0435\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435" },
|
||||
{ "DBHost", "\u0421\u0435\u0440\u0432\u0435\u0440 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445" },
|
||||
{ "DBPort", "\u041f\u043e\u0440\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445" },
|
||||
{ "DBName", "\u0418\u043c\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445" },
|
||||
{ "DBUidPwd", "\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c / \u041f\u0430\u0440\u043e\u043b\u044c" },
|
||||
{ "ViaFirewall", "\u0447\u0435\u0440\u0435\u0437 Firewall" },
|
||||
{ "FWHost", "\u0421\u0435\u0440\u0432\u0435\u0440 Firewall" },
|
||||
{ "FWPort", "\u041f\u043e\u0440\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 Firewall" },
|
||||
{ "TestConnection", "\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445" },
|
||||
{ "Type", "\u0422\u0438\u043f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445" },
|
||||
{ "BequeathConnection", "Bequeath \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435" },
|
||||
{ "Overwrite", "\u041f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "\u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f" },
|
||||
{ "ServerNotActive", "\u0421\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u0430\u043a\u0442\u0438\u0432\u0435\u043d" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Matja\u017e Godec
|
||||
* @version $Id: DBRes_sl.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_sl extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Adempiere povezava" },
|
||||
{ "Name", "Ime" },
|
||||
{ "AppsHost", "Programski stre\u017enik" },
|
||||
{ "AppsPort", "Vrata programskega stre\u017enika" },
|
||||
{ "TestApps", "Test programskega stre\u017enika" },
|
||||
{ "DBHost", "Stre\u017enik baze podatkov" },
|
||||
{ "DBPort", "Vrata baze podatkov" },
|
||||
{ "DBName", "Ime baze podatkov" },
|
||||
{ "DBUidPwd", "Uporabnik / geslo" },
|
||||
{ "ViaFirewall", "Skozi po\u017earni zid" },
|
||||
{ "FWHost", "Po\u017earni zid" },
|
||||
{ "FWPort", "Vrata po\u017earnega zidu" },
|
||||
{ "TestConnection", "Testiranje baze podatkov" },
|
||||
{ "Type", "Tip baze podatkov" },
|
||||
{ "BequeathConnection", "Bequeath Connection" },
|
||||
{ "Overwrite", "Prepi\u0161i" },
|
||||
{ "ConnectionProfile", "Povezava" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Napaka na povezavi" },
|
||||
{ "ServerNotActive", "Stre\u017enik ni aktiven" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Swedish Connection Resource Strings
|
||||
*
|
||||
* @author Thomas Dilts
|
||||
* @version $Id: DBRes_sv.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_sv extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Adempiere anslutning" },
|
||||
{ "Name", "Namn" },
|
||||
{ "AppsHost", "Program v<>rddator" },
|
||||
{ "AppsPort", "Program port" },
|
||||
{ "TestApps", "Test program" },
|
||||
{ "DBHost", "Databas v<>rddator" },
|
||||
{ "DBPort", "Databas port" },
|
||||
{ "DBName", "Databas namn" },
|
||||
{ "DBUidPwd", "Anv<EFBFBD>ndarnamn / l<>senord" },
|
||||
{ "ViaFirewall", "via Firewall" },
|
||||
{ "FWHost", "Firewall v<>rddator" },
|
||||
{ "FWPort", "Firewall port" },
|
||||
{ "TestConnection", "Test databas" },
|
||||
{ "Type", "Databas typ" },
|
||||
{ "BequeathConnection", "Efterl<EFBFBD>mna anslutning" },
|
||||
{ "Overwrite", "Skriv <20>ver" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "Anslutningsfel" },
|
||||
{ "ServerNotActive", "Server ej activ" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,63 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings (Thai)
|
||||
*
|
||||
* @author Sureeraya Limpaibul
|
||||
* @version $Id: DBRes_th.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_th extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]{
|
||||
{ "CConnectionDialog", "Adempiere Connection" },
|
||||
{ "Name", "\u0e0a\u0e37\u0e48\u0e2d" },
|
||||
{ "AppsHost", "\u0e41\u0e2d\u0e47\u0e1e\u0e1e\u0e25\u0e34\u0e40\u0e04\u0e0a\u0e31\u0e48\u0e19 \u0e42\u0e2e\u0e2a" },
|
||||
{ "AppsPort", "\u0e41\u0e2d\u0e47\u0e1e\u0e1e\u0e25\u0e34\u0e40\u0e04\u0e0a\u0e31\u0e48\u0e19 \u0e1e\u0e2d\u0e23\u0e4c\u0e15" },
|
||||
{ "TestApps", "\u0e17\u0e14\u0e2a\u0e2d\u0e1a\u0e41\u0e2d\u0e47\u0e1e\u0e1e\u0e25\u0e34\u0e40\u0e04\u0e0a\u0e31\u0e48\u0e19" },
|
||||
{ "DBHost", "\u0e42\u0e2e\u0e2a\u0e02\u0e2d\u0e07\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25" },
|
||||
{ "DBPort", "\u0e1e\u0e2d\u0e23\u0e4c\u0e15\u0e02\u0e2d\u0e07\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25" },
|
||||
{ "DBName", "\u0e0a\u0e37\u0e48\u0e2d\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25" },
|
||||
{ "DBUidPwd", "\u0e0a\u0e37\u0e48\u0e2d\u0e1c\u0e39\u0e49\u0e43\u0e0a\u0e49 / \u0e23\u0e2b\u0e31\u0e2a\u0e1c\u0e48\u0e32\u0e19" },
|
||||
{ "ViaFirewall", "\u0e1c\u0e48\u0e32\u0e19\u0e44\u0e1f\u0e23\u0e27\u0e2d\u0e25" },
|
||||
{ "FWHost", "\u0e44\u0e1f\u0e23\u0e27\u0e2d\u0e25 \u0e42\u0e2e\u0e2a" },
|
||||
{ "FWPort", "\u0e1e\u0e2d\u0e23\u0e4c\u0e15\u0e44\u0e1f\u0e23\u0e27\u0e2d\u0e25" },
|
||||
{ "TestConnection", "\u0e17\u0e14\u0e2a\u0e2d\u0e1a\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25" },
|
||||
{ "Type", "\u0e1b\u0e23\u0e30\u0e40\u0e20\u0e17\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25" },
|
||||
{ "BequeathConnection", "Bequeath Connection" },
|
||||
{ "Overwrite", "\u0e1a\u0e31\u0e19\u0e17\u0e36\u0e01\u0e17\u0e31\u0e1a" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "\u0e01\u0e32\u0e23\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e15\u0e48\u0e2d\u0e1c\u0e34\u0e14\u0e1e\u0e25\u0e32\u0e14" },
|
||||
{ "ServerNotActive", "\u0e40\u0e0a\u0e34\u0e23\u0e4c\u0e1f\u0e40\u0e27\u0e2d\u0e23\u0e4c\u0e44\u0e21\u0e48\u0e41\u0e2d\u0e47\u0e04\u0e17\u0e35\u0e1f" }};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
}
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author Bui Chi Trung
|
||||
* @version $Id: DBRes_vi.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_vi extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "K\u1EBFt n\u1ED1i" },
|
||||
{ "Name", "T<EFBFBD>n" },
|
||||
{ "AppsHost", "M<EFBFBD>y ch\u1EE7 \u1EE9ng d\u1EE5ng" },
|
||||
{ "AppsPort", "C\u1ED5ng \u1EE9ng d\u1EE5ng" },
|
||||
{ "TestApps", "Th\u1EED nghi\u1EC7m \u1EE9ng d\u1EE5ng" },
|
||||
{ "DBHost", "M<EFBFBD>y ch\u1EE7 CSDL" },
|
||||
{ "DBPort", "C\u1ED5ng CSDL" },
|
||||
{ "DBName", "T<EFBFBD>n CSDL" },
|
||||
{ "DBUidPwd", "Ng\u01B0\u1EDDi d<>ng / M\u1EADt kh\u1EA9u" },
|
||||
{ "ViaFirewall", "Qua b\u1EE9c t\u01B0\u1EDDng l\u1EEDa" },
|
||||
{ "FWHost", "M<EFBFBD>y ch\u1EE7 b\u1EE9c t\u01B0\u1EDDng l\u1EEDa" },
|
||||
{ "FWPort", "C\u1ED5ng v<>o b\u1EE9c t\u01B0\u1EDDng l\u1EEDa" },
|
||||
{ "TestConnection", "Ki\u1EC3m tra CSDL" },
|
||||
{ "Type", "Lo\u1EA1i CSDL" },
|
||||
{ "BequeathConnection", "Truy\u1EC1n l\u1EA1i k\u1EBFt n\u1ED1i" },
|
||||
{ "Overwrite", "Ghi \u0111<EFBFBD>" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "L\u1ED7i k\u1EBFt n\u1ED1i" },
|
||||
{ "ServerNotActive", "M<EFBFBD>y ch\u1EE7 hi\u1EC7n kh<6B>ng ho\u1EA1t \u0111\u1ED9ng" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author kirinlin
|
||||
* @version $Id: DBRes_zh.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_zh extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Adempiere \u9023\u7dda" },
|
||||
{ "Name", "\u540d\u7a31" },
|
||||
{ "AppsHost", "\u61c9\u7528\u7a0b\u5f0f\u4e3b\u6a5f" },
|
||||
{ "AppsPort", "\u61c9\u7528\u7a0b\u5f0f\u57e0" },
|
||||
{ "TestApps", "\u6e2c\u8a66" },
|
||||
{ "DBHost", "\u8cc7\u6599\u5eab\u4e3b\u6a5f" },
|
||||
{ "DBPort", "\u8cc7\u6599\u5eab\u9023\u63a5\u57e0" },
|
||||
{ "DBName", "\u8cc7\u6599\u5eab\u540d\u7a31" },
|
||||
{ "DBUidPwd", "\u5e33\u865f / \u5bc6\u78bc" },
|
||||
{ "ViaFirewall", "\u7d93\u904e\u9632\u706b\u7246" },
|
||||
{ "FWHost", "\u9632\u706b\u7246\u4e3b\u6a5f" },
|
||||
{ "FWPort", "\u9632\u706b\u7246\u57e0" },
|
||||
{ "TestConnection", "\u6e2c\u8a66\u8cc7\u6599\u5eab" },
|
||||
{ "Type", "\u8cc7\u6599\u5eab\u7a2e\u985e" },
|
||||
{ "BequeathConnection", "\u907a\u7559\u9023\u7dda" },
|
||||
{ "Overwrite", "\u8986\u5beb" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "\u9023\u7dda\u932f\u8aa4" },
|
||||
{ "ServerNotActive", "\u4f3a\u670d\u5668\u672a\u52d5\u4f5c" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Connection Resource Strings
|
||||
*
|
||||
* @author ZhaoXing Meng
|
||||
* @version $Id: DBRes_zh_CN.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class DBRes_zh_CN extends ListResourceBundle
|
||||
{
|
||||
/** Data */
|
||||
static final Object[][] contents = new String[][]
|
||||
{
|
||||
{ "CConnectionDialog", "Adempiere \u8fde\u673a" },
|
||||
{ "Name", "\u540d\u79f0" },
|
||||
{ "AppsHost", "\u5e94\u7528\u670d\u52a1\u5668\u4e3b\u673a" },
|
||||
{ "AppsPort", "\u5e94\u7528\u670d\u52a1\u5668\u7aef\u53e3" },
|
||||
{ "TestApps", "\u6d4b\u8bd5\u5e94\u7528\u670d\u52a1\u5668" },
|
||||
{ "DBHost", "\u6570\u636e\u5e93\u4e3b\u673a" },
|
||||
{ "DBPort", "\u6570\u636e\u5e93\u7aef\u53e3" },
|
||||
{ "DBName", "\u6570\u636e\u5e93\u540d" },
|
||||
{ "DBUidPwd", "\u7528\u6237\u53f7 / \u53e3\u4ee4" },
|
||||
{ "ViaFirewall", "\u901a\u8fc7\u9632\u706b\u5899" },
|
||||
{ "FWHost", "\u9632\u706b\u5899\u4e3b\u673a" },
|
||||
{ "FWPort", "\u9632\u706b\u5899\u7aef\u53e3" },
|
||||
{ "TestConnection", "\u6d4b\u8bd5\u6570\u636e\u5e93" },
|
||||
{ "Type", "\u6570\u636e\u5e93\u7c7b\u578b" },
|
||||
{ "BequeathConnection", "\u9057\u7559\u8fde\u7ebf" },
|
||||
{ "Overwrite", "\u8986\u5199" },
|
||||
{ "ConnectionProfile", "Connection" },
|
||||
{ "LAN", "LAN" },
|
||||
{ "TerminalServer", "Terminal Server" },
|
||||
{ "VPN", "VPN" },
|
||||
{ "WAN", "WAN" },
|
||||
{ "ConnectionError", "\u8fde\u673a\u9519\u8bef" },
|
||||
{ "ServerNotActive", "\u670d\u52a1\u5668\u6ca1\u53cd\u5e94" }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Contsnts
|
||||
* @return contents
|
||||
*/
|
||||
public Object[][] getContents()
|
||||
{
|
||||
return contents;
|
||||
} // getContent
|
||||
} // Res
|
|
@ -0,0 +1,836 @@
|
|||
/******************************************************************************
|
||||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
import javax.sql.*;
|
||||
|
||||
import org.compiere.util.*;
|
||||
|
||||
import com.ibm.db2.jcc.*;
|
||||
|
||||
/**
|
||||
* DB2 Database Driver
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DB_DB2.java,v 1.5 2006/09/22 23:35:19 jjanke Exp $
|
||||
*/
|
||||
public class DB_DB2
|
||||
implements AdempiereDatabase
|
||||
{
|
||||
/**
|
||||
* Database DB2
|
||||
*/
|
||||
public DB_DB2()
|
||||
{
|
||||
|
||||
} // DB_DB2
|
||||
|
||||
/** Static Driver */
|
||||
private static DB2Driver s_driver = null;
|
||||
/** Driver Class Name */
|
||||
public static final String DRIVER = "com.ibm.db2.jcc.DB2Driver";
|
||||
/** Type 2 Driver */
|
||||
public static final String DRIVER2 = "COM.ibm.db2.jdbc.app.DB2Driver";
|
||||
|
||||
/** Default Port 446 */
|
||||
public static final int DEFAULT_PORT = 446;
|
||||
/** Default Port 50000 */
|
||||
public static final int DEFAULT_PORT_0 = 50000;
|
||||
|
||||
/** Cached User Name */
|
||||
private String m_userName = null;
|
||||
|
||||
/** Connection String */
|
||||
private String m_connectionURL;
|
||||
private DB2SimpleDataSource m_ds = null;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger (DB_DB2.class);
|
||||
|
||||
/**
|
||||
* Get Database Name
|
||||
* @return database short name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return Database.DB_DB2;
|
||||
} // getName
|
||||
|
||||
/**
|
||||
* Get Database Description
|
||||
* @return database long name and version
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (s_driver == null)
|
||||
getDriver();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
if (s_driver != null)
|
||||
return s_driver.toString();
|
||||
return "No Driver";
|
||||
} // getDescription
|
||||
|
||||
/**
|
||||
* Get Standard JDBC Port
|
||||
* @return standard port
|
||||
*/
|
||||
public int getStandardPort()
|
||||
{
|
||||
return DEFAULT_PORT_0;
|
||||
} // getStandardPort
|
||||
|
||||
/**
|
||||
* Get and register Database Driver
|
||||
* @return Driver
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Driver getDriver() throws SQLException
|
||||
{
|
||||
if (s_driver == null)
|
||||
{
|
||||
s_driver = new DB2Driver();
|
||||
DriverManager.registerDriver (s_driver);
|
||||
DriverManager.setLoginTimeout (Database.CONNECTION_TIMEOUT);
|
||||
}
|
||||
return s_driver;
|
||||
} // getDriver
|
||||
|
||||
/**
|
||||
* Get Database Connection String.
|
||||
* <pre>
|
||||
* Timing:
|
||||
* </pre>
|
||||
* @param connection Connection Descriptor
|
||||
* @return connection String
|
||||
*/
|
||||
public String getConnectionURL (CConnection connection)
|
||||
{
|
||||
StringBuffer sb = null;
|
||||
// connection//server:port/database
|
||||
sb = new StringBuffer ("jdbc:db2:");
|
||||
// Cloudscape = jdbc:db2j:net:
|
||||
sb.append("//")
|
||||
.append(connection.getDbHost())
|
||||
.append(":").append(connection.getDbPort())
|
||||
.append("/").append(connection.getDbName());
|
||||
m_connectionURL = sb.toString();
|
||||
// log.config(m_connectionURL);
|
||||
//
|
||||
m_userName = connection.getDbUid();
|
||||
return m_connectionURL;
|
||||
} // getConnectionURL
|
||||
|
||||
/**
|
||||
* Get Connection URL.
|
||||
* @param dbHost db Host
|
||||
* @param dbPort db Port
|
||||
* @param dbName db Name
|
||||
* @param userName user name
|
||||
* @return connection
|
||||
*/
|
||||
public String getConnectionURL (String dbHost, int dbPort, String dbName,
|
||||
String userName)
|
||||
{
|
||||
m_userName = userName;
|
||||
m_connectionURL = "jdbc:db2://"
|
||||
+ dbHost + ":" + dbPort + "/" + dbName;
|
||||
return m_connectionURL;
|
||||
} // getConnectionURL
|
||||
|
||||
/**
|
||||
* Get Database Connection String
|
||||
* @param connectionURL Connection URL
|
||||
* @param userName user name
|
||||
* @return connection String
|
||||
*/
|
||||
public String getConnectionURL (String connectionURL, String userName)
|
||||
{
|
||||
m_userName = userName;
|
||||
m_connectionURL = connectionURL;
|
||||
return m_connectionURL;
|
||||
} // getConnectionURL
|
||||
|
||||
/**
|
||||
* Get JDBC Catalog
|
||||
* @return null - not used
|
||||
*/
|
||||
public String getCatalog()
|
||||
{
|
||||
return null;
|
||||
} // getCatalog
|
||||
|
||||
/**
|
||||
* Get JDBC Schema
|
||||
* @return user name
|
||||
*/
|
||||
public String getSchema()
|
||||
{
|
||||
if (m_userName != null)
|
||||
return m_userName.toUpperCase();
|
||||
log.severe("User Name not set (yet) - call getConnectionURL first");
|
||||
return null;
|
||||
} // getSchema
|
||||
|
||||
/**
|
||||
* Supports BLOB
|
||||
* @return true if BLOB is supported
|
||||
*/
|
||||
public boolean supportsBLOB()
|
||||
{
|
||||
return true;
|
||||
} // supportsBLOB
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("DB_DB2[");
|
||||
sb.append(m_connectionURL);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Get Status
|
||||
* @return status info
|
||||
*/
|
||||
public String getStatus()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
return sb.toString();
|
||||
} // getStatus
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Convert an individual Oracle Style statements to target database statement syntax.
|
||||
* @param oraStatement oracle statement
|
||||
* @return converted Statement oracle statement
|
||||
*/
|
||||
public String convertStatement (String oraStatement)
|
||||
{
|
||||
return oraStatement;
|
||||
} // convertStatement
|
||||
|
||||
|
||||
/**
|
||||
* Check if DBMS support the sql statement
|
||||
* @sql SQL statement
|
||||
* @return true: yes
|
||||
*/
|
||||
public boolean isSupported(String sql)
|
||||
{
|
||||
return true;
|
||||
//jz temp, modify later
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get constraint type associated with the index
|
||||
* @tableName table name
|
||||
* @IXName Index name
|
||||
* @return String[0] = 0: do not know, 1: Primary Key 2: Foreign Key
|
||||
* String[1] - String[n] = Constraint Name
|
||||
*/
|
||||
public String getConstraintType(Connection conn, String tableName, String IXName)
|
||||
{
|
||||
if (IXName == null || IXName.length()==0)
|
||||
return "0";
|
||||
|
||||
return "0";
|
||||
//jz temp, modify later
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name of System User
|
||||
* @return system
|
||||
*/
|
||||
public String getSystemUser()
|
||||
{
|
||||
return "db2adm";
|
||||
} // getSystemUser
|
||||
|
||||
/**
|
||||
* Get Name of System Database
|
||||
* @param databaseName database Name
|
||||
* @return e.g. master or database Name
|
||||
*/
|
||||
public String getSystemDatabase(String databaseName)
|
||||
{
|
||||
return databaseName;
|
||||
} // getSystemDatabase
|
||||
|
||||
|
||||
/**
|
||||
* Create SQL TO Date String from Timestamp
|
||||
*
|
||||
* @param time Date to be converted
|
||||
* @param dayOnly true if time set to 00:00:00
|
||||
*
|
||||
* @return TO_DATE('1999-12-31 23:59:59', 'YYYY-MM-DD HH24:MI:SS')
|
||||
* or TIMESTAMP('2000-01-10-00.00.00.000000')
|
||||
*/
|
||||
public String TO_DATE (Timestamp time, boolean dayOnly)
|
||||
{
|
||||
|
||||
if (time == null)
|
||||
{
|
||||
if (dayOnly)
|
||||
return "trunc(CURRENT TIMESTAMP)";
|
||||
return "CURRENT TIMESTAMP";
|
||||
}
|
||||
|
||||
// TIMESTAMP('2000-01-10-00.00.00.000000')
|
||||
StringBuffer dateString = new StringBuffer("TIMESTAMP('");
|
||||
// YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format
|
||||
String myDate = time.toString();
|
||||
if (dayOnly)
|
||||
{
|
||||
dateString.append(myDate.substring(0,10));
|
||||
dateString.append("-00.00.00.000000')");
|
||||
}
|
||||
else
|
||||
{
|
||||
myDate = myDate.replace('-', ' ');
|
||||
myDate = myDate.replace(':', '.');
|
||||
dateString.append(myDate);
|
||||
dateString.append("00')");
|
||||
}
|
||||
return dateString.toString();
|
||||
} // TO_DATE
|
||||
|
||||
/**
|
||||
* Create SQL for formatted Date, Number
|
||||
*
|
||||
* @param columnName the column name in the SQL
|
||||
* @param displayType Display Type
|
||||
* @param AD_Language 6 character language setting (from Env.LANG_*)
|
||||
*
|
||||
* @return TRIM(TO_CHAR(columnName,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.'''))
|
||||
* or TRIM(TO_CHAR(columnName,'TM9')) depending on DisplayType and Language
|
||||
* @see org.compiere.util.DisplayType
|
||||
* @see org.compiere.util.Env
|
||||
*
|
||||
* */
|
||||
public String TO_CHAR (String columnName, int displayType, String AD_Language)
|
||||
{
|
||||
return columnName;
|
||||
/**
|
||||
StringBuffer retValue = new StringBuffer("TRIM(TO_CHAR(");
|
||||
retValue.append(columnName);
|
||||
|
||||
// Numbers
|
||||
if (DisplayType.isNumeric(displayType))
|
||||
{
|
||||
if (displayType == DisplayType.Amount)
|
||||
retValue.append(",'9G999G990D00'");
|
||||
else
|
||||
retValue.append(",'TM9'");
|
||||
// TO_CHAR(GrandTotal,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.''')
|
||||
if (!Language.isDecimalPoint(AD_Language)) // reversed
|
||||
retValue.append(",'NLS_NUMERIC_CHARACTERS='',.'''");
|
||||
}
|
||||
else if (DisplayType.isDate(displayType))
|
||||
{
|
||||
retValue.append(",'")
|
||||
.append(Language.getLanguage(AD_Language).getDBdatePattern())
|
||||
.append("'");
|
||||
}
|
||||
retValue.append("))");
|
||||
//
|
||||
return retValue.toString();
|
||||
**/
|
||||
} // TO_CHAR
|
||||
|
||||
/**
|
||||
* Return number as string for INSERT statements with correct precision
|
||||
* @param number number
|
||||
* @param displayType display Type
|
||||
* @return number as string
|
||||
*/
|
||||
public String TO_NUMBER (BigDecimal number, int displayType)
|
||||
{
|
||||
if (number == null)
|
||||
return "NULL";
|
||||
return number.toString();
|
||||
} // TO_NUMBER
|
||||
|
||||
|
||||
/**
|
||||
* Get SQL Commands.
|
||||
* The following variables are resolved:
|
||||
* @SystemPassword@, @AdempiereUser@, @AdempierePassword@
|
||||
* @SystemPassword@, @DatabaseName@, @DatabaseDevice@
|
||||
* @param cmdType CMD_*
|
||||
* @return array of commands to be executed
|
||||
*/
|
||||
public String[] getCommands (int cmdType)
|
||||
{
|
||||
if (CMD_CREATE_USER == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
|
||||
};
|
||||
//
|
||||
if (CMD_CREATE_DATABASE == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
|
||||
};
|
||||
//
|
||||
if (CMD_DROP_DATABASE == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
|
||||
};
|
||||
//
|
||||
return null;
|
||||
} // getCommands
|
||||
|
||||
/**
|
||||
* Create DataSource
|
||||
* @param connection connection
|
||||
* @return data dource
|
||||
*/
|
||||
public DataSource getDataSource(CConnection connection)
|
||||
{
|
||||
if (m_ds == null)
|
||||
{
|
||||
m_ds = new DB2SimpleDataSource();
|
||||
m_ds.setServerName(connection.getDbHost());
|
||||
m_ds.setPortNumber(connection.getDbPort());
|
||||
m_ds.setDatabaseName(connection.getDbName());
|
||||
m_ds.setDescription("Adempiere DataSource");
|
||||
m_ds.setUser(connection.getDbUid());
|
||||
m_ds.setPassword(connection.getDbPwd());
|
||||
m_ds.setLoginTimeout(5); // seconds
|
||||
// m_ds.setUseCachedCursor(true);
|
||||
}
|
||||
return m_ds;
|
||||
} // getDataSource
|
||||
|
||||
|
||||
/**
|
||||
* Get Cached Connection
|
||||
* @param connection info
|
||||
* @param autoCommit true if autocommit connection
|
||||
* @param transactionIsolation Connection transaction level
|
||||
* @return connection or null
|
||||
* @throws Exception
|
||||
*/
|
||||
public Connection getCachedConnection (CConnection connection,
|
||||
boolean autoCommit, int transactionIsolation)
|
||||
throws Exception
|
||||
{
|
||||
Connection conn = getDataSource(connection).getConnection();
|
||||
conn.setAutoCommit(autoCommit);
|
||||
conn.setTransactionIsolation(transactionIsolation);
|
||||
return conn;
|
||||
} // getCachedConnection
|
||||
|
||||
/**
|
||||
* Get Connection from Driver
|
||||
* @param connection info
|
||||
* @return connection or null
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Connection getDriverConnection (CConnection connection) throws SQLException
|
||||
{
|
||||
getDriver();
|
||||
return DriverManager.getConnection (getConnectionURL (connection),
|
||||
connection.getDbUid(), connection.getDbPwd());
|
||||
} // getDriverConnection
|
||||
|
||||
/**
|
||||
* Get Driver Connection
|
||||
* @param dbUrl URL
|
||||
* @param dbUid user
|
||||
* @param dbPwd password
|
||||
* @return connection
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Connection getDriverConnection (String dbUrl, String dbUid, String dbPwd)
|
||||
throws SQLException
|
||||
{
|
||||
getDriver();
|
||||
return DriverManager.getConnection (dbUrl, dbUid, dbPwd);
|
||||
} // getDriverConnection
|
||||
|
||||
/**
|
||||
* Close
|
||||
*/
|
||||
public void close()
|
||||
{
|
||||
log.config(toString());
|
||||
m_ds = null;
|
||||
} // close
|
||||
|
||||
/**
|
||||
* Clean up
|
||||
*/
|
||||
public void cleanup()
|
||||
{
|
||||
log.config("");
|
||||
} // cleanup
|
||||
|
||||
|
||||
/**
|
||||
* Get Data Type
|
||||
* @param displayType display type
|
||||
* @param precision precision
|
||||
* @param defaultValue if true adds default value
|
||||
* @return data type
|
||||
*/
|
||||
public String getDataType (int displayType, int precision,
|
||||
boolean defaultValue)
|
||||
{
|
||||
String retValue = null;
|
||||
switch (displayType)
|
||||
{
|
||||
// IDs
|
||||
case DisplayType.Account:
|
||||
case DisplayType.Assignment:
|
||||
case DisplayType.Color:
|
||||
case DisplayType.ID:
|
||||
case DisplayType.Location:
|
||||
case DisplayType.Locator:
|
||||
case DisplayType.PAttribute:
|
||||
case DisplayType.Search:
|
||||
case DisplayType.Table:
|
||||
case DisplayType.TableDir:
|
||||
case DisplayType.Image:
|
||||
retValue = "INTEGER";
|
||||
break;
|
||||
|
||||
// Dynamic Precision
|
||||
case DisplayType.Amount:
|
||||
retValue = "DECIMAL(18,2)";
|
||||
if (defaultValue)
|
||||
retValue += " DEFAULT 0";
|
||||
break;
|
||||
|
||||
case DisplayType.Binary:
|
||||
retValue = "BLOB";
|
||||
break;
|
||||
|
||||
case DisplayType.Button:
|
||||
retValue = "CHAR(1)";
|
||||
break;
|
||||
|
||||
// Number Dynamic Precision
|
||||
case DisplayType.CostPrice:
|
||||
retValue = "DECIMAL(22,6)";
|
||||
if (defaultValue)
|
||||
retValue += " DEFAULT 0";
|
||||
break;
|
||||
|
||||
// Date
|
||||
case DisplayType.Date:
|
||||
case DisplayType.DateTime:
|
||||
case DisplayType.Time:
|
||||
retValue = "Timestamp";
|
||||
if (defaultValue)
|
||||
retValue += " DEFAULT 0";
|
||||
break;
|
||||
|
||||
// Number(10)
|
||||
case DisplayType.Integer:
|
||||
retValue = "NUMBER(10)";
|
||||
break;
|
||||
|
||||
case DisplayType.List:
|
||||
retValue = "CHAR(" + precision + ")";
|
||||
break;
|
||||
|
||||
// NVARCHAR
|
||||
case DisplayType.Memo:
|
||||
case DisplayType.String:
|
||||
case DisplayType.Text:
|
||||
retValue = "NVARCHAR(" + precision + ")";
|
||||
break;
|
||||
|
||||
case DisplayType.TextLong:
|
||||
retValue = "CLOB";
|
||||
break;
|
||||
|
||||
// Dyn Prec
|
||||
case DisplayType.Quantity:
|
||||
retValue = "NUMBER";
|
||||
break;
|
||||
|
||||
case DisplayType.YesNo:
|
||||
retValue = "CHAR(1)";
|
||||
break;
|
||||
|
||||
default:
|
||||
log.severe("Unknown: " + displayType);
|
||||
break;
|
||||
}
|
||||
return retValue;
|
||||
} // getDataType
|
||||
|
||||
|
||||
/**
|
||||
* Check and generate an alternative SQL
|
||||
* @reExNo number of re-execution
|
||||
* @msg previous execution error message
|
||||
* @sql previous executed SQL
|
||||
* @return String, the alternative SQL, null if no alternative
|
||||
*/
|
||||
public String getAlternativeSQL(int reExNo, String msg, String sql)
|
||||
{
|
||||
return null; //do not do re-execution of alternative SQL
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Testing
|
||||
* @param args ignored
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
/**
|
||||
Adempiere.startupEnvironment(true);
|
||||
CConnection cc = CConnection.get();
|
||||
DB_Oracle db = (DB_Oracle)cc.getDatabase();
|
||||
db.cleanup();
|
||||
|
||||
try
|
||||
{
|
||||
Connection conn = ;
|
||||
// System.out.println("Driver=" + db.getDriverConnection(cc));
|
||||
DataSource ds = db.getDataSource(cc);
|
||||
System.out.println("DS=" + ds.getConnection());
|
||||
conn = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED);
|
||||
System.out.println("Cached=" + conn);
|
||||
System.out.println(db);
|
||||
//////////////////////////
|
||||
System.out.println("JAVA classpath: [\n" +
|
||||
System.getProperty("java.class.path") + "\n]");
|
||||
DatabaseMetaData dmd = conn.getMetaData();
|
||||
System.out.println("DriverVersion: ["+
|
||||
dmd.getDriverVersion()+"]");
|
||||
System.out.println("DriverMajorVersion: ["+
|
||||
dmd.getDriverMajorVersion()+"]");
|
||||
System.out.println("DriverMinorVersion: ["+
|
||||
dmd.getDriverMinorVersion()+"]");
|
||||
System.out.println("DriverName: ["+
|
||||
dmd.getDriverName()+"]");
|
||||
System.out.println("ProductName: ["+
|
||||
dmd.getDatabaseProductName() +"]");
|
||||
System.out.println("ProductVersion: [\n"+
|
||||
dmd.getDatabaseProductVersion()+"\n]");
|
||||
//////////////////////////
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
db.cleanup();
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
try
|
||||
{
|
||||
Connection conn1 = db.getCachedConnection(cc, false, Connection.TRANSACTION_READ_COMMITTED);
|
||||
Connection conn2 = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED);
|
||||
Connection conn3 = db.getCachedConnection(cc, false, Connection.TRANSACTION_READ_COMMITTED);
|
||||
System.out.println("3 -> " + db);
|
||||
conn1.close();
|
||||
conn2.close();
|
||||
conn1 = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED);
|
||||
conn2 = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED);
|
||||
System.out.println("3 -> " + db);
|
||||
conn1.close();
|
||||
conn2.close();
|
||||
conn3.close();
|
||||
System.out.println("0 -> " + db);
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
db.cleanup();
|
||||
|
||||
// System.exit(0);
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
System.out.println(DB.getConnectionRO());
|
||||
System.out.println(DB.getConnectionRW());
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(DB.getConnectionRO());
|
||||
System.out.println(DB.getConnectionRW());
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(DB.getConnectionRO());
|
||||
System.out.println(DB.getConnectionRW());
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(DB.getConnectionRO());
|
||||
System.out.println(DB.getConnectionRW());
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(DB.getConnectionRO());
|
||||
System.out.println(DB.getConnectionRW());
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(DB.getConnectionRO());
|
||||
System.out.println(DB.getConnectionRW());
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(DB.getConnectionRO());
|
||||
System.out.println(DB.getConnectionRW());
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(DB.getConnectionRO());
|
||||
System.out.println(DB.getConnectionRW());
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
|
||||
|
||||
System.out.println(db);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
System.out.println("-- Sleeping --");
|
||||
Thread.sleep(60000);
|
||||
System.out.println(db);
|
||||
db.close();
|
||||
db.cleanup();
|
||||
System.out.println(db);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
/** **/
|
||||
|
||||
|
||||
/** **/
|
||||
// Connection option 1
|
||||
try
|
||||
{
|
||||
DB2Driver driver = new DB2Driver();
|
||||
DriverManager.registerDriver(driver);
|
||||
|
||||
Connection con = DriverManager.getConnection("jdbc:db2://dev1:50000/sample",
|
||||
"db2admin", "db2admin");
|
||||
// "adempiere", "adempiere");
|
||||
// "db2inst1", "daDm7rfr");
|
||||
System.out.println("Connection Catalog = " + con.getCatalog());
|
||||
//
|
||||
DatabaseMetaData md = con.getMetaData();
|
||||
System.out.println(md.getDatabaseProductName() + " - " + md.getDatabaseProductVersion());
|
||||
// System.out.println(md.getDatabaseMajorVersion() + " - " + md.getDatabaseMinorVersion());
|
||||
System.out.println(md.getDriverName() + " - " + md.getDriverVersion());
|
||||
// System.out.println(md.getDriverMajorVersion() + " - " + md.getDriverMinorVersion());
|
||||
System.out.println("URL=" + md.getURL());
|
||||
System.out.println("User=" + md.getUserName());
|
||||
//
|
||||
System.out.println(md.getNumericFunctions());
|
||||
System.out.println(md.getStringFunctions());
|
||||
System.out.println(md.getTimeDateFunctions());
|
||||
System.out.println(md.getSystemFunctions());
|
||||
//
|
||||
System.out.println("Catalogs - " + md.getCatalogTerm());
|
||||
ResultSet rs = md.getCatalogs();
|
||||
while (rs.next())
|
||||
System.out.println("- " + rs.getString(1));
|
||||
//
|
||||
System.out.println("Schemas - " + md.getSchemaTerm());
|
||||
rs = md.getSchemas();
|
||||
while (rs.next())
|
||||
System.out.println("- " + rs.getString(1));
|
||||
|
||||
|
||||
String sql = "SELECT GRANTOR,GRANTEE,DBADMAUTH FROM SYSCAT.DBAUTH";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = con.prepareStatement (sql);
|
||||
rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
String GRANTOR = rs.getString(1);
|
||||
String GRANTEE = rs.getString(2);
|
||||
String DBADMAUTH = rs.getString(3);
|
||||
System.out.println(GRANTOR + " -> " + GRANTEE + " = " + DBADMAUTH);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("SysCat Table");
|
||||
rs = md.getTables(null, "SYSCAT", null, new String[] {"TABLE", "VIEW"});
|
||||
while (rs.next())
|
||||
System.out.println("- User=" + rs.getString(2) + " | Table=" + rs.getString(3)
|
||||
+ " | Type=" + rs.getString(4) + " | " + rs.getString(5));
|
||||
//
|
||||
System.out.println("Column");
|
||||
rs = md.getColumns(null, "SYSCAT", "DBAUTH", null);
|
||||
while (rs.next())
|
||||
System.out.println("- Tab=" + rs.getString(3) + " | Col=" + rs.getString(4)
|
||||
+ " | Type=" + rs.getString(5) + ", " + rs.getString(6)
|
||||
+ " | Size=" + rs.getString(7) + " | " + rs.getString(8)
|
||||
+ " | Digits=" + rs.getString(9) + " | Radix=" + rs.getString(10)
|
||||
+ " | Null=" + rs.getString(11) + " | Rem=" + rs.getString(12)
|
||||
+ " | Def=" + rs.getString(13) + " | " + rs.getString(14)
|
||||
+ " | " + rs.getString(15) + " | " + rs.getString(16)
|
||||
+ " | Ord=" + rs.getString(17) + " | Null=" + rs.getString(18)
|
||||
);
|
||||
|
||||
con.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
/** **/
|
||||
} // main
|
||||
|
||||
} // DB_DB2
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,621 @@
|
|||
/******************************************************************************
|
||||
* 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
|
||||
*****************************************************************************/
|
||||
package org.compiere.db;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.sql.*;
|
||||
import org.compiere.dbPort.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* PostgreSQL Database Port
|
||||
*
|
||||
* @author @author Jorg Janke, Victor P<EFBFBD>rez
|
||||
* @version $Id: DB_PostgreSQL.java,v 1.23 2005/03/11 20:29:01 jjanke Exp $
|
||||
*/
|
||||
public class DB_PostgreSQL implements AdempiereDatabase
|
||||
{
|
||||
/**
|
||||
* PostgreSQL Database
|
||||
*/
|
||||
public DB_PostgreSQL()
|
||||
{
|
||||
} // DB_PostgreSQL
|
||||
|
||||
/** Driver */
|
||||
private org.postgresql.Driver s_driver = null;
|
||||
|
||||
/** Default Port */
|
||||
public static final int DEFAULT_PORT = 5432;
|
||||
|
||||
/** Data Source */
|
||||
private org.postgresql.ds.PGPoolingDataSource m_ds = null;
|
||||
|
||||
/** Statement Converter */
|
||||
private Convert m_convert = new Convert(Database.DB_POSTGRESQL);
|
||||
/** Connection String */
|
||||
private String m_connection;
|
||||
/** Cached Database Name */
|
||||
private String m_dbName = null;
|
||||
|
||||
private String m_userName = null;
|
||||
/** Connection String */
|
||||
private String m_connectionURL;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger (DB_PostgreSQL.class);
|
||||
|
||||
/**
|
||||
* Get Database Name
|
||||
* @return database short name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return Database.DB_POSTGRESQL;
|
||||
} // getName
|
||||
|
||||
/**
|
||||
* Get Database Description
|
||||
* @return database long name and version
|
||||
*/
|
||||
public String getDescription()
|
||||
{ //begin vpj-cd e-evolution 30.09.2005
|
||||
//return s_driver.toString();
|
||||
try
|
||||
{
|
||||
if (s_driver == null)
|
||||
getDriver();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
if (s_driver != null)
|
||||
return s_driver.toString();
|
||||
return "No Driver";
|
||||
//end vpj-cd e-evolution 30.09.2005
|
||||
} // getDescription
|
||||
|
||||
/**
|
||||
* Get Standard JDBC Port
|
||||
* @return standard port
|
||||
*/
|
||||
public int getStandardPort()
|
||||
{
|
||||
return DEFAULT_PORT;
|
||||
} // getStandardPort
|
||||
|
||||
/**
|
||||
* Get and register Database Driver
|
||||
* @return Driver
|
||||
*/
|
||||
public java.sql.Driver getDriver() throws SQLException
|
||||
{
|
||||
if (s_driver == null)
|
||||
{
|
||||
s_driver = new org.postgresql.Driver();
|
||||
DriverManager.registerDriver (s_driver);
|
||||
DriverManager.setLoginTimeout (Database.CONNECTION_TIMEOUT);
|
||||
}
|
||||
return s_driver;
|
||||
} // getDriver
|
||||
|
||||
/**
|
||||
* Get Database Connection String.
|
||||
* Requirements:
|
||||
* - createdb -E UNICODE compiere
|
||||
* @param connection Connection Descriptor
|
||||
* @return connection String
|
||||
*/
|
||||
public String getConnectionURL (CConnection connection)
|
||||
{
|
||||
// jdbc:postgresql://hostname:portnumber/databasename?encoding=UNICODE
|
||||
StringBuffer sb = new StringBuffer("jdbc:postgresql:");
|
||||
sb.append("//").append(connection.getDbHost())
|
||||
.append(":").append(connection.getDbPort())
|
||||
.append("/").append(connection.getDbName())
|
||||
.append("?encoding=UNICODE");
|
||||
m_connection = sb.toString();
|
||||
return m_connection;
|
||||
} // getConnectionString
|
||||
|
||||
/**
|
||||
* Get Connection URL
|
||||
* @param dbHost db Host
|
||||
* @param dbPort db Port
|
||||
* @param dbName sb Name
|
||||
* @param userName user name
|
||||
* @return connection url
|
||||
*/
|
||||
public String getConnectionURL (String dbHost, int dbPort, String dbName,
|
||||
String userName)
|
||||
{
|
||||
return "jdbc:postgresql://"
|
||||
+ dbHost + ":" + dbPort + "/" + dbName;
|
||||
} // getConnectionURL
|
||||
|
||||
/**
|
||||
* Get Database Connection String
|
||||
* @param connectionURL Connection URL
|
||||
* @param userName user name
|
||||
* @return connection String
|
||||
*/
|
||||
public String getConnectionURL (String connectionURL, String userName)
|
||||
{
|
||||
m_userName = userName;
|
||||
m_connectionURL = connectionURL;
|
||||
return m_connectionURL;
|
||||
} // getConnectionURL
|
||||
|
||||
/**
|
||||
* Get JDBC Catalog
|
||||
* @return catalog (database name)
|
||||
*/
|
||||
public String getCatalog()
|
||||
{
|
||||
if (m_dbName != null)
|
||||
return m_dbName;
|
||||
// log.severe("Database Name not set (yet) - call getConnectionURL first");
|
||||
return null;
|
||||
} // getCatalog
|
||||
|
||||
/**
|
||||
* Get JDBC Schema
|
||||
* @return schema (dbo)
|
||||
*/
|
||||
public String getSchema()
|
||||
{
|
||||
//begin vpj-cd e-evolution 03/04/2005
|
||||
return "adempiere";
|
||||
//end vpj-cd e-evolution 03/04/2005
|
||||
} // getSchema
|
||||
|
||||
/**
|
||||
* Supports BLOB
|
||||
* @return true if BLOB is supported
|
||||
*/
|
||||
public boolean supportsBLOB()
|
||||
{
|
||||
return true;
|
||||
} // supportsBLOB
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("DB_PostgreSQL[");
|
||||
sb.append(m_connection)
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Get Status
|
||||
* @return status info
|
||||
*/
|
||||
public String getStatus()
|
||||
{
|
||||
return "";
|
||||
} // getStatus
|
||||
|
||||
/*************************************************************************
|
||||
* Convert an individual Oracle Style statements to target database statement syntax
|
||||
*
|
||||
* @param oraStatement
|
||||
* @return converted Statement
|
||||
* @throws Exception
|
||||
*/
|
||||
public String convertStatement (String oraStatement)
|
||||
{
|
||||
String retValue[] = m_convert.convert(oraStatement);
|
||||
|
||||
//begin vpj-cd e-evolution 03/14/2005
|
||||
if (retValue.length == 0 )
|
||||
return oraStatement;
|
||||
//end vpj-cd e-evolution 03/14/2005
|
||||
|
||||
if (retValue == null)
|
||||
//begin vpj-cd 24/06/2005 e-evolution
|
||||
{
|
||||
log.log(Level.SEVERE,("DB_PostgreSQL.convertStatement - Not Converted (" + oraStatement + ") - "
|
||||
+ m_convert.getConversionError()));
|
||||
throw new IllegalArgumentException
|
||||
("DB_PostgreSQL.convertStatement - Not Converted (" + oraStatement + ") - "
|
||||
+ m_convert.getConversionError());
|
||||
}
|
||||
// end vpj-cd 24/06/2005 e-evolution
|
||||
if (retValue.length != 1)
|
||||
//begin vpj-cd 24/06/2005 e-evolution
|
||||
{
|
||||
log.log(Level.SEVERE, ("DB_PostgreSQL.convertStatement - Convert Command Number=" + retValue.length
|
||||
+ " (" + oraStatement + ") - " + m_convert.getConversionError()));
|
||||
throw new IllegalArgumentException
|
||||
("DB_PostgreSQL.convertStatement - Convert Command Number=" + retValue.length
|
||||
+ " (" + oraStatement + ") - " + m_convert.getConversionError());
|
||||
}
|
||||
//end vpj-cd 24/06/2005 e-evolution
|
||||
// Diagnostics (show changed, but not if AD_Error
|
||||
if (!oraStatement.equals(retValue[0]) && retValue[0].indexOf("AD_Error") == -1)
|
||||
//begin vpj-cd 24/06/2005 e-evolution
|
||||
//System.out.println("PostgreSQL =>" + retValue[0] + "<= <" + oraStatement + ">");
|
||||
log.log(Level.INFO, "PostgreSQL =>" + retValue[0] + "<= <" + oraStatement + ">");
|
||||
//end vpj-cd 24/06/2005 e-evolution
|
||||
//
|
||||
return retValue[0];
|
||||
} // convertStatement
|
||||
|
||||
|
||||
/**
|
||||
* Get Name of System User
|
||||
* @return e.g. sa, system
|
||||
*/
|
||||
public String getSystemUser()
|
||||
{
|
||||
return "postgres";
|
||||
} // getSystemUser
|
||||
|
||||
/**
|
||||
* Get Name of System Database
|
||||
* @param databaseName database Name
|
||||
* @return e.g. master or database Name
|
||||
*/
|
||||
public String getSystemDatabase(String databaseName)
|
||||
{
|
||||
return "template1";
|
||||
} // getSystemDatabase
|
||||
|
||||
|
||||
/**
|
||||
* Create SQL TO Date String from Timestamp
|
||||
*
|
||||
* @param time Date to be converted
|
||||
* @param dayOnly true if time set to 00:00:00
|
||||
*
|
||||
* @return TO_DATE('2001-01-30 18:10:20',''YYYY-MM-DD HH24:MI:SS')
|
||||
* or TO_DATE('2001-01-30',''YYYY-MM-DD')
|
||||
*/
|
||||
public String TO_DATE (Timestamp time, boolean dayOnly)
|
||||
{
|
||||
if (time == null)
|
||||
{
|
||||
if (dayOnly)
|
||||
return "current_date()";
|
||||
return "current_date()";
|
||||
}
|
||||
|
||||
StringBuffer dateString = new StringBuffer("TO_DATE('");
|
||||
// YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format
|
||||
String myDate = time.toString();
|
||||
if (dayOnly)
|
||||
{
|
||||
dateString.append(myDate.substring(0,10));
|
||||
dateString.append("','YYYY-MM-DD')");
|
||||
}
|
||||
else
|
||||
{
|
||||
dateString.append(myDate.substring(0, myDate.indexOf("."))); // cut off miliseconds
|
||||
dateString.append("','YYYY-MM-DD HH24:MI:SS')");
|
||||
}
|
||||
return dateString.toString();
|
||||
} // TO_DATE
|
||||
|
||||
/**
|
||||
* Create SQL for formatted Date, Number
|
||||
*
|
||||
* @param columnName the column name in the SQL
|
||||
* @param displayType Display Type
|
||||
* @param AD_Language 6 character language setting (from Env.LANG_*)
|
||||
*
|
||||
* @return TRIM(TO_CHAR(columnName,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.'''))
|
||||
* or TRIM(TO_CHAR(columnName,'TM9')) depending on DisplayType and Language
|
||||
* @see org.compiere.util.DisplayType
|
||||
* @see org.compiere.util.Env
|
||||
*
|
||||
**/
|
||||
public String TO_CHAR (String columnName, int displayType, String AD_Language)
|
||||
{
|
||||
StringBuffer retValue = new StringBuffer("CAST (");
|
||||
retValue.append(columnName);
|
||||
retValue.append(" AS Text)");
|
||||
|
||||
// Numbers
|
||||
/*
|
||||
if (DisplayType.isNumeric(displayType))
|
||||
{
|
||||
if (displayType == DisplayType.Amount)
|
||||
retValue.append(" AS TEXT");
|
||||
else
|
||||
retValue.append(" AS TEXT");
|
||||
//if (!Language.isDecimalPoint(AD_Language)) // reversed
|
||||
//retValue.append(",'NLS_NUMERIC_CHARACTERS='',.'''");
|
||||
}
|
||||
else if (DisplayType.isDate(displayType))
|
||||
{
|
||||
retValue.append(",'")
|
||||
.append(Language.getLanguage(AD_Language).getDBdatePattern())
|
||||
.append("'");
|
||||
}
|
||||
retValue.append(")");
|
||||
//*/
|
||||
return retValue.toString();
|
||||
} // TO_CHAR
|
||||
|
||||
/**
|
||||
* Return number as string for INSERT statements with correct precision
|
||||
* @param number number
|
||||
* @param displayType display Type
|
||||
* @return number as string
|
||||
*/
|
||||
public String TO_NUMBER (BigDecimal number, int displayType)
|
||||
{
|
||||
if (number == null)
|
||||
return "NULL";
|
||||
BigDecimal result = number;
|
||||
int scale = DisplayType.getDefaultPrecision(displayType);
|
||||
if (scale > number.scale())
|
||||
{
|
||||
try
|
||||
{
|
||||
result = number.setScale(scale, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// log.severe("Number=" + number + ", Scale=" + " - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
} // TO_NUMBER
|
||||
|
||||
|
||||
/**
|
||||
* Get SQL Commands
|
||||
* @param cmdType CMD_*
|
||||
* @return array of commands to be executed
|
||||
*/
|
||||
public String[] getCommands (int cmdType)
|
||||
{
|
||||
if (CMD_CREATE_USER == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
"CREATE USER compiere;",
|
||||
};
|
||||
//
|
||||
if (CMD_CREATE_DATABASE == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
"CREATE DATABASE compiere OWNER compiere;",
|
||||
"GRANT ALL PRIVILEGES ON compiere TO compiere;" ,
|
||||
"CREATE SCHEMA compiere;",
|
||||
"SET search_path TO compiere;"
|
||||
};
|
||||
//
|
||||
if (CMD_DROP_DATABASE == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
"DROP DATABASE compiere;"
|
||||
};
|
||||
//
|
||||
return null;
|
||||
} // getCommands
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Get RowSet
|
||||
* @param rs ResultSet
|
||||
* @return RowSet
|
||||
* @throws SQLException
|
||||
*/
|
||||
public RowSet getRowSet (java.sql.ResultSet rs) throws SQLException
|
||||
{
|
||||
throw new UnsupportedOperationException("PostgreSQL does not support RowSets");
|
||||
} // getRowSet
|
||||
|
||||
|
||||
/**
|
||||
* Get Cached Connection
|
||||
* @param connection connection
|
||||
* @param autoCommit auto commit
|
||||
* @param transactionIsolation trx isolation
|
||||
* @return Connection
|
||||
* @throws Exception
|
||||
*/
|
||||
public Connection getCachedConnection (CConnection connection,
|
||||
boolean autoCommit, int transactionIsolation)
|
||||
throws Exception
|
||||
{
|
||||
if (m_ds == null)
|
||||
getDataSource(connection);
|
||||
//
|
||||
Connection conn = m_ds.getConnection();
|
||||
// Connection conn = getDriverConnection(connection);
|
||||
//
|
||||
conn.setAutoCommit(autoCommit);
|
||||
conn.setTransactionIsolation(transactionIsolation);
|
||||
return conn;
|
||||
} // getCachedConnection
|
||||
|
||||
|
||||
/**
|
||||
* Create DataSource (Client)
|
||||
* @param connection connection
|
||||
* @return data dource
|
||||
*/
|
||||
public DataSource getDataSource(CConnection connection)
|
||||
{
|
||||
//throw new UnsupportedOperationException("Not supported/implemented");
|
||||
if (m_ds != null)
|
||||
return m_ds;
|
||||
|
||||
//org.postgresql.ds.PGPoolingDataSource ds = new org.postgresql.ds.PGPoolingDataSource();
|
||||
org.postgresql.jdbc3.Jdbc3PoolingDataSource ds = new org.postgresql.jdbc3.Jdbc3PoolingDataSource();
|
||||
ds.setDataSourceName("CompiereDS");
|
||||
ds.setServerName(connection.getDbHost());
|
||||
ds.setDatabaseName(connection.getDbName());
|
||||
ds.setUser(connection.getDbUid());
|
||||
ds.setPassword(connection.getDbPwd());
|
||||
ds.setPortNumber(connection.getDbPort());
|
||||
ds.setMaxConnections(50);
|
||||
ds.setInitialConnections(20);
|
||||
|
||||
//new InitialContext().rebind("DataSource", source);
|
||||
m_ds = ds;
|
||||
|
||||
return m_ds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Pooled DataSource (Server)
|
||||
* @param connection connection
|
||||
* @return data dource
|
||||
*/
|
||||
public ConnectionPoolDataSource createPoolDataSource(CConnection connection)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported/implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Connection from Driver
|
||||
* @param connection info
|
||||
* @return connection or null
|
||||
*/
|
||||
public Connection getDriverConnection (CConnection connection) throws SQLException
|
||||
{
|
||||
getDriver();
|
||||
return DriverManager.getConnection (getConnectionURL (connection),
|
||||
connection.getDbUid(), connection.getDbPwd());
|
||||
} // getDriverConnection
|
||||
|
||||
/**
|
||||
* Get Driver Connection
|
||||
* @param dbUrl URL
|
||||
* @param dbUid user
|
||||
* @param dbPwd password
|
||||
* @return connection
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Connection getDriverConnection (String dbUrl, String dbUid, String dbPwd)
|
||||
throws SQLException
|
||||
{
|
||||
getDriver();
|
||||
return DriverManager.getConnection (dbUrl, dbUid, dbPwd);
|
||||
} // getDriverConnection
|
||||
|
||||
|
||||
/**
|
||||
* Close
|
||||
*/
|
||||
public void close()
|
||||
{
|
||||
|
||||
log.config(toString());
|
||||
if (m_ds != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_ds.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
m_ds = null;
|
||||
} // close
|
||||
|
||||
|
||||
/**
|
||||
* Check and generate an alternative SQL
|
||||
* @reExNo number of re-execution
|
||||
* @msg previous execution error message
|
||||
* @sql previous executed SQL
|
||||
* @return String, the alternative SQL, null if no alternative
|
||||
*/
|
||||
public String getAlternativeSQL(int reExNo, String msg, String sql)
|
||||
{
|
||||
return null; //do not do re-execution of alternative SQL
|
||||
}
|
||||
|
||||
/**
|
||||
* Get constraint type associated with the index
|
||||
* @tableName table name
|
||||
* @IXName Index name
|
||||
* @return String[0] = 0: do not know, 1: Primary Key 2: Foreign Key
|
||||
* String[1] - String[n] = Constraint Name
|
||||
*/
|
||||
public String getConstraintType(Connection conn, String tableName, String IXName)
|
||||
{
|
||||
if (IXName == null || IXName.length()==0)
|
||||
return "0";
|
||||
if (IXName.endsWith("_KEY"))
|
||||
return "1"+IXName;
|
||||
else
|
||||
return "0";
|
||||
//jz temp, modify later from user.constraints
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if DBMS support the sql statement
|
||||
* @sql SQL statement
|
||||
* @return true: yes
|
||||
*/
|
||||
public boolean isSupported(String sql)
|
||||
{
|
||||
return true;
|
||||
//jz temp, modify later
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test
|
||||
* @param args ignored
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
DB_PostgreSQL postgresql = new DB_PostgreSQL();
|
||||
//
|
||||
String databaseName = "adempiere";
|
||||
String uid = "adempiere";
|
||||
String pwd = "adempiere";
|
||||
String jdbcURL = postgresql.getConnectionURL("vpj", DEFAULT_PORT, databaseName, uid);
|
||||
System.out.println(jdbcURL);
|
||||
try
|
||||
{
|
||||
postgresql.getDriver();
|
||||
Connection conn = DriverManager.getConnection (jdbcURL, uid, pwd);
|
||||
|
||||
//CachedRowSetImpl crs = null;
|
||||
//crs = new CachedRowSetImpl();
|
||||
//crs.setSyncProvider("com.sun.rowset.providers.RIOptimisticProvider");
|
||||
//crs.setConcurrency(ResultSet.CONCUR_READ_ONLY);
|
||||
//crs.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
|
||||
//crs.setCommand("SELECT * FROM AD_Client");
|
||||
//
|
||||
//crs.execute(conn);
|
||||
//
|
||||
conn.close();
|
||||
conn = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} // main
|
||||
|
||||
} // DB_PostgreSQL
|
|
@ -0,0 +1,70 @@
|
|||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* General Database Constants and Utilities
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: Database.java,v 1.3 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class Database
|
||||
{
|
||||
/** Oracle ID */
|
||||
public static String DB_ORACLE = "Oracle";
|
||||
/** IBM DB/2 ID */
|
||||
public static String DB_DB2 = "DB2";
|
||||
/** Derby ID */
|
||||
public static String DB_DERBY = "Derby";
|
||||
/** Microsoft ID */
|
||||
public static String DB_MSSQLServer = "SQLServer";
|
||||
/** PostgreSQL ID */
|
||||
public static String DB_POSTGRESQL = "PostgreSQL";
|
||||
// begin vpj-c e-evolution 11/30/2005 EDB
|
||||
/** Enterprise DB */
|
||||
//public static String DB_EDB = "EnterpriseDB";
|
||||
// end vpj-c e-evolution 11/30/2005 EDB
|
||||
|
||||
|
||||
/** Supported Databases */
|
||||
public static String[] DB_NAMES = new String[] {
|
||||
DB_ORACLE
|
||||
,DB_DB2
|
||||
// ,DB_DERBY
|
||||
// ,DB_MSSQLServer
|
||||
// begin vpj-c e-evolution 02/08/205 PostgreSQL
|
||||
,DB_POSTGRESQL
|
||||
// ,DB_EDB
|
||||
// end e-evolution 02/08/2005 PostgreSQL
|
||||
};
|
||||
|
||||
/** Database Classes */
|
||||
protected static Class[] DB_CLASSES = new Class[] {
|
||||
DB_Oracle.class
|
||||
,DB_DB2.class
|
||||
// ,DB_Derby.class
|
||||
// ,DB_MSSQLServer.class
|
||||
//begin vpj-c e-evolution 02/08/2005 PostgreSQL
|
||||
,DB_PostgreSQL.class
|
||||
// ,DB_EDB.class
|
||||
//end e-evolution 02/08/205 PostgreSQL
|
||||
};
|
||||
|
||||
/** Connection Timeout in seconds */
|
||||
public static int CONNECTION_TIMEOUT = 10;
|
||||
|
||||
} // Database
|
Binary file not shown.
After Width: | Height: | Size: 590 B |
|
@ -0,0 +1,180 @@
|
|||
/******************************************************************************
|
||||
* 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.sql.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* JDBC Meta Info
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: JDBCInfo.java,v 1.3 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class JDBCInfo
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param conn connection
|
||||
* @throws SQLException
|
||||
*/
|
||||
public JDBCInfo(Connection conn) throws SQLException
|
||||
{
|
||||
m_md = conn.getMetaData();
|
||||
log.info(m_md.getDatabaseProductName());
|
||||
log.config(m_md.getDatabaseProductVersion());
|
||||
// log.config(m_md.getDatabaseMajorVersion() + "/" + m_md.getDatabaseMinorVersion());
|
||||
//
|
||||
log.info(m_md.getDriverName());
|
||||
log.config(m_md.getDriverVersion());
|
||||
log.config(m_md.getDriverMajorVersion() + "/" + m_md.getDriverMinorVersion());
|
||||
//
|
||||
// log.info("JDBC = " + m_md.getJDBCMajorVersion() + "/" + m_md.getJDBCMinorVersion());
|
||||
} // JDBCInfo
|
||||
|
||||
/** Mata Data */
|
||||
private DatabaseMetaData m_md = null;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger (JDBCInfo.class);
|
||||
|
||||
/**
|
||||
* List All
|
||||
*/
|
||||
public void listAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
listSchemas();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.severe(e.getMessage());
|
||||
}
|
||||
try
|
||||
{
|
||||
listCatalogs();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.severe(e.getMessage());
|
||||
}
|
||||
try
|
||||
{
|
||||
listTypes();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.severe(e.getMessage());
|
||||
}
|
||||
} // listAll
|
||||
|
||||
/**
|
||||
* List Catalogs
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void listCatalogs() throws SQLException
|
||||
{
|
||||
log.info(m_md.getCatalogTerm() + " -> " + m_md.getCatalogSeparator());
|
||||
ResultSet rs = m_md.getCatalogs();
|
||||
while (rs.next())
|
||||
{
|
||||
dump(rs);
|
||||
}
|
||||
} // listCatalogs
|
||||
|
||||
/**
|
||||
* List Schemas
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void listSchemas() throws SQLException
|
||||
{
|
||||
log.info(m_md.getSchemaTerm());
|
||||
ResultSet rs = m_md.getSchemas();
|
||||
while (rs.next())
|
||||
{
|
||||
dump(rs);
|
||||
}
|
||||
} // listSchemas
|
||||
|
||||
/**
|
||||
* List Types
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void listTypes() throws SQLException
|
||||
{
|
||||
ResultSet rs = m_md.getTypeInfo();
|
||||
while (rs.next())
|
||||
{
|
||||
log.info("");
|
||||
dump(rs);
|
||||
}
|
||||
} // listTypes
|
||||
|
||||
/**
|
||||
* Dump the current row of a Result Set
|
||||
* @param rs result set
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static void dump(ResultSet rs) throws SQLException
|
||||
{
|
||||
ResultSetMetaData md = rs.getMetaData();
|
||||
for (int i = 0; i < md.getColumnCount(); i++)
|
||||
{
|
||||
int index = i + 1;
|
||||
String info = md.getColumnLabel(index);
|
||||
String name = md.getColumnName(index);
|
||||
if (info == null)
|
||||
info = name;
|
||||
else if (name != null && !name.equals(info))
|
||||
info += " (" + name + ")";
|
||||
info += " = "
|
||||
+ rs.getString(index);
|
||||
info += " [" + md.getColumnTypeName(index)
|
||||
+ "(" + md.getPrecision(index);
|
||||
if (md.getScale(index) != 0)
|
||||
info += "," + md.getScale(index);
|
||||
info += ")]";
|
||||
log.fine(info);
|
||||
}
|
||||
} // dump
|
||||
|
||||
/**************************************************************************
|
||||
* Test
|
||||
* @param args ignored
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Adempiere.startup(true);
|
||||
CLogMgt.setLevel(Level.ALL);
|
||||
//
|
||||
try
|
||||
{
|
||||
JDBCInfo info = new JDBCInfo(DB.createConnection(true, Connection.TRANSACTION_READ_COMMITTED));
|
||||
info.listCatalogs();
|
||||
info.listSchemas();
|
||||
info.listTypes();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "", e);
|
||||
}
|
||||
} // main
|
||||
|
||||
} // JDBCInfo
|
|
@ -0,0 +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
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 642 B |
|
@ -0,0 +1,225 @@
|
|||
/******************************************************************************
|
||||
* 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.sql.*;
|
||||
|
||||
/**
|
||||
* Test Connection (speed)
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: TestConnection.java,v 1.2 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class TestConnection
|
||||
{
|
||||
|
||||
/**
|
||||
* Test Connection
|
||||
*
|
||||
* @param jdbcURL JDBC URL
|
||||
* @param uid user
|
||||
* @param pwd password
|
||||
*/
|
||||
public TestConnection (String jdbcURL, String uid, String pwd)
|
||||
{
|
||||
System.out.println("Test Connection for " + jdbcURL);
|
||||
m_jdbcURL = jdbcURL;
|
||||
m_uid = uid;
|
||||
m_pwd = pwd;
|
||||
init();
|
||||
if (m_conn != null)
|
||||
{
|
||||
long time = test();
|
||||
time += test();
|
||||
time += test();
|
||||
time += test();
|
||||
System.out.println("");
|
||||
System.out.println("Total Average (" + m_jdbcURL + ")= " + (time/4) + "ms");
|
||||
}
|
||||
} // TestConnection
|
||||
|
||||
private String m_jdbcURL;
|
||||
private String m_uid = "adempiere";
|
||||
private String m_pwd = "adempiere";
|
||||
private String m_sql = "SELECT * FROM AD_Element";
|
||||
private Connection m_conn;
|
||||
|
||||
/**
|
||||
* Initialize & Open Connection
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
Driver driver = null;
|
||||
try
|
||||
{
|
||||
driver = DriverManager.getDriver(m_jdbcURL);
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
// System.err.println("Init - get Driver: " + ex);
|
||||
}
|
||||
if (driver == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
System.err.println("Init = register Driver: " + ex);
|
||||
}
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("(1) Driver = " + (end - start) + "ms");
|
||||
//
|
||||
start = System.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
m_conn = DriverManager.getConnection(m_jdbcURL, m_uid, m_pwd);
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
System.err.println("Init = get Connection: " + ex);
|
||||
}
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("(2) Get Connection = " + (end - start) + "ms");
|
||||
//
|
||||
start = System.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
if (m_conn != null)
|
||||
m_conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
System.err.println("Init = close Connection: " + ex);
|
||||
}
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("(3) Close Connection = " + (end - start) + "ms");
|
||||
} // init
|
||||
|
||||
/**
|
||||
* Test ResultSet
|
||||
* @return time in ms
|
||||
*/
|
||||
private long test()
|
||||
{
|
||||
System.out.println("");
|
||||
long totalStart = System.currentTimeMillis();
|
||||
long start = System.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
m_conn = DriverManager.getConnection(m_jdbcURL, m_uid, m_pwd);
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
System.err.println("Test get Connection: " + ex);
|
||||
return -1;
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("(A) Get Connection = " + (end - start) + "ms");
|
||||
//
|
||||
try
|
||||
{
|
||||
start = System.currentTimeMillis();
|
||||
Statement stmt = m_conn.createStatement();
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("(B) Create Statement = " + (end - start) + "ms");
|
||||
//
|
||||
start = System.currentTimeMillis();
|
||||
ResultSet rs = stmt.executeQuery(m_sql);
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("(C) Execute Query = " + (end - start) + "ms");
|
||||
//
|
||||
int no = 0;
|
||||
start = System.currentTimeMillis();
|
||||
while (rs.next())
|
||||
{
|
||||
int i = rs.getInt("AD_Client_ID");
|
||||
String s = rs.getString("Name");
|
||||
i += s.length();
|
||||
no++;
|
||||
}
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("(D) Read ResultSet = " + (end - start) + "ms - per 10 rows " + ((end - start)/(no/10)) + "ms");
|
||||
//
|
||||
start = System.currentTimeMillis();
|
||||
rs.close();
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("(E) Close ResultSet = " + (end - start) + "ms");
|
||||
//
|
||||
start = System.currentTimeMillis();
|
||||
stmt.close();
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("(F) Close Statement = " + (end - start) + "ms");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
System.err.println("Test: " + e);
|
||||
}
|
||||
//
|
||||
start = System.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
if (m_conn != null)
|
||||
m_conn.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
System.err.println("Test close Connection: " + ex);
|
||||
}
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("(G) Close Connection = " + (end - start) + "ms");
|
||||
|
||||
long totalEnd = System.currentTimeMillis();
|
||||
System.out.println("Total Test = " + (totalEnd - totalStart) + "ms");
|
||||
return (totalEnd - totalStart);
|
||||
} // test
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Test Connection.
|
||||
* java -cp dbPort.jar;oracle.jar org.compiere.db.TestConnection
|
||||
* @param args arguments optional <jdbcURL> <uid> <pwd>
|
||||
* Example: jdbc:oracle:thin:@dev:1521:dev adempiere adempiere
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String url = "jdbc:oracle:thin:@//24.151.26.64:1521/lap11";
|
||||
String uid = "adempiere";
|
||||
String pwd = "adempiere";
|
||||
//
|
||||
if (args.length == 0)
|
||||
{
|
||||
System.out.println("TestConnection <jdbcUrl> <uid> <pwd>");
|
||||
System.out.println("Example: jdbc:oracle:thin:@//dev:1521/dev adempiere adempiere");
|
||||
System.out.println("Example: jdbc:oracle:oci8:@dev adempiere adempiere");
|
||||
}
|
||||
else if (args.length > 0)
|
||||
url = args[0];
|
||||
else if (args.length > 1)
|
||||
url = args[1];
|
||||
else if (args.length > 2)
|
||||
url = args[2];
|
||||
|
||||
System.out.println("");
|
||||
TestConnection test = new TestConnection(url, uid, pwd);
|
||||
} // main
|
||||
|
||||
} // TestConnection
|
|
@ -0,0 +1,85 @@
|
|||
/******************************************************************************
|
||||
* 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 javax.naming.*;
|
||||
import org.compiere.interfaces.*;
|
||||
|
||||
/**
|
||||
* Test EJB
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: TestEJB.java,v 1.3 2006/07/30 00:55:13 jjanke Exp $
|
||||
*/
|
||||
public class TestEJB
|
||||
{
|
||||
/**
|
||||
* TestEJB
|
||||
*/
|
||||
public TestEJB ()
|
||||
{
|
||||
CConnection cc = CConnection.get(null);
|
||||
cc.setAppsHost("dev1");
|
||||
InitialContext ic = cc.getInitialContext(false);
|
||||
/**/
|
||||
try
|
||||
{
|
||||
System.out.println(ic.getEnvironment());
|
||||
System.out.println("----------------");
|
||||
NamingEnumeration ne = ic.list("");
|
||||
while (ne.hasMore())
|
||||
{
|
||||
System.out.println(ne.next());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("..");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
/**/
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
StatusHome statusHome = (StatusHome)ic.lookup ("Status");
|
||||
Status status = statusHome.create ();
|
||||
//
|
||||
}
|
||||
catch (CommunicationException ce) // not a "real" error
|
||||
{
|
||||
System.err.println("=ce=");
|
||||
ce.printStackTrace();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("=e=");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* main
|
||||
* @param args
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
new TestEJB();
|
||||
} // main
|
||||
|
||||
} // TestEJB
|
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
|
||||
$Id: package.html,v 1.1 2006/04/21 17:53:31 jjanke Exp $
|
||||
|
||||
Copyright 1999-2002 Jorg Janke, Inc.
|
||||
40 Old Tannery Rd, Monroe, CT 06468, U.S.A.
|
||||
All Rights Reserved.
|
||||
|
||||
-->
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Provides for....
|
||||
|
||||
<h2>Package Specification</h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="http://www.adempiere.org">http://www.adempiere.org</a>
|
||||
</ul>
|
||||
|
||||
<h2>Related Documentation</h2>
|
||||
|
||||
For overviews, tutorials, examples, guides, and tool documentation, please see:
|
||||
<ul>
|
||||
<li><a href="http://www.adempiere.org">http://www.adempiere.org</a>
|
||||
</ul>
|
||||
|
||||
<!-- Put @see and @since tags down here. -->
|
||||
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,322 @@
|
|||
/******************************************************************************
|
||||
* 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.dbPort;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import javax.swing.*;
|
||||
import org.compiere.*;
|
||||
import org.compiere.db.*;
|
||||
import org.compiere.swing.*;
|
||||
|
||||
/**
|
||||
* Conversion Dialog
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: ConvertDialog.java,v 1.2 2006/07/30 00:55:04 jjanke Exp $
|
||||
*/
|
||||
public class ConvertDialog extends CFrame implements ActionListener
|
||||
{
|
||||
/**
|
||||
* Convert Dialog
|
||||
*/
|
||||
public ConvertDialog()
|
||||
{
|
||||
try
|
||||
{
|
||||
jbInit();
|
||||
//
|
||||
fSelectFile.addItem("D:\\adempiere\\db\\database\\create\\views.sql");
|
||||
fSelectFile.addItem("D:\\adempiere\\db\\database\\create\\temporary.sql");
|
||||
fSelectFile.addItem("D:\\adempiere\\db\\database\\create\\sequences.sql");
|
||||
fSelectFile.addItem("D:\\adempiere\\db\\database\\create\\adempiere.sql");
|
||||
// Set up environment
|
||||
fConnect.setValue(CConnection.get(Database.DB_DB2,
|
||||
"linux", DB_DB2.DEFAULT_PORT, "adempiere"));
|
||||
fTarget.setSelectedItem(Database.DB_DB2);
|
||||
fExecute.setSelected(true);
|
||||
|
||||
cmd_execute(); // set UI
|
||||
//
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.err.println(e);
|
||||
}
|
||||
} // ConvertDialog
|
||||
|
||||
private JPanel parameterPanel = new JPanel();
|
||||
private GridBagLayout gridBagLayout1 = new GridBagLayout();
|
||||
private JLabel lSelectFile = new JLabel();
|
||||
private JComboBox fSelectFile = new JComboBox();
|
||||
private JButton bSelectFile = new JButton();
|
||||
private JCheckBox fExecute = new JCheckBox();
|
||||
private JLabel lConnect = new JLabel();
|
||||
private CConnectionEditor fConnect = new CConnectionEditor();
|
||||
private JButton bStart = new JButton();
|
||||
private JScrollPane scrollPane = new JScrollPane();
|
||||
private JTextArea infoPane = new JTextArea();
|
||||
private Component component1;
|
||||
private Component component2;
|
||||
private Component component3;
|
||||
private Component component4;
|
||||
private JLabel lTarget = new JLabel();
|
||||
private JComboBox fTarget = new JComboBox(Database.DB_NAMES);
|
||||
private JCheckBox fVerbose = new JCheckBox();
|
||||
|
||||
/**
|
||||
* Static Layout
|
||||
* @throws Exception
|
||||
*/
|
||||
private void jbInit() throws Exception
|
||||
{
|
||||
component1 = Box.createHorizontalStrut(8);
|
||||
component2 = Box.createHorizontalStrut(8);
|
||||
component3 = Box.createVerticalStrut(8);
|
||||
component4 = Box.createVerticalStrut(8);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setTitle("DB Convert Dialog");
|
||||
//
|
||||
parameterPanel.setLayout(gridBagLayout1);
|
||||
lSelectFile.setText("Select File");
|
||||
fSelectFile.setEditable(true);
|
||||
bSelectFile.setText("add file");
|
||||
bSelectFile.addActionListener(this);
|
||||
fExecute.setText("Execute Directly");
|
||||
fExecute.addActionListener(this);
|
||||
lConnect.setText("Connection");
|
||||
bStart.setText("Start");
|
||||
bStart.addActionListener(this);
|
||||
//
|
||||
infoPane.setBackground(Color.lightGray);
|
||||
infoPane.setEditable(false);
|
||||
scrollPane.setPreferredSize(new Dimension(200, 200));
|
||||
lTarget.setText("Target");
|
||||
fVerbose.setText("Verbose");
|
||||
//
|
||||
this.getContentPane().add(parameterPanel, BorderLayout.NORTH);
|
||||
parameterPanel.add(lSelectFile, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
|
||||
parameterPanel.add(fSelectFile, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterPanel.add(bSelectFile, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterPanel.add(fExecute, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterPanel.add(lConnect, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
|
||||
parameterPanel.add(fConnect, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
|
||||
parameterPanel.add(bStart, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterPanel.add(component1, new GridBagConstraints(5, 0, 1, 2, 0.0, 0.0
|
||||
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
|
||||
parameterPanel.add(component2, new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0
|
||||
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
|
||||
parameterPanel.add(component3, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
|
||||
parameterPanel.add(component4, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
|
||||
parameterPanel.add(lTarget, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
this.getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||
scrollPane.getViewport().add(infoPane, null);
|
||||
parameterPanel.add(fTarget, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
parameterPanel.add(fVerbose, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
} // jbInit
|
||||
|
||||
/**
|
||||
* Action Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
//
|
||||
if (e.getSource() == bStart)
|
||||
{
|
||||
bStart.setEnabled(false);
|
||||
cmd_start();
|
||||
bStart.setEnabled(true);
|
||||
}
|
||||
else if (e.getSource() == bSelectFile)
|
||||
cmd_selectFile();
|
||||
|
||||
else if (e.getSource() == fExecute)
|
||||
cmd_execute();
|
||||
//
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
} // actionListener
|
||||
|
||||
/**
|
||||
* Execute toggle
|
||||
*/
|
||||
private void cmd_execute()
|
||||
{
|
||||
lConnect.setEnabled(fExecute.isSelected());
|
||||
fConnect.setReadWrite(fExecute.isSelected());
|
||||
lTarget.setEnabled(!fExecute.isSelected());
|
||||
fTarget.setEnabled(!fExecute.isSelected());
|
||||
} // cmd_execute
|
||||
|
||||
/**
|
||||
* Select File and add to selection
|
||||
*/
|
||||
private void cmd_selectFile()
|
||||
{
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setMultiSelectionEnabled(false);
|
||||
if (fc.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
|
||||
return;
|
||||
File f = fc.getSelectedFile();
|
||||
if (f == null || !f.isFile())
|
||||
return;
|
||||
String fileName = f.getAbsolutePath();
|
||||
//
|
||||
fSelectFile.addItem(fileName);
|
||||
fSelectFile.setSelectedItem(fileName);
|
||||
} // cmd_selectFile
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Start Pressed
|
||||
*/
|
||||
private void cmd_start()
|
||||
{
|
||||
// Open and read File
|
||||
File file = new File ((String)fSelectFile.getSelectedItem());
|
||||
if (!file.exists() || file.isDirectory())
|
||||
{
|
||||
infoPane.append("File does not exist or a directory: " + file + "\n");
|
||||
return;
|
||||
}
|
||||
infoPane.append("Opening file: " + file + "\n");
|
||||
StringBuffer sb = new StringBuffer (1000);
|
||||
//
|
||||
try
|
||||
{
|
||||
FileReader fr = new FileReader(file);
|
||||
BufferedReader in = new BufferedReader(fr);
|
||||
|
||||
String line = null;
|
||||
int lines = 0;
|
||||
while((line = in.readLine()) != null)
|
||||
{
|
||||
lines++;
|
||||
sb.append(line).append('\n');
|
||||
}
|
||||
in.close();
|
||||
fr.close();
|
||||
infoPane.append("- Read lines: " + lines + ", size: " + sb.length() + "\n");
|
||||
}
|
||||
catch (FileNotFoundException fnf)
|
||||
{
|
||||
infoPane.append("Error: " + fnf + "\n");
|
||||
return;
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
infoPane.append("Error: " + ioe + "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Target system
|
||||
if (fExecute.isSelected())
|
||||
{
|
||||
CConnection cc = (CConnection)fConnect.getValue();
|
||||
Convert convert = new Convert (cc.getType());
|
||||
convert.setVerbose(fVerbose.isSelected());
|
||||
//
|
||||
Connection conn = cc.getConnection (true, Connection.TRANSACTION_READ_COMMITTED);
|
||||
convert.execute(sb.toString(), conn);
|
||||
if (convert.hasError())
|
||||
{
|
||||
StringBuffer sbb = new StringBuffer ("- Error: ");
|
||||
if (convert.getConversionError() != null)
|
||||
sbb.append(convert.getConversionError()).append(' ');
|
||||
if (convert.getException() != null)
|
||||
{
|
||||
sbb.append(convert.getException());
|
||||
convert.getException().printStackTrace();
|
||||
}
|
||||
sbb.append("\n");
|
||||
infoPane.append(sbb.toString());
|
||||
}
|
||||
else
|
||||
infoPane.append("- OK\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
String target = (String)fTarget.getSelectedItem();
|
||||
if (Database.DB_ORACLE.equals(target))
|
||||
{
|
||||
infoPane.append("No conversion needed.\n");
|
||||
return;
|
||||
}
|
||||
Convert convert = new Convert (target);
|
||||
//
|
||||
String cc = convert.convertAll(sb.toString());
|
||||
|
||||
// Output file name
|
||||
String fileName = file.getAbsolutePath();
|
||||
int pos = fileName.lastIndexOf(".");
|
||||
if (pos == -1)
|
||||
fileName += target;
|
||||
else
|
||||
fileName = fileName.substring(0, pos) + target + fileName.substring(pos);
|
||||
infoPane.append("Writing to: " + fileName + "\n");
|
||||
// Write to file
|
||||
try
|
||||
{
|
||||
FileWriter fw = new FileWriter(fileName, false);
|
||||
BufferedWriter out = new BufferedWriter (fw);
|
||||
out.write("-- Adempiere dbPort - Convert Oracle to " + target);
|
||||
out.newLine();
|
||||
out.write("-- " + Adempiere.getSummary());
|
||||
out.newLine();
|
||||
//
|
||||
out.write(cc);
|
||||
//
|
||||
out.close();
|
||||
fw.close();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
infoPane.append("Error: " + ioe + "\n");
|
||||
}
|
||||
infoPane.append("- Written: " + cc.length() + "\n");
|
||||
}
|
||||
} // cmd_start
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Start Dialog
|
||||
* @param args ignored
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
new ConvertDialog();
|
||||
} // main
|
||||
} // ConvertDialog
|
|
@ -0,0 +1,260 @@
|
|||
/******************************************************************************
|
||||
* 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.dbPort;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Database Syntax Conversion Map.
|
||||
*
|
||||
*
|
||||
* @author Jorg Janke & Victor Perez
|
||||
* @version $Id: ConvertMap.java,v 1.6 2006/09/22 23:35:19 jjanke Exp $
|
||||
*/
|
||||
public class ConvertMap
|
||||
{
|
||||
/**
|
||||
* Return Map for Derby
|
||||
* @return TreeMap with pattern as key and the replacement as value
|
||||
*/
|
||||
public static TreeMap getDerbyMap()
|
||||
{
|
||||
if (s_derby.size() == 0)
|
||||
initDerby();
|
||||
return s_derby;
|
||||
} // getDerbyMap
|
||||
|
||||
/**
|
||||
* Return Map for DB/2
|
||||
* @return TreeMap with pattern as key and the replacement as value
|
||||
*/
|
||||
public static TreeMap getDB2Map()
|
||||
{
|
||||
if (s_db2.size() == 0)
|
||||
initDB2();
|
||||
return s_db2;
|
||||
} // getDB2Map
|
||||
// begin e-evolution PostgreSQL
|
||||
/**
|
||||
* Return Map for PostgreSQL
|
||||
* @return TreeMap with pattern as key and the replacement as value
|
||||
*/
|
||||
public static TreeMap getPostgeSQLMap()
|
||||
{
|
||||
if (s_pg.size() == 0)
|
||||
initPostgreSQL();
|
||||
return s_pg;
|
||||
} // getPostgreSQLMap
|
||||
// end e-evolution PostgreSQL
|
||||
|
||||
/** Tree Map for Derby */
|
||||
private static TreeMap<String,String> s_derby = new TreeMap<String,String>();
|
||||
/** Tree Map for PostgreSQL */
|
||||
private static TreeMap<String,String> s_db2 = new TreeMap<String,String>();
|
||||
// begin e-evolution PostgreSQL
|
||||
/** Tree Map for PostgreSQL */
|
||||
private static TreeMap<String,String> s_pg = new TreeMap<String,String>();
|
||||
// end e-evolution PostgreSQL
|
||||
/**
|
||||
* Derby Init
|
||||
*/
|
||||
static private void initDerby()
|
||||
{ // C:\Sources\db-derby-10.1.2.1-bin\docs\html\ref\index.html
|
||||
|
||||
// Oracle Pattern Replacement
|
||||
|
||||
// Data Types
|
||||
s_derby.put("\\bNUMBER\\b", "DECIMAL(31,6)"); //jz: changed from decimal to decimal(31,6)
|
||||
s_derby.put("\\bDATE\\b", "TIMESTAMP");
|
||||
s_derby.put("\\bVARCHAR2\\b", "VARCHAR");
|
||||
s_derby.put("\\bNVARCHAR2\\b", "VARCHAR");
|
||||
s_derby.put("\\bNCHAR\\b", "CHAR");
|
||||
|
||||
// Storage
|
||||
s_derby.put("\\bCACHE\\b", "");
|
||||
s_derby.put("\\bUSING INDEX\\b", "");
|
||||
s_derby.put("\\bTABLESPACE\\s\\w+\\b", "");
|
||||
s_derby.put("\\bSTORAGE\\([\\w\\s]+\\)", "");
|
||||
//
|
||||
s_derby.put("\\bBITMAP INDEX\\b", "INDEX");
|
||||
|
||||
// Select
|
||||
s_derby.put("\\bFOR UPDATE\\b", "");
|
||||
s_derby.put("\\bTRUNC\\(", "convert(date,");
|
||||
|
||||
// Functions
|
||||
s_derby.put("\\bSysDate\\b", "CURRENT_TIMESTAMP");
|
||||
s_derby.put("\\bSYSDATE\\b", "CURRENT_TIMESTAMP");
|
||||
s_derby.put("\\bNVL\\b", "NULLIF");
|
||||
s_derby.put("\\bCOALESCE\\b", "NULLIF");
|
||||
|
||||
s_derby.put("\\bTO_DATE\\b", "TO_TIMESTAMP");
|
||||
//
|
||||
// s_derby.put("\\bDBMS_OUTPUT.PUT_LINE\\b", "RAISE NOTICE");
|
||||
|
||||
// Temporary
|
||||
s_derby.put("\\bGLOBAL TEMPORARY\\b", "TEMPORARY");
|
||||
s_derby.put("\\bON COMMIT DELETE ROWS\\b", "");
|
||||
s_derby.put("\\bON COMMIT PRESERVE ROWS\\b", "");
|
||||
|
||||
|
||||
// DROP TABLE x CASCADE CONSTRAINTS
|
||||
// s_derby.put("\\bCASCADE CONSTRAINTS\\b", "");
|
||||
|
||||
// Select
|
||||
s_derby.put("\\sFROM\\s+DUAL\\b", "");
|
||||
|
||||
// Statements
|
||||
s_derby.put("\\bELSIF\\b", "ELSE IF");
|
||||
|
||||
// Sequences
|
||||
s_derby.put("\\bSTART WITH\\b", "START");
|
||||
s_derby.put("\\bINCREMENT BY\\b", "INCREMENT");
|
||||
|
||||
} // initDerby
|
||||
|
||||
/**
|
||||
* DB/2 Init
|
||||
*/
|
||||
static private void initDB2()
|
||||
{
|
||||
// Oracle Pattern Replacement
|
||||
|
||||
// Data Types
|
||||
s_db2.put("\\bNUMBER\\b", "NUMERIC");
|
||||
s_db2.put("\\bDATE\\b", "TIMESTAMP");
|
||||
s_db2.put("\\bVARCHAR2\\b", "VARCHAR");
|
||||
s_db2.put("\\bNVARCHAR2\\b", "VARCHAR");
|
||||
s_db2.put("\\bNCHAR\\b", "CHAR");
|
||||
s_db2.put("\\bBLOB\\b", "OID"); // BLOB not directly supported
|
||||
s_db2.put("\\bCLOB\\b", "TEXT"); // CLOB not directly supported
|
||||
|
||||
// Storage
|
||||
s_db2.put("\\bCACHE\\b", "");
|
||||
s_db2.put("\\bUSING INDEX\\b", "");
|
||||
s_db2.put("\\bTABLESPACE\\s\\w+\\b", "");
|
||||
s_db2.put("\\bSTORAGE\\([\\w\\s]+\\)", "");
|
||||
//
|
||||
s_db2.put("\\bBITMAP INDEX\\b", "INDEX");
|
||||
|
||||
// Functions
|
||||
s_db2.put("\\bSYSDATE\\b", "CURRENT_TIMESTAMP"); // alternative: NOW()
|
||||
s_db2.put("\\bNVL\\b", "COALESCE");
|
||||
s_db2.put("\\bTO_DATE\\b", "TO_TIMESTAMP");
|
||||
//
|
||||
s_db2.put("\\bDBMS_OUTPUT.PUT_LINE\\b", "RAISE NOTICE");
|
||||
|
||||
// Temporary
|
||||
s_db2.put("\\bGLOBAL TEMPORARY\\b", "TEMPORARY");
|
||||
s_db2.put("\\bON COMMIT DELETE ROWS\\b", "");
|
||||
s_db2.put("\\bON COMMIT PRESERVE ROWS\\b", "");
|
||||
|
||||
|
||||
// DROP TABLE x CASCADE CONSTRAINTS
|
||||
s_db2.put("\\bCASCADE CONSTRAINTS\\b", "");
|
||||
|
||||
// Select
|
||||
s_db2.put("\\sFROM\\s+DUAL\\b", "");
|
||||
|
||||
// Statements
|
||||
s_db2.put("\\bELSIF\\b", "ELSE IF");
|
||||
|
||||
// Sequences
|
||||
s_db2.put("\\bSTART WITH\\b", "START");
|
||||
s_db2.put("\\bINCREMENT BY\\b", "INCREMENT");
|
||||
|
||||
} // initPostgreSQL
|
||||
|
||||
/**
|
||||
* PostgreSQL Init
|
||||
*/
|
||||
static private void initPostgreSQL()
|
||||
{
|
||||
// Oracle Pattern Replacement
|
||||
|
||||
// Data Types
|
||||
s_pg.put("\\bNUMBER\\b", "NUMERIC");
|
||||
s_pg.put("\\bDATE\\b", "TIMESTAMP");
|
||||
s_pg.put("\\bVARCHAR2\\b", "VARCHAR");
|
||||
s_pg.put("\\bNVARCHAR2\\b", "VARCHAR");
|
||||
s_pg.put("\\bNCHAR\\b", "CHAR");
|
||||
//begin vpj-cd e-evolution 03/11/2005 PostgreSQL
|
||||
s_pg.put("\\bBLOB\\b", "BYTEA"); // BLOB not directly supported
|
||||
s_pg.put("\\bCLOB\\b", "BYTEA"); // CLOB not directly supported
|
||||
s_pg.put("\\bLIMIT\\b","\"limit\"");
|
||||
s_pg.put("\\bACTION\\b","\"action\"");
|
||||
//s_pg.put("\\bBLOB\\b", "OID"); // BLOB not directly supported
|
||||
//s_pg.put("\\bCLOB\\b", "OID"); // CLOB not directly supported
|
||||
//end vpj-cd e-evolution 03/11/2005 PostgreSQL
|
||||
|
||||
// Storage
|
||||
s_pg.put("\\bCACHE\\b", "");
|
||||
s_pg.put("\\bUSING INDEX\\b", "");
|
||||
s_pg.put("\\bTABLESPACE\\s\\w+\\b", "");
|
||||
s_pg.put("\\bSTORAGE\\([\\w\\s]+\\)", "");
|
||||
//
|
||||
s_pg.put("\\bBITMAP INDEX\\b", "INDEX");
|
||||
|
||||
// Functions
|
||||
s_pg.put("\\bSYSDATE\\b", "CURRENT_TIMESTAMP"); // alternative: NOW()
|
||||
//Bug fix, Gunther Hoppe 08.07.2005 e-evolution
|
||||
//Begin ----------------------------------------------------------------------------------------
|
||||
s_pg.put("\\bSysDate\\b", "CURRENT_TIMESTAMP");
|
||||
s_pg.put("SysDate", "CURRENT_TIMESTAMP");
|
||||
//end ----------------------------------------------------------------------------------------
|
||||
//begin vpj-cd e-evolution 03/11/2005 PostgreSQL
|
||||
s_pg.put("\\bDUMP\\b", "MD5");
|
||||
s_pg.put("END CASE", "END");
|
||||
s_pg.put("\\bgetDate()\\b", "CURRENT_TIMESTAMP"); // alternative: NOW()
|
||||
//end vpj-cd e-evolution 03/11/2005 PostgreSQL
|
||||
s_pg.put("\\bNVL\\b", "COALESCE");
|
||||
s_pg.put("\\bTO_DATE\\b", "TO_TIMESTAMP");
|
||||
//
|
||||
s_pg.put("\\bDBMS_OUTPUT.PUT_LINE\\b", "RAISE NOTICE");
|
||||
|
||||
// Temporary
|
||||
s_pg.put("\\bGLOBAL TEMPORARY\\b", "TEMPORARY");
|
||||
s_pg.put("\\bON COMMIT DELETE ROWS\\b", "");
|
||||
s_pg.put("\\bON COMMIT PRESERVE ROWS\\b", "");
|
||||
|
||||
//DDL
|
||||
|
||||
// begin vpj-cd e-evolution 08/02/2005 PostgreSQL
|
||||
//s_pg.put("\\bMODIFY\\b","ALTER COLUMN");
|
||||
//s_pg.put("\\bDEFAULT\\b","SET DEFAULT");
|
||||
// end vpj-cd e-evolution 08/02/2005 PostgreSQL
|
||||
|
||||
// DROP TABLE x CASCADE CONSTRAINTS
|
||||
s_pg.put("\\bCASCADE CONSTRAINTS\\b", "");
|
||||
|
||||
// Select
|
||||
s_pg.put("\\sFROM\\s+DUAL\\b", "");
|
||||
|
||||
// Statements
|
||||
s_pg.put("\\bELSIF\\b", "ELSE IF");
|
||||
// begin vpj-cd e-evolution 03/11/2005 PostgreSQL
|
||||
s_pg.put("\\bREC \\b", "AS REC ");
|
||||
//s_pg.put("\\bAND\\sROWNUM=\\b", "LIMIT ");
|
||||
// end vpj-cd e-evolution 03/11/2005 PostgreSQL
|
||||
|
||||
// Sequences
|
||||
s_pg.put("\\bSTART WITH\\b", "START");
|
||||
s_pg.put("\\bINCREMENT BY\\b", "INCREMENT");
|
||||
|
||||
} // initPostgreSQL
|
||||
|
||||
} // ConvertMap
|
|
@ -0,0 +1,524 @@
|
|||
/******************************************************************************
|
||||
* 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.dbPort;
|
||||
|
||||
import java.sql.*;
|
||||
import javax.sql.*;
|
||||
import oracle.jdbc.pool.*;
|
||||
|
||||
//import oracle.jdbc.rowset.*;
|
||||
|
||||
/**
|
||||
* JDBC Performance Test - Oracle
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: JdbcTest.java,v 1.2 2006/07/30 00:55:04 jjanke Exp $
|
||||
*/
|
||||
public class JdbcTest extends Thread
|
||||
{
|
||||
/*****************************************************************************
|
||||
|
||||
Multiple Connections Fetch=10 Conn=2032 Stmt=0 Query=47 Retrieve=2109 ClRs=0 ClStmt=0 ClConn=0 - Total=4188 Stmt=2156 Query=2156
|
||||
Multiple Connections Fetch=10 Conn=141 Stmt=0 Query=31 Retrieve=1875 ClRs=0 ClStmt=0 ClConn=0 - Total=2047 Stmt=1906 Query=1906
|
||||
Multiple Connections Fetch=10 Conn=141 Stmt=0 Query=31 Retrieve=1844 ClRs=0 ClStmt=0 ClConn=0 - Total=2016 Stmt=1875 Query=1875
|
||||
Data Source Fetch=10 Conn=172 Stmt=0 Query=16 Retrieve=1875 ClRs=0 ClStmt=0 ClConn=0 - Total=2063 Stmt=1891 Query=1891
|
||||
Data Source Fetch=10 Conn=672 Stmt=15 Query=16 Retrieve=1797 ClRs=0 ClStmt=0 ClConn=0 - Total=2500 Stmt=1828 Query=1813
|
||||
Data Source Fetch=10 Conn=156 Stmt=0 Query=16 Retrieve=1766 ClRs=0 ClStmt=0 ClConn=15 - Total=1953 Stmt=1782 Query=1782
|
||||
Connection Cache Fetch=10 Conn=141 Stmt=0 Query=125 Retrieve=1766 ClRs=0 ClStmt=0 ClConn=0 - Total=2032 Stmt=1891 Query=1891
|
||||
Connection Cache Fetch=10 Conn=0 Stmt=0 Query=15 Retrieve=1766 ClRs=0 ClStmt=0 ClConn=0 - Total=1781 Stmt=1781 Query=1781
|
||||
Connection Cache Fetch=10 Conn=0 Stmt=0 Query=16 Retrieve=1765 ClRs=0 ClStmt=0 ClConn=0 - Total=1781 Stmt=1781 Query=1781
|
||||
Multiple Connections Fetch=20 Conn=4501 Stmt=0 Query=15 Retrieve=1313 ClRs=0 ClStmt=0 ClConn=0 - Total=5829 Stmt=1328 Query=1328
|
||||
Multiple Connections Fetch=20 Conn=125 Stmt=0 Query=16 Retrieve=1312 ClRs=0 ClStmt=0 ClConn=0 - Total=1453 Stmt=1328 Query=1328
|
||||
Multiple Connections Fetch=20 Conn=141 Stmt=0 Query=31 Retrieve=1406 ClRs=0 ClStmt=0 ClConn=0 - Total=1578 Stmt=1437 Query=1437
|
||||
Data Source Fetch=20 Conn=126 Stmt=0 Query=31 Retrieve=1297 ClRs=0 ClStmt=0 ClConn=0 - Total=1454 Stmt=1328 Query=1328
|
||||
Data Source Fetch=20 Conn=125 Stmt=0 Query=16 Retrieve=1328 ClRs=0 ClStmt=0 ClConn=0 - Total=1469 Stmt=1344 Query=1344
|
||||
Data Source Fetch=20 Conn=140 Stmt=0 Query=16 Retrieve=1469 ClRs=0 ClStmt=0 ClConn=0 - Total=1625 Stmt=1485 Query=1485
|
||||
Connection Cache Fetch=20 Conn=0 Stmt=0 Query=31 Retrieve=1344 ClRs=0 ClStmt=0 ClConn=0 - Total=1375 Stmt=1375 Query=1375
|
||||
Connection Cache Fetch=20 Conn=0 Stmt=0 Query=16 Retrieve=1375 ClRs=0 ClStmt=0 ClConn=0 - Total=1391 Stmt=1391 Query=1391
|
||||
Connection Cache Fetch=20 Conn=0 Stmt=0 Query=15 Retrieve=1375 ClRs=0 ClStmt=0 ClConn=0 - Total=1390 Stmt=1390 Query=1390
|
||||
JDBC RowSet Fetch=10 Conn=16 Stmt=0 Query=3969 Retrieve=3047 ClRs=0 ClStmt=0 ClConn=0 - Total=7032 Stmt=7016 Query=7016
|
||||
JDBC RowSet Fetch=10 Conn=0 Stmt=0 Query=172 Retrieve=2781 ClRs=0 ClStmt=0 ClConn=0 - Total=2953 Stmt=2953 Query=2953
|
||||
JDBC RowSet Fetch=10 Conn=0 Stmt=0 Query=313 Retrieve=2609 ClRs=0 ClStmt=0 ClConn=0 - Total=2922 Stmt=2922 Query=2922
|
||||
Cached RowSet Fetch=10 Conn=63 Stmt=0 Query=5406 Retrieve=16 ClRs=0 ClStmt=0 ClConn=0 - Total=5485 Stmt=5422 Query=5422
|
||||
Cached RowSet Fetch=10 Conn=0 Stmt=0 Query=3907 Retrieve=0 ClRs=0 ClStmt=0 ClConn=0 - Total=3907 Stmt=3907 Query=3907
|
||||
Cached RowSet Fetch=10 Conn=0 Stmt=0 Query=3890 Retrieve=0 ClRs=0 ClStmt=0 ClConn=0 - Total=3890 Stmt=3890 Query=3890
|
||||
Shared Connection Threads=10 Yield=false ms= 18267 each= 1826
|
||||
Shared Connection Threads=10 Yield=false ms= 18220 each= 1822
|
||||
Shared Connection Threads=10 Yield=true ms= 18329 each= 1832
|
||||
Shared Connection Threads=10 Yield=true ms= 18314 each= 1831
|
||||
Multiple Connections Threads=10 Yield=false ms= 14610 each= 1461
|
||||
Multiple Connections Threads=10 Yield=false ms= 14360 each= 1436
|
||||
Multiple Connections Threads=10 Yield=true ms= 13986 each= 1398
|
||||
Multiple Connections Threads=10 Yield=true ms= 14017 each= 1401
|
||||
Multiple PreCreated Threads=10 Yield=false ms= 5376 each= 537
|
||||
Multiple PreCreated Threads=10 Yield=false ms= 1828 each= 182
|
||||
Multiple PreCreated Threads=10 Yield=true ms= 12017 each= 1201
|
||||
Multiple PreCreated Threads=10 Yield=true ms= 12032 each= 1203
|
||||
Data Source Threads=10 Yield=false ms= 13391 each= 1339
|
||||
Data Source Threads=10 Yield=false ms= 13532 each= 1353
|
||||
Data Source Threads=10 Yield=true ms= 13923 each= 1392
|
||||
Data Source Threads=10 Yield=true ms= 13829 each= 1382
|
||||
Connection Cache Threads=10 Yield=false ms= 12907 each= 1290 CacheSize=2, Active=0
|
||||
Connection Cache Threads=10 Yield=false ms= 12907 each= 1290 CacheSize=2, Active=0
|
||||
Connection Cache Threads=10 Yield=true ms= 12813 each= 1281 CacheSize=2, Active=0
|
||||
Connection Cache Threads=10 Yield=true ms= 12813 each= 1281 CacheSize=2, Active=0
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
// Default no of threads to 10
|
||||
private static final int NUM_OF_THREADS = 10;
|
||||
|
||||
private static final String DRIVER =
|
||||
// "oci8";
|
||||
"thin";
|
||||
|
||||
private static final String CONNECTION =
|
||||
// "jdbc:oracle:oci8:@";
|
||||
// "jdbc:oracle:oci8:@dev1";
|
||||
"jdbc:oracle:thin:@//dev:1521/dev1";
|
||||
|
||||
|
||||
private static final String UID = "adempiere";
|
||||
private static final String PWD = "adempiere";
|
||||
private static final String STATEMENT = "SELECT * FROM AD_Column";
|
||||
private static final boolean WITH_OUTPUT = false;
|
||||
|
||||
private static boolean s_do_yield = true;
|
||||
|
||||
private static Connection s_sconn = null;
|
||||
private static Connection[] s_conn = null;
|
||||
private static OracleDataSource s_ds = null;
|
||||
// private static OracleConnectionCacheImpl s_cc = null;
|
||||
|
||||
private static int s_fetchSize = 10;
|
||||
|
||||
// Connection
|
||||
private static int s_cType = 0;
|
||||
private static final String[] C_INFO = {
|
||||
"Shared Connection ",
|
||||
"Multiple Connections ",
|
||||
"Multiple PreCreated ",
|
||||
"Data Source ",
|
||||
"Connection Cache "};
|
||||
private static final int C_SHARED = 0;
|
||||
private static final int C_MULTIPLE = 1;
|
||||
private static final int C_PRECREATED = 2;
|
||||
private static final int C_DATASOURCE = 3;
|
||||
private static final int C_CACHE = 4;
|
||||
|
||||
// Data
|
||||
private static int s_rType = 0;
|
||||
private static final String[] R_INFO = {
|
||||
"ResultSet ",
|
||||
"Cached RowSet ",
|
||||
"JDBC RowSet "};
|
||||
private static final int R_RESULTSET = 0;
|
||||
private static final int R_CACHED_ROWSET = 1;
|
||||
private static final int R_JDBC_ROWSET = 2;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Main Test Start
|
||||
* @param args
|
||||
*/
|
||||
public static void main (String args [])
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Load the JDBC driver */
|
||||
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
|
||||
|
||||
s_ds = new OracleDataSource();
|
||||
s_ds.setDriverType(DRIVER);
|
||||
s_ds.setServerName("dev");
|
||||
s_ds.setNetworkProtocol("tcp");
|
||||
s_ds.setDatabaseName("dev1");
|
||||
s_ds.setPortNumber(1521);
|
||||
s_ds.setUser("adempiere");
|
||||
s_ds.setPassword("adempiere");
|
||||
/*
|
||||
s_cc = new OracleConnectionCacheImpl();
|
||||
s_cc.setDriverType(DRIVER);
|
||||
s_cc.setServerName("dev");
|
||||
s_cc.setNetworkProtocol("tcp");
|
||||
s_cc.setDatabaseName("dev1");
|
||||
s_cc.setPortNumber(1521);
|
||||
s_cc.setUser("adempiere");
|
||||
s_cc.setPassword("adempiere");
|
||||
s_cc.setMaxLimit(NUM_OF_THREADS/4);
|
||||
s_cc.setCacheScheme(OracleConnectionCacheImpl.FIXED_WAIT_SCHEME);
|
||||
// s_cc.setCacheScheme(OracleConnectionCacheImpl.DYNAMIC_SCHEME);
|
||||
*/
|
||||
|
||||
s_fetchSize = 10;
|
||||
s_cType = C_MULTIPLE;
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
s_cType = C_DATASOURCE;
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
s_cType = C_CACHE;
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
s_fetchSize = 20;
|
||||
s_cType = C_MULTIPLE;
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
s_cType = C_DATASOURCE;
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
s_cType = C_CACHE;
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
//
|
||||
s_fetchSize = 10; // standard value
|
||||
/**
|
||||
s_rType = R_JDBC_ROWSET;
|
||||
rowSetTiming();
|
||||
rowSetTiming();
|
||||
rowSetTiming();
|
||||
s_rType = R_CACHED_ROWSET;
|
||||
rowSetTiming();
|
||||
rowSetTiming();
|
||||
rowSetTiming();
|
||||
**/
|
||||
//
|
||||
s_cType = C_SHARED;
|
||||
s_do_yield = false;
|
||||
runTest();
|
||||
runTest();
|
||||
s_do_yield = true;
|
||||
runTest();
|
||||
runTest();
|
||||
//
|
||||
s_cType = C_MULTIPLE;
|
||||
s_do_yield = false;
|
||||
runTest();
|
||||
runTest();
|
||||
s_do_yield = true;
|
||||
runTest();
|
||||
runTest();
|
||||
//
|
||||
s_cType = C_PRECREATED;
|
||||
s_do_yield = false;
|
||||
runTest();
|
||||
runTest();
|
||||
s_do_yield = true;
|
||||
runTest();
|
||||
runTest();
|
||||
//
|
||||
s_cType = C_DATASOURCE;
|
||||
s_do_yield = false;
|
||||
runTest();
|
||||
runTest();
|
||||
s_do_yield = true;
|
||||
runTest();
|
||||
runTest();
|
||||
//
|
||||
s_cType = C_CACHE;
|
||||
s_do_yield = false;
|
||||
runTest();
|
||||
runTest();
|
||||
s_do_yield = true;
|
||||
runTest();
|
||||
runTest();
|
||||
//
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
} // main
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Run the test
|
||||
* @throws Exception
|
||||
*/
|
||||
static void runTest() throws Exception
|
||||
{
|
||||
// Create the threads
|
||||
Thread[] threadList = new Thread[NUM_OF_THREADS];
|
||||
s_conn = new Connection[NUM_OF_THREADS];
|
||||
|
||||
if (s_cType == C_SHARED)
|
||||
s_sconn = DriverManager.getConnection (CONNECTION, UID, PWD);
|
||||
//
|
||||
// spawn threads
|
||||
for (int i = 0; i < NUM_OF_THREADS; i++)
|
||||
{
|
||||
if (s_cType == C_PRECREATED)
|
||||
s_conn[i] = DriverManager.getConnection (CONNECTION, UID, PWD);
|
||||
//
|
||||
threadList[i] = new JdbcTest(i);
|
||||
threadList[i].start();
|
||||
}
|
||||
// Start everyone at the same time
|
||||
long start = System.currentTimeMillis();
|
||||
setGreenLight ();
|
||||
// wait for all threads to end
|
||||
for (int i = 0; i < NUM_OF_THREADS; i++)
|
||||
threadList[i].join();
|
||||
//
|
||||
if (s_sconn != null)
|
||||
s_sconn.close();
|
||||
s_sconn = null;
|
||||
for (int i = 0; i < NUM_OF_THREADS; i++)
|
||||
{
|
||||
if (s_conn[i] != null)
|
||||
s_conn[i].close();
|
||||
s_conn[i] = null;
|
||||
}
|
||||
long result = System.currentTimeMillis() - start;
|
||||
System.out.print (C_INFO[s_cType]
|
||||
+ "Threads=" + NUM_OF_THREADS
|
||||
+ " \tYield=" + s_do_yield
|
||||
+ " \tms= " + result
|
||||
+ " \teach= " + (result/NUM_OF_THREADS));
|
||||
// if (s_cType == C_CACHE)
|
||||
// System.out.print (" \tCacheSize=" + s_cc.getCacheSize() + ", Active=" + s_cc.getActiveSize());
|
||||
System.out.println();
|
||||
} // runTest
|
||||
|
||||
|
||||
/**
|
||||
* Statement Timing
|
||||
*/
|
||||
private static void statementTiming()
|
||||
{
|
||||
try
|
||||
{
|
||||
long startConnection = System.currentTimeMillis();
|
||||
Connection conn = null;
|
||||
if (s_cType == C_MULTIPLE)
|
||||
conn = DriverManager.getConnection (CONNECTION, UID, PWD);
|
||||
if (s_cType == C_DATASOURCE)
|
||||
conn = s_ds.getConnection();
|
||||
// if (s_cType == C_CACHE)
|
||||
// conn = s_cc.getConnection();
|
||||
|
||||
long startStatement = System.currentTimeMillis();
|
||||
Statement stmt = conn.createStatement ();
|
||||
stmt.setFetchSize(s_fetchSize);
|
||||
|
||||
long startQuery = System.currentTimeMillis();
|
||||
ResultSet rs = stmt.executeQuery (STATEMENT);
|
||||
|
||||
int i = 0;
|
||||
long startRetrieve = System.currentTimeMillis();
|
||||
while (rs.next())
|
||||
{
|
||||
rs.getString(1);
|
||||
i++;
|
||||
}
|
||||
long endRetrieve = System.currentTimeMillis();
|
||||
// System.out.println(i);
|
||||
|
||||
rs.close();
|
||||
rs = null;
|
||||
long endQuery = System.currentTimeMillis();
|
||||
|
||||
stmt.close();
|
||||
stmt = null;
|
||||
long endStatement = System.currentTimeMillis();
|
||||
|
||||
conn.close();
|
||||
conn = null;
|
||||
long endConnection = System.currentTimeMillis();
|
||||
|
||||
//
|
||||
System.out.println(C_INFO[s_cType]
|
||||
+ "Fetch=" + s_fetchSize
|
||||
+ " \tConn=" + (startStatement - startConnection)
|
||||
+ " \tStmt=" + (startQuery - startStatement)
|
||||
+ " \tQuery=" + (startRetrieve - startQuery)
|
||||
+ " \tRetrieve=" + (endRetrieve - startRetrieve)
|
||||
+ " \tClRs=" + (endQuery - endRetrieve)
|
||||
+ " \tClStmt=" + (endStatement - endQuery)
|
||||
+ " \tClConn=" + (endConnection - endStatement)
|
||||
+ " \t- Total=" + (endConnection - startConnection)
|
||||
+ " \tStmt=" + (endStatement - startStatement)
|
||||
+ " \tQuery=" + (endQuery - startQuery));
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
} // statementTiming
|
||||
|
||||
/**
|
||||
* Row Set Timing
|
||||
*/
|
||||
private static void rowSetTiming()
|
||||
{
|
||||
try
|
||||
{
|
||||
long startConnection = System.currentTimeMillis();
|
||||
RowSet rowset = null;
|
||||
/**
|
||||
if (s_rType == R_JDBC_ROWSET)
|
||||
rowset = new OracleJDBCRowSet ();
|
||||
else if (s_rType == R_CACHED_ROWSET)
|
||||
rowset = new OracleCachedRowSet();
|
||||
**/
|
||||
rowset.setUrl (CONNECTION);
|
||||
rowset.setUsername (UID);
|
||||
rowset.setPassword (PWD);
|
||||
rowset.setFetchSize(s_fetchSize);
|
||||
|
||||
long startStatement = System.currentTimeMillis();
|
||||
rowset.setCommand (STATEMENT);
|
||||
|
||||
long startQuery = System.currentTimeMillis();
|
||||
rowset.execute ();
|
||||
|
||||
long startRetrieve = System.currentTimeMillis();
|
||||
while (rowset.next ())
|
||||
{
|
||||
}
|
||||
long endRetrieve = System.currentTimeMillis();
|
||||
long endQuery = System.currentTimeMillis();
|
||||
|
||||
rowset.close();
|
||||
long endStatement = System.currentTimeMillis();
|
||||
long endConnection = System.currentTimeMillis();
|
||||
//
|
||||
System.out.println(R_INFO[s_rType]
|
||||
+ "Fetch=" + s_fetchSize
|
||||
+ " \tConn=" + (startStatement - startConnection)
|
||||
+ " \tStmt=" + (startQuery - startStatement)
|
||||
+ " \tQuery=" + (startRetrieve - startQuery)
|
||||
+ " \tRetrieve=" + (endRetrieve - startRetrieve)
|
||||
+ " \tClRs=" + (endQuery - endRetrieve)
|
||||
+ " \tClStmt=" + (endStatement - endQuery)
|
||||
+ " \tClConn=" + (endConnection - endStatement)
|
||||
+ " \t- Total=" + (endConnection - startConnection)
|
||||
+ " \tStmt=" + (endStatement - startStatement)
|
||||
+ " \tQuery=" + (endQuery - startQuery));
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
} // rowSetTiming
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* JDBC Test
|
||||
* @param id Thread ID
|
||||
*/
|
||||
public JdbcTest(int id)
|
||||
{
|
||||
super();
|
||||
m_myId = id;
|
||||
} // JdbcTest
|
||||
|
||||
private int m_myId = 0;
|
||||
|
||||
/**
|
||||
* Async Worker
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
ResultSet rs = null;
|
||||
Statement stmt = null;
|
||||
|
||||
try
|
||||
{
|
||||
while (!getGreenLight())
|
||||
yield();
|
||||
if (WITH_OUTPUT)
|
||||
System.out.println("Thread " + m_myId + " started");
|
||||
|
||||
// Get the connection & statement
|
||||
if (s_cType == C_SHARED)
|
||||
stmt = s_sconn.createStatement ();
|
||||
else if (s_cType == C_MULTIPLE)
|
||||
{
|
||||
s_conn[m_myId] = DriverManager.getConnection (CONNECTION, UID, PWD);
|
||||
stmt = s_conn[m_myId].createStatement ();
|
||||
}
|
||||
else if (s_cType == C_PRECREATED)
|
||||
{
|
||||
stmt = s_conn[m_myId].createStatement ();
|
||||
}
|
||||
else if (s_cType == C_DATASOURCE)
|
||||
{
|
||||
s_conn[m_myId] = s_ds.getConnection();
|
||||
stmt = s_conn[m_myId].createStatement ();
|
||||
}
|
||||
// else if (s_cType == C_CACHE)
|
||||
// {
|
||||
// s_conn[m_myId] = s_cc.getConnection();
|
||||
// stmt = s_conn[m_myId].createStatement ();
|
||||
// }
|
||||
stmt.setFetchSize(s_fetchSize);
|
||||
|
||||
// Execute the Query
|
||||
rs = stmt.executeQuery (STATEMENT);
|
||||
|
||||
// Loop through the results
|
||||
while (rs.next())
|
||||
{
|
||||
if (s_do_yield)
|
||||
yield(); // Yield To other threads
|
||||
}
|
||||
|
||||
// Close all the resources
|
||||
rs.close();
|
||||
rs = null;
|
||||
|
||||
// Close the statement
|
||||
stmt.close();
|
||||
stmt = null;
|
||||
|
||||
// Close the local connection
|
||||
if (s_cType == C_SHARED || s_cType == C_PRECREATED)
|
||||
;
|
||||
else
|
||||
{
|
||||
s_conn[m_myId].close();
|
||||
s_conn[m_myId] = null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Thread " + m_myId + " got Exception: " + e);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (WITH_OUTPUT)
|
||||
System.out.println("Thread " + m_myId + " finished");
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
static boolean greenLight = false;
|
||||
static synchronized void setGreenLight () { greenLight = true; }
|
||||
synchronized boolean getGreenLight () { return greenLight; }
|
||||
|
||||
} // JdbcTest
|
|
@ -0,0 +1,346 @@
|
|||
/******************************************************************************
|
||||
* 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): ______________________________________.
|
||||
*****************************************************************************/
|
||||
package org.compiere.dbPort;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* JDBC Performance Test.
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: JdbcTestPG.java,v 1.4 2005/03/11 20:29:03 jjanke Exp $
|
||||
*/
|
||||
public class JdbcTestPG extends Thread
|
||||
{
|
||||
/*****************************************************************************
|
||||
|
||||
Multiple Connections Fetch=10 Conn=407 Stmt=15 Query=1516 Retrieve=203 ClRs=0 ClStmt=0 ClConn=0 - Total=2141 Stmt=1734 Query=1719
|
||||
Multiple Connections Fetch=10 Conn=47 Stmt=0 Query=1234 Retrieve=31 ClRs=0 ClStmt=0 ClConn=0 - Total=1312 Stmt=1265 Query=1265
|
||||
Multiple Connections Fetch=10 Conn=31 Stmt=0 Query=1266 Retrieve=15 ClRs=0 ClStmt=0 ClConn=0 - Total=1312 Stmt=1281 Query=1281
|
||||
Shared Connection Threads=10 Yield=false ms= 13047 each= 1304
|
||||
Shared Connection Threads=10 Yield=false ms= 12891 each= 1289
|
||||
Shared Connection Threads=10 Yield=true ms= 13422 each= 1342
|
||||
Shared Connection Threads=10 Yield=true ms= 12969 each= 1296
|
||||
Multiple Connections Threads=10 Yield=false ms= 13046 each= 1304
|
||||
Multiple Connections Threads=10 Yield=false ms= 12891 each= 1289
|
||||
Multiple Connections Threads=10 Yield=true ms= 13062 each= 1306
|
||||
Multiple Connections Threads=10 Yield=true ms= 13062 each= 1306
|
||||
Multiple PreCreated Threads=10 Yield=false ms= 9968 each= 996
|
||||
Multiple PreCreated Threads=10 Yield=false ms= 10250 each= 1025
|
||||
Multiple PreCreated Threads=10 Yield=true ms= 10109 each= 1010
|
||||
Multiple PreCreated Threads=10 Yield=true ms= 9906 each= 990
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
// Default no of threads to 10
|
||||
private static final int NUM_OF_THREADS = 10;
|
||||
|
||||
private static final String CONNECTION =
|
||||
"jdbc:postgresql://linux:5432/compiere";
|
||||
|
||||
private static final String UID = "compiere";
|
||||
private static final String PWD = "compiere";
|
||||
private static final String STATEMENT = "SELECT * FROM AD_Column";
|
||||
private static final boolean WITH_OUTPUT = false;
|
||||
|
||||
private static boolean s_do_yield = true;
|
||||
|
||||
private static Connection s_sconn = null;
|
||||
private static Connection[] s_conn = null;
|
||||
|
||||
private static int s_fetchSize = 10;
|
||||
|
||||
// Connection
|
||||
private static int s_cType = 0;
|
||||
private static final String[] C_INFO = {
|
||||
"Shared Connection ",
|
||||
"Multiple Connections ",
|
||||
"Multiple PreCreated ",
|
||||
// "Data Source ",
|
||||
// "Connection Cache "
|
||||
};
|
||||
private static final int C_SHARED = 0;
|
||||
private static final int C_MULTIPLE = 1;
|
||||
private static final int C_PRECREATED = 2;
|
||||
// private static final int C_DATASOURCE = 3;
|
||||
// private static final int C_CACHE = 4;
|
||||
|
||||
// Data
|
||||
private static int s_rType = 0;
|
||||
private static final String[] R_INFO = {
|
||||
"ResultSet ",
|
||||
// "Cached RowSet ",
|
||||
// "JDBC RowSet "
|
||||
};
|
||||
private static final int R_RESULTSET = 0;
|
||||
// private static final int R_CACHED_ROWSET = 1;
|
||||
// private static final int R_JDBC_ROWSET = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Main Test
|
||||
* @param args
|
||||
*/
|
||||
public static void main (String args [])
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Load the JDBC driver */
|
||||
DriverManager.registerDriver(new org.postgresql.Driver());
|
||||
|
||||
s_cType = C_MULTIPLE;
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
statementTiming();
|
||||
//
|
||||
s_fetchSize = 10; // standard value
|
||||
|
||||
//
|
||||
s_cType = C_SHARED;
|
||||
s_do_yield = false;
|
||||
runTest();
|
||||
runTest();
|
||||
s_do_yield = true;
|
||||
runTest();
|
||||
runTest();
|
||||
//
|
||||
s_cType = C_MULTIPLE;
|
||||
s_do_yield = false;
|
||||
runTest();
|
||||
runTest();
|
||||
s_do_yield = true;
|
||||
runTest();
|
||||
runTest();
|
||||
//
|
||||
s_cType = C_PRECREATED;
|
||||
s_do_yield = false;
|
||||
runTest();
|
||||
runTest();
|
||||
s_do_yield = true;
|
||||
runTest();
|
||||
runTest();
|
||||
//
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
} // main
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Run the test
|
||||
* @throws Exception
|
||||
*/
|
||||
static void runTest() throws Exception
|
||||
{
|
||||
// Create the threads
|
||||
Thread[] threadList = new Thread[NUM_OF_THREADS];
|
||||
s_conn = new Connection[NUM_OF_THREADS];
|
||||
|
||||
if (s_cType == C_SHARED)
|
||||
s_sconn = DriverManager.getConnection (CONNECTION, UID, PWD);
|
||||
//
|
||||
// spawn threads
|
||||
for (int i = 0; i < NUM_OF_THREADS; i++)
|
||||
{
|
||||
if (WITH_OUTPUT)
|
||||
System.out.println("Starting #" + i);
|
||||
if (s_cType == C_PRECREATED)
|
||||
s_conn[i] = DriverManager.getConnection (CONNECTION, UID, PWD);
|
||||
//
|
||||
threadList[i] = new JdbcTestPG(i);
|
||||
threadList[i].start();
|
||||
}
|
||||
|
||||
// Start everyone at the same time
|
||||
long start = System.currentTimeMillis();
|
||||
setGreenLight ();
|
||||
|
||||
// wait for all threads to end
|
||||
for (int i = 0; i < NUM_OF_THREADS; i++)
|
||||
threadList[i].join();
|
||||
//
|
||||
if (s_sconn != null)
|
||||
s_sconn.close();
|
||||
s_sconn = null;
|
||||
for (int i = 0; i < NUM_OF_THREADS; i++)
|
||||
{
|
||||
if (s_conn[i] != null)
|
||||
s_conn[i].close();
|
||||
s_conn[i] = null;
|
||||
}
|
||||
long result = System.currentTimeMillis() - start;
|
||||
System.out.print (C_INFO[s_cType]
|
||||
+ "Threads=" + NUM_OF_THREADS
|
||||
+ " \tYield=" + s_do_yield
|
||||
+ " \tms= " + result
|
||||
+ " \teach= " + (result/NUM_OF_THREADS));
|
||||
System.out.println();
|
||||
} // runTest
|
||||
|
||||
|
||||
/**
|
||||
* Statement Timing
|
||||
*/
|
||||
private static void statementTiming()
|
||||
{
|
||||
try
|
||||
{
|
||||
long startConnection = System.currentTimeMillis();
|
||||
Connection conn = null;
|
||||
if (s_cType == C_MULTIPLE)
|
||||
conn = DriverManager.getConnection (CONNECTION, UID, PWD);
|
||||
|
||||
long startStatement = System.currentTimeMillis();
|
||||
Statement stmt = conn.createStatement ();
|
||||
// stmt.setFetchSize(s_fetchSize);
|
||||
|
||||
long startQuery = System.currentTimeMillis();
|
||||
ResultSet rs = stmt.executeQuery (STATEMENT);
|
||||
|
||||
int i = 0;
|
||||
long startRetrieve = System.currentTimeMillis();
|
||||
while (rs.next())
|
||||
{
|
||||
rs.getString(1);
|
||||
i++;
|
||||
}
|
||||
long endRetrieve = System.currentTimeMillis();
|
||||
// System.out.println(i);
|
||||
|
||||
rs.close();
|
||||
rs = null;
|
||||
long endQuery = System.currentTimeMillis();
|
||||
|
||||
stmt.close();
|
||||
stmt = null;
|
||||
long endStatement = System.currentTimeMillis();
|
||||
|
||||
conn.close();
|
||||
conn = null;
|
||||
long endConnection = System.currentTimeMillis();
|
||||
|
||||
//
|
||||
System.out.println(C_INFO[s_cType]
|
||||
+ "Fetch=" + s_fetchSize
|
||||
+ " \tConn=" + (startStatement - startConnection)
|
||||
+ " \tStmt=" + (startQuery - startStatement)
|
||||
+ " \tQuery=" + (startRetrieve - startQuery)
|
||||
+ " \tRetrieve=" + (endRetrieve - startRetrieve)
|
||||
+ " \tClRs=" + (endQuery - endRetrieve)
|
||||
+ " \tClStmt=" + (endStatement - endQuery)
|
||||
+ " \tClConn=" + (endConnection - endStatement)
|
||||
+ " \t- Total=" + (endConnection - startConnection)
|
||||
+ " \tStmt=" + (endStatement - startStatement)
|
||||
+ " \tQuery=" + (endQuery - startQuery));
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
} // statementTiming
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* JdbcTest Thread
|
||||
* @param id Thread ID
|
||||
*/
|
||||
public JdbcTestPG (int id)
|
||||
{
|
||||
super();
|
||||
m_myId = id;
|
||||
}
|
||||
|
||||
private int m_myId = 0;
|
||||
|
||||
/**
|
||||
* Async Worker
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
ResultSet rs = null;
|
||||
Statement stmt = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (WITH_OUTPUT)
|
||||
System.out.println("Thread " + m_myId + " waiting");
|
||||
while (!getGreenLight())
|
||||
yield();
|
||||
if (WITH_OUTPUT)
|
||||
System.out.println("Thread " + m_myId + " started");
|
||||
|
||||
// Get the connection & statement
|
||||
if (s_cType == C_SHARED)
|
||||
stmt = s_sconn.createStatement ();
|
||||
else if (s_cType == C_MULTIPLE)
|
||||
{
|
||||
s_conn[m_myId] = DriverManager.getConnection (CONNECTION, UID, PWD);
|
||||
stmt = s_conn[m_myId].createStatement ();
|
||||
}
|
||||
else if (s_cType == C_PRECREATED)
|
||||
{
|
||||
stmt = s_conn[m_myId].createStatement ();
|
||||
}
|
||||
// stmt.setFetchSize(s_fetchSize);
|
||||
|
||||
// Execute the Query
|
||||
rs = stmt.executeQuery (STATEMENT);
|
||||
|
||||
// Loop through the results
|
||||
while (rs.next())
|
||||
{
|
||||
if (s_do_yield)
|
||||
yield(); // Yield To other threads
|
||||
}
|
||||
|
||||
// Close all the resources
|
||||
rs.close();
|
||||
rs = null;
|
||||
|
||||
// Close the statement
|
||||
stmt.close();
|
||||
stmt = null;
|
||||
|
||||
// Close the local connection
|
||||
if (s_cType == C_SHARED || s_cType == C_PRECREATED)
|
||||
;
|
||||
else
|
||||
{
|
||||
s_conn[m_myId].close();
|
||||
s_conn[m_myId] = null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Thread " + m_myId + " got Exception: " + e);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (WITH_OUTPUT)
|
||||
System.out.println("Thread " + m_myId + " finished");
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
static boolean greenLight = false;
|
||||
static synchronized void setGreenLight () { greenLight = true; }
|
||||
synchronized boolean getGreenLight () { return greenLight; }
|
||||
|
||||
} // JdbcTestPG
|
|
@ -0,0 +1,211 @@
|
|||
/******************************************************************************
|
||||
* 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.dbPort;
|
||||
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Join Clause.
|
||||
* <pre>
|
||||
* f.AD_Column_ID = c.AD_Column_ID(+)
|
||||
* </pre>
|
||||
* @author Jorg Janke
|
||||
* @version $Id: Join.java,v 1.2 2006/07/30 00:55:04 jjanke Exp $
|
||||
*/
|
||||
public class Join
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param joinClause
|
||||
*/
|
||||
public Join (String joinClause)
|
||||
{
|
||||
if (joinClause == null)
|
||||
throw new IllegalArgumentException("Join - clause cannot be null");
|
||||
evaluate (joinClause);
|
||||
} // Join
|
||||
|
||||
private String m_joinClause;
|
||||
private String m_mainTable;
|
||||
private String m_mainAlias;
|
||||
private String m_joinTable;
|
||||
private String m_joinAlias;
|
||||
private boolean m_left;
|
||||
private String m_condition;
|
||||
|
||||
/**
|
||||
* Evaluate the clause.
|
||||
* e.g. tb.AD_User_ID(+)=?
|
||||
* f.AD_Column_ID = c.AD_Column_ID(+)
|
||||
* @param joinClause
|
||||
*/
|
||||
private void evaluate (String joinClause)
|
||||
{
|
||||
m_joinClause = joinClause;
|
||||
int indexEqual = joinClause.indexOf('=');
|
||||
m_left = indexEqual < joinClause.indexOf("(+)"); // converts to LEFT if true
|
||||
// get table alias of it
|
||||
if (m_left) // f.AD_Column_ID = c.AD_Column_ID(+) => f / c
|
||||
{
|
||||
m_mainAlias = joinClause.substring
|
||||
(0, Util.findIndexOf(joinClause, '.','=')).trim(); // f
|
||||
int end = joinClause.indexOf('.', indexEqual);
|
||||
if (end == -1) // no alias
|
||||
end = joinClause.indexOf('(', indexEqual);
|
||||
m_joinAlias = joinClause.substring(indexEqual+1, end).trim(); // c
|
||||
}
|
||||
else // f.AD_Column_ID(+) = c.AD_Column_ID => c / f
|
||||
{
|
||||
int end = joinClause.indexOf('.', indexEqual);
|
||||
if (end == -1) // no alias
|
||||
end = joinClause.length();
|
||||
m_mainAlias = joinClause.substring(indexEqual+1, end).trim(); // c
|
||||
m_joinAlias = joinClause.substring
|
||||
(0, Util.findIndexOf(joinClause, '.','(')).trim(); // f
|
||||
}
|
||||
m_condition = Util.replace(joinClause, "(+)", "").trim();
|
||||
} // evaluate
|
||||
|
||||
/**
|
||||
* Get origial Join Clause.
|
||||
* e.g. f.AD_Column_ID = c.AD_Column_ID(+)
|
||||
* @return Join cluase
|
||||
*/
|
||||
public String getJoinClause()
|
||||
{
|
||||
return m_joinClause;
|
||||
} // getJoinClause
|
||||
|
||||
/**
|
||||
* Get Main Table Alias
|
||||
* @return Main Table Alias
|
||||
*/
|
||||
public String getMainAlias()
|
||||
{
|
||||
return m_mainAlias;
|
||||
} // getMainAlias
|
||||
|
||||
/**
|
||||
* Get Join Table Alias
|
||||
* @return Join Table Alias
|
||||
*/
|
||||
public String getJoinAlias()
|
||||
{
|
||||
return m_joinAlias;
|
||||
} // getJoinAlias
|
||||
|
||||
/**
|
||||
* Is Left Aouter Join
|
||||
* @return true if left outer join
|
||||
*/
|
||||
public boolean isLeft()
|
||||
{
|
||||
return m_left;
|
||||
} // isLeft
|
||||
|
||||
/**
|
||||
* Get Join condition.
|
||||
* e.g. f.AD_Column_ID = c.AD_Column_ID
|
||||
* @return join condition
|
||||
*/
|
||||
public String getCondition()
|
||||
{
|
||||
return m_condition;
|
||||
} // getCondition
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Set Main Table Name.
|
||||
* If table name equals alias, the alias is set to ""
|
||||
* @param mainTable
|
||||
*/
|
||||
public void setMainTable(String mainTable)
|
||||
{
|
||||
if (mainTable == null || mainTable.length() == 0)
|
||||
return;
|
||||
m_mainTable = mainTable;
|
||||
if (m_mainAlias.equals(mainTable))
|
||||
m_mainAlias = "";
|
||||
} // setMainTable
|
||||
|
||||
/**
|
||||
* Get Main Table Name
|
||||
* @return Main Table Name
|
||||
*/
|
||||
public String getMainTable()
|
||||
{
|
||||
return m_mainTable;
|
||||
} // getMainTable
|
||||
|
||||
/**
|
||||
* Set Main Table Name.
|
||||
* If table name equals alias, the alias is set to ""
|
||||
* @param joinTable
|
||||
*/
|
||||
public void setJoinTable(String joinTable)
|
||||
{
|
||||
if (joinTable == null || joinTable.length() == 0)
|
||||
return;
|
||||
m_joinTable = joinTable;
|
||||
if (m_joinAlias.equals(joinTable))
|
||||
m_joinAlias = "";
|
||||
} // setJoinTable
|
||||
|
||||
/**
|
||||
* Get Join Table Name
|
||||
* @return Join Table Name
|
||||
*/
|
||||
public String getJoinTable()
|
||||
{
|
||||
return m_joinTable;
|
||||
} // getJoinTable
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This Join is a condition of the first Join.
|
||||
* e.g. tb.AD_User_ID(+)=? or tb.AD_User_ID(+)='123'
|
||||
* @param first
|
||||
* @return true if condition
|
||||
*/
|
||||
public boolean isConditionOf (Join first)
|
||||
{
|
||||
if (m_mainTable == null // did not find Table from "Alias"
|
||||
&& (first.getJoinTable().equals(m_joinTable) // same join table
|
||||
|| first.getMainAlias().equals(m_joinTable))) // same main table
|
||||
return true;
|
||||
return false;
|
||||
} // isConditionOf
|
||||
|
||||
/**
|
||||
* String representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("Join[");
|
||||
sb.append(m_joinClause)
|
||||
.append(" - Main=").append(m_mainTable).append("/").append(m_mainAlias)
|
||||
.append(", Join=").append(m_joinTable).append("/").append(m_joinAlias)
|
||||
.append(", Left=").append(m_left)
|
||||
.append(", Condition=").append(m_condition)
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
} // Join
|
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
|
||||
$Id: package.html,v 1.1 2006/04/21 17:53:31 jjanke Exp $
|
||||
|
||||
Copyright 1999-2002 Jorg Janke, Inc.
|
||||
40 Old Tannery Rd, Monroe, CT 06468, U.S.A.
|
||||
All Rights Reserved.
|
||||
|
||||
-->
|
||||
</head>
|
||||
<body>
|
||||
Provides for conversion of SQL commands from Oracle to other databases.
|
||||
<h2>Package Specification</h2>
|
||||
|
||||
<ul>
|
||||
<li>The Oracle Source code statements need to be delimited by "/"
|
||||
<li>Details of mapping see class ConvertMap
|
||||
<li><a href="http://www.adempiere.org">http://www.adempiere.org</a>
|
||||
</ul>
|
||||
|
||||
<h2>Related Documentation</h2>
|
||||
|
||||
For overviews, tutorials, examples, guides, and tool documentation, please see:
|
||||
<ul>
|
||||
<li><a href="http://www.adempiere.org">http://www.adempiere.org</a>
|
||||
</ul>
|
||||
|
||||
<!-- Put @see and @since tags down here. -->
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,81 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Adempiere Public License</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
<h1>ADEMPIERE PUBLIC LICENSE</h1>
|
||||
<b>Version 1.2</b>
|
||||
<p>Contact <a href="mailto:info@adempiere.org">info@adempiere.org</a> for licensing alternatives. </p>
|
||||
<H1>GNU General Public License</H1>
|
||||
<P>Version 2, June 1991 </P>
|
||||
<PRE>Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
</PRE>
|
||||
</center>
|
||||
<H2 align="center">Preamble</H2>
|
||||
<P>The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. </P>
|
||||
<P>When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. </P>
|
||||
<P>To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. </P>
|
||||
<P>For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. </P>
|
||||
<P>We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. </P>
|
||||
<P>Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. </P>
|
||||
<P>Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. </P>
|
||||
<P>The precise terms and conditions for copying, distribution and modification follow. </P>
|
||||
<H2 align="center">TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION</H2>
|
||||
<P><STRONG>0.</STRONG> This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
|
||||
<P>Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
|
||||
<P><STRONG>1.</STRONG> You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
|
||||
<P>You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
||||
<P><STRONG>2.</STRONG> You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
||||
<P>
|
||||
<div>
|
||||
<UL>
|
||||
<LI><STRONG>a)</STRONG> You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
|
||||
<LI>
|
||||
<STRONG>b)</STRONG> You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
|
||||
<LI>
|
||||
<STRONG>c)</STRONG> If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
|
||||
</UL>
|
||||
</div>
|
||||
<div>These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. </div>
|
||||
<P>Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
|
||||
<P>In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
||||
<P><STRONG>3.</STRONG> You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
|
||||
<div>
|
||||
<UL>
|
||||
<LI><STRONG>a)</STRONG> Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
<LI> <STRONG>b)</STRONG> Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
<LI>
|
||||
<div><STRONG>c)</STRONG> Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) </div>
|
||||
</LI>
|
||||
</UL>
|
||||
</div>
|
||||
<div>The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. </div>
|
||||
<P>If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
|
||||
<P><STRONG>4.</STRONG> You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
||||
<P><STRONG>5.</STRONG> You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
|
||||
<P><STRONG>6.</STRONG> Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
|
||||
<P><STRONG>7.</STRONG> If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
|
||||
<P>If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
|
||||
<P>It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
||||
<P>This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
||||
<P><STRONG>8.</STRONG> If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
||||
<P><STRONG>9.</STRONG> The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
<P>Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
|
||||
<P><STRONG>10.</STRONG> If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
||||
<P><STRONG>NO WARRANTY</STRONG></P>
|
||||
<P><STRONG>11.</STRONG> BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
<P><STRONG>12.</STRONG> IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
<P>
|
||||
<H2 align="center">END OF TERMS AND CONDITION</H2>
|
||||
<p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,436 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Parse FROM in SQL WHERE clause
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: AccessSqlParser.java,v 1.3 2006/07/30 00:58:36 jjanke Exp $
|
||||
*/
|
||||
public class AccessSqlParser
|
||||
{
|
||||
/**
|
||||
* Base Constructor.
|
||||
* You need to set the SQL and start the parsing manually.
|
||||
*/
|
||||
public AccessSqlParser ()
|
||||
{
|
||||
} // AccessSqlParser
|
||||
|
||||
/**
|
||||
* Full Constructor
|
||||
* @param sql sql command
|
||||
*/
|
||||
public AccessSqlParser (String sql)
|
||||
{
|
||||
setSql(sql);
|
||||
} // AccessSqlParser
|
||||
|
||||
/** FROM String */
|
||||
private static final String FROM = " FROM ";
|
||||
private static final int FROM_LENGTH = FROM.length();
|
||||
private static final String WHERE = " WHERE ";
|
||||
private static final String ON = " ON ";
|
||||
|
||||
/** Logger */
|
||||
private CLogger log = CLogger.getCLogger(getClass());
|
||||
/** Original SQL */
|
||||
private String m_sqlOriginal;
|
||||
/** SQL Selects */
|
||||
private String[] m_sql;
|
||||
/** List of Arrays */
|
||||
private ArrayList<TableInfo[]> m_tableInfo = new ArrayList<TableInfo[]>();
|
||||
|
||||
/**
|
||||
* Set Sql and parse it
|
||||
* @param sql sql
|
||||
*/
|
||||
public void setSql (String sql)
|
||||
{
|
||||
if (sql == null)
|
||||
throw new IllegalArgumentException("No SQL");
|
||||
m_sqlOriginal = sql;
|
||||
int index = m_sqlOriginal.indexOf("\nFROM ");
|
||||
if (index != -1)
|
||||
m_sqlOriginal = m_sqlOriginal.replace("\nFROM ", FROM);
|
||||
index = m_sqlOriginal.indexOf("\nWHERE ");
|
||||
if (index != -1)
|
||||
m_sqlOriginal = m_sqlOriginal.replace("\nWHERE ", WHERE);
|
||||
//
|
||||
parse();
|
||||
} // setSQL
|
||||
|
||||
/**
|
||||
* Get (original) Sql
|
||||
* @return sql
|
||||
*/
|
||||
public String getSql()
|
||||
{
|
||||
return m_sqlOriginal;
|
||||
} // getSql
|
||||
|
||||
/**
|
||||
* Parse Original SQL.
|
||||
* Called from setSql or Constructor.
|
||||
* @return true if pased
|
||||
*/
|
||||
public boolean parse()
|
||||
{
|
||||
if (m_sqlOriginal == null || m_sqlOriginal.length() == 0)
|
||||
throw new IllegalArgumentException("No SQL");
|
||||
//
|
||||
// if (CLogMgt.isLevelFinest())
|
||||
// log.fine(m_sqlOriginal);
|
||||
getSelectStatements();
|
||||
// analyse each select
|
||||
for (int i = 0; i < m_sql.length; i++)
|
||||
{
|
||||
TableInfo[] info = getTableInfo(m_sql[i].trim());
|
||||
m_tableInfo.add(info);
|
||||
}
|
||||
//
|
||||
if (CLogMgt.isLevelFinest())
|
||||
log.fine(toString());
|
||||
return m_tableInfo.size() > 0;
|
||||
} // parse
|
||||
|
||||
/**
|
||||
* Parses m_sqlOriginal and creates Array of m_sql statements
|
||||
*/
|
||||
private void getSelectStatements()
|
||||
{
|
||||
String[] sqlIn = new String[] {m_sqlOriginal};
|
||||
String[] sqlOut = null;
|
||||
try
|
||||
{
|
||||
sqlOut = getSubSQL (sqlIn);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, m_sqlOriginal, e);
|
||||
throw new IllegalArgumentException(m_sqlOriginal);
|
||||
}
|
||||
// a sub-query was found
|
||||
while (sqlIn.length != sqlOut.length)
|
||||
{
|
||||
sqlIn = sqlOut;
|
||||
try
|
||||
{
|
||||
sqlOut = getSubSQL (sqlIn);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, m_sqlOriginal, e);
|
||||
throw new IllegalArgumentException(sqlOut.length + ": "+ m_sqlOriginal);
|
||||
}
|
||||
}
|
||||
m_sql = sqlOut;
|
||||
/** List & check **
|
||||
for (int i = 0; i < m_sql.length; i++)
|
||||
{
|
||||
if (m_sql[i].indexOf("SELECT ",2) != -1)
|
||||
log.log(Level.SEVERE, "#" + i + " Has embedded SQL - " + m_sql[i]);
|
||||
else
|
||||
log.fine("#" + i + " - " + m_sql[i]);
|
||||
}
|
||||
/** **/
|
||||
} // getSelectStatements
|
||||
|
||||
/**
|
||||
* Get Sub SQL of sql statements
|
||||
* @param sqlIn array of input sql
|
||||
* @return array of resulting sql
|
||||
*/
|
||||
private String[] getSubSQL (String[] sqlIn)
|
||||
{
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
for (int sqlIndex = 0; sqlIndex < sqlIn.length; sqlIndex++)
|
||||
{
|
||||
String sql = sqlIn[sqlIndex];
|
||||
int index = sql.indexOf("(SELECT ", 7);
|
||||
while (index != -1)
|
||||
{
|
||||
int endIndex = index+1;
|
||||
int parenthesisLevel = 0;
|
||||
// search for the end of the sql
|
||||
while (endIndex++ < sql.length())
|
||||
{
|
||||
char c = sql.charAt(endIndex);
|
||||
if (c == ')')
|
||||
{
|
||||
if (parenthesisLevel == 0)
|
||||
break;
|
||||
else
|
||||
parenthesisLevel--;
|
||||
}
|
||||
else if (c == '(')
|
||||
parenthesisLevel++;
|
||||
}
|
||||
String subSQL = sql.substring(index, endIndex+1);
|
||||
list.add(subSQL);
|
||||
// remove inner SQL (##)
|
||||
sql = sql.substring(0,index+1) + "##"
|
||||
+ sql.substring(endIndex);
|
||||
index = sql.indexOf("(SELECT ", 7);
|
||||
}
|
||||
list.add(sql); // last SQL
|
||||
}
|
||||
String[] retValue = new String[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
} // getSubSQL
|
||||
|
||||
/**
|
||||
* Get Table Info for SQL
|
||||
* @param sql sql
|
||||
* @return array of table info for sql
|
||||
*/
|
||||
private TableInfo[] getTableInfo (String sql)
|
||||
{
|
||||
ArrayList<TableInfo> list = new ArrayList<TableInfo>();
|
||||
// remove ()
|
||||
if (sql.startsWith("(") && sql.endsWith(")"))
|
||||
sql = sql.substring(1,sql.length()-1);
|
||||
|
||||
int fromIndex = sql.indexOf(FROM);
|
||||
if (fromIndex != sql.lastIndexOf(FROM))
|
||||
log.log(Level.WARNING, "More than one FROM clause - " + sql);
|
||||
while (fromIndex != -1)
|
||||
{
|
||||
String from = sql.substring(fromIndex+FROM_LENGTH);
|
||||
int index = from.lastIndexOf(WHERE); // end at where
|
||||
if (index != -1)
|
||||
from = from.substring(0, index);
|
||||
from = Util.replace(from, " AS ", " ");
|
||||
from = Util.replace(from, " as ", " ");
|
||||
from = Util.replace(from, " INNER JOIN ", ", ");
|
||||
from = Util.replace(from, " LEFT OUTER JOIN ", ", ");
|
||||
from = Util.replace(from, " RIGHT OUTER JOIN ", ", ");
|
||||
from = Util.replace(from, " FULL JOIN ", ", ");
|
||||
// Remove ON clause - assumes that there is no IN () in the clause
|
||||
index = from.indexOf(ON);
|
||||
while (index != -1)
|
||||
{
|
||||
int indexClose = from.indexOf(')'); // does not catch "IN (1,2)" in ON
|
||||
int indexNextOn = from.indexOf(ON, index+4);
|
||||
if (indexNextOn != -1)
|
||||
indexClose = from.lastIndexOf(')', indexNextOn);
|
||||
if (indexClose != -1)
|
||||
from = from.substring(0, index) + from.substring(indexClose+1);
|
||||
else
|
||||
{
|
||||
log.log(Level.SEVERE, "Could not remove ON " + from);
|
||||
break;
|
||||
}
|
||||
index = from.indexOf(ON);
|
||||
}
|
||||
|
||||
// log.fine("getTableInfo - " + from);
|
||||
StringTokenizer tableST = new StringTokenizer (from, ",");
|
||||
while (tableST.hasMoreTokens())
|
||||
{
|
||||
String tableString = tableST.nextToken().trim();
|
||||
StringTokenizer synST = new StringTokenizer (tableString, " ");
|
||||
TableInfo tableInfo = null;
|
||||
if (synST.countTokens() > 1)
|
||||
tableInfo = new TableInfo(synST.nextToken(), synST.nextToken());
|
||||
else
|
||||
tableInfo = new TableInfo(tableString);
|
||||
// log.fine("getTableInfo -- " + tableInfo);
|
||||
list.add(tableInfo);
|
||||
}
|
||||
//
|
||||
sql = sql.substring(0, fromIndex);
|
||||
fromIndex = sql.lastIndexOf(FROM);
|
||||
}
|
||||
TableInfo[] retValue = new TableInfo[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
} // getTableInfo
|
||||
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("AccessSqlParser[");
|
||||
if (m_tableInfo == null)
|
||||
sb.append(m_sqlOriginal);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m_tableInfo.size(); i++)
|
||||
{
|
||||
if (i > 0)
|
||||
sb.append("|");
|
||||
TableInfo[] info = (TableInfo[])m_tableInfo.get(i);
|
||||
for (int ii = 0; ii < info.length; ii++)
|
||||
{
|
||||
if (ii > 0)
|
||||
sb.append(",");
|
||||
sb.append(info[ii].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("|").append(getMainSqlIndex());
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Get Table Info.
|
||||
* @param index record index
|
||||
* @return table info
|
||||
*/
|
||||
public TableInfo[] getTableInfo (int index)
|
||||
{
|
||||
if (index < 0 || index > m_tableInfo.size())
|
||||
return null;
|
||||
TableInfo[] retValue = (TableInfo[])m_tableInfo.get(index);
|
||||
return retValue;
|
||||
} // getTableInfo
|
||||
|
||||
/**
|
||||
* Get Sql Statements
|
||||
* @param index record index
|
||||
* @return index index of query
|
||||
*/
|
||||
public String getSqlStatement (int index)
|
||||
{
|
||||
if (index < 0 || index > m_sql.length)
|
||||
return null;
|
||||
return m_sql[index];
|
||||
} // getSqlStatement
|
||||
|
||||
/**
|
||||
* Get No of SQL Statements
|
||||
* @return FROM clause count
|
||||
*/
|
||||
public int getNoSqlStatments()
|
||||
{
|
||||
if (m_sql == null)
|
||||
return 0;
|
||||
return m_sql.length;
|
||||
} // getNoSqlStatments
|
||||
|
||||
/**
|
||||
* Get index of main Statements
|
||||
* @return index of main statement or -1 if not found
|
||||
*/
|
||||
public int getMainSqlIndex()
|
||||
{
|
||||
if (m_sql == null)
|
||||
return -1;
|
||||
else if (m_sql.length == 1)
|
||||
return 0;
|
||||
for (int i = m_sql.length-1; i >= 0; i--)
|
||||
{
|
||||
if (m_sql[i].charAt(0) != '(')
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
} // getMainSqlIndex
|
||||
|
||||
/**
|
||||
* Get main sql Statement
|
||||
* @return main statement
|
||||
*/
|
||||
public String getMainSql()
|
||||
{
|
||||
if (m_sql == null)
|
||||
return m_sqlOriginal;
|
||||
|
||||
if (m_sql.length == 1)
|
||||
return m_sql[0];
|
||||
for (int i = m_sql.length-1; i >= 0; i--)
|
||||
{
|
||||
if (m_sql[i].charAt(0) != '(')
|
||||
return m_sql[i];
|
||||
}
|
||||
return "";
|
||||
} // getMainSql
|
||||
|
||||
/**
|
||||
* Table Info VO
|
||||
*/
|
||||
public class TableInfo
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param tableName table
|
||||
* @param synonym synonym
|
||||
*/
|
||||
public TableInfo (String tableName, String synonym)
|
||||
{
|
||||
m_tableName = tableName;
|
||||
m_synonym = synonym;
|
||||
} // TableInfo
|
||||
|
||||
/**
|
||||
* Short Constuctor - no syn
|
||||
* @param tableName table
|
||||
*/
|
||||
public TableInfo (String tableName)
|
||||
{
|
||||
this (tableName, null);
|
||||
} // TableInfo
|
||||
|
||||
private String m_tableName;
|
||||
private String m_synonym;
|
||||
|
||||
/**
|
||||
* Get Table Synonym
|
||||
* @return synonym
|
||||
*/
|
||||
public String getSynonym()
|
||||
{
|
||||
if (m_synonym == null)
|
||||
return "";
|
||||
return m_synonym;
|
||||
} // getSynonym
|
||||
|
||||
/**
|
||||
* Get TableName
|
||||
* @return table name
|
||||
*/
|
||||
public String getTableName()
|
||||
{
|
||||
return m_tableName;
|
||||
} // getTableName
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer(m_tableName);
|
||||
if (getSynonym().length() > 0)
|
||||
sb.append("=").append(m_synonym);
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
} // TableInfo
|
||||
|
||||
} // AccessSqlParser
|
|
@ -0,0 +1,231 @@
|
|||
/******************************************************************************
|
||||
* 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.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();
|
||||
Adempiere.startup(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)<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
|
||||
*/
|
|
@ -0,0 +1,36 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
|
||||
/**
|
||||
* Document Value Workflow Manager
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DocWorkflowMgr.java,v 1.2 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public interface DocWorkflowMgr
|
||||
{
|
||||
/**
|
||||
* Process Document Value Workflow
|
||||
* @param document document
|
||||
* @param AD_Table_ID table
|
||||
* @return true if WF started
|
||||
*/
|
||||
public boolean process (PO document, int AD_Table_ID);
|
||||
|
||||
} // DocWorkflowMgr
|
|
@ -0,0 +1,529 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Field Model Value Object
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: GridFieldVO.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class GridFieldVO implements Serializable
|
||||
{
|
||||
/**
|
||||
* Return the SQL statement used for the MFieldVO.create
|
||||
* @param ctx context
|
||||
* @return SQL with or w/o translation and 1 parameter
|
||||
*/
|
||||
public static String getSQL (Properties ctx)
|
||||
{
|
||||
// IsActive is part of View
|
||||
String sql = "SELECT * FROM AD_Field_v WHERE AD_Tab_ID=?"
|
||||
+ " ORDER BY IsDisplayed DESC, SeqNo";
|
||||
if (!Env.isBaseLanguage(ctx, "AD_Tab"))
|
||||
sql = "SELECT * FROM AD_Field_vt WHERE AD_Tab_ID=?"
|
||||
+ " AND AD_Language='" + Env.getAD_Language(ctx) + "'"
|
||||
+ " ORDER BY IsDisplayed DESC, SeqNo";
|
||||
return sql;
|
||||
} // getSQL
|
||||
|
||||
/**
|
||||
* Create Field Value Object
|
||||
* @param ctx context
|
||||
* @param WindowNo window
|
||||
* @param TabNo tab
|
||||
* @param AD_Window_ID window
|
||||
* @param AD_Tab_ID tab
|
||||
* @param readOnly r/o
|
||||
* @param rs resultset AD_Field_v
|
||||
* @return MFieldVO
|
||||
*/
|
||||
public static GridFieldVO create (Properties ctx, int WindowNo, int TabNo,
|
||||
int AD_Window_ID, int AD_Tab_ID, boolean readOnly, ResultSet rs)
|
||||
{
|
||||
GridFieldVO vo = new GridFieldVO (ctx, WindowNo, TabNo,
|
||||
AD_Window_ID, AD_Tab_ID, readOnly);
|
||||
String columnName = "ColumnName";
|
||||
try
|
||||
{
|
||||
vo.ColumnName = rs.getString("ColumnName");
|
||||
if (vo.ColumnName == null)
|
||||
return null;
|
||||
|
||||
CLogger.get().fine(vo.ColumnName);
|
||||
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
for (int i = 1; i <= rsmd.getColumnCount(); i++)
|
||||
{
|
||||
columnName = rsmd.getColumnName (i);
|
||||
if (columnName.equalsIgnoreCase("Name"))
|
||||
vo.Header = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("AD_Reference_ID"))
|
||||
vo.displayType = rs.getInt (i);
|
||||
else if (columnName.equalsIgnoreCase("AD_Column_ID"))
|
||||
vo.AD_Column_ID = rs.getInt (i);
|
||||
else if (columnName.equalsIgnoreCase("AD_Table_ID"))
|
||||
vo.AD_Table_ID = rs.getInt (i);
|
||||
else if (columnName.equalsIgnoreCase("DisplayLength"))
|
||||
vo.DisplayLength = rs.getInt (i);
|
||||
else if (columnName.equalsIgnoreCase("IsSameLine"))
|
||||
vo.IsSameLine = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsDisplayed"))
|
||||
vo.IsDisplayed = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("DisplayLogic"))
|
||||
vo.DisplayLogic = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("DefaultValue"))
|
||||
vo.DefaultValue = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("IsMandatory"))
|
||||
vo.IsMandatory = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsReadOnly"))
|
||||
vo.IsReadOnly = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsUpdateable"))
|
||||
vo.IsUpdateable = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsAlwaysUpdateable"))
|
||||
vo.IsAlwaysUpdateable = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsHeading"))
|
||||
vo.IsHeading = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsFieldOnly"))
|
||||
vo.IsFieldOnly = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsEncryptedField"))
|
||||
vo.IsEncryptedField = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsEncryptedColumn"))
|
||||
vo.IsEncryptedColumn = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsSelectionColumn"))
|
||||
vo.IsSelectionColumn = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("SortNo"))
|
||||
vo.SortNo = rs.getInt (i);
|
||||
else if (columnName.equalsIgnoreCase("FieldLength"))
|
||||
vo.FieldLength = rs.getInt (i);
|
||||
else if (columnName.equalsIgnoreCase("VFormat"))
|
||||
vo.VFormat = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("ValueMin"))
|
||||
vo.ValueMin = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("ValueMax"))
|
||||
vo.ValueMax = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("FieldGroup"))
|
||||
vo.FieldGroup = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("IsKey"))
|
||||
vo.IsKey = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("IsParent"))
|
||||
vo.IsParent = "Y".equals(rs.getString (i));
|
||||
else if (columnName.equalsIgnoreCase("Description"))
|
||||
vo.Description = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("Help"))
|
||||
vo.Help = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("Callout"))
|
||||
vo.Callout = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("AD_Process_ID"))
|
||||
vo.AD_Process_ID = rs.getInt (i);
|
||||
else if (columnName.equalsIgnoreCase("ReadOnlyLogic"))
|
||||
vo.ReadOnlyLogic = rs.getString (i);
|
||||
else if (columnName.equalsIgnoreCase("ObscureType"))
|
||||
vo.ObscureType = rs.getString (i);
|
||||
//
|
||||
else if (columnName.equalsIgnoreCase("AD_Reference_Value_ID"))
|
||||
vo.AD_Reference_Value_ID = rs.getInt(i);
|
||||
else if (columnName.equalsIgnoreCase("ValidationCode"))
|
||||
vo.ValidationCode = rs.getString(i);
|
||||
else if (columnName.equalsIgnoreCase("ColumnSQL"))
|
||||
vo.ColumnSQL = rs.getString(i);
|
||||
}
|
||||
if (vo.Header == null)
|
||||
vo.Header = vo.ColumnName;
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "ColumnName=" + columnName, e);
|
||||
return null;
|
||||
}
|
||||
vo.initFinish();
|
||||
return vo;
|
||||
} // create
|
||||
|
||||
/**
|
||||
* Init Field for Process Parameter
|
||||
* @param ctx context
|
||||
* @param WindowNo window
|
||||
* @param rs result set AD_Process_Para
|
||||
* @return MFieldVO
|
||||
*/
|
||||
public static GridFieldVO createParameter (Properties ctx, int WindowNo, ResultSet rs)
|
||||
{
|
||||
GridFieldVO vo = new GridFieldVO (ctx, WindowNo, 0, 0, 0, false);
|
||||
vo.isProcess = true;
|
||||
vo.IsDisplayed = true;
|
||||
vo.IsReadOnly = false;
|
||||
vo.IsUpdateable = true;
|
||||
|
||||
try
|
||||
{
|
||||
vo.AD_Table_ID = 0;
|
||||
vo.AD_Column_ID = rs.getInt("AD_Process_Para_ID"); // **
|
||||
vo.ColumnName = rs.getString("ColumnName");
|
||||
vo.Header = rs.getString("Name");
|
||||
vo.Description = rs.getString("Description");
|
||||
vo.Help = rs.getString("Help");
|
||||
vo.displayType = rs.getInt("AD_Reference_ID");
|
||||
vo.IsMandatory = rs.getString("IsMandatory").equals("Y");
|
||||
vo.FieldLength = rs.getInt("FieldLength");
|
||||
vo.DisplayLength = vo.FieldLength;
|
||||
vo.DefaultValue = rs.getString("DefaultValue");
|
||||
vo.DefaultValue2 = rs.getString("DefaultValue2");
|
||||
vo.VFormat = rs.getString("VFormat");
|
||||
vo.ValueMin = rs.getString("ValueMin");
|
||||
vo.ValueMax = rs.getString("ValueMax");
|
||||
vo.isRange = rs.getString("IsRange").equals("Y");
|
||||
//
|
||||
vo.AD_Reference_Value_ID = rs.getInt("AD_Reference_Value_ID");
|
||||
vo.ValidationCode = rs.getString("ValidationCode");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "createParameter", e);
|
||||
}
|
||||
//
|
||||
vo.initFinish();
|
||||
if (vo.DefaultValue2 == null)
|
||||
vo.DefaultValue2 = "";
|
||||
return vo;
|
||||
} // createParameter
|
||||
|
||||
/**
|
||||
* Create range "to" Parameter Field from "from" Parameter Field
|
||||
* @param voF field value object
|
||||
* @return to MFieldVO
|
||||
*/
|
||||
public static GridFieldVO createParameter (GridFieldVO voF)
|
||||
{
|
||||
GridFieldVO voT = new GridFieldVO (voF.ctx, voF.WindowNo, voF.TabNo,
|
||||
voF.AD_Window_ID, voF.AD_Tab_ID, voF.tabReadOnly);
|
||||
voT.isProcess = true;
|
||||
voT.IsDisplayed = true;
|
||||
voT.IsReadOnly = false;
|
||||
voT.IsUpdateable = true;
|
||||
//
|
||||
voT.AD_Table_ID = voF.AD_Table_ID;
|
||||
voT.AD_Column_ID = voF.AD_Column_ID; // AD_Process_Para_ID
|
||||
voT.ColumnName = voF.ColumnName;
|
||||
voT.Header = voF.Header;
|
||||
voT.Description = voF.Description;
|
||||
voT.Help = voF.Help;
|
||||
voT.displayType = voF.displayType;
|
||||
voT.IsMandatory = voF.IsMandatory;
|
||||
voT.FieldLength = voF.FieldLength;
|
||||
voT.DisplayLength = voF.FieldLength;
|
||||
voT.DefaultValue = voF.DefaultValue2;
|
||||
voT.VFormat = voF.VFormat;
|
||||
voT.ValueMin = voF.ValueMin;
|
||||
voT.ValueMax = voF.ValueMax;
|
||||
voT.isRange = voF.isRange;
|
||||
//
|
||||
return voT;
|
||||
} // createParameter
|
||||
|
||||
|
||||
/**
|
||||
* Make a standard field (Created/Updated/By)
|
||||
* @param ctx context
|
||||
* @param WindowNo window
|
||||
* @param TabNo tab
|
||||
* @param AD_Window_ID window
|
||||
* @param AD_Tab_ID tab
|
||||
* @param tabReadOnly rab is r/o
|
||||
* @param isCreated is Created field
|
||||
* @param isTimestamp is the timestamp (not by)
|
||||
* @return MFieldVO
|
||||
*/
|
||||
public static GridFieldVO createStdField (Properties ctx, int WindowNo, int TabNo,
|
||||
int AD_Window_ID, int AD_Tab_ID, boolean tabReadOnly,
|
||||
boolean isCreated, boolean isTimestamp)
|
||||
{
|
||||
GridFieldVO vo = new GridFieldVO (ctx, WindowNo, TabNo,
|
||||
AD_Window_ID, AD_Tab_ID, tabReadOnly);
|
||||
vo.ColumnName = isCreated ? "Created" : "Updated";
|
||||
if (!isTimestamp)
|
||||
vo.ColumnName += "By";
|
||||
vo.displayType = isTimestamp ? DisplayType.DateTime : DisplayType.Table;
|
||||
if (!isTimestamp)
|
||||
vo.AD_Reference_Value_ID = 110; // AD_User Table Reference
|
||||
vo.IsDisplayed = false;
|
||||
vo.IsMandatory = false;
|
||||
vo.IsReadOnly = false;
|
||||
vo.IsUpdateable = true;
|
||||
vo.initFinish();
|
||||
return vo;
|
||||
} // initStdField
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Private constructor.
|
||||
* @param Ctx context
|
||||
* @param windowNo window
|
||||
* @param tabNo tab
|
||||
* @param ad_Window_ID window
|
||||
* @param ad_Tab_ID tab
|
||||
* @param TabReadOnly tab read only
|
||||
*/
|
||||
private GridFieldVO (Properties Ctx, int windowNo, int tabNo,
|
||||
int ad_Window_ID, int ad_Tab_ID, boolean TabReadOnly)
|
||||
{
|
||||
ctx = Ctx;
|
||||
WindowNo = windowNo;
|
||||
TabNo = tabNo;
|
||||
AD_Window_ID = ad_Window_ID;
|
||||
AD_Tab_ID = ad_Tab_ID;
|
||||
tabReadOnly = TabReadOnly;
|
||||
} // MFieldVO
|
||||
|
||||
static final long serialVersionUID = 4385061125114436797L;
|
||||
|
||||
/** Context */
|
||||
public Properties ctx = null;
|
||||
/** Window No */
|
||||
public int WindowNo;
|
||||
/** Tab No */
|
||||
public int TabNo;
|
||||
/** AD_Winmdow_ID */
|
||||
public int AD_Window_ID;
|
||||
/** AD_Tab_ID */
|
||||
public int AD_Tab_ID;
|
||||
/** Is the Tab Read Only */
|
||||
public boolean tabReadOnly = false;
|
||||
|
||||
/** Is Process Parameter */
|
||||
public boolean isProcess = false;
|
||||
|
||||
/** Column name */
|
||||
public String ColumnName = "";
|
||||
/** Column sql */
|
||||
public String ColumnSQL;
|
||||
/** Label */
|
||||
public String Header = "";
|
||||
/** DisplayType */
|
||||
public int displayType = 0;
|
||||
/** Table ID */
|
||||
public int AD_Table_ID = 0;
|
||||
/** Clumn ID */
|
||||
public int AD_Column_ID = 0;
|
||||
/** Display Length */
|
||||
public int DisplayLength = 0;
|
||||
/** Same Line */
|
||||
public boolean IsSameLine = false;
|
||||
/** Displayed */
|
||||
public boolean IsDisplayed = false;
|
||||
/** Dislay Logic */
|
||||
public String DisplayLogic = "";
|
||||
/** Default Value */
|
||||
public String DefaultValue = "";
|
||||
/** Mandatory */
|
||||
public boolean IsMandatory = false;
|
||||
/** Read Only */
|
||||
public boolean IsReadOnly = false;
|
||||
/** Updateable */
|
||||
public boolean IsUpdateable = false;
|
||||
/** Always Updateable */
|
||||
public boolean IsAlwaysUpdateable = false;
|
||||
/** Heading Only */
|
||||
public boolean IsHeading = false;
|
||||
/** Field Only */
|
||||
public boolean IsFieldOnly = false;
|
||||
/** Display Encryption */
|
||||
public boolean IsEncryptedField = false;
|
||||
/** Storage Encryption */
|
||||
public boolean IsEncryptedColumn = false;
|
||||
/** Find Selection */
|
||||
public boolean IsSelectionColumn = false;
|
||||
/** Order By */
|
||||
public int SortNo = 0;
|
||||
/** Field Length */
|
||||
public int FieldLength = 0;
|
||||
/** Format enforcement */
|
||||
public String VFormat = "";
|
||||
/** Min. Value */
|
||||
public String ValueMin = "";
|
||||
/** Max. Value */
|
||||
public String ValueMax = "";
|
||||
/** Field Group */
|
||||
public String FieldGroup = "";
|
||||
/** PK */
|
||||
public boolean IsKey = false;
|
||||
/** FK */
|
||||
public boolean IsParent = false;
|
||||
/** Callout */
|
||||
public String Callout = "";
|
||||
/** Process */
|
||||
public int AD_Process_ID = 0;
|
||||
/** Description */
|
||||
public String Description = "";
|
||||
/** Help */
|
||||
public String Help = "";
|
||||
/** Read Only Logic */
|
||||
public String ReadOnlyLogic = "";
|
||||
/** Display Obscure */
|
||||
public String ObscureType = null;
|
||||
|
||||
|
||||
/** Lookup Validation code */
|
||||
public String ValidationCode = "";
|
||||
/** Reference Value */
|
||||
public int AD_Reference_Value_ID = 0;
|
||||
|
||||
/** Process Parameter Range */
|
||||
public boolean isRange = false;
|
||||
/** Process Parameter Value2 */
|
||||
public String DefaultValue2 = "";
|
||||
|
||||
/** Lookup Value Object */
|
||||
public MLookupInfo lookupInfo = null;
|
||||
|
||||
|
||||
/**
|
||||
* Set Context including contained elements
|
||||
* @param newCtx new context
|
||||
*/
|
||||
public void setCtx (Properties newCtx)
|
||||
{
|
||||
ctx = newCtx;
|
||||
if (lookupInfo != null)
|
||||
lookupInfo.ctx = newCtx;
|
||||
} // setCtx
|
||||
|
||||
/**
|
||||
* Validate Fields and create LookupInfo if required
|
||||
*/
|
||||
protected void initFinish()
|
||||
{
|
||||
// Not null fields
|
||||
if (DisplayLogic == null)
|
||||
DisplayLogic = "";
|
||||
if (DefaultValue == null)
|
||||
DefaultValue = "";
|
||||
if (FieldGroup == null)
|
||||
FieldGroup = "";
|
||||
if (Description == null)
|
||||
Description = "";
|
||||
if (Help == null)
|
||||
Help = "";
|
||||
if (Callout == null)
|
||||
Callout = "";
|
||||
if (ReadOnlyLogic == null)
|
||||
ReadOnlyLogic = "";
|
||||
|
||||
|
||||
// Create Lookup, if not ID
|
||||
if (DisplayType.isLookup(displayType))
|
||||
{
|
||||
try
|
||||
{
|
||||
lookupInfo = MLookupFactory.getLookupInfo (ctx, WindowNo, AD_Column_ID, displayType,
|
||||
Env.getLanguage(ctx), ColumnName, AD_Reference_Value_ID,
|
||||
IsParent, ValidationCode);
|
||||
}
|
||||
catch (Exception e) // Cannot create Lookup
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "No LookupInfo for " + ColumnName, e);
|
||||
displayType = DisplayType.ID;
|
||||
}
|
||||
}
|
||||
} // initFinish
|
||||
|
||||
/**
|
||||
* Clone Field.
|
||||
* @param Ctx ctx
|
||||
* @param windowNo window no
|
||||
* @param tabNo tab no
|
||||
* @param ad_Window_ID window id
|
||||
* @param ad_Tab_ID tab id
|
||||
* @param TabReadOnly r/o
|
||||
* @return Field or null
|
||||
*/
|
||||
protected GridFieldVO clone(Properties Ctx, int windowNo, int tabNo,
|
||||
int ad_Window_ID, int ad_Tab_ID,
|
||||
boolean TabReadOnly)
|
||||
{
|
||||
GridFieldVO clone = new GridFieldVO(Ctx, windowNo, tabNo,
|
||||
ad_Window_ID, ad_Tab_ID, TabReadOnly);
|
||||
//
|
||||
clone.isProcess = false;
|
||||
// Database Fields
|
||||
clone.ColumnName = ColumnName;
|
||||
clone.ColumnSQL = ColumnSQL;
|
||||
clone.Header = Header;
|
||||
clone.displayType = displayType;
|
||||
clone.AD_Table_ID = AD_Table_ID;
|
||||
clone.AD_Column_ID = AD_Column_ID;
|
||||
clone.DisplayLength = DisplayLength;
|
||||
clone.IsSameLine = IsSameLine;
|
||||
clone.IsDisplayed = IsDisplayed;
|
||||
clone.DisplayLogic = DisplayLogic;
|
||||
clone.DefaultValue = DefaultValue;
|
||||
clone.IsMandatory = IsMandatory;
|
||||
clone.IsReadOnly = IsReadOnly;
|
||||
clone.IsUpdateable = IsUpdateable;
|
||||
clone.IsAlwaysUpdateable = IsAlwaysUpdateable;
|
||||
clone.IsHeading = IsHeading;
|
||||
clone.IsFieldOnly = IsFieldOnly;
|
||||
clone.IsEncryptedField = IsEncryptedField;
|
||||
clone.IsEncryptedColumn = IsEncryptedColumn;
|
||||
clone.IsSelectionColumn = IsSelectionColumn;
|
||||
clone.SortNo = SortNo;
|
||||
clone.FieldLength = FieldLength;
|
||||
clone.VFormat = VFormat;
|
||||
clone.ValueMin = ValueMin;
|
||||
clone.ValueMax = ValueMax;
|
||||
clone.FieldGroup = FieldGroup;
|
||||
clone.IsKey = IsKey;
|
||||
clone.IsParent = IsParent;
|
||||
clone.Callout = Callout;
|
||||
clone.AD_Process_ID = AD_Process_ID;
|
||||
clone.Description = Description;
|
||||
clone.Help = Help;
|
||||
clone.ReadOnlyLogic = ReadOnlyLogic;
|
||||
clone.ObscureType = ObscureType;
|
||||
// Lookup
|
||||
clone.ValidationCode = ValidationCode;
|
||||
clone.AD_Reference_Value_ID = AD_Reference_Value_ID;
|
||||
clone.lookupInfo = lookupInfo;
|
||||
|
||||
// Process Parameter
|
||||
clone.isRange = isRange;
|
||||
clone.DefaultValue2 = DefaultValue2;
|
||||
|
||||
return clone;
|
||||
} // clone
|
||||
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MFieldVO[");
|
||||
sb.append(AD_Column_ID).append("-").append(ColumnName)
|
||||
.append ("]");
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
} // MFieldVO
|
|
@ -0,0 +1,472 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Model Tab Value Object
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: GridTabVO.java,v 1.4 2006/07/30 00:58:38 jjanke Exp $
|
||||
*/
|
||||
public class GridTabVO implements Evaluatee, Serializable
|
||||
{
|
||||
/**************************************************************************
|
||||
* Create MTab VO
|
||||
*
|
||||
* @param wVO value object
|
||||
* @param TabNo tab no
|
||||
* @param rs ResultSet from AD_Tab_v
|
||||
* @param isRO true if window is r/o
|
||||
* @param onlyCurrentRows if true query is limited to not processed records
|
||||
* @return TabVO
|
||||
*/
|
||||
public static GridTabVO create (GridWindowVO wVO, int TabNo, ResultSet rs,
|
||||
boolean isRO, boolean onlyCurrentRows)
|
||||
{
|
||||
CLogger.get().config("#" + TabNo);
|
||||
|
||||
GridTabVO vo = new GridTabVO (wVO.ctx, wVO.WindowNo);
|
||||
vo.AD_Window_ID = wVO.AD_Window_ID;
|
||||
vo.TabNo = TabNo;
|
||||
//
|
||||
if (!loadTabDetails(vo, rs))
|
||||
return null;
|
||||
|
||||
if (isRO)
|
||||
{
|
||||
CLogger.get().fine("Tab is ReadOnly");
|
||||
vo.IsReadOnly = true;
|
||||
}
|
||||
vo.onlyCurrentRows = onlyCurrentRows;
|
||||
|
||||
// Create Fields
|
||||
if (vo.IsSortTab)
|
||||
{
|
||||
vo.Fields = new ArrayList<GridFieldVO>(); // dummy
|
||||
}
|
||||
else
|
||||
{
|
||||
createFields (vo);
|
||||
if (vo.Fields == null || vo.Fields.size() == 0)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "No Fields");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return vo;
|
||||
} // create
|
||||
|
||||
/**
|
||||
* Load Tab Details from rs into vo
|
||||
* @param vo Tab value object
|
||||
* @param rs ResultSet from AD_Tab_v/t
|
||||
* @return true if read ok
|
||||
*/
|
||||
private static boolean loadTabDetails (GridTabVO vo, ResultSet rs)
|
||||
{
|
||||
MRole role = MRole.getDefault(vo.ctx, false);
|
||||
boolean showTrl = "Y".equals(Env.getContext(vo.ctx, "#ShowTrl"));
|
||||
boolean showAcct = "Y".equals(Env.getContext(vo.ctx, "#ShowAcct"));
|
||||
boolean showAdvanced = "Y".equals(Env.getContext(vo.ctx, "#ShowAdvanced"));
|
||||
// CLogger.get().warning("ShowTrl=" + showTrl + ", showAcct=" + showAcct);
|
||||
try
|
||||
{
|
||||
vo.AD_Tab_ID = rs.getInt("AD_Tab_ID");
|
||||
Env.setContext(vo.ctx, vo.WindowNo, vo.TabNo, "AD_Tab_ID", String.valueOf(vo.AD_Tab_ID));
|
||||
vo.Name = rs.getString("Name");
|
||||
Env.setContext(vo.ctx, vo.WindowNo, vo.TabNo, "Name", vo.Name);
|
||||
|
||||
// Translation Tab **
|
||||
if (rs.getString("IsTranslationTab").equals("Y"))
|
||||
{
|
||||
// Document Translation
|
||||
vo.TableName = rs.getString("TableName");
|
||||
if (!Env.isBaseTranslation(vo.TableName) // C_UOM, ...
|
||||
&& !Env.isMultiLingualDocument(vo.ctx))
|
||||
showTrl = false;
|
||||
if (!showTrl)
|
||||
{
|
||||
CLogger.get().config("TrlTab Not displayed - AD_Tab_ID="
|
||||
+ vo.AD_Tab_ID + "=" + vo.Name + ", Table=" + vo.TableName
|
||||
+ ", BaseTrl=" + Env.isBaseTranslation(vo.TableName)
|
||||
+ ", MultiLingual=" + Env.isMultiLingualDocument(vo.ctx));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Advanced Tab **
|
||||
if (!showAdvanced && rs.getString("IsAdvancedTab").equals("Y"))
|
||||
{
|
||||
CLogger.get().config("AdvancedTab Not displayed - AD_Tab_ID="
|
||||
+ vo.AD_Tab_ID + " " + vo.Name);
|
||||
return false;
|
||||
}
|
||||
// Accounting Info Tab **
|
||||
if (!showAcct && rs.getString("IsInfoTab").equals("Y"))
|
||||
{
|
||||
CLogger.get().fine("AcctTab Not displayed - AD_Tab_ID="
|
||||
+ vo.AD_Tab_ID + " " + vo.Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
// DisplayLogic
|
||||
vo.DisplayLogic = rs.getString("DisplayLogic");
|
||||
|
||||
// Access Level
|
||||
vo.AccessLevel = rs.getString("AccessLevel");
|
||||
if (!role.canView (vo.ctx, vo.AccessLevel)) // No Access
|
||||
{
|
||||
CLogger.get().fine("No Role Access - AD_Tab_ID=" + vo.AD_Tab_ID + " " + vo. Name);
|
||||
return false;
|
||||
} // Used by MField.getDefault
|
||||
Env.setContext(vo.ctx, vo.WindowNo, vo.TabNo, "AccessLevel", vo.AccessLevel);
|
||||
|
||||
// Table Access
|
||||
vo.AD_Table_ID = rs.getInt("AD_Table_ID");
|
||||
Env.setContext(vo.ctx, vo.WindowNo, vo.TabNo, "AD_Table_ID", String.valueOf(vo.AD_Table_ID));
|
||||
if (!role.isTableAccess(vo.AD_Table_ID, true))
|
||||
{
|
||||
CLogger.get().config("No Table Access - AD_Tab_ID="
|
||||
+ vo.AD_Tab_ID + " " + vo. Name);
|
||||
return false;
|
||||
}
|
||||
if (rs.getString("IsReadOnly").equals("Y"))
|
||||
vo.IsReadOnly = true;
|
||||
vo.ReadOnlyLogic = rs.getString("ReadOnlyLogic");
|
||||
if (rs.getString("IsInsertRecord").equals("N"))
|
||||
vo.IsInsertRecord = false;
|
||||
|
||||
//
|
||||
vo.Description = rs.getString("Description");
|
||||
if (vo.Description == null)
|
||||
vo.Description = "";
|
||||
vo.Help = rs.getString("Help");
|
||||
if (vo.Help == null)
|
||||
vo.Help = "";
|
||||
|
||||
if (rs.getString("IsSingleRow").equals("Y"))
|
||||
vo.IsSingleRow = true;
|
||||
if (rs.getString("HasTree").equals("Y"))
|
||||
vo.HasTree = true;
|
||||
|
||||
vo.AD_Table_ID = rs.getInt("AD_Table_ID");
|
||||
vo.TableName = rs.getString("TableName");
|
||||
if (rs.getString("IsView").equals("Y"))
|
||||
vo.IsView = true;
|
||||
vo.AD_Column_ID = rs.getInt("AD_Column_ID"); // Primary Parent Column
|
||||
|
||||
if (rs.getString("IsSecurityEnabled").equals("Y"))
|
||||
vo.IsSecurityEnabled = true;
|
||||
if (rs.getString("IsDeleteable").equals("Y"))
|
||||
vo.IsDeleteable = true;
|
||||
if (rs.getString("IsHighVolume").equals("Y"))
|
||||
vo.IsHighVolume = true;
|
||||
|
||||
vo.CommitWarning = rs.getString("CommitWarning");
|
||||
if (vo.CommitWarning == null)
|
||||
vo.CommitWarning = "";
|
||||
vo.WhereClause = rs.getString("WhereClause");
|
||||
if (vo.WhereClause == null)
|
||||
vo.WhereClause = "";
|
||||
vo.OrderByClause = rs.getString("OrderByClause");
|
||||
if (vo.OrderByClause == null)
|
||||
vo.OrderByClause = "";
|
||||
|
||||
vo.AD_Process_ID = rs.getInt("AD_Process_ID");
|
||||
if (rs.wasNull())
|
||||
vo.AD_Process_ID = 0;
|
||||
vo.AD_Image_ID = rs.getInt("AD_Image_ID");
|
||||
if (rs.wasNull())
|
||||
vo.AD_Image_ID = 0;
|
||||
vo.Included_Tab_ID = rs.getInt("Included_Tab_ID");
|
||||
if (rs.wasNull())
|
||||
vo.Included_Tab_ID = 0;
|
||||
//
|
||||
vo.TabLevel = rs.getInt("TabLevel");
|
||||
if (rs.wasNull())
|
||||
vo.TabLevel = 0;
|
||||
//
|
||||
vo.IsSortTab = rs.getString("IsSortTab").equals("Y");
|
||||
if (vo.IsSortTab)
|
||||
{
|
||||
vo.AD_ColumnSortOrder_ID = rs.getInt("AD_ColumnSortOrder_ID");
|
||||
vo.AD_ColumnSortYesNo_ID = rs.getInt("AD_ColumnSortYesNo_ID");
|
||||
}
|
||||
//
|
||||
// Replication Type - set R/O if Reference
|
||||
try
|
||||
{
|
||||
int index = rs.findColumn ("ReplicationType");
|
||||
vo.ReplicationType = rs.getString (index);
|
||||
if ("R".equals(vo.ReplicationType))
|
||||
vo.IsReadOnly = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "", ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} // loadTabDetails
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Create Tab Fields
|
||||
* @param mTabVO tab value object
|
||||
* @return true if fields were created
|
||||
*/
|
||||
private static boolean createFields (GridTabVO mTabVO)
|
||||
{
|
||||
mTabVO.Fields = new ArrayList<GridFieldVO>();
|
||||
|
||||
String sql = GridFieldVO.getSQL(mTabVO.ctx);
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, mTabVO.AD_Tab_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
GridFieldVO voF = GridFieldVO.create (mTabVO.ctx,
|
||||
mTabVO.WindowNo, mTabVO.TabNo,
|
||||
mTabVO.AD_Window_ID, mTabVO.AD_Tab_ID,
|
||||
mTabVO.IsReadOnly, rs);
|
||||
if (voF != null)
|
||||
mTabVO.Fields.add(voF);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "", e);
|
||||
return false;
|
||||
}
|
||||
return mTabVO.Fields.size() != 0;
|
||||
} // createFields
|
||||
|
||||
/**
|
||||
* Return the SQL statement used for the MTabVO.create
|
||||
* @param ctx context
|
||||
* @return SQL SELECT String
|
||||
*/
|
||||
protected static String getSQL (Properties ctx)
|
||||
{
|
||||
// View only returns IsActive='Y'
|
||||
String sql = "SELECT * FROM AD_Tab_v WHERE AD_Window_ID=?"
|
||||
+ " ORDER BY SeqNo";
|
||||
if (!Env.isBaseLanguage(ctx, "AD_Window"))
|
||||
sql = "SELECT * FROM AD_Tab_vt WHERE AD_Window_ID=?"
|
||||
+ " AND AD_Language='" + Env.getAD_Language(ctx) + "'"
|
||||
+ " ORDER BY SeqNo";
|
||||
return sql;
|
||||
} // getSQL
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Private constructor - must use Factory
|
||||
* @param Ctx context
|
||||
* @param windowNo window
|
||||
*/
|
||||
private GridTabVO (Properties Ctx, int windowNo)
|
||||
{
|
||||
ctx = Ctx;
|
||||
WindowNo = windowNo;
|
||||
} // MTabVO
|
||||
|
||||
static final long serialVersionUID = 9160212869277319305L;
|
||||
|
||||
/** Context - replicated */
|
||||
public Properties ctx;
|
||||
/** Window No - replicated */
|
||||
public int WindowNo;
|
||||
/** AD Window - replicated */
|
||||
public int AD_Window_ID;
|
||||
|
||||
/** Tab No (not AD_Tab_ID) 0.. */
|
||||
public int TabNo;
|
||||
|
||||
/** Tab ID */
|
||||
public int AD_Tab_ID;
|
||||
/** Name */
|
||||
public String Name = "";
|
||||
/** Description */
|
||||
public String Description = "";
|
||||
/** Help */
|
||||
public String Help = "";
|
||||
/** Single Row */
|
||||
public boolean IsSingleRow = false;
|
||||
/** Read Only */
|
||||
public boolean IsReadOnly = false;
|
||||
/** Insert Record */
|
||||
public boolean IsInsertRecord = true;
|
||||
/** Tree */
|
||||
public boolean HasTree = false;
|
||||
/** Table */
|
||||
public int AD_Table_ID;
|
||||
/** Primary Parent Column */
|
||||
public int AD_Column_ID = 0;
|
||||
/** Table Name */
|
||||
public String TableName;
|
||||
/** Table is View */
|
||||
public boolean IsView = false;
|
||||
/** Table Access Level */
|
||||
public String AccessLevel;
|
||||
/** Security */
|
||||
public boolean IsSecurityEnabled = false;
|
||||
/** Table Deleteable */
|
||||
public boolean IsDeleteable = false;
|
||||
/** Table High Volume */
|
||||
public boolean IsHighVolume = false;
|
||||
/** Process */
|
||||
public int AD_Process_ID = 0;
|
||||
/** Commot Warning */
|
||||
public String CommitWarning;
|
||||
/** Where */
|
||||
public String WhereClause;
|
||||
/** Order by */
|
||||
public String OrderByClause;
|
||||
/** Tab Read Only */
|
||||
public String ReadOnlyLogic;
|
||||
/** Tab Display */
|
||||
public String DisplayLogic;
|
||||
/** Level */
|
||||
public int TabLevel = 0;
|
||||
/** Image */
|
||||
public int AD_Image_ID = 0;
|
||||
/** Included Tab */
|
||||
public int Included_Tab_ID = 0;
|
||||
/** Replication Type */
|
||||
public String ReplicationType = "L";
|
||||
|
||||
/** Sort Tab */
|
||||
public boolean IsSortTab = false;
|
||||
/** Column Sort */
|
||||
public int AD_ColumnSortOrder_ID = 0;
|
||||
/** Column Displayed */
|
||||
public int AD_ColumnSortYesNo_ID = 0;
|
||||
|
||||
/** Only Current Rows - derived */
|
||||
public boolean onlyCurrentRows = true;
|
||||
/** Only Current Days - derived */
|
||||
public int onlyCurrentDays = 0;
|
||||
|
||||
/** Fields contain MFieldVO entities */
|
||||
public ArrayList<GridFieldVO> Fields = null;
|
||||
|
||||
|
||||
/**
|
||||
* Set Context including contained elements
|
||||
* @param newCtx new context
|
||||
*/
|
||||
public void setCtx (Properties newCtx)
|
||||
{
|
||||
ctx = newCtx;
|
||||
for (int i = 0; i < Fields.size() ; i++)
|
||||
{
|
||||
GridFieldVO field = (GridFieldVO)Fields.get(i);
|
||||
field.setCtx(newCtx);
|
||||
}
|
||||
} // setCtx
|
||||
|
||||
/**
|
||||
* Get Variable Value (Evaluatee)
|
||||
* @param variableName name
|
||||
* @return value
|
||||
*/
|
||||
public String get_ValueAsString (String variableName)
|
||||
{
|
||||
return Env.getContext (ctx, WindowNo, variableName, false); // not just window
|
||||
} // get_ValueAsString
|
||||
|
||||
/**
|
||||
* Clone
|
||||
* @param Ctx context
|
||||
* @param windowNo no
|
||||
* @return MTabVO or null
|
||||
*/
|
||||
protected GridTabVO clone(Properties Ctx, int windowNo)
|
||||
{
|
||||
GridTabVO clone = new GridTabVO(Ctx, windowNo);
|
||||
clone.AD_Window_ID = AD_Window_ID;
|
||||
clone.TabNo = TabNo;
|
||||
Env.setContext(Ctx, windowNo, clone.TabNo, "AD_Tab_ID", String.valueOf(clone.AD_Tab_ID));
|
||||
//
|
||||
clone.AD_Tab_ID = AD_Tab_ID;
|
||||
clone.Name = Name;
|
||||
Env.setContext(Ctx, windowNo, clone.TabNo, "Name", clone.Name);
|
||||
clone.Description = Description;
|
||||
clone.Help = Help;
|
||||
clone.IsSingleRow = IsSingleRow;
|
||||
clone.IsReadOnly = IsReadOnly;
|
||||
clone.IsInsertRecord = IsInsertRecord;
|
||||
clone.HasTree = HasTree;
|
||||
clone.AD_Table_ID = AD_Table_ID;
|
||||
clone.AD_Column_ID = AD_Column_ID;
|
||||
clone.TableName = TableName;
|
||||
clone.IsView = IsView;
|
||||
clone.AccessLevel = AccessLevel;
|
||||
clone.IsSecurityEnabled = IsSecurityEnabled;
|
||||
clone.IsDeleteable = IsDeleteable;
|
||||
clone.IsHighVolume = IsHighVolume;
|
||||
clone.AD_Process_ID = AD_Process_ID;
|
||||
clone.CommitWarning = CommitWarning;
|
||||
clone.WhereClause = WhereClause;
|
||||
clone.OrderByClause = OrderByClause;
|
||||
clone.ReadOnlyLogic = ReadOnlyLogic;
|
||||
clone.DisplayLogic = DisplayLogic;
|
||||
clone.TabLevel = TabLevel;
|
||||
clone.AD_Image_ID = AD_Image_ID;
|
||||
clone.Included_Tab_ID = Included_Tab_ID;
|
||||
clone.ReplicationType = ReplicationType;
|
||||
Env.setContext(Ctx, windowNo, clone.TabNo, "AccessLevel", clone.AccessLevel);
|
||||
Env.setContext(Ctx, windowNo, clone.TabNo, "AD_Table_ID", String.valueOf(clone.AD_Table_ID));
|
||||
|
||||
//
|
||||
clone.IsSortTab = IsSortTab;
|
||||
clone.AD_ColumnSortOrder_ID = AD_ColumnSortOrder_ID;
|
||||
clone.AD_ColumnSortYesNo_ID = AD_ColumnSortYesNo_ID;
|
||||
// Derived
|
||||
clone.onlyCurrentRows = true;
|
||||
clone.onlyCurrentDays = 0;
|
||||
|
||||
clone.Fields = new ArrayList<GridFieldVO>();
|
||||
for (int i = 0; i < Fields.size(); i++)
|
||||
{
|
||||
GridFieldVO field = Fields.get(i);
|
||||
GridFieldVO cloneField = field.clone(Ctx, windowNo, TabNo,
|
||||
AD_Window_ID, AD_Tab_ID, IsReadOnly);
|
||||
if (cloneField == null)
|
||||
return null;
|
||||
clone.Fields.add(cloneField);
|
||||
}
|
||||
|
||||
return clone;
|
||||
} // clone
|
||||
|
||||
} // MTabVO
|
||||
|
|
@ -0,0 +1,346 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Model Window Value Object
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: GridWindowVO.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class GridWindowVO implements Serializable
|
||||
{
|
||||
/**
|
||||
* Create Window Value Object
|
||||
* @param ctx context
|
||||
* @param WindowNo window no for ctx
|
||||
* @param AD_Window_ID window id
|
||||
* @return MWindowVO
|
||||
*/
|
||||
public static GridWindowVO create (Properties ctx, int WindowNo, int AD_Window_ID)
|
||||
{
|
||||
return create (ctx, WindowNo, AD_Window_ID, 0);
|
||||
} // create
|
||||
|
||||
/**
|
||||
* Create Window Value Object
|
||||
*
|
||||
* @param ctx context
|
||||
* @param WindowNo window no for ctx
|
||||
* @param AD_Window_ID window id
|
||||
* @param AD_Menu_ID menu id
|
||||
* @return MWindowVO
|
||||
*/
|
||||
public static GridWindowVO create (Properties ctx, int WindowNo, int AD_Window_ID, int AD_Menu_ID)
|
||||
{
|
||||
CLogger.get().config("#" + WindowNo
|
||||
+ " - AD_Window_ID=" + AD_Window_ID + "; AD_Menu_ID=" + AD_Menu_ID);
|
||||
GridWindowVO vo = new GridWindowVO (ctx, WindowNo);
|
||||
vo.AD_Window_ID = AD_Window_ID;
|
||||
|
||||
// Get Window_ID if required - (used by HTML UI)
|
||||
if (vo.AD_Window_ID == 0 && AD_Menu_ID != 0)
|
||||
{
|
||||
String sql = "SELECT AD_Window_ID, IsSOTrx, IsReadOnly FROM AD_Menu "
|
||||
+ "WHERE AD_Menu_ID=? AND Action='W'";
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, AD_Menu_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
vo.AD_Window_ID = rs.getInt(1);
|
||||
String IsSOTrx = rs.getString(2);
|
||||
Env.setContext(ctx, WindowNo, "IsSOTrx", (IsSOTrx != null && IsSOTrx.equals("Y")));
|
||||
//
|
||||
String IsReadOnly = rs.getString(3);
|
||||
if (IsReadOnly != null && IsReadOnly.equals("Y"))
|
||||
vo.IsReadWrite = "Y";
|
||||
else
|
||||
vo.IsReadWrite = "N";
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "Menu", e);
|
||||
return null;
|
||||
}
|
||||
CLogger.get().config("AD_Window_ID=" + vo.AD_Window_ID);
|
||||
}
|
||||
|
||||
// -- Get Window
|
||||
|
||||
StringBuffer sql = new StringBuffer("SELECT Name,Description,Help,WindowType, "
|
||||
+ "AD_Color_ID,AD_Image_ID, a.IsReadWrite, WinHeight,WinWidth, "
|
||||
+ "IsSOTrx ");
|
||||
|
||||
if (Env.isBaseLanguage(vo.ctx, "AD_Window"))
|
||||
sql.append("FROM AD_Window w, AD_Window_Access a "
|
||||
+ "WHERE w.AD_Window_ID=?"
|
||||
+ " AND w.AD_Window_ID=a.AD_Window_ID AND a.AD_Role_ID=?"
|
||||
+ " AND w.IsActive='Y' AND a.IsActive='Y'");
|
||||
else
|
||||
sql.append("FROM AD_Window_vt w, AD_Window_Access a "
|
||||
+ "WHERE w.AD_Window_ID=?"
|
||||
+ " AND w.AD_Window_ID=a.AD_Window_ID AND a.AD_Role_ID=?"
|
||||
+ " AND a.IsActive='Y'")
|
||||
.append(" AND AD_Language='")
|
||||
.append(Env.getAD_Language(vo.ctx)).append("'");
|
||||
|
||||
int AD_Role_ID = Env.getContextAsInt(vo.ctx, "#AD_Role_ID");
|
||||
try
|
||||
{
|
||||
// create statement
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
pstmt.setInt(1, vo.AD_Window_ID);
|
||||
pstmt.setInt(2, AD_Role_ID);
|
||||
// get data
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
vo.Name = rs.getString(1);
|
||||
vo.Description = rs.getString(2);
|
||||
if (vo.Description == null)
|
||||
vo.Description = "";
|
||||
vo.Help = rs.getString(3);
|
||||
if (vo.Help == null)
|
||||
vo.Help = "";
|
||||
vo.WindowType = rs.getString(4);
|
||||
//
|
||||
vo.AD_Color_ID = rs.getInt(5);
|
||||
vo.AD_Image_ID = rs.getInt(6);
|
||||
vo.IsReadWrite = rs.getString(7);
|
||||
//
|
||||
vo.WinHeight = rs.getInt(8);
|
||||
vo.WinWidth = rs.getInt(9);
|
||||
//
|
||||
vo.IsSOTrx = "Y".equals(rs.getString(10));
|
||||
}
|
||||
else
|
||||
vo = null;
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, sql.toString(), ex);
|
||||
return null;
|
||||
}
|
||||
// Not found
|
||||
if (vo == null)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "No Window - AD_Window_ID=" + AD_Window_ID
|
||||
+ ", AD_Role_ID=" + AD_Role_ID + " - " + sql);
|
||||
CLogger.get().saveError("AccessTableNoView", "(Not found)");
|
||||
return null;
|
||||
}
|
||||
// Read Write
|
||||
if (vo.IsReadWrite == null)
|
||||
{
|
||||
CLogger.get().saveError("AccessTableNoView", "(found)");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create Tabs
|
||||
createTabs (vo);
|
||||
if (vo.Tabs == null || vo.Tabs.size() == 0)
|
||||
return null;
|
||||
|
||||
return vo;
|
||||
} // create
|
||||
|
||||
/**
|
||||
* Create Window Tabs
|
||||
* @param mWindowVO Window Value Object
|
||||
* @return true if tabs were created
|
||||
*/
|
||||
private static boolean createTabs (GridWindowVO mWindowVO)
|
||||
{
|
||||
mWindowVO.Tabs = new ArrayList<GridTabVO>();
|
||||
|
||||
String sql = GridTabVO.getSQL(mWindowVO.ctx);
|
||||
int TabNo = 0;
|
||||
try
|
||||
{
|
||||
// create statement
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, mWindowVO.AD_Window_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
boolean firstTab = true;
|
||||
while (rs.next())
|
||||
{
|
||||
if (mWindowVO.AD_Table_ID == 0)
|
||||
mWindowVO.AD_Table_ID = rs.getInt("AD_Table_ID");
|
||||
// Create TabVO
|
||||
GridTabVO mTabVO = GridTabVO.create(mWindowVO, TabNo, rs,
|
||||
mWindowVO.WindowType.equals(WINDOWTYPE_QUERY), // isRO
|
||||
mWindowVO.WindowType.equals(WINDOWTYPE_TRX)); // onlyCurrentRows
|
||||
if (mTabVO == null && firstTab)
|
||||
break; // don't continue if first tab is null
|
||||
if (mTabVO != null)
|
||||
{
|
||||
if (!mTabVO.IsReadOnly && "N".equals(mWindowVO.IsReadWrite))
|
||||
mTabVO.IsReadOnly = true;
|
||||
mWindowVO.Tabs.add(mTabVO);
|
||||
TabNo++; // must be same as mWindow.getTab(x)
|
||||
firstTab = false;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "createTabs", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
// No Tabs
|
||||
if (TabNo == 0 || mWindowVO.Tabs.size() == 0)
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "No Tabs - AD_Window_ID="
|
||||
+ mWindowVO.AD_Window_ID + " - " + sql);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Put base table of window in ctx (for VDocAction)
|
||||
Env.setContext(mWindowVO.ctx, mWindowVO.WindowNo, "BaseTable_ID", mWindowVO.AD_Table_ID);
|
||||
return true;
|
||||
} // createTabs
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Private Constructor
|
||||
* @param Ctx context
|
||||
* @param windowNo window no
|
||||
*/
|
||||
private GridWindowVO (Properties Ctx, int windowNo)
|
||||
{
|
||||
ctx = Ctx;
|
||||
WindowNo = windowNo;
|
||||
} // MWindowVO
|
||||
|
||||
static final long serialVersionUID = 3802628212531678981L;
|
||||
|
||||
/** Properties */
|
||||
public Properties ctx;
|
||||
/** Window Number */
|
||||
public int WindowNo;
|
||||
|
||||
/** Window */
|
||||
public int AD_Window_ID = 0;
|
||||
/** Name */
|
||||
public String Name = "";
|
||||
/** Desription */
|
||||
public String Description = "";
|
||||
/** Help */
|
||||
public String Help = "";
|
||||
/** Window Type */
|
||||
public String WindowType = "";
|
||||
/** Image */
|
||||
public int AD_Image_ID = 0;
|
||||
/** Color */
|
||||
public int AD_Color_ID = 0;
|
||||
/** Read Write */
|
||||
public String IsReadWrite = null;
|
||||
/** Window Width */
|
||||
public int WinWidth = 0;
|
||||
/** Window Height */
|
||||
public int WinHeight = 0;
|
||||
/** Sales Order Trx */
|
||||
public boolean IsSOTrx = false;
|
||||
|
||||
/** Tabs contains MTabVO elements */
|
||||
public ArrayList<GridTabVO> Tabs = null;
|
||||
/** Base Table */
|
||||
public int AD_Table_ID = 0;
|
||||
|
||||
/** Qyery */
|
||||
public static final String WINDOWTYPE_QUERY = "Q";
|
||||
/** Transaction */
|
||||
public static final String WINDOWTYPE_TRX = "T";
|
||||
/** Maintenance */
|
||||
public static final String WINDOWTYPE_MMAINTAIN = "M";
|
||||
|
||||
/**
|
||||
* Set Context including contained elements
|
||||
* @param newCtx context
|
||||
*/
|
||||
public void setCtx (Properties newCtx)
|
||||
{
|
||||
ctx = newCtx;
|
||||
for (int i = 0; i < Tabs.size() ; i++)
|
||||
{
|
||||
GridTabVO tab = (GridTabVO)Tabs.get(i);
|
||||
tab.setCtx(newCtx);
|
||||
}
|
||||
} // setCtx
|
||||
|
||||
/**
|
||||
* Clone
|
||||
* @param windowNo no
|
||||
* @return WindowVO
|
||||
*/
|
||||
public GridWindowVO clone (int windowNo)
|
||||
{
|
||||
GridWindowVO clone = null;
|
||||
try
|
||||
{
|
||||
clone = new GridWindowVO(ctx, windowNo);
|
||||
clone.AD_Window_ID = AD_Window_ID;
|
||||
clone.Name = Name;
|
||||
clone.Description = Description;
|
||||
clone.Help = Help;
|
||||
clone.WindowType = WindowType;
|
||||
clone.AD_Image_ID = AD_Image_ID;
|
||||
clone.AD_Color_ID = AD_Color_ID;
|
||||
clone.IsReadWrite = IsReadWrite;
|
||||
clone.WinWidth = WinWidth;
|
||||
clone.WinHeight = WinHeight;
|
||||
clone.IsSOTrx = IsSOTrx;
|
||||
Env.setContext(ctx, windowNo, "IsSOTrx", clone.IsSOTrx);
|
||||
clone.AD_Table_ID = AD_Table_ID;
|
||||
Env.setContext(ctx, windowNo, "BaseTable_ID", clone.AD_Table_ID);
|
||||
//
|
||||
clone.Tabs = new ArrayList<GridTabVO>();
|
||||
for (int i = 0; i < Tabs.size(); i++)
|
||||
{
|
||||
GridTabVO tab = Tabs.get(i);
|
||||
GridTabVO cloneTab = tab.clone(clone.ctx, windowNo);
|
||||
if (cloneTab == null)
|
||||
return null;
|
||||
clone.Tabs.add(cloneTab);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
clone = null;
|
||||
}
|
||||
return clone;
|
||||
} // clone
|
||||
|
||||
} // MWindowVO
|
||||
|
|
@ -0,0 +1,457 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Base Class for MLookup, MLocator.
|
||||
* as well as for MLocation, MAccount (only single value)
|
||||
* Maintains selectable data as NamePairs in ArrayList
|
||||
* The objects itself may be shared by the lookup implementation (ususally HashMap)
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: Lookup.java,v 1.3 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public abstract class Lookup extends AbstractListModel
|
||||
implements MutableComboBoxModel, Serializable
|
||||
{
|
||||
/**
|
||||
* Lookup
|
||||
* @param displayType display type
|
||||
* @param windowNo window no
|
||||
*/
|
||||
public Lookup (int displayType, int windowNo)
|
||||
{
|
||||
m_displayType = displayType;
|
||||
m_WindowNo = windowNo;
|
||||
} // Lookup
|
||||
|
||||
/** The Data List */
|
||||
protected volatile ArrayList<Object> p_data = new ArrayList<Object>();
|
||||
|
||||
/** The Selected Item */
|
||||
private volatile Object m_selectedObject;
|
||||
|
||||
/** Temporary Data */
|
||||
private Object[] m_tempData = null;
|
||||
|
||||
/** Logger */
|
||||
protected CLogger log = CLogger.getCLogger(getClass());
|
||||
|
||||
/** Display Type */
|
||||
private int m_displayType;
|
||||
/** Window No */
|
||||
private int m_WindowNo;
|
||||
|
||||
/**
|
||||
* Get Display Type
|
||||
* @return display type
|
||||
*/
|
||||
public int getDisplayType()
|
||||
{
|
||||
return m_displayType;
|
||||
} // getDisplayType
|
||||
|
||||
/**
|
||||
* Get Window No
|
||||
* @return Window No
|
||||
*/
|
||||
public int getWindowNo()
|
||||
{
|
||||
return m_WindowNo;
|
||||
} // getWindowNo
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Set the value of the selected item. The selected item may be null.
|
||||
* <p>
|
||||
* @param anObject The combo box value or null for no selection.
|
||||
*/
|
||||
public void setSelectedItem(Object anObject)
|
||||
{
|
||||
if ((m_selectedObject != null && !m_selectedObject.equals( anObject ))
|
||||
|| m_selectedObject == null && anObject != null)
|
||||
{
|
||||
if (p_data.contains(anObject) || anObject == null)
|
||||
{
|
||||
m_selectedObject = anObject;
|
||||
// Log.trace(s_ll, "Lookup.setSelectedItem", anObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_selectedObject = null;
|
||||
log.fine(getColumnName() + ": setSelectedItem - Set to NULL");
|
||||
}
|
||||
// if (m_worker == null || !m_worker.isAlive())
|
||||
fireContentsChanged(this, -1, -1);
|
||||
}
|
||||
} // setSelectedItem
|
||||
|
||||
/**
|
||||
* Return previously selected Item
|
||||
* @return value
|
||||
*/
|
||||
public Object getSelectedItem()
|
||||
{
|
||||
return m_selectedObject;
|
||||
} // getSelectedItem
|
||||
|
||||
/**
|
||||
* Get Size of Model
|
||||
* @return size
|
||||
*/
|
||||
public int getSize()
|
||||
{
|
||||
return p_data.size();
|
||||
} // getSize
|
||||
|
||||
/**
|
||||
* Get Element at Index
|
||||
* @param index index
|
||||
* @return value
|
||||
*/
|
||||
public Object getElementAt (int index)
|
||||
{
|
||||
return p_data.get(index);
|
||||
} // getElementAt
|
||||
|
||||
/**
|
||||
* Returns the index-position of the specified object in the list.
|
||||
*
|
||||
* @param anObject object
|
||||
* @return an int representing the index position, where 0 is
|
||||
* the first position
|
||||
*/
|
||||
public int getIndexOf (Object anObject)
|
||||
{
|
||||
return p_data.indexOf(anObject);
|
||||
} // getIndexOf
|
||||
|
||||
/**
|
||||
* Add Element at the end
|
||||
* @param anObject object
|
||||
*/
|
||||
public void addElement (Object anObject)
|
||||
{
|
||||
p_data.add(anObject);
|
||||
fireIntervalAdded (this, p_data.size()-1, p_data.size()-1);
|
||||
if (p_data.size() == 1 && m_selectedObject == null && anObject != null)
|
||||
setSelectedItem (anObject);
|
||||
} // addElement
|
||||
|
||||
/**
|
||||
* Insert Element At
|
||||
* @param anObject object
|
||||
* @param index index
|
||||
*/
|
||||
public void insertElementAt (Object anObject, int index)
|
||||
{
|
||||
p_data.add (index, anObject);
|
||||
fireIntervalAdded (this, index, index);
|
||||
} // insertElementAt
|
||||
|
||||
/**
|
||||
* Remove Item at index
|
||||
* @param index index
|
||||
*/
|
||||
public void removeElementAt (int index)
|
||||
{
|
||||
if (getElementAt(index) == m_selectedObject)
|
||||
{
|
||||
if (index == 0)
|
||||
setSelectedItem (getSize() == 1 ? null : getElementAt( index + 1 ));
|
||||
else
|
||||
setSelectedItem (getElementAt (index - 1));
|
||||
}
|
||||
p_data.remove(index);
|
||||
fireIntervalRemoved (this, index, index);
|
||||
} // removeElementAt
|
||||
|
||||
/**
|
||||
* Remove Item
|
||||
* @param anObject object
|
||||
*/
|
||||
public void removeElement (Object anObject)
|
||||
{
|
||||
int index = p_data.indexOf (anObject);
|
||||
if (index != -1)
|
||||
removeElementAt(index);
|
||||
} // removeItem
|
||||
|
||||
/**
|
||||
* Empties the list.
|
||||
*/
|
||||
public void removeAllElements()
|
||||
{
|
||||
if (p_data.size() > 0)
|
||||
{
|
||||
int firstIndex = 0;
|
||||
int lastIndex = p_data.size() - 1;
|
||||
p_data.clear();
|
||||
m_selectedObject = null;
|
||||
fireIntervalRemoved (this, firstIndex, lastIndex);
|
||||
}
|
||||
} // removeAllElements
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Put Value
|
||||
* @param key key
|
||||
* @param value value
|
||||
*/
|
||||
public void put (String key, String value)
|
||||
{
|
||||
NamePair pp = new ValueNamePair (key, value);
|
||||
addElement(pp);
|
||||
} // put
|
||||
|
||||
/**
|
||||
* Put Value
|
||||
* @param key key
|
||||
* @param value value
|
||||
*/
|
||||
public void put (int key, String value)
|
||||
{
|
||||
NamePair pp = new KeyNamePair (key, value);
|
||||
addElement(pp);
|
||||
} // put
|
||||
|
||||
/**
|
||||
* Fill ComboBox with lookup data (async using Worker).
|
||||
* - try to maintain selected item
|
||||
* @param mandatory has mandatory data only (i.e. no "null" selection)
|
||||
* @param onlyValidated only validated
|
||||
* @param onlyActive onlt active
|
||||
* @param temporary save current values - restore via fillComboBox (true)
|
||||
*/
|
||||
public void fillComboBox (boolean mandatory, boolean onlyValidated,
|
||||
boolean onlyActive, boolean temporary)
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// Save current data
|
||||
if (temporary)
|
||||
{
|
||||
int size = p_data.size();
|
||||
m_tempData = new Object[size];
|
||||
// We need to do a deep copy, so store it in Array
|
||||
p_data.toArray(m_tempData);
|
||||
// for (int i = 0; i < size; i++)
|
||||
// m_tempData[i] = p_data.get(i);
|
||||
}
|
||||
|
||||
|
||||
Object obj = m_selectedObject;
|
||||
p_data.clear();
|
||||
|
||||
// may cause delay *** The Actual Work ***
|
||||
p_data = getData (mandatory, onlyValidated, onlyActive, temporary);
|
||||
|
||||
// Selected Object changed
|
||||
if (obj != m_selectedObject)
|
||||
{
|
||||
log.finest(getColumnName() + ": SelectedValue Changed=" + obj + "->" + m_selectedObject);
|
||||
obj = m_selectedObject;
|
||||
}
|
||||
|
||||
// if nothing selected & mandatory, select first
|
||||
if (obj == null && mandatory && p_data.size() > 0)
|
||||
{
|
||||
obj = p_data.get(0);
|
||||
m_selectedObject = obj;
|
||||
log.finest(getColumnName() + ": SelectedValue SetToFirst=" + obj);
|
||||
// fireContentsChanged(this, -1, -1);
|
||||
}
|
||||
fireContentsChanged(this, 0, p_data.size());
|
||||
if (p_data.size() == 0)
|
||||
log.fine(getColumnName() + ": #0 - ms="
|
||||
+ String.valueOf(System.currentTimeMillis()-startTime));
|
||||
else
|
||||
log.fine(getColumnName() + ": #" + p_data.size() + " - ms="
|
||||
+ String.valueOf(System.currentTimeMillis()-startTime));
|
||||
} // fillComboBox
|
||||
|
||||
/**
|
||||
* Fill ComboBox with old saved data (if exists) or all data available
|
||||
* @param restore if true, use saved data - else fill it with all data
|
||||
*/
|
||||
public void fillComboBox (boolean restore)
|
||||
{
|
||||
if (restore && m_tempData != null)
|
||||
{
|
||||
Object obj = m_selectedObject;
|
||||
p_data.clear();
|
||||
// restore old data
|
||||
p_data = new ArrayList<Object>(m_tempData.length);
|
||||
for (int i = 0; i < m_tempData.length; i++)
|
||||
p_data.add(m_tempData[i]);
|
||||
m_tempData = null;
|
||||
|
||||
// if nothing selected, select first
|
||||
if (obj == null && p_data.size() > 0)
|
||||
obj = p_data.get(0);
|
||||
setSelectedItem(obj);
|
||||
fireContentsChanged(this, 0, p_data.size());
|
||||
return;
|
||||
}
|
||||
if (p_data != null)
|
||||
fillComboBox(false, false, false, false);
|
||||
} // fillComboBox
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Get Display of Key Value
|
||||
* @param key key
|
||||
* @return String
|
||||
*/
|
||||
public abstract String getDisplay (Object key);
|
||||
|
||||
/**
|
||||
* Get Object of Key Value
|
||||
* @param key key
|
||||
* @return Object or null
|
||||
*/
|
||||
public abstract NamePair get (Object key);
|
||||
|
||||
|
||||
/**
|
||||
* Fill ComboBox with Data (Value/KeyNamePair)
|
||||
* @param mandatory has mandatory data only (i.e. no "null" selection)
|
||||
* @param onlyValidated only validated
|
||||
* @param onlyActive only active
|
||||
* @param temporary force load for temporary display
|
||||
* @return ArrayList
|
||||
*/
|
||||
public abstract ArrayList<Object> getData (boolean mandatory,
|
||||
boolean onlyValidated, boolean onlyActive, boolean temporary);
|
||||
|
||||
/**
|
||||
* Get underlying fully qualified Table.Column Name.
|
||||
* Used for VLookup.actionButton (Zoom)
|
||||
* @return column name
|
||||
*/
|
||||
public abstract String getColumnName();
|
||||
|
||||
/**
|
||||
* The Lookup contains the key
|
||||
* @param key key
|
||||
* @return true if contains key
|
||||
*/
|
||||
public abstract boolean containsKey (Object key);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Refresh Values - default implementation
|
||||
* @return size
|
||||
*/
|
||||
public int refresh()
|
||||
{
|
||||
return 0;
|
||||
} // refresh
|
||||
|
||||
/**
|
||||
* Is Validated - default implementation
|
||||
* @return true if validated
|
||||
*/
|
||||
public boolean isValidated()
|
||||
{
|
||||
return true;
|
||||
} // isValidated
|
||||
|
||||
/**
|
||||
* Get dynamic Validation SQL (none)
|
||||
* @return validation
|
||||
*/
|
||||
public String getValidation()
|
||||
{
|
||||
return "";
|
||||
} // getValidation
|
||||
|
||||
/**
|
||||
* Has Inactive records - default implementation
|
||||
* @return true if inactive
|
||||
*/
|
||||
public boolean hasInactive()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Zoom - default implementation
|
||||
* @return Zoom AD_Window_ID
|
||||
*/
|
||||
public int getZoom()
|
||||
{
|
||||
return 0;
|
||||
} // getZoom
|
||||
|
||||
/**
|
||||
* Get Zoom - default implementation
|
||||
* @param query query
|
||||
* @return Zoom Window - here 0
|
||||
*/
|
||||
public int getZoom(MQuery query)
|
||||
{
|
||||
return 0;
|
||||
} // getZoom
|
||||
|
||||
/**
|
||||
* Get Zoom Query String - default implementation
|
||||
* @return Zoom Query
|
||||
*/
|
||||
public MQuery getZoomQuery()
|
||||
{
|
||||
return null;
|
||||
} // getZoomQuery
|
||||
|
||||
/**
|
||||
* Get Data Direct from Table.
|
||||
* Default implementation - does not requery
|
||||
* @param key key
|
||||
* @param saveInCache save in cache for r/w
|
||||
* @param cacheLocal cache locally for r/o
|
||||
* @return value
|
||||
*/
|
||||
public NamePair getDirect (Object key, boolean saveInCache, boolean cacheLocal)
|
||||
{
|
||||
return get (key);
|
||||
} // getDirect
|
||||
|
||||
/**
|
||||
* Dispose - clear items w/o firing events
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
if (p_data != null)
|
||||
p_data.clear();
|
||||
p_data = null;
|
||||
m_selectedObject = null;
|
||||
m_tempData = null;
|
||||
} // dispose
|
||||
|
||||
/**
|
||||
* Wait until async Load Complete
|
||||
*/
|
||||
public void loadComplete()
|
||||
{
|
||||
} // loadComplete
|
||||
|
||||
} // Lookup
|
|
@ -0,0 +1,72 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* Lookup Display Column Value Object
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: LookupDisplayColumn.java,v 1.3 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public class LookupDisplayColumn implements Serializable
|
||||
{
|
||||
/**
|
||||
* Lookup Column Value Object
|
||||
* @param columnName column name
|
||||
* @param isTranslated translated
|
||||
* @param ad_Reference_ID display type
|
||||
* @param ad_Reference_Value_ID table/list reference id
|
||||
*/
|
||||
public LookupDisplayColumn(String columnName, boolean isTranslated,
|
||||
int ad_Reference_ID, int ad_Reference_Value_ID)
|
||||
{
|
||||
ColumnName = columnName;
|
||||
IsTranslated = isTranslated;
|
||||
DisplayType = ad_Reference_ID;
|
||||
AD_Reference_ID = ad_Reference_Value_ID;
|
||||
} //
|
||||
|
||||
/** Column Name */
|
||||
public String ColumnName;
|
||||
/** Translated */
|
||||
public boolean IsTranslated;
|
||||
/** Display Type */
|
||||
public int DisplayType;
|
||||
/** Value Reference */
|
||||
public int AD_Reference_ID;
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("LookupDisplayColumn[");
|
||||
sb.append("ColumnName=").append(ColumnName);
|
||||
if (IsTranslated)
|
||||
sb.append(",IsTranslated");
|
||||
sb.append(",DisplayType=").append(DisplayType);
|
||||
if (AD_Reference_ID != 0)
|
||||
sb.append(",AD_Reference_ID=").append(AD_Reference_ID);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
} // LookupDisplayColumn
|
|
@ -0,0 +1,87 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Access Log Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAccessLog.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class MAccessLog extends X_AD_AccessLog
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_AccessLog_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAccessLog (Properties ctx, int AD_AccessLog_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_AccessLog_ID, trxName);
|
||||
} // MAccessLog
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAccessLog (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MAccessLog
|
||||
|
||||
/**
|
||||
* New Constructor
|
||||
* @param ctx context
|
||||
* @param Remote_Host host
|
||||
* @param Remote_Addr address
|
||||
* @param TextMsg text message
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAccessLog (Properties ctx, String Remote_Host, String Remote_Addr,
|
||||
String TextMsg, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setRemote_Addr(Remote_Addr);
|
||||
setRemote_Host(Remote_Host);
|
||||
setTextMsg(TextMsg);
|
||||
} // MAccessLog
|
||||
|
||||
/**
|
||||
* New Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Table_ID table
|
||||
* @param AD_Column_ID column
|
||||
* @param Record_ID record
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAccessLog (Properties ctx, int AD_Table_ID, int AD_Column_ID, int Record_ID, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setAD_Table_ID(AD_Table_ID);
|
||||
setAD_Column_ID(AD_Column_ID);
|
||||
setRecord_ID(Record_ID);
|
||||
} // MAccessLog
|
||||
|
||||
} // MAccessLog
|
|
@ -0,0 +1,869 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Account Object Entity to maintain all segment values.
|
||||
* C_ValidCombination
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAccount.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class MAccount extends X_C_ValidCombination
|
||||
{
|
||||
/**
|
||||
* Get existing Account or create it
|
||||
* @param ctx context
|
||||
* @param AD_Client_ID
|
||||
* @param AD_Org_ID
|
||||
* @param C_AcctSchema_ID
|
||||
* @param Account_ID
|
||||
* @param C_SubAcct_ID
|
||||
* @param M_Product_ID
|
||||
* @param C_BPartner_ID
|
||||
* @param AD_OrgTrx_ID
|
||||
* @param C_LocFrom_ID
|
||||
* @param C_LocTo_ID
|
||||
* @param C_SalesRegion_ID
|
||||
* @param C_Project_ID
|
||||
* @param C_Campaign_ID
|
||||
* @param C_Activity_ID
|
||||
* @param User1_ID
|
||||
* @param User2_ID
|
||||
* @param UserElement1_ID
|
||||
* @param UserElement2_ID
|
||||
* @return account or null
|
||||
*/
|
||||
public static MAccount get (Properties ctx,
|
||||
int AD_Client_ID, int AD_Org_ID, int C_AcctSchema_ID,
|
||||
int Account_ID, int C_SubAcct_ID,
|
||||
int M_Product_ID, int C_BPartner_ID, int AD_OrgTrx_ID,
|
||||
int C_LocFrom_ID, int C_LocTo_ID, int C_SalesRegion_ID,
|
||||
int C_Project_ID, int C_Campaign_ID, int C_Activity_ID,
|
||||
int User1_ID, int User2_ID, int UserElement1_ID, int UserElement2_ID)
|
||||
{
|
||||
MAccount existingAccount = null;
|
||||
//
|
||||
StringBuffer info = new StringBuffer();
|
||||
StringBuffer sql = new StringBuffer("SELECT * FROM C_ValidCombination "
|
||||
// Mandatory fields
|
||||
+ "WHERE AD_Client_ID=?" // #1
|
||||
+ " AND AD_Org_ID=?"
|
||||
+ " AND C_AcctSchema_ID=?"
|
||||
+ " AND Account_ID=?"); // #4
|
||||
// Optional fields
|
||||
if (C_SubAcct_ID == 0)
|
||||
sql.append(" AND C_SubAcct_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND C_SubAcct_ID=?");
|
||||
if (M_Product_ID == 0)
|
||||
sql.append(" AND M_Product_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND M_Product_ID=?");
|
||||
if (C_BPartner_ID == 0)
|
||||
sql.append(" AND C_BPartner_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND C_BPartner_ID=?");
|
||||
if (AD_OrgTrx_ID == 0)
|
||||
sql.append(" AND AD_OrgTrx_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND AD_OrgTrx_ID=?");
|
||||
if (C_LocFrom_ID == 0)
|
||||
sql.append(" AND C_LocFrom_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND C_LocFrom_ID=?");
|
||||
if (C_LocTo_ID == 0)
|
||||
sql.append(" AND C_LocTo_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND C_LocTo_ID=?");
|
||||
if (C_SalesRegion_ID == 0)
|
||||
sql.append(" AND C_SalesRegion_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND C_SalesRegion_ID=?");
|
||||
if (C_Project_ID == 0)
|
||||
sql.append(" AND C_Project_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND C_Project_ID=?");
|
||||
if (C_Campaign_ID == 0)
|
||||
sql.append(" AND C_Campaign_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND C_Campaign_ID=?");
|
||||
if (C_Activity_ID == 0)
|
||||
sql.append(" AND C_Activity_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND C_Activity_ID=?");
|
||||
if (User1_ID == 0)
|
||||
sql.append(" AND User1_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND User1_ID=?");
|
||||
if (User2_ID == 0)
|
||||
sql.append(" AND User2_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND User2_ID=?");
|
||||
if (UserElement1_ID == 0)
|
||||
sql.append(" AND UserElement1_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND UserElement1_ID=?");
|
||||
if (UserElement2_ID == 0)
|
||||
sql.append(" AND UserElement2_ID IS NULL");
|
||||
else
|
||||
sql.append(" AND UserElement2_ID=?");
|
||||
sql.append(" AND IsActive='Y'");
|
||||
// sql.append(" ORDER BY IsFullyQualified DESC");
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
// -- Mandatory Accounting fields
|
||||
int index = 1;
|
||||
pstmt.setInt(index++, AD_Client_ID);
|
||||
pstmt.setInt(index++, AD_Org_ID);
|
||||
info.append("AD_Client_ID=").append(AD_Client_ID).append(",AD_Org_ID=").append(AD_Org_ID);
|
||||
// Schema
|
||||
pstmt.setInt(index++, C_AcctSchema_ID);
|
||||
info.append(",C_AcctSchema_ID=").append(C_AcctSchema_ID);
|
||||
// Account
|
||||
pstmt.setInt(index++, Account_ID);
|
||||
info.append(",Account_ID=").append(Account_ID).append(" ");
|
||||
|
||||
// -- Optional Accounting fields
|
||||
if (C_SubAcct_ID != 0)
|
||||
pstmt.setInt(index++, C_SubAcct_ID);
|
||||
if (M_Product_ID != 0)
|
||||
pstmt.setInt(index++, M_Product_ID);
|
||||
if (C_BPartner_ID != 0)
|
||||
pstmt.setInt(index++, C_BPartner_ID);
|
||||
if (AD_OrgTrx_ID != 0)
|
||||
pstmt.setInt(index++, AD_OrgTrx_ID);
|
||||
if (C_LocFrom_ID != 0)
|
||||
pstmt.setInt(index++, C_LocFrom_ID);
|
||||
if (C_LocTo_ID != 0)
|
||||
pstmt.setInt(index++, C_LocTo_ID);
|
||||
if (C_SalesRegion_ID != 0)
|
||||
pstmt.setInt(index++, C_SalesRegion_ID);
|
||||
if (C_Project_ID != 0)
|
||||
pstmt.setInt(index++, C_Project_ID);
|
||||
if (C_Campaign_ID != 0)
|
||||
pstmt.setInt(index++, C_Campaign_ID);
|
||||
if (C_Activity_ID != 0)
|
||||
pstmt.setInt(index++, C_Activity_ID);
|
||||
if (User1_ID != 0)
|
||||
pstmt.setInt(index++, User1_ID);
|
||||
if (User2_ID != 0)
|
||||
pstmt.setInt(index++, User2_ID);
|
||||
if (UserElement1_ID != 0)
|
||||
pstmt.setInt(index++, UserElement1_ID);
|
||||
if (UserElement2_ID != 0)
|
||||
pstmt.setInt(index++, UserElement2_ID);
|
||||
//
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
existingAccount = new MAccount (ctx, rs, null);
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, info + "\n" + sql, e);
|
||||
}
|
||||
// Existing
|
||||
if (existingAccount != null)
|
||||
return existingAccount;
|
||||
|
||||
// New
|
||||
MAccount newAccount = new MAccount (ctx, 0, null);
|
||||
newAccount.setClientOrg(AD_Client_ID, AD_Org_ID);
|
||||
newAccount.setC_AcctSchema_ID(C_AcctSchema_ID);
|
||||
newAccount.setAccount_ID(Account_ID);
|
||||
// -- Optional Accounting fields
|
||||
newAccount.setC_SubAcct_ID(C_SubAcct_ID);
|
||||
newAccount.setM_Product_ID(M_Product_ID);
|
||||
newAccount.setC_BPartner_ID(C_BPartner_ID);
|
||||
newAccount.setAD_OrgTrx_ID(AD_OrgTrx_ID);
|
||||
newAccount.setC_LocFrom_ID(C_LocFrom_ID);
|
||||
newAccount.setC_LocTo_ID(C_LocTo_ID);
|
||||
newAccount.setC_SalesRegion_ID(C_SalesRegion_ID);
|
||||
newAccount.setC_Project_ID(C_Project_ID);
|
||||
newAccount.setC_Campaign_ID(C_Campaign_ID);
|
||||
newAccount.setC_Activity_ID(C_Activity_ID);
|
||||
newAccount.setUser1_ID(User1_ID);
|
||||
newAccount.setUser2_ID(User2_ID);
|
||||
newAccount.setUserElement1_ID(UserElement1_ID);
|
||||
newAccount.setUserElement2_ID(UserElement2_ID);
|
||||
//
|
||||
if (!newAccount.save())
|
||||
{
|
||||
s_log.log(Level.SEVERE, "Could not create new account - " + info);
|
||||
return null;
|
||||
}
|
||||
s_log.fine("New: " + newAccount);
|
||||
return newAccount;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get first with Alias
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID as
|
||||
* @param alias alias
|
||||
* @return account
|
||||
*/
|
||||
public static MAccount get (Properties ctx, int C_AcctSchema_ID, String alias)
|
||||
{
|
||||
MAccount retValue = null;
|
||||
String sql = "SELECT * FROM C_ValidCombination WHERE C_AcctSchema_ID=? AND Alias=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt(1, C_AcctSchema_ID);
|
||||
pstmt.setString (2, alias);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
retValue = new MAccount (ctx, rs, null);
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log (Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get from existing Accounting fact
|
||||
* @param fa accounting fact
|
||||
* @return account
|
||||
*/
|
||||
public static MAccount get (X_Fact_Acct fa)
|
||||
{
|
||||
MAccount acct = get (fa.getCtx(),
|
||||
fa.getAD_Client_ID(), fa.getAD_Org_ID(), fa.getC_AcctSchema_ID(),
|
||||
fa.getAccount_ID(), fa.getC_SubAcct_ID(),
|
||||
fa.getM_Product_ID(), fa.getC_BPartner_ID(), fa.getAD_OrgTrx_ID(),
|
||||
fa.getC_LocFrom_ID(), fa.getC_LocTo_ID(), fa.getC_SalesRegion_ID(),
|
||||
fa.getC_Project_ID(), fa.getC_Campaign_ID(), fa.getC_Activity_ID(),
|
||||
fa.getUser1_ID(), fa.getUser2_ID(), fa.getUserElement1_ID(), fa.getUserElement2_ID());
|
||||
return acct;
|
||||
} // get
|
||||
|
||||
/**************************************************************************
|
||||
* Factory: default combination
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID accounting schema
|
||||
* @param optionalNull if true the optional values are null
|
||||
* @param trxName transaction
|
||||
* @return Account
|
||||
*/
|
||||
public static MAccount getDefault (Properties ctx, int C_AcctSchema_ID,
|
||||
boolean optionalNull, String trxName)
|
||||
{
|
||||
MAcctSchema acctSchema = new MAcctSchema (ctx, C_AcctSchema_ID, trxName);
|
||||
return getDefault (acctSchema, optionalNull);
|
||||
} // getDefault
|
||||
|
||||
/**
|
||||
* Factory: default combination
|
||||
* @param acctSchema accounting schema
|
||||
* @param optionalNull if true, the optional values are null
|
||||
* @return Account
|
||||
*/
|
||||
public static MAccount getDefault (MAcctSchema acctSchema, boolean optionalNull)
|
||||
{
|
||||
MAccount vc = new MAccount(acctSchema);
|
||||
// Active Elements
|
||||
MAcctSchemaElement[] elements = acctSchema.getAcctSchemaElements();
|
||||
for (int i = 0; i < elements.length; i++)
|
||||
{
|
||||
MAcctSchemaElement ase = elements[i];
|
||||
String elementType = ase.getElementType();
|
||||
int defaultValue = ase.getDefaultValue();
|
||||
boolean setValue = ase.isMandatory() || (!ase.isMandatory() && !optionalNull);
|
||||
//
|
||||
if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Organization))
|
||||
vc.setAD_Org_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Account))
|
||||
vc.setAccount_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount) && setValue)
|
||||
vc.setC_SubAcct_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner) && setValue)
|
||||
vc.setC_BPartner_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Product) && setValue)
|
||||
vc.setM_Product_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Activity) && setValue)
|
||||
vc.setC_Activity_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom) && setValue)
|
||||
vc.setC_LocFrom_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo) && setValue)
|
||||
vc.setC_LocTo_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign) && setValue)
|
||||
vc.setC_Campaign_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx) && setValue)
|
||||
vc.setAD_OrgTrx_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Project) && setValue)
|
||||
vc.setC_Project_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion) && setValue)
|
||||
vc.setC_SalesRegion_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1) && setValue)
|
||||
vc.setUser1_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2) && setValue)
|
||||
vc.setUser2_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserElement1) && setValue)
|
||||
vc.setUserElement1_ID(defaultValue);
|
||||
else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserElement2) && setValue)
|
||||
vc.setUserElement2_ID(defaultValue);
|
||||
}
|
||||
s_log.fine("Client_ID="
|
||||
+ vc.getAD_Client_ID() + ", Org_ID=" + vc.getAD_Org_ID()
|
||||
+ " - AcctSchema_ID=" + vc.getC_AcctSchema_ID() + ", Account_ID=" + vc.getAccount_ID());
|
||||
return vc;
|
||||
} // getDefault
|
||||
|
||||
|
||||
/**
|
||||
* Get Account
|
||||
* @param ctx context
|
||||
* @param C_ValidCombination_ID combination
|
||||
* @return Account
|
||||
*/
|
||||
public static MAccount get (Properties ctx, int C_ValidCombination_ID)
|
||||
{
|
||||
// Maybe later cache
|
||||
return new MAccount(ctx, C_ValidCombination_ID, null);
|
||||
} // getAccount
|
||||
|
||||
/**
|
||||
* Update Value/Description after change of
|
||||
* account element value/description.
|
||||
* @param ctx context
|
||||
* @param where where clause
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public static void updateValueDescription (Properties ctx, String where, String trxName)
|
||||
{
|
||||
String sql = "SELECT * FROM C_ValidCombination";
|
||||
if (where != null && where.length() > 0)
|
||||
sql += " WHERE " + where;
|
||||
sql += " ORDER BY C_ValidCombination_ID";
|
||||
int count = 0;
|
||||
int errors = 0;
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, trxName);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
MAccount account = new MAccount (ctx, rs, trxName);
|
||||
account.setValueDescription();
|
||||
if (account.save())
|
||||
count++;
|
||||
else
|
||||
errors++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
s_log.info(where + " #" + count + ", Errors=" + errors);
|
||||
} // updateValueDescription
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MAccount.class);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Default constructor
|
||||
* @param ctx context
|
||||
* @param C_ValidCombination_ID combination
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAccount (Properties ctx, int C_ValidCombination_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_ValidCombination_ID, trxName);
|
||||
if (C_ValidCombination_ID == 0)
|
||||
{
|
||||
// setAccount_ID (0);
|
||||
// setC_AcctSchema_ID (0);
|
||||
setIsFullyQualified (false);
|
||||
}
|
||||
} // MAccount
|
||||
|
||||
/**
|
||||
* Load constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAccount (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MAccount
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param as account schema
|
||||
*/
|
||||
public MAccount (MAcctSchema as)
|
||||
{
|
||||
this (as.getCtx(), 0, as.get_TrxName());
|
||||
setClientOrg(as);
|
||||
setC_AcctSchema_ID(as.getC_AcctSchema_ID());
|
||||
} // Account
|
||||
|
||||
/** Account Segment */
|
||||
private MElementValue m_accountEV = null;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Return String representation
|
||||
* @return String
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MAccount=[");
|
||||
sb.append(getC_ValidCombination_ID());
|
||||
if (getCombination() != null)
|
||||
sb.append(",")
|
||||
.append(getCombination());
|
||||
else
|
||||
{
|
||||
// .append(",Client=").append(getAD_Client_ID())
|
||||
sb.append(",Schema=").append(getC_AcctSchema_ID())
|
||||
.append(",Org=").append(getAD_Org_ID())
|
||||
.append(",Acct=").append(getAccount_ID())
|
||||
.append(" ");
|
||||
if (getC_SubAcct_ID() != 0)
|
||||
sb.append(",C_SubAcct_ID=").append(getC_SubAcct_ID());
|
||||
if (getM_Product_ID() != 0)
|
||||
sb.append(",M_Product_ID=").append(getM_Product_ID());
|
||||
if (getC_BPartner_ID() != 0)
|
||||
sb.append(",C_BPartner_ID=").append(getC_BPartner_ID());
|
||||
if (getAD_OrgTrx_ID() != 0)
|
||||
sb.append(",AD_OrgTrx_ID=").append(getAD_OrgTrx_ID());
|
||||
if (getC_LocFrom_ID() != 0)
|
||||
sb.append(",C_LocFrom_ID=").append(getC_LocFrom_ID());
|
||||
if (getC_LocTo_ID() != 0)
|
||||
sb.append(",C_LocTo_ID=").append(getC_LocTo_ID());
|
||||
if (getC_SalesRegion_ID() != 0)
|
||||
sb.append(",C_SalesRegion_ID=").append(getC_SalesRegion_ID());
|
||||
if (getC_Project_ID() != 0)
|
||||
sb.append(",C_Project_ID=").append(getC_Project_ID());
|
||||
if (getC_Campaign_ID() != 0)
|
||||
sb.append(",C_Campaign_ID=").append(getC_Campaign_ID());
|
||||
if (getC_Activity_ID() != 0)
|
||||
sb.append(",C_Activity_ID=").append(getC_Activity_ID());
|
||||
if (getUser1_ID() != 0)
|
||||
sb.append(",User1_ID=").append(getUser1_ID());
|
||||
if (getUser2_ID() != 0)
|
||||
sb.append(",User2_ID=").append(getUser2_ID());
|
||||
if (getUserElement1_ID() != 0)
|
||||
sb.append(",UserElement1_ID=").append(getUserElement1_ID());
|
||||
if (getUserElement2_ID() != 0)
|
||||
sb.append(",UserElement2_ID=").append(getUserElement2_ID());
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Set Account_ID
|
||||
* @param Account_ID id
|
||||
*/
|
||||
public void setAccount_ID (int Account_ID)
|
||||
{
|
||||
m_accountEV = null; // reset
|
||||
super.setAccount_ID(Account_ID);
|
||||
} // setAccount
|
||||
|
||||
/**
|
||||
* Set Account_ID
|
||||
* @return element value
|
||||
*/
|
||||
public MElementValue getAccount ()
|
||||
{
|
||||
if (m_accountEV == null)
|
||||
{
|
||||
if (getAccount_ID() != 0)
|
||||
m_accountEV = new MElementValue(getCtx(), getAccount_ID(), get_TrxName());
|
||||
}
|
||||
return m_accountEV;
|
||||
} // setAccount
|
||||
|
||||
|
||||
/**
|
||||
* Get Account Type
|
||||
* @return Account Type of Account Element
|
||||
*/
|
||||
public String getAccountType()
|
||||
{
|
||||
if (m_accountEV == null)
|
||||
getAccount();
|
||||
if (m_accountEV == null)
|
||||
{
|
||||
log.log(Level.SEVERE, "No ElementValue for Account_ID=" + getAccount_ID());
|
||||
return "";
|
||||
}
|
||||
return m_accountEV.getAccountType();
|
||||
} // getAccountType
|
||||
|
||||
/**
|
||||
* Is this a Balance Sheet Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isBalanceSheet()
|
||||
{
|
||||
String accountType = getAccountType();
|
||||
return (MElementValue.ACCOUNTTYPE_Asset.equals(accountType)
|
||||
|| MElementValue.ACCOUNTTYPE_Liability.equals(accountType)
|
||||
|| MElementValue.ACCOUNTTYPE_OwnerSEquity.equals(accountType));
|
||||
} // isBalanceSheet
|
||||
|
||||
/**
|
||||
* Is this an Activa Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isActiva()
|
||||
{
|
||||
return MElementValue.ACCOUNTTYPE_Asset.equals(getAccountType());
|
||||
} // isActive
|
||||
|
||||
/**
|
||||
* Is this a Passiva Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isPassiva()
|
||||
{
|
||||
String accountType = getAccountType();
|
||||
return (MElementValue.ACCOUNTTYPE_Liability.equals(accountType)
|
||||
|| MElementValue.ACCOUNTTYPE_OwnerSEquity.equals(accountType));
|
||||
} // isPassiva
|
||||
|
||||
/**
|
||||
* Set Value and Description and Fully Qualified Flag for Combination
|
||||
*/
|
||||
public void setValueDescription()
|
||||
{
|
||||
StringBuffer combi = new StringBuffer();
|
||||
StringBuffer descr = new StringBuffer();
|
||||
boolean fullyQualified = true;
|
||||
//
|
||||
MAcctSchema as = new MAcctSchema(getCtx(), getC_AcctSchema_ID(), get_TrxName()); // In Trx!
|
||||
MAcctSchemaElement[] elements = MAcctSchemaElement.getAcctSchemaElements(as);
|
||||
for (int i = 0; i < elements.length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
combi.append(as.getSeparator());
|
||||
descr.append(as.getSeparator());
|
||||
}
|
||||
MAcctSchemaElement element = elements[i];
|
||||
String combiStr = "_"; // not defined
|
||||
String descrStr = "_";
|
||||
|
||||
if (MAcctSchemaElement.ELEMENTTYPE_Organization.equals(element.getElementType()))
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
{
|
||||
MOrg org = new MOrg(getCtx(), getAD_Org_ID(), get_TrxName()); // in Trx!
|
||||
combiStr = org.getValue();
|
||||
descrStr = org.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
combiStr = "*";
|
||||
descrStr = "*";
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_Account.equals(element.getElementType()))
|
||||
{
|
||||
if (getAccount_ID() != 0)
|
||||
{
|
||||
if (m_accountEV == null)
|
||||
m_accountEV = new MElementValue(getCtx(), getAccount_ID(), get_TrxName());
|
||||
combiStr = m_accountEV.getValue();
|
||||
descrStr = m_accountEV.getName();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Account");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_SubAccount.equals(element.getElementType()))
|
||||
{
|
||||
if (getC_SubAcct_ID() != 0)
|
||||
{
|
||||
X_C_SubAcct sa = new X_C_SubAcct(getCtx(), getC_SubAcct_ID(), get_TrxName());
|
||||
combiStr = sa.getValue();
|
||||
descrStr = sa.getName();
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_Product.equals(element.getElementType()))
|
||||
{
|
||||
if (getM_Product_ID() != 0)
|
||||
{
|
||||
X_M_Product product = new X_M_Product (getCtx(), getM_Product_ID(), get_TrxName());
|
||||
combiStr = product.getValue();
|
||||
descrStr = product.getName();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Product");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_BPartner.equals(element.getElementType()))
|
||||
{
|
||||
if (getC_BPartner_ID() != 0)
|
||||
{
|
||||
X_C_BPartner partner = new X_C_BPartner (getCtx(), getC_BPartner_ID(),get_TrxName());
|
||||
combiStr = partner.getValue();
|
||||
descrStr = partner.getName();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Business Partner");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_OrgTrx.equals(element.getElementType()))
|
||||
{
|
||||
if (getAD_OrgTrx_ID() != 0)
|
||||
{
|
||||
MOrg org = new MOrg(getCtx(), getAD_OrgTrx_ID(), get_TrxName()); // in Trx!
|
||||
combiStr = org.getValue();
|
||||
descrStr = org.getName();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Trx Org");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_LocationFrom.equals(element.getElementType()))
|
||||
{
|
||||
if (getC_LocFrom_ID() != 0)
|
||||
{
|
||||
MLocation loc = new MLocation(getCtx(), getC_LocFrom_ID(), get_TrxName()); // in Trx!
|
||||
combiStr = loc.getPostal();
|
||||
descrStr = loc.getCity();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Location From");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_LocationTo.equals(element.getElementType()))
|
||||
{
|
||||
if (getC_LocTo_ID() != 0)
|
||||
{
|
||||
MLocation loc = new MLocation(getCtx(), getC_LocFrom_ID(), get_TrxName()); // in Trx!
|
||||
combiStr = loc.getPostal();
|
||||
descrStr = loc.getCity();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Location To");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_SalesRegion.equals(element.getElementType()))
|
||||
{
|
||||
if (getC_SalesRegion_ID() != 0)
|
||||
{
|
||||
MSalesRegion loc = new MSalesRegion(getCtx(), getC_SalesRegion_ID(), get_TrxName());
|
||||
combiStr = loc.getValue();
|
||||
descrStr = loc.getName();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: SalesRegion");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_Project.equals(element.getElementType()))
|
||||
{
|
||||
if (getC_Project_ID() != 0)
|
||||
{
|
||||
X_C_Project project = new X_C_Project (getCtx(), getC_Project_ID(), get_TrxName());
|
||||
combiStr = project.getValue();
|
||||
descrStr = project.getName();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Project");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_Campaign.equals(element.getElementType()))
|
||||
{
|
||||
if (getC_Campaign_ID() != 0)
|
||||
{
|
||||
X_C_Campaign campaign = new X_C_Campaign (getCtx(), getC_Campaign_ID(), get_TrxName());
|
||||
combiStr = campaign.getValue();
|
||||
descrStr = campaign.getName();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Campaign");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_Activity.equals(element.getElementType()))
|
||||
{
|
||||
if (getC_Activity_ID() != 0)
|
||||
{
|
||||
X_C_Activity act = new X_C_Activity (getCtx(), getC_Activity_ID(), get_TrxName());
|
||||
combiStr = act.getValue();
|
||||
descrStr = act.getName();
|
||||
}
|
||||
else if (element.isMandatory())
|
||||
{
|
||||
log.warning("Mandatory Element missing: Campaign");
|
||||
fullyQualified = false;
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_UserList1.equals(element.getElementType()))
|
||||
{
|
||||
if (getUser1_ID() != 0)
|
||||
{
|
||||
MElementValue ev = new MElementValue(getCtx(), getUser1_ID(), get_TrxName());
|
||||
combiStr = ev.getValue();
|
||||
descrStr = ev.getName();
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_UserList2.equals(element.getElementType()))
|
||||
{
|
||||
if (getUser2_ID() != 0)
|
||||
{
|
||||
MElementValue ev = new MElementValue(getCtx(), getUser2_ID(), get_TrxName());
|
||||
combiStr = ev.getValue();
|
||||
descrStr = ev.getName();
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_UserElement1.equals(element.getElementType()))
|
||||
{
|
||||
if (getUserElement1_ID() != 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (MAcctSchemaElement.ELEMENTTYPE_UserElement2.equals(element.getElementType()))
|
||||
{
|
||||
if (getUserElement2_ID() != 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
combi.append(combiStr);
|
||||
descr.append(descrStr);
|
||||
}
|
||||
// Set Values
|
||||
super.setCombination(combi.toString());
|
||||
super.setDescription(descr.toString());
|
||||
if (fullyQualified != isFullyQualified())
|
||||
setIsFullyQualified(fullyQualified);
|
||||
log.fine("Combination=" + getCombination()
|
||||
+ " - " + getDescription()
|
||||
+ " - FullyQualified=" + fullyQualified);
|
||||
} // setValueDescription
|
||||
|
||||
/**
|
||||
* Validate combination
|
||||
* @return true if valid
|
||||
*/
|
||||
public boolean validate()
|
||||
{
|
||||
boolean ok = true;
|
||||
// Validate Sub-Account
|
||||
if (getC_SubAcct_ID() != 0)
|
||||
{
|
||||
X_C_SubAcct sa = new X_C_SubAcct(getCtx(), getC_SubAcct_ID(), get_TrxName());
|
||||
if (sa.getC_ElementValue_ID() != getAccount_ID())
|
||||
{
|
||||
log.saveError("Error", "C_SubAcct.C_ElementValue_ID=" + sa.getC_ElementValue_ID()
|
||||
+ "<>Account_ID=" + getAccount_ID());
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
} // validate
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
setValueDescription();
|
||||
return validate();
|
||||
} // beforeSave
|
||||
|
||||
|
||||
/**
|
||||
* Test
|
||||
* @param args
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
org.compiere.Adempiere.startup(true);
|
||||
MAccount acct = get (Env.getCtx(), 11, 11, 101, 600, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
System.out.println(acct);
|
||||
System.out.println(acct.get_xmlString(new StringBuffer ("xxxx")));
|
||||
|
||||
//
|
||||
MAccount acct2 = get (Env.getCtx(), 11, 12, 101, 600, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
System.out.println(acct2);
|
||||
|
||||
} // main
|
||||
|
||||
} // Account
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Account Model Lookup - Maintains ValidCombination Info for Display & Edit - not cached
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAccountLookup.java,v 1.3 2006/07/30 00:54:54 jjanke Exp $
|
||||
*/
|
||||
public final class MAccountLookup extends Lookup implements Serializable
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param WindowNo window no
|
||||
*/
|
||||
public MAccountLookup (Properties ctx, int WindowNo)
|
||||
{
|
||||
super (DisplayType.TableDir, WindowNo);
|
||||
m_ctx = ctx;
|
||||
} // MAccountLookup
|
||||
|
||||
/** Context */
|
||||
private Properties m_ctx;
|
||||
/** Account_ID */
|
||||
public int C_ValidCombination_ID;
|
||||
private String Combination;
|
||||
private String Description;
|
||||
|
||||
/**
|
||||
* Get Display for Value
|
||||
* @param value value
|
||||
* @return String
|
||||
*/
|
||||
public String getDisplay (Object value)
|
||||
{
|
||||
if (!containsKey (value))
|
||||
return "<" + value.toString() + ">";
|
||||
return toString();
|
||||
} // getDisplay
|
||||
|
||||
/**
|
||||
* Get Object of Key Value
|
||||
* @param value value
|
||||
* @return Object or null
|
||||
*/
|
||||
public NamePair get (Object value)
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
if (!containsKey (value))
|
||||
return null;
|
||||
return new KeyNamePair (C_ValidCombination_ID, toString());
|
||||
} // get
|
||||
|
||||
/**
|
||||
* The Lookup contains the key
|
||||
* @param key key
|
||||
* @return true if exists
|
||||
*/
|
||||
public boolean containsKey (Object key)
|
||||
{
|
||||
int intValue = 0;
|
||||
if (key instanceof Integer)
|
||||
intValue = ((Integer)key).intValue();
|
||||
else if (key != null)
|
||||
intValue = Integer.parseInt(key.toString());
|
||||
//
|
||||
return load (intValue);
|
||||
} // containsKey
|
||||
|
||||
/**
|
||||
* Get Description
|
||||
* @return Description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return Description;
|
||||
} // getDescription
|
||||
|
||||
/**
|
||||
* Return String representation
|
||||
* @return Combination
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
if (C_ValidCombination_ID == 0)
|
||||
return "";
|
||||
return Combination;
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Load C_ValidCombination with ID
|
||||
* @param ID C_ValidCombination_ID
|
||||
* @return true if found
|
||||
*/
|
||||
public boolean load (int ID)
|
||||
{
|
||||
if (ID == 0) // new
|
||||
{
|
||||
C_ValidCombination_ID = 0;
|
||||
Combination = "";
|
||||
Description = "";
|
||||
return true;
|
||||
}
|
||||
if (ID == C_ValidCombination_ID) // already loaded
|
||||
return true;
|
||||
|
||||
String SQL = "SELECT C_ValidCombination_ID, Combination, Description "
|
||||
+ "FROM C_ValidCombination WHERE C_ValidCombination_ID=?";
|
||||
try
|
||||
{
|
||||
// Prepare Statement
|
||||
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
|
||||
pstmt.setInt(1, ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (!rs.next())
|
||||
{
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
return false;
|
||||
}
|
||||
//
|
||||
C_ValidCombination_ID = rs.getInt(1);
|
||||
Combination = rs.getString(2);
|
||||
Description = rs.getString(3);
|
||||
//
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // load
|
||||
|
||||
/**
|
||||
* Get underlying fully qualified Table.Column Name
|
||||
* @return ""
|
||||
*/
|
||||
public String getColumnName()
|
||||
{
|
||||
return "";
|
||||
} // getColumnName
|
||||
|
||||
/**
|
||||
* Return data as sorted Array.
|
||||
* Used in Web Interface
|
||||
* @param mandatory mandatory
|
||||
* @param onlyValidated only valid
|
||||
* @param onlyActive only active
|
||||
* @param temporary force load for temporary display
|
||||
* @return ArrayList with KeyNamePair
|
||||
*/
|
||||
public ArrayList<Object> getData (boolean mandatory, boolean onlyValidated,
|
||||
boolean onlyActive, boolean temporary)
|
||||
{
|
||||
ArrayList<Object> list = new ArrayList<Object>();
|
||||
if (!mandatory)
|
||||
list.add(new KeyNamePair (-1, ""));
|
||||
//
|
||||
StringBuffer sql = new StringBuffer ("SELECT C_ValidCombination_ID, Combination, Description "
|
||||
+ "FROM C_ValidCombination WHERE AD_Client_ID=?");
|
||||
if (onlyActive)
|
||||
sql.append(" AND IsActive='Y'");
|
||||
sql.append(" ORDER BY 2");
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
|
||||
pstmt.setInt(1, Env.getAD_Client_ID(m_ctx));
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
list.add (new KeyNamePair(rs.getInt(1), rs.getString(2) + " - " + rs.getString(3)));
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql.toString(), e);
|
||||
}
|
||||
|
||||
// Sort & return
|
||||
return list;
|
||||
} // getData
|
||||
|
||||
} // MAccountLookup
|
|
@ -0,0 +1,605 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Accounting Schema Model (base)
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAcctSchema.java,v 1.4 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class MAcctSchema extends X_C_AcctSchema
|
||||
{
|
||||
/**
|
||||
* Get AccountSchema of Client
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID schema id
|
||||
* @return Accounting schema
|
||||
*/
|
||||
public static MAcctSchema get (Properties ctx, int C_AcctSchema_ID)
|
||||
{
|
||||
return get(ctx, C_AcctSchema_ID, null);
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get AccountSchema of Client
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID schema id
|
||||
* @param trxName optional trx
|
||||
* @return Accounting schema
|
||||
*/
|
||||
public static MAcctSchema get (Properties ctx, int C_AcctSchema_ID, String trxName)
|
||||
{
|
||||
// Check Cache
|
||||
Integer key = new Integer(C_AcctSchema_ID);
|
||||
MAcctSchema retValue = (MAcctSchema)s_cache.get(key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MAcctSchema (ctx, C_AcctSchema_ID, trxName);
|
||||
if (trxName == null)
|
||||
s_cache.put(key, retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get AccountSchema of Client
|
||||
* @param ctx context
|
||||
* @param AD_Client_ID client or 0 for all
|
||||
* @return Array of AcctSchema of Client
|
||||
*/
|
||||
public static MAcctSchema[] getClientAcctSchema (Properties ctx, int AD_Client_ID)
|
||||
{
|
||||
return getClientAcctSchema(ctx, AD_Client_ID, null);
|
||||
} // getClientAcctSchema
|
||||
|
||||
/**
|
||||
* Get AccountSchema of Client
|
||||
* @param ctx context
|
||||
* @param AD_Client_ID client or 0 for all
|
||||
* @param trxName optional trx
|
||||
* @return Array of AcctSchema of Client
|
||||
*/
|
||||
public static MAcctSchema[] getClientAcctSchema (Properties ctx, int AD_Client_ID, String trxName)
|
||||
{
|
||||
// Check Cache
|
||||
Integer key = new Integer(AD_Client_ID);
|
||||
if (s_schema.containsKey(key))
|
||||
return (MAcctSchema[])s_schema.get(key);
|
||||
|
||||
// Create New
|
||||
ArrayList<MAcctSchema> list = new ArrayList<MAcctSchema>();
|
||||
MClientInfo info = MClientInfo.get(ctx, AD_Client_ID, trxName);
|
||||
MAcctSchema as = MAcctSchema.get (ctx, info.getC_AcctSchema1_ID(), trxName);
|
||||
if (as.get_ID() != 0 && trxName == null)
|
||||
list.add(as);
|
||||
|
||||
// Other
|
||||
String sql = "SELECT C_AcctSchema_ID FROM C_AcctSchema acs "
|
||||
+ "WHERE IsActive='Y'"
|
||||
+ " AND EXISTS (SELECT * FROM C_AcctSchema_GL gl WHERE acs.C_AcctSchema_ID=gl.C_AcctSchema_ID)"
|
||||
+ " AND EXISTS (SELECT * FROM C_AcctSchema_Default d WHERE acs.C_AcctSchema_ID=d.C_AcctSchema_ID)";
|
||||
if (AD_Client_ID != 0)
|
||||
sql += " AND AD_Client_ID=?";
|
||||
sql += " ORDER BY C_AcctSchema_ID";
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, trxName);
|
||||
if (AD_Client_ID != 0)
|
||||
pstmt.setInt(1, AD_Client_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
int id = rs.getInt(1);
|
||||
if (id != info.getC_AcctSchema1_ID()) // already in list
|
||||
{
|
||||
as = MAcctSchema.get (ctx, id, trxName);
|
||||
if (as.get_ID() != 0 && trxName == null)
|
||||
list.add(as);
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
// Save
|
||||
MAcctSchema[] retValue = new MAcctSchema [list.size()];
|
||||
list.toArray(retValue);
|
||||
if (trxName == null)
|
||||
s_schema.put(key, retValue);
|
||||
return retValue;
|
||||
} // getClientAcctSchema
|
||||
|
||||
/** Cache of Client AcctSchema Arrays **/
|
||||
private static CCache<Integer,MAcctSchema[]> s_schema = new CCache<Integer,MAcctSchema[]>("AD_ClientInfo", 3); // 3 clients
|
||||
/** Cache of AcctSchemas **/
|
||||
private static CCache<Integer,MAcctSchema> s_cache = new CCache<Integer,MAcctSchema>("C_AcctSchema", 3); // 3 accounting schemas
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger(MAcctSchema.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAcctSchema (Properties ctx, int C_AcctSchema_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_AcctSchema_ID, trxName);
|
||||
if (C_AcctSchema_ID == 0)
|
||||
{
|
||||
// setC_Currency_ID (0);
|
||||
// setName (null);
|
||||
setAutoPeriodControl (true);
|
||||
setPeriod_OpenFuture(2);
|
||||
setPeriod_OpenHistory(2);
|
||||
setCostingMethod (COSTINGMETHOD_StandardCosting);
|
||||
setCostingLevel(COSTINGLEVEL_Client);
|
||||
setIsAdjustCOGS(false);
|
||||
setGAAP (GAAP_InternationalGAAP);
|
||||
setHasAlias (true);
|
||||
setHasCombination (false);
|
||||
setIsAccrual (true); // Y
|
||||
setCommitmentType(COMMITMENTTYPE_None);
|
||||
setIsDiscountCorrectsTax (false);
|
||||
setTaxCorrectionType(TAXCORRECTIONTYPE_None);
|
||||
setIsTradeDiscountPosted (false);
|
||||
setIsPostServices(false);
|
||||
setIsExplicitCostAdjustment(false);
|
||||
setSeparator ("-"); // -
|
||||
}
|
||||
} // MAcctSchema
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAcctSchema (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MAcctSchema
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param client client
|
||||
* @param currency currency
|
||||
*/
|
||||
public MAcctSchema (MClient client, KeyNamePair currency)
|
||||
{
|
||||
this (client.getCtx(), 0, client.get_TrxName());
|
||||
setClientOrg(client);
|
||||
setC_Currency_ID (currency.getKey());
|
||||
setName (client.getName() + " " + getGAAP() + "/" + get_ColumnCount() + " " + currency.getName());
|
||||
} // MAcctSchema
|
||||
|
||||
|
||||
/** Element List */
|
||||
private MAcctSchemaElement[] m_elements = null;
|
||||
/** GL Info */
|
||||
private MAcctSchemaGL m_gl = null;
|
||||
/** Default Info */
|
||||
private MAcctSchemaDefault m_default = null;
|
||||
|
||||
private MAccount m_SuspenseError_Acct = null;
|
||||
private MAccount m_CurrencyBalancing_Acct = null;
|
||||
private MAccount m_DueTo_Acct = null;
|
||||
private MAccount m_DueFrom_Acct = null;
|
||||
/** Accounting Currency Precision */
|
||||
private int m_stdPrecision = -1;
|
||||
/** Costing Currency Precision */
|
||||
private int m_costPrecision = -1;
|
||||
|
||||
/** Only Post Org */
|
||||
private MOrg m_onlyOrg = null;
|
||||
/** Only Post Org Childs */
|
||||
private Integer[] m_onlyOrgs = null;
|
||||
|
||||
/**************************************************************************
|
||||
* AcctSchema Elements
|
||||
* @return ArrayList of AcctSchemaElement
|
||||
*/
|
||||
public MAcctSchemaElement[] getAcctSchemaElements()
|
||||
{
|
||||
if (m_elements == null)
|
||||
m_elements = MAcctSchemaElement.getAcctSchemaElements(this);
|
||||
return m_elements;
|
||||
} // getAcctSchemaElements
|
||||
|
||||
/**
|
||||
* Get AcctSchema Element
|
||||
* @param elementType segment type - AcctSchemaElement.ELEMENTTYPE_
|
||||
* @return AcctSchemaElement
|
||||
*/
|
||||
public MAcctSchemaElement getAcctSchemaElement (String elementType)
|
||||
{
|
||||
if (m_elements == null)
|
||||
getAcctSchemaElements();
|
||||
for (int i = 0; i < m_elements.length; i++)
|
||||
{
|
||||
MAcctSchemaElement ase = m_elements[i];
|
||||
if (ase.getElementType().equals(elementType))
|
||||
return ase;
|
||||
}
|
||||
return null;
|
||||
} // getAcctSchemaElement
|
||||
|
||||
/**
|
||||
* Has AcctSchema Element
|
||||
* @param segmentType segment type - AcctSchemaElement.SEGMENT_
|
||||
* @return true if schema has segment type
|
||||
*/
|
||||
public boolean isAcctSchemaElement (String segmentType)
|
||||
{
|
||||
return getAcctSchemaElement(segmentType) != null;
|
||||
} // isAcctSchemaElement
|
||||
|
||||
/**
|
||||
* Get AcctSchema GL info
|
||||
* @return GL info
|
||||
*/
|
||||
public MAcctSchemaGL getAcctSchemaGL()
|
||||
{
|
||||
if (m_gl == null)
|
||||
m_gl = MAcctSchemaGL.get(getCtx(), getC_AcctSchema_ID());
|
||||
if (m_gl == null)
|
||||
throw new IllegalStateException("No GL Definition for C_AcctSchema_ID=" + getC_AcctSchema_ID());
|
||||
return m_gl;
|
||||
} // getAcctSchemaGL
|
||||
|
||||
/**
|
||||
* Get AcctSchema Defaults
|
||||
* @return defaults
|
||||
*/
|
||||
public MAcctSchemaDefault getAcctSchemaDefault()
|
||||
{
|
||||
if (m_default == null)
|
||||
m_default = MAcctSchemaDefault.get(getCtx(), getC_AcctSchema_ID());
|
||||
if (m_default == null)
|
||||
throw new IllegalStateException("No Default Definition for C_AcctSchema_ID=" + getC_AcctSchema_ID());
|
||||
return m_default;
|
||||
} // getAcctSchemaDefault
|
||||
|
||||
/**
|
||||
* String representation
|
||||
* @return String rep
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("AcctSchema[");
|
||||
sb.append(get_ID()).append("-").append(getName())
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Is Suspense Balancing active
|
||||
* @return suspense balancing
|
||||
*/
|
||||
public boolean isSuspenseBalancing()
|
||||
{
|
||||
if (m_gl == null)
|
||||
getAcctSchemaGL();
|
||||
return m_gl.isUseSuspenseBalancing() && m_gl.getSuspenseBalancing_Acct() != 0;
|
||||
} // isSuspenseBalancing
|
||||
|
||||
/**
|
||||
* Get Suspense Error Account
|
||||
* @return suspense error account
|
||||
*/
|
||||
public MAccount getSuspenseBalancing_Acct()
|
||||
{
|
||||
if (m_SuspenseError_Acct != null)
|
||||
return m_SuspenseError_Acct;
|
||||
if (m_gl == null)
|
||||
getAcctSchemaGL();
|
||||
int C_ValidCombination_ID = m_gl.getSuspenseBalancing_Acct();
|
||||
m_SuspenseError_Acct = MAccount.get(getCtx(), C_ValidCombination_ID);
|
||||
return m_SuspenseError_Acct;
|
||||
} // getSuspenseBalancing_Acct
|
||||
|
||||
/**
|
||||
* Is Currency Balancing active
|
||||
* @return suspense balancing
|
||||
*/
|
||||
public boolean isCurrencyBalancing()
|
||||
{
|
||||
if (m_gl == null)
|
||||
getAcctSchemaGL();
|
||||
return m_gl.isUseCurrencyBalancing();
|
||||
} // isSuspenseBalancing
|
||||
|
||||
/**
|
||||
* Get Currency Balancing Account
|
||||
* @return currency balancing account
|
||||
*/
|
||||
public MAccount getCurrencyBalancing_Acct()
|
||||
{
|
||||
if (m_CurrencyBalancing_Acct != null)
|
||||
return m_CurrencyBalancing_Acct;
|
||||
if (m_gl == null)
|
||||
getAcctSchemaGL();
|
||||
int C_ValidCombination_ID = m_gl.getCurrencyBalancing_Acct();
|
||||
m_CurrencyBalancing_Acct = MAccount.get(getCtx(), C_ValidCombination_ID);
|
||||
return m_CurrencyBalancing_Acct;
|
||||
} // getCurrencyBalancing_Acct
|
||||
|
||||
|
||||
/**
|
||||
* Get Due To Account for Segment
|
||||
* @param segment ignored
|
||||
* @return Account
|
||||
*/
|
||||
public MAccount getDueTo_Acct(String segment)
|
||||
{
|
||||
if (m_DueTo_Acct != null)
|
||||
return m_DueTo_Acct;
|
||||
if (m_gl == null)
|
||||
getAcctSchemaGL();
|
||||
int C_ValidCombination_ID = m_gl.getIntercompanyDueTo_Acct();
|
||||
m_DueTo_Acct = MAccount.get(getCtx(), C_ValidCombination_ID);
|
||||
return m_DueTo_Acct;
|
||||
} // getDueTo_Acct
|
||||
|
||||
/**
|
||||
* Get Due From Account for Segment
|
||||
* @param segment ignored
|
||||
* @return Account
|
||||
*/
|
||||
public MAccount getDueFrom_Acct(String segment)
|
||||
{
|
||||
if (m_DueFrom_Acct != null)
|
||||
return m_DueFrom_Acct;
|
||||
if (m_gl == null)
|
||||
getAcctSchemaGL();
|
||||
int C_ValidCombination_ID = m_gl.getIntercompanyDueFrom_Acct();
|
||||
m_DueFrom_Acct = MAccount.get(getCtx(), C_ValidCombination_ID);
|
||||
return m_DueFrom_Acct;
|
||||
} // getDueFrom_Acct
|
||||
|
||||
/**
|
||||
* Set Only Org Childs
|
||||
* @param orgs
|
||||
*/
|
||||
public void setOnlyOrgs (Integer[] orgs)
|
||||
{
|
||||
m_onlyOrgs = orgs;
|
||||
} // setOnlyOrgs
|
||||
|
||||
/**
|
||||
* Set Only Org Childs
|
||||
* @return orgs
|
||||
*/
|
||||
public Integer[] getOnlyOrgs()
|
||||
{
|
||||
return m_onlyOrgs;
|
||||
} // getOnlyOrgs
|
||||
|
||||
/**
|
||||
* Skip creating postings for this Org.
|
||||
* Requires setOnlyOrgs (MReportTree requires MTree in Basis)
|
||||
* @param AD_Org_ID
|
||||
* @return true if to skip
|
||||
*/
|
||||
public boolean isSkipOrg (int AD_Org_ID)
|
||||
{
|
||||
if (getAD_OrgOnly_ID() == 0)
|
||||
return false;
|
||||
// Only Organization
|
||||
if (getAD_OrgOnly_ID() == AD_Org_ID)
|
||||
return false;
|
||||
if (m_onlyOrg == null)
|
||||
m_onlyOrg = MOrg.get(getCtx(), getAD_OrgOnly_ID());
|
||||
// Not Summary Only - i.e. skip it
|
||||
if (!m_onlyOrg.isSummary())
|
||||
return true;
|
||||
if (m_onlyOrgs == null)
|
||||
return false;
|
||||
for (int i = 0; i < m_onlyOrgs.length; i++)
|
||||
{
|
||||
if (AD_Org_ID == m_onlyOrgs[i].intValue())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // isSkipOrg
|
||||
|
||||
/**
|
||||
* Get Std Precision of accounting Currency
|
||||
* @return precision
|
||||
*/
|
||||
public int getStdPrecision()
|
||||
{
|
||||
if (m_stdPrecision < 0)
|
||||
{
|
||||
MCurrency cur = MCurrency.get(getCtx(), getC_Currency_ID());
|
||||
m_stdPrecision = cur.getStdPrecision();
|
||||
m_costPrecision = cur.getCostingPrecision();
|
||||
}
|
||||
return m_stdPrecision;
|
||||
} // getStdPrecision
|
||||
|
||||
/**
|
||||
* Get Costing Precision of accounting Currency
|
||||
* @return precision
|
||||
*/
|
||||
public int getCostingPrecision()
|
||||
{
|
||||
if (m_costPrecision < 0)
|
||||
getStdPrecision();
|
||||
return m_costPrecision;
|
||||
} // getCostingPrecision
|
||||
|
||||
|
||||
/**
|
||||
* Check Costing Setup.
|
||||
* Make sure that there is a Cost Type and Cost Element
|
||||
*/
|
||||
public void checkCosting()
|
||||
{
|
||||
log.info(toString());
|
||||
// Create Cost Type
|
||||
if (getM_CostType_ID() == 0)
|
||||
{
|
||||
MCostType ct = new MCostType (getCtx(), 0, get_TrxName());
|
||||
ct.setClientOrg(getAD_Client_ID(), 0);
|
||||
ct.setName(getName());
|
||||
ct.save();
|
||||
setM_CostType_ID(ct.getM_CostType_ID());
|
||||
}
|
||||
|
||||
// Create Cost Elements
|
||||
MCostElement.getMaterialCostElement(this, getCostingMethod());
|
||||
|
||||
// Default Costing Level
|
||||
if (getCostingLevel() == null)
|
||||
setCostingLevel(COSTINGLEVEL_Client);
|
||||
if (getCostingMethod() == null)
|
||||
setCostingMethod (COSTINGMETHOD_StandardCosting);
|
||||
if (getGAAP() == null)
|
||||
setGAAP (GAAP_InternationalGAAP);
|
||||
} // checkCosting
|
||||
|
||||
/**
|
||||
* Is Client Costing Level (default)
|
||||
* @return true if Client
|
||||
*/
|
||||
public boolean isCostingLevelClient()
|
||||
{
|
||||
String s = getCostingLevel();
|
||||
if (s == null || COSTINGLEVEL_Client.equals(s))
|
||||
return true;
|
||||
return false;
|
||||
} // isCostingLevelClient
|
||||
|
||||
/**
|
||||
* Is Org Costing Level
|
||||
* @return true if Org
|
||||
*/
|
||||
public boolean isCostingLevelOrg()
|
||||
{
|
||||
return COSTINGLEVEL_Organization.equals(getCostingLevel());
|
||||
} // isCostingLevelOrg
|
||||
|
||||
/**
|
||||
* Is Batch Costing Level
|
||||
* @return true if Batch
|
||||
*/
|
||||
public boolean isCostingLevelBatch()
|
||||
{
|
||||
return COSTINGLEVEL_BatchLot.equals(getCostingLevel());
|
||||
} // isCostingLevelBatch
|
||||
|
||||
/**
|
||||
* Create Commitment Accounting
|
||||
* @return true if creaet commitments
|
||||
*/
|
||||
public boolean isCreateCommitment()
|
||||
{
|
||||
String s = getCommitmentType();
|
||||
if (s == null)
|
||||
return false;
|
||||
return COMMITMENTTYPE_CommitmentOnly.equals(s)
|
||||
|| COMMITMENTTYPE_CommitmentReservation.equals(s);
|
||||
} // isCreateCommitment
|
||||
|
||||
/**
|
||||
* Create Commitment/Reservation Accounting
|
||||
* @return true if create reservations
|
||||
*/
|
||||
public boolean isCreateReservation()
|
||||
{
|
||||
String s = getCommitmentType();
|
||||
if (s == null)
|
||||
return false;
|
||||
return COMMITMENTTYPE_CommitmentReservation.equals(s);
|
||||
} // isCreateReservation
|
||||
|
||||
/**
|
||||
* Get Tax Correction Type
|
||||
* @return tax correction type
|
||||
*/
|
||||
public String getTaxCorrectionType()
|
||||
{
|
||||
if (super.getTaxCorrectionType() == null) // created 07/23/06 2.5.3d
|
||||
setTaxCorrectionType(isDiscountCorrectsTax()
|
||||
? TAXCORRECTIONTYPE_Write_OffAndDiscount : TAXCORRECTIONTYPE_None);
|
||||
return super.getTaxCorrectionType ();
|
||||
} // getTaxCorrectionType
|
||||
|
||||
/**
|
||||
* Tax Correction
|
||||
* @return true if not none
|
||||
*/
|
||||
public boolean isTaxCorrection()
|
||||
{
|
||||
return !getTaxCorrectionType().equals(TAXCORRECTIONTYPE_None);
|
||||
} // isTaxCorrection
|
||||
|
||||
/**
|
||||
* Tax Correction for Discount
|
||||
* @return true if tax is corrected for Discount
|
||||
*/
|
||||
public boolean isTaxCorrectionDiscount()
|
||||
{
|
||||
return getTaxCorrectionType().equals(TAXCORRECTIONTYPE_DiscountOnly)
|
||||
|| getTaxCorrectionType().equals(TAXCORRECTIONTYPE_Write_OffAndDiscount);
|
||||
} // isTaxCorrectionDiscount
|
||||
|
||||
/**
|
||||
* Tax Correction for WriteOff
|
||||
* @return true if tax is corrected for WriteOff
|
||||
*/
|
||||
public boolean isTaxCorrectionWriteOff()
|
||||
{
|
||||
return getTaxCorrectionType().equals(TAXCORRECTIONTYPE_Write_OffOnly)
|
||||
|| getTaxCorrectionType().equals(TAXCORRECTIONTYPE_Write_OffAndDiscount);
|
||||
} // isTaxCorrectionWriteOff
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
if (super.getTaxCorrectionType() == null)
|
||||
setTaxCorrectionType(isDiscountCorrectsTax()
|
||||
? TAXCORRECTIONTYPE_Write_OffAndDiscount : TAXCORRECTIONTYPE_None);
|
||||
checkCosting();
|
||||
// Check Primary
|
||||
if (getAD_OrgOnly_ID() != 0)
|
||||
{
|
||||
MClientInfo info = MClientInfo.get(getCtx(), getAD_Client_ID());
|
||||
if (info.getC_AcctSchema1_ID() == getC_AcctSchema_ID())
|
||||
setAD_OrgOnly_ID(0);
|
||||
}
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
} // MAcctSchema
|
|
@ -0,0 +1,167 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Default Accounts for MAcctSchema
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAcctSchemaDefault.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
|
||||
*/
|
||||
public class MAcctSchemaDefault extends X_C_AcctSchema_Default
|
||||
{
|
||||
/**
|
||||
* Get Accounting Schema Default Info
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID id
|
||||
* @return defaults
|
||||
*/
|
||||
public static MAcctSchemaDefault get (Properties ctx, int C_AcctSchema_ID)
|
||||
{
|
||||
MAcctSchemaDefault retValue = null;
|
||||
String sql = "SELECT * FROM C_AcctSchema_Default WHERE C_AcctSchema_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, C_AcctSchema_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
retValue = new MAcctSchemaDefault (ctx, rs, null);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Logger */
|
||||
protected static CLogger s_log = CLogger.getCLogger(MAcctSchemaDefault.class);
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID parent
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAcctSchemaDefault(Properties ctx, int C_AcctSchema_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_AcctSchema_ID, trxName);
|
||||
} // MAcctSchemaDefault
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAcctSchemaDefault(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MAcctSchemaDefault
|
||||
|
||||
/**
|
||||
* Get Realized Gain Acct for currency
|
||||
* @param C_Currency_ID currency
|
||||
* @return gain acct
|
||||
*/
|
||||
public int getRealizedGain_Acct (int C_Currency_ID)
|
||||
{
|
||||
MCurrencyAcct acct = MCurrencyAcct.get (this, C_Currency_ID);
|
||||
if (acct != null)
|
||||
return acct.getRealizedGain_Acct();
|
||||
return super.getRealizedGain_Acct();
|
||||
} // getRealizedGain_Acct
|
||||
|
||||
/**
|
||||
* Get Realized Loss Acct for currency
|
||||
* @param C_Currency_ID currency
|
||||
* @return loss acct
|
||||
*/
|
||||
public int getRealizedLoss_Acct (int C_Currency_ID)
|
||||
{
|
||||
MCurrencyAcct acct = MCurrencyAcct.get (this, C_Currency_ID);
|
||||
if (acct != null)
|
||||
return acct.getRealizedLoss_Acct();
|
||||
return super.getRealizedLoss_Acct();
|
||||
} // getRealizedLoss_Acct
|
||||
|
||||
/**
|
||||
* Get Acct Info list
|
||||
* @return list
|
||||
*/
|
||||
public ArrayList<KeyNamePair> getAcctInfo()
|
||||
{
|
||||
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
|
||||
for (int i = 0; i < get_ColumnCount(); i++)
|
||||
{
|
||||
String columnName = get_ColumnName(i);
|
||||
if (columnName.endsWith("Acct"))
|
||||
{
|
||||
int id = ((Integer)get_Value(i));
|
||||
list.add(new KeyNamePair (id, columnName));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
} // getAcctInfo
|
||||
|
||||
/**
|
||||
* Set Value (don't use)
|
||||
* @param columnName column name
|
||||
* @param value value
|
||||
* @return true if value set
|
||||
*/
|
||||
public boolean setValue (String columnName, Integer value)
|
||||
{
|
||||
return super.set_Value (columnName, value);
|
||||
} // setValue
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
} // MAcctSchemaDefault
|
|
@ -0,0 +1,513 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Account Schema Element Object
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAcctSchemaElement.java,v 1.4 2006/08/10 01:00:44 jjanke Exp $
|
||||
*/
|
||||
public final class MAcctSchemaElement extends X_C_AcctSchema_Element
|
||||
{
|
||||
/**
|
||||
* Factory: Return ArrayList of Account Schema Elements
|
||||
* @param as Accounting Schema
|
||||
* @return ArrayList with Elements
|
||||
*/
|
||||
public static MAcctSchemaElement[] getAcctSchemaElements (MAcctSchema as)
|
||||
{
|
||||
Integer key = new Integer (as.getC_AcctSchema_ID());
|
||||
MAcctSchemaElement[] retValue = (MAcctSchemaElement[]) s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
|
||||
s_log.fine("C_AcctSchema_ID=" + as.getC_AcctSchema_ID());
|
||||
ArrayList<MAcctSchemaElement> list = new ArrayList<MAcctSchemaElement>();
|
||||
//
|
||||
String sql = "SELECT * FROM C_AcctSchema_Element "
|
||||
+ "WHERE C_AcctSchema_ID=? AND IsActive='Y' ORDER BY SeqNo";
|
||||
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, as.get_TrxName());
|
||||
pstmt.setInt(1, as.getC_AcctSchema_ID());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
MAcctSchemaElement ase = new MAcctSchemaElement(as.getCtx(), rs, as.get_TrxName());
|
||||
s_log.fine(" - " + ase);
|
||||
if (ase.isMandatory() && ase.getDefaultValue() == 0)
|
||||
s_log.log(Level.SEVERE, "No default value for " + ase.getName());
|
||||
list.add(ase);
|
||||
//
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
|
||||
retValue = new MAcctSchemaElement[list.size()];
|
||||
list.toArray(retValue);
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
} // getAcctSchemaElements
|
||||
|
||||
/**
|
||||
* Get Column Name of ELEMENTTYPE
|
||||
* @param elementType ELEMENTTYPE
|
||||
* @return column name
|
||||
*/
|
||||
public static String getColumnName(String elementType)
|
||||
{
|
||||
if (elementType.equals(ELEMENTTYPE_Organization))
|
||||
return "AD_Org_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_Account))
|
||||
return "Account_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_BPartner))
|
||||
return "C_BPartner_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_Product))
|
||||
return "M_Product_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_Activity))
|
||||
return "C_Activity_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_LocationFrom))
|
||||
return "C_LocFrom_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_LocationTo))
|
||||
return "C_LocTo_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_Campaign))
|
||||
return "C_Campaign_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_OrgTrx))
|
||||
return "AD_OrgTrx_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_Project))
|
||||
return "C_Project_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_SalesRegion))
|
||||
return "C_SalesRegion_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_UserList1))
|
||||
return "User1_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_UserList2))
|
||||
return "User2_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_UserElement1))
|
||||
return "UserElement1_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_UserElement2))
|
||||
return "UserElement2_ID";
|
||||
//
|
||||
return "";
|
||||
} // getColumnName
|
||||
|
||||
/**
|
||||
* Get Value Query for ELEMENTTYPE Type
|
||||
* @param elementType ELEMENTTYPE type
|
||||
* @return query "SELECT Value,Name FROM Table WHERE ID="
|
||||
*/
|
||||
public static String getValueQuery (String elementType)
|
||||
{
|
||||
if (elementType.equals(ELEMENTTYPE_Organization))
|
||||
return "SELECT Value,Name FROM AD_Org WHERE AD_Org_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_Account))
|
||||
return "SELECT Value,Name FROM C_ElementValue WHERE C_ElementValue_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_SubAccount))
|
||||
return "SELECT Value,Name FROM C_SubAccount WHERE C_SubAccount_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_BPartner))
|
||||
return "SELECT Value,Name FROM C_BPartner WHERE C_BPartner_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_Product))
|
||||
return "SELECT Value,Name FROM M_Product WHERE M_Product_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_Activity))
|
||||
return "SELECT Value,Name FROM C_Activity WHERE C_Activity_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_LocationFrom))
|
||||
return "SELECT City,Address1 FROM C_Location WHERE C_Location_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_LocationTo))
|
||||
return "SELECT City,Address1 FROM C_Location WHERE C_Location_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_Campaign))
|
||||
return "SELECT Value,Name FROM C_Campaign WHERE C_Campaign_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_OrgTrx))
|
||||
return "SELECT Value,Name FROM AD_Org WHERE AD_Org_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_Project))
|
||||
return "SELECT Value,Name FROM C_Project WHERE C_Project_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_SalesRegion))
|
||||
return "SELECT Value,Name FROM C_SalesRegion WHERE C_SalesRegion_ID";
|
||||
else if (elementType.equals(ELEMENTTYPE_UserList1))
|
||||
return "SELECT Value,Name FROM C_ElementValue WHERE C_ElementValue_ID=";
|
||||
else if (elementType.equals(ELEMENTTYPE_UserList2))
|
||||
return "SELECT Value,Name FROM C_ElementValue WHERE C_ElementValue_ID=";
|
||||
//
|
||||
else if (elementType.equals(ELEMENTTYPE_UserElement1))
|
||||
return null;
|
||||
else if (elementType.equals(ELEMENTTYPE_UserElement2))
|
||||
return null;
|
||||
//
|
||||
return "";
|
||||
} // getColumnName
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MAcctSchemaElement.class);
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer,MAcctSchemaElement[]> s_cache = new CCache<Integer,MAcctSchemaElement[]>("C_AcctSchema_Element", 10);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_Element_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAcctSchemaElement (Properties ctx, int C_AcctSchema_Element_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_AcctSchema_Element_ID, trxName);
|
||||
if (C_AcctSchema_Element_ID == 0)
|
||||
{
|
||||
// setC_AcctSchema_Element_ID (0);
|
||||
// setC_AcctSchema_ID (0);
|
||||
// setC_Element_ID (0);
|
||||
// setElementType (null);
|
||||
setIsBalanced (false);
|
||||
setIsMandatory (false);
|
||||
// setName (null);
|
||||
// setOrg_ID (0);
|
||||
// setSeqNo (0);
|
||||
}
|
||||
} // MAcctSchemaElement
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAcctSchemaElement (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MAcctSchemaElement
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param as accounting schema
|
||||
*/
|
||||
public MAcctSchemaElement (MAcctSchema as)
|
||||
{
|
||||
this (as.getCtx(), 0, as.get_TrxName());
|
||||
setClientOrg(as);
|
||||
setC_AcctSchema_ID (as.getC_AcctSchema_ID());
|
||||
|
||||
// setC_Element_ID (0);
|
||||
// setElementType (null);
|
||||
// setName (null);
|
||||
// setSeqNo (0);
|
||||
|
||||
} // MAcctSchemaElement
|
||||
|
||||
/** User Element Column Name */
|
||||
private String m_ColumnName = null;
|
||||
|
||||
/**
|
||||
* Set Organization Type
|
||||
* @param SeqNo sequence
|
||||
* @param Name name
|
||||
* @param Org_ID id
|
||||
*/
|
||||
public void setTypeOrg (int SeqNo, String Name, int Org_ID)
|
||||
{
|
||||
setElementType (ELEMENTTYPE_Organization);
|
||||
setSeqNo(SeqNo);
|
||||
setName (Name);
|
||||
setOrg_ID(Org_ID);
|
||||
} // setTypeOrg
|
||||
|
||||
/**
|
||||
* Set Type Account
|
||||
* @param SeqNo squence
|
||||
* @param Name name
|
||||
* @param C_Element_ID element
|
||||
* @param C_ElementValue_ID element value
|
||||
*/
|
||||
public void setTypeAccount (int SeqNo, String Name, int C_Element_ID, int C_ElementValue_ID)
|
||||
{
|
||||
setElementType (ELEMENTTYPE_Account);
|
||||
setSeqNo(SeqNo);
|
||||
setName (Name);
|
||||
setC_Element_ID (C_Element_ID);
|
||||
setC_ElementValue_ID(C_ElementValue_ID);
|
||||
} // setTypeAccount
|
||||
|
||||
/**
|
||||
* Set Type BPartner
|
||||
* @param SeqNo sequence
|
||||
* @param Name name
|
||||
* @param C_BPartner_ID id
|
||||
*/
|
||||
public void setTypeBPartner (int SeqNo, String Name, int C_BPartner_ID)
|
||||
{
|
||||
setElementType (ELEMENTTYPE_BPartner);
|
||||
setSeqNo(SeqNo);
|
||||
setName (Name);
|
||||
setC_BPartner_ID(C_BPartner_ID);
|
||||
} // setTypeBPartner
|
||||
|
||||
/**
|
||||
* Set Type Product
|
||||
* @param SeqNo sequence
|
||||
* @param Name name
|
||||
* @param M_Product_ID id
|
||||
*/
|
||||
public void setTypeProduct (int SeqNo, String Name, int M_Product_ID)
|
||||
{
|
||||
setElementType (ELEMENTTYPE_Product);
|
||||
setSeqNo(SeqNo);
|
||||
setName (Name);
|
||||
setM_Product_ID(M_Product_ID);
|
||||
} // setTypeProduct
|
||||
|
||||
/**
|
||||
* Set Type Project
|
||||
* @param SeqNo sequence
|
||||
* @param Name name
|
||||
* @param C_Project_ID id
|
||||
*/
|
||||
public void setTypeProject (int SeqNo, String Name, int C_Project_ID)
|
||||
{
|
||||
setElementType (ELEMENTTYPE_Project);
|
||||
setSeqNo(SeqNo);
|
||||
setName (Name);
|
||||
setC_Project_ID(C_Project_ID);
|
||||
} // setTypeProject
|
||||
|
||||
/**
|
||||
* Is Element Type
|
||||
* @param elementType type
|
||||
* @return ELEMENTTYPE type
|
||||
*/
|
||||
public boolean isElementType (String elementType)
|
||||
{
|
||||
if (elementType == null)
|
||||
return false;
|
||||
return elementType.equals(getElementType());
|
||||
} // isElementType
|
||||
|
||||
/**
|
||||
* Get Default element value
|
||||
* @return default
|
||||
*/
|
||||
public int getDefaultValue()
|
||||
{
|
||||
String elementType = getElementType();
|
||||
int defaultValue = 0;
|
||||
if (elementType.equals(ELEMENTTYPE_Organization))
|
||||
defaultValue = getOrg_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_Account))
|
||||
defaultValue = getC_ElementValue_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_BPartner))
|
||||
defaultValue = getC_BPartner_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_Product))
|
||||
defaultValue = getM_Product_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_Activity))
|
||||
defaultValue = getC_Activity_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_LocationFrom))
|
||||
defaultValue = getC_Location_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_LocationTo))
|
||||
defaultValue = getC_Location_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_Campaign))
|
||||
defaultValue = getC_Campaign_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_OrgTrx))
|
||||
defaultValue = getOrg_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_Project))
|
||||
defaultValue = getC_Project_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_SalesRegion))
|
||||
defaultValue = getC_SalesRegion_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_UserList1))
|
||||
defaultValue = getC_ElementValue_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_UserList2))
|
||||
defaultValue = getC_ElementValue_ID();
|
||||
else if (elementType.equals(ELEMENTTYPE_UserElement1))
|
||||
defaultValue = 0;
|
||||
else if (elementType.equals(ELEMENTTYPE_UserElement2))
|
||||
defaultValue = 0;
|
||||
return defaultValue;
|
||||
} // getDefault
|
||||
|
||||
|
||||
/**
|
||||
* Get Acct Fact ColumnName
|
||||
* @return column name
|
||||
*/
|
||||
public String getColumnName()
|
||||
{
|
||||
String et = getElementType();
|
||||
return getColumnName(et);
|
||||
} // getColumnName
|
||||
|
||||
/**
|
||||
* Get Display ColumnName
|
||||
* @return column name
|
||||
*/
|
||||
public String getDisplayColumnName()
|
||||
{
|
||||
String et = getElementType();
|
||||
if (ELEMENTTYPE_UserElement1.equals(et) || ELEMENTTYPE_UserElement2.equals(et))
|
||||
{
|
||||
if (m_ColumnName == null)
|
||||
m_ColumnName = MColumn.getColumnName(getCtx(), getAD_Column_ID());
|
||||
return m_ColumnName;
|
||||
}
|
||||
return getColumnName(et);
|
||||
} // getColumnName
|
||||
|
||||
|
||||
/**
|
||||
* String representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "AcctSchemaElement[" + get_ID()
|
||||
+ "-" + getName()
|
||||
+ "(" + getElementType() + ")=" + getDefaultValue()
|
||||
+ ",Pos=" + getSeqNo() + "]";
|
||||
} // toString
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true if it can be saved
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
String et = getElementType();
|
||||
if (isMandatory() &&
|
||||
(ELEMENTTYPE_UserList1.equals(et) || ELEMENTTYPE_UserList2.equals(et)
|
||||
|| ELEMENTTYPE_UserElement1.equals(et) || ELEMENTTYPE_UserElement2.equals(et)))
|
||||
setIsMandatory(false);
|
||||
else if (isMandatory())
|
||||
{
|
||||
String errorField = null;
|
||||
if (ELEMENTTYPE_Account.equals(et) && getC_ElementValue_ID() == 0)
|
||||
errorField = "C_ElementValue_ID";
|
||||
else if (ELEMENTTYPE_Activity.equals(et) && getC_Activity_ID() == 0)
|
||||
errorField = "C_Activity_ID";
|
||||
else if (ELEMENTTYPE_BPartner.equals(et) && getC_BPartner_ID() == 0)
|
||||
errorField = "C_BPartner_ID";
|
||||
else if (ELEMENTTYPE_Campaign.equals(et) && getC_Campaign_ID() == 0)
|
||||
errorField = "C_Campaign_ID";
|
||||
else if (ELEMENTTYPE_LocationFrom.equals(et) && getC_Location_ID() == 0)
|
||||
errorField = "C_Location_ID";
|
||||
else if (ELEMENTTYPE_LocationTo.equals(et) && getC_Location_ID() == 0)
|
||||
errorField = "C_Location_ID";
|
||||
else if (ELEMENTTYPE_Organization.equals(et) && getOrg_ID() == 0)
|
||||
errorField = "Org_ID";
|
||||
else if (ELEMENTTYPE_OrgTrx.equals(et) && getOrg_ID() == 0)
|
||||
errorField = "Org_ID";
|
||||
else if (ELEMENTTYPE_Product.equals(et) && getM_Product_ID() == 0)
|
||||
errorField = "M_Product_ID";
|
||||
else if (ELEMENTTYPE_Project.equals(et) && getC_Project_ID() == 0)
|
||||
errorField = "C_Project_ID";
|
||||
else if (ELEMENTTYPE_SalesRegion.equals(et) && getC_SalesRegion_ID() == 0)
|
||||
errorField = "C_SalesRegion_ID";
|
||||
if (errorField != null)
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@IsMandatory@: @" + errorField + "@"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//
|
||||
if (getAD_Column_ID() == 0
|
||||
&& (ELEMENTTYPE_UserElement1.equals(et) || ELEMENTTYPE_UserElement2.equals(et)))
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@IsMandatory@: @AD_Column_ID@"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
// Default Value
|
||||
if (isMandatory() && is_ValueChanged("IsMandatory"))
|
||||
{
|
||||
if (ELEMENTTYPE_Activity.equals(getElementType()))
|
||||
updateData ("C_Activity_ID", getC_Activity_ID());
|
||||
else if (ELEMENTTYPE_BPartner.equals(getElementType()))
|
||||
updateData ("C_BPartner_ID", getC_BPartner_ID());
|
||||
else if (ELEMENTTYPE_Product.equals(getElementType()))
|
||||
updateData ("M_Product_ID", getM_Product_ID());
|
||||
else if (ELEMENTTYPE_Project.equals(getElementType()))
|
||||
updateData ("C_Project_ID", getC_Project_ID());
|
||||
}
|
||||
// Resequence
|
||||
if (newRecord || is_ValueChanged("SeqNo"))
|
||||
MAccount.updateValueDescription(getCtx(),
|
||||
"AD_Client_ID=" + getAD_Client_ID(), get_TrxName());
|
||||
// Clear Cache
|
||||
s_cache.clear();
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* Update ValidCombination and Fact with mandatory value
|
||||
* @param element element
|
||||
* @param id new default
|
||||
*/
|
||||
private void updateData (String element, int id)
|
||||
{
|
||||
MAccount.updateValueDescription(getCtx(),
|
||||
element + "=" + id, get_TrxName());
|
||||
//
|
||||
String sql = "UPDATE C_ValidCombination SET " + element + "=" + id
|
||||
+ " WHERE " + element + " IS NULL AND AD_Client_ID=" + getAD_Client_ID();
|
||||
int noC = DB.executeUpdate(sql, get_TrxName());
|
||||
//
|
||||
sql = "UPDATE Fact_Acct SET " + element + "=" + id
|
||||
+ " WHERE " + element + " IS NULL AND C_AcctSchema_ID=" + getC_AcctSchema_ID();
|
||||
int noF = DB.executeUpdate(sql, get_TrxName());
|
||||
//
|
||||
log.fine("ValidCombination=" + noC + ", Fact=" + noF);
|
||||
} // updateData
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* After Delete
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
// Update Account Info
|
||||
MAccount.updateValueDescription(getCtx(),
|
||||
"AD_Client_ID=" + getAD_Client_ID(), get_TrxName());
|
||||
//
|
||||
s_cache.clear();
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
} // AcctSchemaElement
|
|
@ -0,0 +1,148 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Accounting Schema GL info
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAcctSchemaGL.java,v 1.3 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public class MAcctSchemaGL extends X_C_AcctSchema_GL
|
||||
{
|
||||
/**
|
||||
* Get Accounting Schema GL Info
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID id
|
||||
* @return defaults
|
||||
*/
|
||||
public static MAcctSchemaGL get (Properties ctx, int C_AcctSchema_ID)
|
||||
{
|
||||
MAcctSchemaGL retValue = null;
|
||||
String sql = "SELECT * FROM C_AcctSchema_GL WHERE C_AcctSchema_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, C_AcctSchema_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
retValue = new MAcctSchemaGL (ctx, rs, null);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Logger */
|
||||
protected static CLogger s_log = CLogger.getCLogger(MAcctSchemaGL.class);
|
||||
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param C_AcctSchema_ID AcctSchema
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAcctSchemaGL (Properties ctx, int C_AcctSchema_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_AcctSchema_ID, trxName);
|
||||
if (C_AcctSchema_ID == 0)
|
||||
{
|
||||
setUseCurrencyBalancing (false);
|
||||
setUseSuspenseBalancing (false);
|
||||
setUseSuspenseError (false);
|
||||
}
|
||||
} // MAcctSchemaGL
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAcctSchemaGL (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MAcctSchemaGL
|
||||
|
||||
/**
|
||||
* Get Acct Info list
|
||||
* @return list
|
||||
*/
|
||||
public ArrayList<KeyNamePair> getAcctInfo()
|
||||
{
|
||||
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
|
||||
for (int i = 0; i < get_ColumnCount(); i++)
|
||||
{
|
||||
String columnName = get_ColumnName(i);
|
||||
if (columnName.endsWith("Acct"))
|
||||
{
|
||||
int id = ((Integer)get_Value(i));
|
||||
list.add(new KeyNamePair (id, columnName));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
} // getAcctInfo
|
||||
|
||||
/**
|
||||
* Set Value (don't use)
|
||||
* @param columnName column name
|
||||
* @param value value
|
||||
* @return true if set
|
||||
*/
|
||||
public boolean setValue (String columnName, Integer value)
|
||||
{
|
||||
return super.set_Value (columnName, value);
|
||||
} // setValue
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
} // MAcctSchemaGL
|
|
@ -0,0 +1,309 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import java.util.zip.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Archive Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MArchive.java,v 1.3 2006/07/30 00:58:36 jjanke Exp $
|
||||
*/
|
||||
public class MArchive extends X_AD_Archive
|
||||
{
|
||||
/**
|
||||
* Get Archives
|
||||
* @param ctx context
|
||||
* @param whereClause optional where clause (starting with AND)
|
||||
* @return archives
|
||||
*/
|
||||
public static MArchive[] get (Properties ctx, String whereClause)
|
||||
{
|
||||
ArrayList<MArchive> list = new ArrayList<MArchive>();
|
||||
PreparedStatement pstmt = null;
|
||||
String sql = "SELECT * FROM AD_Archive WHERE AD_Client_ID=?";
|
||||
if (whereClause != null && whereClause.length() > 0)
|
||||
sql += whereClause;
|
||||
sql += " ORDER BY Created";
|
||||
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, Env.getAD_Client_ID(ctx));
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add (new MArchive(ctx, rs, null));
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
if (list.size() == 0)
|
||||
s_log.fine(sql);
|
||||
else
|
||||
s_log.finer(sql);
|
||||
//
|
||||
MArchive[] retValue = new MArchive[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger(MArchive.class);
|
||||
|
||||
private Integer m_inflated = null;
|
||||
private Integer m_deflated = null;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Archive_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MArchive (Properties ctx, int AD_Archive_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_Archive_ID, trxName);
|
||||
} // MArchive
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MArchive (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MArchive
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param info print info
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MArchive (Properties ctx, PrintInfo info, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setName(info.getName());
|
||||
setIsReport(info.isReport());
|
||||
//
|
||||
setAD_Process_ID(info.getAD_Process_ID());
|
||||
setAD_Table_ID(info.getAD_Table_ID());
|
||||
setRecord_ID(info.getRecord_ID());
|
||||
setC_BPartner_ID(info.getC_BPartner_ID());
|
||||
} // MArchive
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MArchive[");
|
||||
sb.append(get_ID()).append(",Name=").append(getName());
|
||||
if (m_inflated != null)
|
||||
sb.append(",Inflated=" + m_inflated);
|
||||
if (m_deflated != null)
|
||||
sb.append(",Deflated=" + m_deflated);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Get Binary Data.
|
||||
* (inflate)
|
||||
* @return inflated data
|
||||
*/
|
||||
public byte[] getBinaryData()
|
||||
{
|
||||
byte[] deflatedData = super.getBinaryData();
|
||||
m_deflated = null;
|
||||
m_inflated = null;
|
||||
if (deflatedData == null)
|
||||
return null;
|
||||
//
|
||||
log.fine("ZipSize=" + deflatedData.length);
|
||||
m_deflated = new Integer(deflatedData.length);
|
||||
if (deflatedData.length == 0)
|
||||
return null;
|
||||
|
||||
byte[] inflatedData = null;
|
||||
try
|
||||
{
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(deflatedData);
|
||||
ZipInputStream zip = new ZipInputStream (in);
|
||||
ZipEntry entry = zip.getNextEntry();
|
||||
if (entry != null) // just one entry
|
||||
{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[2048];
|
||||
int length = zip.read(buffer);
|
||||
while (length != -1)
|
||||
{
|
||||
out.write(buffer, 0, length);
|
||||
length = zip.read(buffer);
|
||||
}
|
||||
//
|
||||
inflatedData = out.toByteArray();
|
||||
log.fine("Size=" + inflatedData.length + " - zip="
|
||||
+ entry.getCompressedSize() + "(" + entry.getSize() + ") "
|
||||
+ (entry.getCompressedSize()*100/entry.getSize())+ "%");
|
||||
m_inflated = new Integer(inflatedData.length);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "", e);
|
||||
inflatedData = null;
|
||||
}
|
||||
return inflatedData;
|
||||
} // getBinaryData
|
||||
|
||||
/**
|
||||
* Get Data as Input Stream
|
||||
* @return input stream or null
|
||||
*/
|
||||
public InputStream getInputStream()
|
||||
{
|
||||
byte[] inflatedData = getBinaryData();
|
||||
if (inflatedData == null)
|
||||
return null;
|
||||
return new ByteArrayInputStream(inflatedData);
|
||||
} // getInputStream
|
||||
|
||||
/**
|
||||
* Save Binary Data.
|
||||
* (deflate)
|
||||
* @param inflatedData inflated data
|
||||
*/
|
||||
public void setBinaryData (byte[] inflatedData)
|
||||
{
|
||||
if (inflatedData == null || inflatedData.length == 0)
|
||||
throw new IllegalArgumentException("InflatedData is NULL");
|
||||
m_inflated = new Integer(inflatedData.length);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(out);
|
||||
zip.setMethod(ZipOutputStream.DEFLATED);
|
||||
zip.setLevel(Deflater.BEST_COMPRESSION);
|
||||
zip.setComment("adempiere");
|
||||
//
|
||||
byte[] deflatedData = null;
|
||||
try
|
||||
{
|
||||
ZipEntry entry = new ZipEntry("AdempiereArchive");
|
||||
entry.setTime(System.currentTimeMillis());
|
||||
entry.setMethod(ZipEntry.DEFLATED);
|
||||
zip.putNextEntry(entry);
|
||||
zip.write (inflatedData, 0, inflatedData.length);
|
||||
zip.closeEntry();
|
||||
log.fine(entry.getCompressedSize() + " (" + entry.getSize() + ") "
|
||||
+ (entry.getCompressedSize()*100/entry.getSize())+ "%");
|
||||
//
|
||||
// zip.finish();
|
||||
zip.close();
|
||||
deflatedData = out.toByteArray();
|
||||
log.fine("Length=" + inflatedData.length);
|
||||
m_deflated = new Integer(deflatedData.length);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "saveLOBData", e);
|
||||
deflatedData = null;
|
||||
m_deflated = null;
|
||||
}
|
||||
super.setBinaryData (deflatedData);
|
||||
} // setBinaryData
|
||||
|
||||
/**
|
||||
* Get Created By (User) Name
|
||||
* @return name
|
||||
*/
|
||||
public String getCreatedByName()
|
||||
{
|
||||
String name = "?";
|
||||
String sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, getCreatedBy());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
name = rs.getString(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;
|
||||
}
|
||||
return name;
|
||||
} // getCreatedByName
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true if can be saved
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
// Binary Data is Mandatory
|
||||
byte[] data = super.getBinaryData();
|
||||
if (data == null || data.length == 0)
|
||||
return false;
|
||||
//
|
||||
log.fine(toString());
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
} // MArchive
|
|
@ -0,0 +1,545 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import java.util.zip.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Attachment Model.
|
||||
* One Attachment can have multiple entries
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAttachment.java,v 1.4 2006/07/30 00:58:37 jjanke Exp $
|
||||
*/
|
||||
public class MAttachment extends X_AD_Attachment
|
||||
{
|
||||
/**
|
||||
* Get Attachment
|
||||
* @param ctx context
|
||||
* @param AD_Table_ID table
|
||||
* @param Record_ID record
|
||||
* @return attachment or null
|
||||
*/
|
||||
public static MAttachment get (Properties ctx, int AD_Table_ID, int Record_ID)
|
||||
{
|
||||
MAttachment retValue = null;
|
||||
PreparedStatement pstmt = null;
|
||||
String sql = "SELECT * FROM AD_Attachment WHERE AD_Table_ID=? AND Record_ID=?";
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, AD_Table_ID);
|
||||
pstmt.setInt (2, Record_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
retValue = new MAttachment (ctx, rs, null);
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MAttachment.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Attachment_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAttachment(Properties ctx, int AD_Attachment_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_Attachment_ID, trxName);
|
||||
} // MAttachment
|
||||
|
||||
/**
|
||||
* New Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Table_ID table
|
||||
* @param Record_ID record
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setAD_Table_ID (AD_Table_ID);
|
||||
setRecord_ID (Record_ID);
|
||||
} // MAttachment
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAttachment(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MAttachment
|
||||
|
||||
/** Indicator for no data */
|
||||
public static final String NONE = ".";
|
||||
/** Indicator for zip data */
|
||||
public static final String ZIP = "zip";
|
||||
|
||||
/** List of Entry Data */
|
||||
private ArrayList<MAttachmentEntry> m_items = null;
|
||||
|
||||
/**
|
||||
* Set Client Org
|
||||
* @param AD_Client_ID client
|
||||
* @param AD_Org_ID org
|
||||
*/
|
||||
public void setClientOrg(int AD_Client_ID, int AD_Org_ID)
|
||||
{
|
||||
super.setClientOrg(AD_Client_ID, AD_Org_ID);
|
||||
} // setClientOrg
|
||||
|
||||
/**
|
||||
* Add to Text Msg
|
||||
* @param added text
|
||||
*/
|
||||
public void addTextMsg (String added)
|
||||
{
|
||||
String oldTextMsg = getTextMsg();
|
||||
if (oldTextMsg == null)
|
||||
setTextMsg (added);
|
||||
else if (added != null)
|
||||
setTextMsg (oldTextMsg + added);
|
||||
} // addTextMsg
|
||||
|
||||
/**
|
||||
* Get Text Msg
|
||||
* @return trimmed message
|
||||
*/
|
||||
public String getTextMsg ()
|
||||
{
|
||||
String msg = super.getTextMsg ();
|
||||
if (msg == null)
|
||||
return null;
|
||||
return msg.trim();
|
||||
} // setTextMsg
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MAttachment[");
|
||||
sb.append(getAD_Attachment_ID()).append(",Title=").append(getTitle())
|
||||
.append(",Entries=").append(getEntryCount());
|
||||
for (int i = 0; i < getEntryCount(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
sb.append(":");
|
||||
else
|
||||
sb.append(",");
|
||||
sb.append(getEntryName(i));
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Add new Data Entry
|
||||
* @param file file
|
||||
* @return true if added
|
||||
*/
|
||||
public boolean addEntry (File file)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
log.warning("No File");
|
||||
return false;
|
||||
}
|
||||
if (!file.exists() || file.isDirectory())
|
||||
{
|
||||
log.warning("not added - " + file
|
||||
+ ", Exists=" + file.exists() + ", Directory=" + file.isDirectory());
|
||||
return false;
|
||||
}
|
||||
log.fine("addEntry - " + file);
|
||||
//
|
||||
String name = file.getName();
|
||||
byte[] data = null;
|
||||
try
|
||||
{
|
||||
FileInputStream fis = new FileInputStream (file);
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024*8]; // 8kB
|
||||
int length = -1;
|
||||
while ((length = fis.read(buffer)) != -1)
|
||||
os.write(buffer, 0, length);
|
||||
fis.close();
|
||||
data = os.toByteArray();
|
||||
os.close();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
log.log(Level.SEVERE, "(file)", ioe);
|
||||
}
|
||||
return addEntry (name, data);
|
||||
} // addEntry
|
||||
|
||||
/**
|
||||
* Add new Data Entry
|
||||
* @param name name
|
||||
* @param data data
|
||||
* @return true if added
|
||||
*/
|
||||
public boolean addEntry (String name, byte[] data)
|
||||
{
|
||||
if (name == null || data == null)
|
||||
return false;
|
||||
return addEntry (new MAttachmentEntry (name, data)); // random index
|
||||
} // addEntry
|
||||
|
||||
/**
|
||||
* Add Entry
|
||||
* @param item attachment entry
|
||||
* @return true if added
|
||||
*/
|
||||
public boolean addEntry (MAttachmentEntry item)
|
||||
{
|
||||
if (item == null)
|
||||
return false;
|
||||
if (m_items == null)
|
||||
loadLOBData();
|
||||
boolean retValue = m_items.add(item);
|
||||
log.fine(item.toStringX());
|
||||
addTextMsg(" "); // otherwise not saved
|
||||
return retValue;
|
||||
} // addEntry
|
||||
|
||||
/**
|
||||
* Get Attachment Entry
|
||||
* @param index index of the item
|
||||
* @return Entry or null
|
||||
*/
|
||||
public MAttachmentEntry getEntry (int index)
|
||||
{
|
||||
if (m_items == null)
|
||||
loadLOBData();
|
||||
if (index < 0 || index >= m_items.size())
|
||||
return null;
|
||||
return (MAttachmentEntry)m_items.get(index);
|
||||
} // getEntry
|
||||
|
||||
/**
|
||||
* Get Attachment Entries as array
|
||||
* @return array or null
|
||||
*/
|
||||
public MAttachmentEntry[] getEntries ()
|
||||
{
|
||||
if (m_items == null)
|
||||
loadLOBData();
|
||||
MAttachmentEntry[] retValue = new MAttachmentEntry[m_items.size()];
|
||||
m_items.toArray (retValue);
|
||||
return retValue;
|
||||
} // getEntries
|
||||
|
||||
/**
|
||||
* Delete Entry
|
||||
* @param index index
|
||||
* @return true if deleted
|
||||
*/
|
||||
public boolean deleteEntry (int index)
|
||||
{
|
||||
if (index >= 0 && index < m_items.size())
|
||||
{
|
||||
m_items.remove(index);
|
||||
log.config("Index=" + index + " - NewSize=" + m_items.size());
|
||||
return true;
|
||||
}
|
||||
log.warning("Not deleted Index=" + index + " - Size=" + m_items.size());
|
||||
return false;
|
||||
} // deleteEntry
|
||||
|
||||
/**
|
||||
* Get Entry Count
|
||||
* @return number of entries
|
||||
*/
|
||||
public int getEntryCount()
|
||||
{
|
||||
if (m_items == null)
|
||||
loadLOBData();
|
||||
return m_items.size();
|
||||
} // getEntryCount
|
||||
|
||||
|
||||
/**
|
||||
* Get Entry Name
|
||||
* @param index index
|
||||
* @return name or null
|
||||
*/
|
||||
public String getEntryName (int index)
|
||||
{
|
||||
MAttachmentEntry item = getEntry(index);
|
||||
if (item != null)
|
||||
return item.getName();
|
||||
return null;
|
||||
} // getEntryName
|
||||
|
||||
/**
|
||||
* Dump Entry Names
|
||||
*/
|
||||
public void dumpEntryNames()
|
||||
{
|
||||
if (m_items == null)
|
||||
loadLOBData();
|
||||
if (m_items == null || m_items.size() == 0)
|
||||
{
|
||||
System.out.println("- no entries -");
|
||||
return;
|
||||
}
|
||||
System.out.println("- entries: " + m_items.size());
|
||||
for (int i = 0; i < m_items.size(); i++)
|
||||
System.out.println(" - " + getEntryName(i));
|
||||
} // dumpEntryNames
|
||||
|
||||
/**
|
||||
* Get Entry Data
|
||||
* @param index index
|
||||
* @return data or null
|
||||
*/
|
||||
public byte[] getEntryData (int index)
|
||||
{
|
||||
MAttachmentEntry item = getEntry(index);
|
||||
if (item != null)
|
||||
return item.getData();
|
||||
return null;
|
||||
} // getEntryData
|
||||
|
||||
/**
|
||||
* Get Entry File with name
|
||||
* @param index index
|
||||
* @param fileName optional file name
|
||||
* @return file
|
||||
*/
|
||||
public File getEntryFile (int index, String fileName)
|
||||
{
|
||||
MAttachmentEntry item = getEntry(index);
|
||||
if (item != null)
|
||||
return item.getFile(fileName);
|
||||
return null;
|
||||
} // getEntryFile
|
||||
|
||||
/**
|
||||
* Get Entry File with name
|
||||
* @param index index
|
||||
* @param file file
|
||||
* @return file
|
||||
*/
|
||||
public File getEntryFile (int index, File file)
|
||||
{
|
||||
MAttachmentEntry item = getEntry(index);
|
||||
if (item != null)
|
||||
return item.getFile(file);
|
||||
return null;
|
||||
} // getEntryFile
|
||||
|
||||
/**
|
||||
* Save Entry Data in Zip File format
|
||||
* @return true if saved
|
||||
*/
|
||||
private boolean saveLOBData()
|
||||
{
|
||||
if (m_items == null || m_items.size() == 0)
|
||||
{
|
||||
setBinaryData(null);
|
||||
return true;
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(out);
|
||||
zip.setMethod(ZipOutputStream.DEFLATED);
|
||||
zip.setLevel(Deflater.BEST_COMPRESSION);
|
||||
zip.setComment("adempiere");
|
||||
//
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < m_items.size(); i++)
|
||||
{
|
||||
MAttachmentEntry item = getEntry(i);
|
||||
ZipEntry entry = new ZipEntry(item.getName());
|
||||
entry.setTime(System.currentTimeMillis());
|
||||
entry.setMethod(ZipEntry.DEFLATED);
|
||||
zip.putNextEntry(entry);
|
||||
byte[] data = item.getData();
|
||||
zip.write (data, 0, data.length);
|
||||
zip.closeEntry();
|
||||
log.fine(entry.getName() + " - "
|
||||
+ entry.getCompressedSize() + " (" + entry.getSize() + ") "
|
||||
+ (entry.getCompressedSize()*100/entry.getSize())+ "%");
|
||||
}
|
||||
// zip.finish();
|
||||
zip.close();
|
||||
byte[] zipData = out.toByteArray();
|
||||
log.fine("Length=" + zipData.length);
|
||||
setBinaryData(zipData);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "saveLOBData", e);
|
||||
}
|
||||
setBinaryData(null);
|
||||
return false;
|
||||
} // saveLOBData
|
||||
|
||||
/**
|
||||
* Load Data into local m_data
|
||||
* @return true if success
|
||||
*/
|
||||
private boolean loadLOBData ()
|
||||
{
|
||||
// Reset
|
||||
m_items = new ArrayList<MAttachmentEntry>();
|
||||
//
|
||||
byte[] data = getBinaryData();
|
||||
if (data == null)
|
||||
return true;
|
||||
log.fine("ZipSize=" + data.length);
|
||||
if (data.length == 0)
|
||||
return true;
|
||||
|
||||
// Old Format - single file
|
||||
if (!ZIP.equals(getTitle()))
|
||||
{
|
||||
m_items.add (new MAttachmentEntry(getTitle(), data, 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(data);
|
||||
ZipInputStream zip = new ZipInputStream (in);
|
||||
ZipEntry entry = zip.getNextEntry();
|
||||
while (entry != null)
|
||||
{
|
||||
String name = entry.getName();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[2048];
|
||||
int length = zip.read(buffer);
|
||||
while (length != -1)
|
||||
{
|
||||
out.write(buffer, 0, length);
|
||||
length = zip.read(buffer);
|
||||
}
|
||||
//
|
||||
byte[] dataEntry = out.toByteArray();
|
||||
log.fine(name
|
||||
+ " - size=" + dataEntry.length + " - zip="
|
||||
+ entry.getCompressedSize() + "(" + entry.getSize() + ") "
|
||||
+ (entry.getCompressedSize()*100/entry.getSize())+ "%");
|
||||
//
|
||||
m_items.add (new MAttachmentEntry (name, dataEntry, m_items.size()+1));
|
||||
entry = zip.getNextEntry();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "loadLOBData", e);
|
||||
m_items = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // loadLOBData
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true if can be saved
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getTitle() == null || !getTitle().equals(ZIP))
|
||||
setTitle (ZIP);
|
||||
return saveLOBData(); // save in BinaryData
|
||||
} // beforeSave
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Test
|
||||
* @param args ignored
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
// System.setProperty("javax.activation.debug", "true");
|
||||
|
||||
System.out.println(MimeType.getMimeType("data.xls"));
|
||||
System.out.println(MimeType.getMimeType("data.cvs"));
|
||||
System.out.println(MimeType.getMimeType("data.txt"));
|
||||
System.out.println(MimeType.getMimeType("data.log"));
|
||||
System.out.println(MimeType.getMimeType("data.html"));
|
||||
System.out.println(MimeType.getMimeType("data.htm"));
|
||||
System.out.println(MimeType.getMimeType("data.png"));
|
||||
System.out.println(MimeType.getMimeType("data.gif"));
|
||||
System.out.println(MimeType.getMimeType("data.jpg"));
|
||||
System.out.println(MimeType.getMimeType("data.xml"));
|
||||
System.out.println(MimeType.getMimeType("data.rtf"));
|
||||
|
||||
System.exit(0);
|
||||
|
||||
org.compiere.Adempiere.startupEnvironment(true);
|
||||
MAttachment att = new MAttachment(Env.getCtx(), 100, 0, null);
|
||||
att.addEntry(new File ("C:\\Adempiere\\Dev.properties"));
|
||||
att.addEntry(new File ("C:\\Adempiere\\index.html"));
|
||||
att.save();
|
||||
System.out.println (att);
|
||||
att.dumpEntryNames();
|
||||
int AD_Attachment_ID = att.getAD_Attachment_ID();
|
||||
//
|
||||
System.out.println ("===========================================");
|
||||
att = new MAttachment (Env.getCtx(), AD_Attachment_ID, null);
|
||||
System.out.println (att);
|
||||
att.dumpEntryNames();
|
||||
System.out.println ("===========================================");
|
||||
MAttachmentEntry[] entries = att.getEntries();
|
||||
for (int i = 0; i < entries.length; i++)
|
||||
{
|
||||
MAttachmentEntry entry = entries[i];
|
||||
entry.dump();
|
||||
}
|
||||
System.out.println ("===========================================");
|
||||
att.delete(true);
|
||||
} // main
|
||||
|
||||
} // MAttachment
|
|
@ -0,0 +1,290 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Individual Attachment Entry of MAttachment
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAttachmentEntry.java,v 1.2 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public class MAttachmentEntry
|
||||
{
|
||||
/**
|
||||
* Attachment Entry
|
||||
* @param name name
|
||||
* @param data binary data
|
||||
* @param index optional index
|
||||
*/
|
||||
public MAttachmentEntry (String name, byte[] data, int index)
|
||||
{
|
||||
super ();
|
||||
setName (name);
|
||||
setData (data);
|
||||
if (index > 0)
|
||||
m_index = index;
|
||||
else
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
if (s_seed+3600000l < now) // older then 1 hour
|
||||
{
|
||||
s_seed = now;
|
||||
s_random = new Random(s_seed);
|
||||
}
|
||||
m_index = s_random.nextInt();
|
||||
}
|
||||
} // MAttachmentItem
|
||||
|
||||
/**
|
||||
* Attachment Entry
|
||||
* @param name name
|
||||
* @param data binary data
|
||||
*/
|
||||
public MAttachmentEntry (String name, byte[] data)
|
||||
{
|
||||
this (name, data, 0);
|
||||
} // MAttachmentItem
|
||||
|
||||
/** The Name */
|
||||
private String m_name = "?";
|
||||
/** The Data */
|
||||
private byte[] m_data = null;
|
||||
|
||||
/** Random Seed */
|
||||
private static long s_seed = System.currentTimeMillis();
|
||||
/** Random Number */
|
||||
private static Random s_random = new Random(s_seed);
|
||||
/** Index */
|
||||
private int m_index = 0;
|
||||
|
||||
/** Logger */
|
||||
protected CLogger log = CLogger.getCLogger(getClass());
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the data.
|
||||
*/
|
||||
public byte[] getData ()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
/**
|
||||
* @param data The data to set.
|
||||
*/
|
||||
public void setData (byte[] data)
|
||||
{
|
||||
m_data = data;
|
||||
}
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName ()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName (String name)
|
||||
{
|
||||
if (name != null)
|
||||
m_name = name;
|
||||
if (m_name == null)
|
||||
m_name = "?";
|
||||
} // setName
|
||||
|
||||
/**
|
||||
* Get Attachment Index
|
||||
* @return timestamp
|
||||
*/
|
||||
public int getIndex()
|
||||
{
|
||||
return m_index;
|
||||
} // getIndex
|
||||
|
||||
/**
|
||||
* To String
|
||||
* @return name
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return m_name;
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* To String Extended
|
||||
* @return name (length)
|
||||
*/
|
||||
public String toStringX ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer (m_name);
|
||||
if (m_data != null)
|
||||
{
|
||||
sb.append(" (");
|
||||
//
|
||||
float size = m_data.length;
|
||||
if (size <= 1024)
|
||||
sb.append(m_data.length).append(" B");
|
||||
else
|
||||
{
|
||||
size /= 1024;
|
||||
if (size > 1024)
|
||||
{
|
||||
size /= 1024;
|
||||
sb.append(size).append(" MB");
|
||||
}
|
||||
else
|
||||
sb.append(size).append(" kB");
|
||||
}
|
||||
//
|
||||
sb.append(")");
|
||||
}
|
||||
sb.append(" - ").append(getContentType());
|
||||
return sb.toString();
|
||||
} // toStringX
|
||||
|
||||
|
||||
/**
|
||||
* Dump Data
|
||||
*/
|
||||
public void dump ()
|
||||
{
|
||||
String hdr = "----- " + getName() + " -----";
|
||||
System.out.println (hdr);
|
||||
if (m_data == null)
|
||||
{
|
||||
System.out.println ("----- no data -----");
|
||||
return;
|
||||
}
|
||||
// raw data
|
||||
for (int i = 0; i < m_data.length; i++)
|
||||
{
|
||||
char data = (char)m_data[i];
|
||||
System.out.print(data);
|
||||
}
|
||||
|
||||
System.out.println ();
|
||||
System.out.println (hdr);
|
||||
// Count nulls at end
|
||||
int ii = m_data.length -1;
|
||||
int nullCount = 0;
|
||||
while (m_data[ii--] == 0)
|
||||
nullCount++;
|
||||
System.out.println("----- Length=" + m_data.length + ", EndNulls=" + nullCount
|
||||
+ ", RealLength=" + (m_data.length-nullCount));
|
||||
/**
|
||||
// Dump w/o nulls
|
||||
if (nullCount > 0)
|
||||
{
|
||||
for (int i = 0; i < m_data.length-nullCount; i++)
|
||||
System.out.print((char)m_data[i]);
|
||||
System.out.println ();
|
||||
System.out.println (hdr);
|
||||
}
|
||||
/** **/
|
||||
} // dump
|
||||
|
||||
/**
|
||||
* Get File with default name
|
||||
* @return File
|
||||
*/
|
||||
public File getFile ()
|
||||
{
|
||||
return getFile (getName());
|
||||
} // getFile
|
||||
|
||||
/**
|
||||
* Get File with name
|
||||
* @param fileName optional file name
|
||||
* @return file
|
||||
*/
|
||||
public File getFile (String fileName)
|
||||
{
|
||||
if (fileName == null || fileName.length() == 0)
|
||||
fileName = getName();
|
||||
return getFile (new File(fileName));
|
||||
} // getFile
|
||||
|
||||
/**
|
||||
* Get File
|
||||
* @param file out file
|
||||
* @return file
|
||||
*/
|
||||
public File getFile (File file)
|
||||
{
|
||||
if (m_data == null || m_data.length == 0)
|
||||
return null;
|
||||
try
|
||||
{
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(m_data);
|
||||
fos.close();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
log.log(Level.SEVERE, "getFile", ioe);
|
||||
}
|
||||
return file;
|
||||
} // getFile
|
||||
|
||||
/**
|
||||
* Is attachment entry a PDF
|
||||
* @return true if PDF
|
||||
*/
|
||||
public boolean isPDF()
|
||||
{
|
||||
return m_name.endsWith(".pdf");
|
||||
} // isPDF
|
||||
|
||||
/**
|
||||
* Isattachment entry a Graphic
|
||||
* @return true if *.gif, *.jpg, *.png
|
||||
*/
|
||||
public boolean isGraphic()
|
||||
{
|
||||
return m_name.endsWith(".gif") || m_name.endsWith(".jpg") || m_name.endsWith(".png");
|
||||
} // isGraphic
|
||||
|
||||
|
||||
/**
|
||||
* Get Content (Mime) Type
|
||||
* @return content type
|
||||
*/
|
||||
public String getContentType()
|
||||
{
|
||||
return MimeType.getMimeType(m_name);
|
||||
} // getContentType
|
||||
|
||||
/**
|
||||
* Get Data as Input Stream
|
||||
* @return input stream
|
||||
*/
|
||||
public InputStream getInputStream()
|
||||
{
|
||||
if (m_data == null)
|
||||
return null;
|
||||
return new ByteArrayInputStream(m_data);
|
||||
} // getInputStream
|
||||
|
||||
} // MAttachmentItem
|
|
@ -0,0 +1,79 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Attachment Note
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MAttachmentNote.java,v 1.3 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public class MAttachmentNote extends X_AD_AttachmentNote
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_AttachmentNote_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAttachmentNote (Properties ctx, int AD_AttachmentNote_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_AttachmentNote_ID, trxName);
|
||||
/**
|
||||
if (AD_AttachmentNote_ID == 0)
|
||||
{
|
||||
setAD_Attachment_ID (0);
|
||||
setAD_User_ID (0);
|
||||
setTextMsg (null);
|
||||
setTitle (null);
|
||||
}
|
||||
/**/
|
||||
} // MAttachmentNote
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MAttachmentNote (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MAttachmentNote
|
||||
|
||||
/**
|
||||
* Parent Constructor.
|
||||
* Sets current user.
|
||||
* @param attach attachment
|
||||
* @param Title title
|
||||
* @param TextMsg ext message
|
||||
*/
|
||||
public MAttachmentNote (MAttachment attach, String Title, String TextMsg)
|
||||
{
|
||||
this (attach.getCtx(), 0, attach.get_TrxName());
|
||||
setClientOrg(attach);
|
||||
setAD_Attachment_ID (attach.getAD_Attachment_ID());
|
||||
setAD_User_ID(Env.getAD_User_ID(attach.getCtx()));
|
||||
setTitle (Title);
|
||||
setTextMsg (TextMsg);
|
||||
} // MAttachmentNote
|
||||
|
||||
} // MAttachmentNote
|
|
@ -0,0 +1,213 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
import org.compiere.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Change Log Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MChangeLog.java,v 1.3 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public class MChangeLog extends X_AD_ChangeLog
|
||||
{
|
||||
/**
|
||||
* Do we track changes for this table
|
||||
* @param AD_Table_ID table
|
||||
* @return true if changes are tracked
|
||||
*/
|
||||
public static boolean isLogged (int AD_Table_ID)
|
||||
{
|
||||
if (s_changeLog == null || s_changeLog.length == 0)
|
||||
fillChangeLog();
|
||||
//
|
||||
int index = Arrays.binarySearch(s_changeLog, AD_Table_ID);
|
||||
return index >= 0;
|
||||
} // trackChanges
|
||||
|
||||
/**
|
||||
* Fill Log with tables to be logged
|
||||
*/
|
||||
private static void fillChangeLog()
|
||||
{
|
||||
ArrayList<Integer> list = new ArrayList<Integer>(40);
|
||||
String sql = "SELECT t.AD_Table_ID FROM AD_Table t "
|
||||
+ "WHERE t.IsChangeLog='Y'" // also inactive
|
||||
+ " OR EXISTS (SELECT * FROM AD_Column c "
|
||||
+ "WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='EntityType') "
|
||||
+ "ORDER BY t.AD_Table_ID";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
list.add(new Integer(rs.getInt(1)));
|
||||
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;
|
||||
}
|
||||
// Convert to Array
|
||||
s_changeLog = new int [list.size()];
|
||||
for (int i = 0; i < s_changeLog.length; i++)
|
||||
{
|
||||
Integer id = (Integer)list.get(i);
|
||||
s_changeLog[i] = id.intValue();
|
||||
}
|
||||
s_log.info("#" + s_changeLog.length);
|
||||
} // fillChangeLog
|
||||
|
||||
/** Change Log */
|
||||
private static int[] s_changeLog = null;
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger(MChangeLog.class);
|
||||
/** NULL Value */
|
||||
public static String NULL = "NULL";
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChangeLog(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MChangeLog
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_ChangeLog_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChangeLog (Properties ctx, int AD_ChangeLog_ID, String trxName)
|
||||
{
|
||||
super (ctx, 0, trxName);
|
||||
} // MChangeLog
|
||||
|
||||
/**
|
||||
* Full Constructor
|
||||
* @param ctx context
|
||||
* @param AD_ChangeLog_ID 0 for new change log
|
||||
* @param TrxName transaction
|
||||
* @param AD_Session_ID session
|
||||
* @param AD_Table_ID table
|
||||
* @param AD_Column_ID column
|
||||
* @param Record_ID record
|
||||
* @param AD_Client_ID client
|
||||
* @param AD_Org_ID org
|
||||
* @param OldValue old
|
||||
* @param NewValue new
|
||||
*/
|
||||
public MChangeLog (Properties ctx,
|
||||
int AD_ChangeLog_ID, String TrxName, int AD_Session_ID,
|
||||
int AD_Table_ID, int AD_Column_ID, int Record_ID,
|
||||
int AD_Client_ID, int AD_Org_ID,
|
||||
Object OldValue, Object NewValue)
|
||||
{
|
||||
this (ctx, 0, null); // out of trx
|
||||
if (AD_ChangeLog_ID == 0)
|
||||
{
|
||||
AD_ChangeLog_ID = DB.getNextID (AD_Client_ID, Table_Name, null);
|
||||
if (AD_ChangeLog_ID <= 0)
|
||||
log.severe("No NextID (" + AD_ChangeLog_ID + ")");
|
||||
}
|
||||
setAD_ChangeLog_ID (AD_ChangeLog_ID);
|
||||
setTrxName(TrxName);
|
||||
setAD_Session_ID (AD_Session_ID);
|
||||
//
|
||||
setAD_Table_ID (AD_Table_ID);
|
||||
setAD_Column_ID (AD_Column_ID);
|
||||
setRecord_ID (Record_ID);
|
||||
//
|
||||
setClientOrg (AD_Client_ID, AD_Org_ID);
|
||||
//
|
||||
setOldValue (OldValue);
|
||||
setNewValue (NewValue);
|
||||
// R2.5.2f_2005-09-25 2.5.2f_20050925-2201
|
||||
setDescription(Adempiere.MAIN_VERSION + "_"
|
||||
+ Adempiere.DATE_VERSION + " " + Adempiere.getImplementationVersion());
|
||||
} // MChangeLog
|
||||
|
||||
|
||||
/**
|
||||
* Set Old Value
|
||||
* @param OldValue old
|
||||
*/
|
||||
public void setOldValue (Object OldValue)
|
||||
{
|
||||
if (OldValue == null)
|
||||
super.setOldValue (NULL);
|
||||
else
|
||||
super.setOldValue (OldValue.toString());
|
||||
} // setOldValue
|
||||
|
||||
/**
|
||||
* Is Old Value Null
|
||||
* @return true if null
|
||||
*/
|
||||
public boolean isOldNull()
|
||||
{
|
||||
String value = getOldValue();
|
||||
return value == null || value.equals(NULL);
|
||||
} // isOldNull
|
||||
|
||||
/**
|
||||
* Set New Value
|
||||
* @param NewValue new
|
||||
*/
|
||||
public void setNewValue (Object NewValue)
|
||||
{
|
||||
if (NewValue == null)
|
||||
super.setNewValue (NULL);
|
||||
else
|
||||
super.setNewValue (NewValue.toString());
|
||||
} // setNewValue
|
||||
|
||||
/**
|
||||
* Is New Value Null
|
||||
* @return true if null
|
||||
*/
|
||||
public boolean isNewNull()
|
||||
{
|
||||
String value = getNewValue();
|
||||
return value == null || value.equals(NULL);
|
||||
} // isNewNull
|
||||
|
||||
} // MChangeLog
|
|
@ -0,0 +1,785 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.rmi.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import javax.mail.internet.*;
|
||||
import java.io.*;
|
||||
|
||||
import org.compiere.db.*;
|
||||
import org.compiere.interfaces.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Client Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MClient.java,v 1.2 2006/07/30 00:58:37 jjanke Exp $
|
||||
*/
|
||||
public class MClient extends X_AD_Client
|
||||
{
|
||||
/**
|
||||
* Get client
|
||||
* @param ctx context
|
||||
* @param AD_Client_ID id
|
||||
* @return client
|
||||
*/
|
||||
public static MClient get (Properties ctx, int AD_Client_ID)
|
||||
{
|
||||
Integer key = new Integer (AD_Client_ID);
|
||||
MClient client = (MClient)s_cache.get(key);
|
||||
if (client != null)
|
||||
return client;
|
||||
client = new MClient (ctx, AD_Client_ID, null);
|
||||
s_cache.put (key, client);
|
||||
return client;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get all clients
|
||||
* @param ctx context
|
||||
* @return clients
|
||||
*/
|
||||
public static MClient[] getAll (Properties ctx)
|
||||
{
|
||||
ArrayList<MClient> list = new ArrayList<MClient>();
|
||||
String sql = "SELECT * FROM AD_Client";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
MClient client = new MClient (ctx, rs, null);
|
||||
s_cache.put (new Integer (client.getAD_Client_ID()), client);
|
||||
list.add (client);
|
||||
}
|
||||
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;
|
||||
}
|
||||
MClient[] retValue = new MClient[list.size ()];
|
||||
list.toArray (retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get optionally cached client
|
||||
* @param ctx context
|
||||
* @return client
|
||||
*/
|
||||
public static MClient get (Properties ctx)
|
||||
{
|
||||
return get (ctx, Env.getAD_Client_ID(ctx));
|
||||
} // get
|
||||
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MClient.class);
|
||||
/** Cache */
|
||||
private static CCache<Integer,MClient> s_cache = new CCache<Integer,MClient>("AD_Client", 3);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Client_ID id
|
||||
* @param createNew create new
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MClient (Properties ctx, int AD_Client_ID, boolean createNew, String trxName)
|
||||
{
|
||||
super (ctx, AD_Client_ID, trxName);
|
||||
m_createNew = createNew;
|
||||
if (AD_Client_ID == 0)
|
||||
{
|
||||
if (m_createNew)
|
||||
{
|
||||
// setValue (null);
|
||||
// setName (null);
|
||||
setAD_Org_ID(0);
|
||||
setIsMultiLingualDocument (false);
|
||||
setIsSmtpAuthorization (false);
|
||||
setIsUseBetaFunctions (true);
|
||||
setIsServerEMail(false);
|
||||
setAD_Language(Language.getBaseAD_Language());
|
||||
setAutoArchive(AUTOARCHIVE_None);
|
||||
setMMPolicy (MMPOLICY_FiFo); // F
|
||||
setIsPostImmediate(false);
|
||||
setIsCostImmediate(false);
|
||||
}
|
||||
else
|
||||
load(get_TrxName());
|
||||
}
|
||||
} // MClient
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Client_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MClient (Properties ctx, int AD_Client_ID, String trxName)
|
||||
{
|
||||
this (ctx, AD_Client_ID, false, trxName);
|
||||
} // MClient
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MClient (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MClient
|
||||
|
||||
/**
|
||||
* Simplified Constructor
|
||||
* @param ctx context
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MClient (Properties ctx, String trxName)
|
||||
{
|
||||
this (ctx, Env.getAD_Client_ID(ctx), trxName);
|
||||
} // MClient
|
||||
|
||||
/** Client Info */
|
||||
private MClientInfo m_info = null;
|
||||
/** Language */
|
||||
private Language m_language = null;
|
||||
/** New Record */
|
||||
private boolean m_createNew = false;
|
||||
/** Client Info Setup Tree for Account */
|
||||
private int m_AD_Tree_Account_ID;
|
||||
|
||||
/**
|
||||
* Get SMTP Host
|
||||
* @return SMTP or loaclhost
|
||||
*/
|
||||
public String getSMTPHost()
|
||||
{
|
||||
String s = super.getSMTPHost();
|
||||
if (s == null)
|
||||
s = "localhost";
|
||||
return s;
|
||||
} // getSMTPHost
|
||||
|
||||
/**
|
||||
* Get Client Info
|
||||
* @return Client Info
|
||||
*/
|
||||
public MClientInfo getInfo()
|
||||
{
|
||||
if (m_info == null)
|
||||
m_info = MClientInfo.get (getCtx(), getAD_Client_ID(), get_TrxName());
|
||||
return m_info;
|
||||
} // getMClientInfo
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MClient[")
|
||||
.append(get_ID()).append("-").append(getValue())
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Get Default Accounting Currency
|
||||
* @return currency or 0
|
||||
*/
|
||||
public int getC_Currency_ID()
|
||||
{
|
||||
if (m_info == null)
|
||||
getInfo();
|
||||
if (m_info != null)
|
||||
return m_info.getC_Currency_ID();
|
||||
return 0;
|
||||
} // getC_Currency_ID
|
||||
|
||||
/**
|
||||
* Get Language
|
||||
* @return client language
|
||||
*/
|
||||
public Language getLanguage()
|
||||
{
|
||||
if (m_language == null)
|
||||
{
|
||||
m_language = Language.getLanguage(getAD_Language());
|
||||
Env.verifyLanguage (getCtx(), m_language);
|
||||
}
|
||||
return m_language;
|
||||
} // getLanguage
|
||||
|
||||
|
||||
/**
|
||||
* Set AD_Language
|
||||
* @param AD_Language new language
|
||||
*/
|
||||
public void setAD_Language (String AD_Language)
|
||||
{
|
||||
m_language = null;
|
||||
super.setAD_Language (AD_Language);
|
||||
} // setAD_Language
|
||||
|
||||
/**
|
||||
* Get AD_Language
|
||||
* @return Language
|
||||
*/
|
||||
public String getAD_Language ()
|
||||
{
|
||||
String s = super.getAD_Language ();
|
||||
if (s == null)
|
||||
return Language.getBaseAD_Language();
|
||||
return s;
|
||||
} // getAD_Language
|
||||
|
||||
/**
|
||||
* Get Locale
|
||||
* @return locale
|
||||
*/
|
||||
public Locale getLocale()
|
||||
{
|
||||
Language lang = getLanguage();
|
||||
if (lang != null)
|
||||
return lang.getLocale();
|
||||
return Locale.getDefault();
|
||||
} // getLocale
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Create Trees and Setup Client Info
|
||||
* @param language language
|
||||
* @return true if created
|
||||
*/
|
||||
public boolean setupClientInfo (String language)
|
||||
{
|
||||
// Create Trees
|
||||
String sql = null;
|
||||
if (Env.isBaseLanguage (language, "AD_Ref_List")) // Get TreeTypes & Name
|
||||
sql = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=120 AND IsActive='Y'";
|
||||
else
|
||||
sql = "SELECT l.Value, t.Name FROM AD_Ref_List l, AD_Ref_List_Trl t "
|
||||
+ "WHERE l.AD_Reference_ID=120 AND l.AD_Ref_List_ID=t.AD_Ref_List_ID AND l.IsActive='Y'";
|
||||
|
||||
// Tree IDs
|
||||
int AD_Tree_Org_ID=0, AD_Tree_BPartner_ID=0, AD_Tree_Project_ID=0,
|
||||
AD_Tree_SalesRegion_ID=0, AD_Tree_Product_ID=0,
|
||||
AD_Tree_Campaign_ID=0, AD_Tree_Activity_ID=0;
|
||||
|
||||
boolean success = false;
|
||||
try
|
||||
{
|
||||
PreparedStatement stmt = DB.prepareStatement(sql, get_TrxName());
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
MTree_Base tree = null;
|
||||
while (rs.next())
|
||||
{
|
||||
String value = rs.getString(1);
|
||||
String name = getName() + " " + rs.getString(2);
|
||||
//
|
||||
if (value.equals(MTree_Base.TREETYPE_Organization))
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
AD_Tree_Org_ID = tree.getAD_Tree_ID();
|
||||
}
|
||||
else if (value.equals(MTree_Base.TREETYPE_BPartner))
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
AD_Tree_BPartner_ID = tree.getAD_Tree_ID();
|
||||
}
|
||||
else if (value.equals(MTree_Base.TREETYPE_Project))
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
AD_Tree_Project_ID = tree.getAD_Tree_ID();
|
||||
}
|
||||
else if (value.equals(MTree_Base.TREETYPE_SalesRegion))
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
AD_Tree_SalesRegion_ID = tree.getAD_Tree_ID();
|
||||
}
|
||||
else if (value.equals(MTree_Base.TREETYPE_Product))
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
AD_Tree_Product_ID = tree.getAD_Tree_ID();
|
||||
}
|
||||
else if (value.equals(MTree_Base.TREETYPE_ElementValue))
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
m_AD_Tree_Account_ID = tree.getAD_Tree_ID();
|
||||
}
|
||||
else if (value.equals(MTree_Base.TREETYPE_Campaign))
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
AD_Tree_Campaign_ID = tree.getAD_Tree_ID();
|
||||
}
|
||||
else if (value.equals(MTree_Base.TREETYPE_Activity))
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
AD_Tree_Activity_ID = tree.getAD_Tree_ID();
|
||||
}
|
||||
else if (value.equals(MTree_Base.TREETYPE_Menu)) // No Menu
|
||||
success = true;
|
||||
else // PC (Product Category), BB (BOM)
|
||||
{
|
||||
tree = new MTree_Base (this, name, value);
|
||||
success = tree.save();
|
||||
}
|
||||
if (!success)
|
||||
{
|
||||
log.log(Level.SEVERE, "Tree NOT created: " + name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
}
|
||||
catch (SQLException e1)
|
||||
{
|
||||
log.log(Level.SEVERE, "Trees", e1);
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
return false;
|
||||
|
||||
// Create ClientInfo
|
||||
MClientInfo clientInfo = new MClientInfo (this,
|
||||
AD_Tree_Org_ID, AD_Tree_BPartner_ID, AD_Tree_Project_ID,
|
||||
AD_Tree_SalesRegion_ID, AD_Tree_Product_ID,
|
||||
AD_Tree_Campaign_ID, AD_Tree_Activity_ID, get_TrxName());
|
||||
success = clientInfo.save();
|
||||
return success;
|
||||
} // createTrees
|
||||
|
||||
/**
|
||||
* Get AD_Tree_Account_ID created in setup client info
|
||||
* @return Account Tree ID
|
||||
*/
|
||||
public int getSetup_AD_Tree_Account_ID()
|
||||
{
|
||||
return m_AD_Tree_Account_ID;
|
||||
} // getSetup_AD_Tree_Account_ID
|
||||
|
||||
/**
|
||||
* Is Auto Archive on
|
||||
* @return true if auto archive
|
||||
*/
|
||||
public boolean isAutoArchive()
|
||||
{
|
||||
String aa = getAutoArchive();
|
||||
return aa != null && !aa.equals(AUTOARCHIVE_None);
|
||||
} // isAutoArchive
|
||||
|
||||
|
||||
/**
|
||||
* Update Trl Tables automatically?
|
||||
* @param TableName table name
|
||||
* @return true if automatically translated
|
||||
*/
|
||||
public boolean isAutoUpdateTrl (String TableName)
|
||||
{
|
||||
if (super.isMultiLingualDocument())
|
||||
return false;
|
||||
if (TableName == null)
|
||||
return false;
|
||||
// Not Multi-Lingual Documents - only Doc Related
|
||||
if (TableName.startsWith("AD"))
|
||||
return false;
|
||||
return true;
|
||||
} // isMultiLingualDocument
|
||||
|
||||
/**
|
||||
* Get Primary Accounting Schema
|
||||
* @return Acct Schema or null
|
||||
*/
|
||||
public MAcctSchema getAcctSchema()
|
||||
{
|
||||
if (m_info == null)
|
||||
m_info = MClientInfo.get (getCtx(), getAD_Client_ID(), get_TrxName());
|
||||
if (m_info != null)
|
||||
{
|
||||
int C_AcctSchema_ID = m_info.getC_AcctSchema1_ID();
|
||||
if (C_AcctSchema_ID != 0)
|
||||
return MAcctSchema.get(getCtx(), C_AcctSchema_ID);
|
||||
}
|
||||
return null;
|
||||
} // getMClientInfo
|
||||
|
||||
/**
|
||||
* Save
|
||||
* @return true if saved
|
||||
*/
|
||||
public boolean save ()
|
||||
{
|
||||
if (get_ID() == 0 && !m_createNew)
|
||||
return saveUpdate();
|
||||
return super.save ();
|
||||
} // save
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Test EMail
|
||||
* @return OK or error
|
||||
*/
|
||||
public String testEMail()
|
||||
{
|
||||
if (getRequestEMail() == null || getRequestEMail().length() == 0)
|
||||
return "No Request EMail for " + getName();
|
||||
//
|
||||
EMail email = createEMail (getRequestEMail(),
|
||||
"Adempiere EMail Test",
|
||||
"Adempiere EMail Test: " + toString());
|
||||
if (email == null)
|
||||
return "Could not create EMail: " + getName();
|
||||
try
|
||||
{
|
||||
String msg = email.send();
|
||||
if (EMail.SENT_OK.equals (msg))
|
||||
{
|
||||
log.info("Sent Test EMail to " + getRequestEMail());
|
||||
return "OK";
|
||||
}
|
||||
else
|
||||
{
|
||||
log.warning("Could NOT send Test EMail from "
|
||||
+ getSMTPHost() + ": " + getRequestEMail()
|
||||
+ " (" + getRequestUser()
|
||||
+ ") to " + getRequestEMail() + ": " + msg);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.severe(getName() + " - " + ex.getLocalizedMessage());
|
||||
return ex.getLocalizedMessage();
|
||||
}
|
||||
} // testEMail
|
||||
|
||||
/**
|
||||
* Send EMail from Request User - with trace
|
||||
* @param AD_User_ID recipient
|
||||
* @param subject subject
|
||||
* @param message message
|
||||
* @param attachment optional attachment
|
||||
* @return true if sent
|
||||
*/
|
||||
public boolean sendEMail (int AD_User_ID,
|
||||
String subject, String message, File attachment)
|
||||
{
|
||||
MUser to = MUser.get(getCtx(), AD_User_ID);
|
||||
String toEMail = to.getEMail();
|
||||
if (toEMail == null || toEMail.length() == 0)
|
||||
{
|
||||
log.warning("No EMail for recipient: " + to);
|
||||
return false;
|
||||
}
|
||||
EMail email = createEMail(null, to, subject, message);
|
||||
if (email == null)
|
||||
return false;
|
||||
if (attachment != null)
|
||||
email.addAttachment(attachment);
|
||||
try
|
||||
{
|
||||
return sendEmailNow(null, to, email);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.severe(getName() + " - " + ex.getLocalizedMessage());
|
||||
return false;
|
||||
}
|
||||
} // sendEMail
|
||||
|
||||
/**
|
||||
* Send EMail from Request User - no trace
|
||||
* @param to recipient email address
|
||||
* @param subject subject
|
||||
* @param message message
|
||||
* @param attachment optional attachment
|
||||
* @return true if sent
|
||||
*/
|
||||
public boolean sendEMail (String to,
|
||||
String subject, String message, File attachment)
|
||||
{
|
||||
EMail email = createEMail(to, subject, message);
|
||||
if (email == null)
|
||||
return false;
|
||||
if (attachment != null)
|
||||
email.addAttachment(attachment);
|
||||
try
|
||||
{
|
||||
String msg = email.send();
|
||||
if (EMail.SENT_OK.equals (msg))
|
||||
{
|
||||
log.info("Sent EMail " + subject + " to " + to);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.warning("Could NOT Send Email: " + subject
|
||||
+ " to " + to + ": " + msg
|
||||
+ " (" + getName() + ")");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.severe(getName() + " - " + ex.getLocalizedMessage());
|
||||
return false;
|
||||
}
|
||||
} // sendEMail
|
||||
|
||||
|
||||
/**
|
||||
* Send EMail from User
|
||||
* @param from sender
|
||||
* @param to recipient
|
||||
* @param subject subject
|
||||
* @param message message
|
||||
* @param attachment optional attachment
|
||||
* @return true if sent
|
||||
*/
|
||||
public boolean sendEMail (MUser from, MUser to,
|
||||
String subject, String message, File attachment)
|
||||
{
|
||||
EMail email = createEMail(from, to, subject, message);
|
||||
if (email == null)
|
||||
return false;
|
||||
if (attachment != null)
|
||||
email.addAttachment(attachment);
|
||||
InternetAddress emailFrom = email.getFrom();
|
||||
try
|
||||
{
|
||||
return sendEmailNow(from, to, email);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.severe(getName() + " - from " + emailFrom
|
||||
+ " to " + to + ": " + ex.getLocalizedMessage());
|
||||
return false;
|
||||
}
|
||||
} // sendEMail
|
||||
|
||||
/**
|
||||
* Send Email Now
|
||||
* @param from optional from user
|
||||
* @param to to user
|
||||
* @param email email
|
||||
* @return true if sent
|
||||
*/
|
||||
private boolean sendEmailNow(MUser from, MUser to, EMail email)
|
||||
{
|
||||
String msg = email.send();
|
||||
//
|
||||
X_AD_UserMail um = new X_AD_UserMail(getCtx(), 0, null);
|
||||
um.setClientOrg(this);
|
||||
um.setAD_User_ID(to.getAD_User_ID());
|
||||
um.setSubject(email.getSubject());
|
||||
um.setMailText(email.getMessageCRLF());
|
||||
if (email.isSentOK())
|
||||
um.setMessageID(email.getMessageID());
|
||||
else
|
||||
{
|
||||
um.setMessageID(email.getSentMsg());
|
||||
um.setIsDelivered(X_AD_UserMail.ISDELIVERED_No);
|
||||
}
|
||||
um.save();
|
||||
|
||||
//
|
||||
if (email.isSentOK())
|
||||
{
|
||||
if (from != null)
|
||||
log.info("Sent Email: " + email.getSubject()
|
||||
+ " from " + from.getEMail()
|
||||
+ " to " + to.getEMail());
|
||||
else
|
||||
log.info("Sent Email: " + email.getSubject()
|
||||
+ " to " + to.getEMail());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (from != null)
|
||||
log.warning("Could NOT Send Email: " + email.getSubject()
|
||||
+ " from " + from.getEMail()
|
||||
+ " to " + to.getEMail() + ": " + msg
|
||||
+ " (" + getName() + ")");
|
||||
else
|
||||
log.warning("Could NOT Send Email: " + email.getSubject()
|
||||
+ " to " + to.getEMail() + ": " + msg
|
||||
+ " (" + getName() + ")");
|
||||
return false;
|
||||
}
|
||||
} // sendEmailNow
|
||||
|
||||
/************
|
||||
* Create EMail from Request User
|
||||
* @param to recipient
|
||||
* @param subject sunject
|
||||
* @param message nessage
|
||||
* @return EMail
|
||||
*/
|
||||
public EMail createEMail (String to,
|
||||
String subject, String message)
|
||||
{
|
||||
if (to == null || to.length() == 0)
|
||||
{
|
||||
log.warning("No To");
|
||||
return null;
|
||||
}
|
||||
//
|
||||
EMail email = null;
|
||||
if (isServerEMail() && Ini.isClient())
|
||||
{
|
||||
Server server = CConnection.get().getServer();
|
||||
try
|
||||
{
|
||||
if (server != null)
|
||||
{ // See ServerBean
|
||||
email = server.createEMail(getCtx(), getAD_Client_ID(),
|
||||
to, subject, message);
|
||||
}
|
||||
else
|
||||
log.log(Level.WARNING, "No AppsServer");
|
||||
}
|
||||
catch (RemoteException ex)
|
||||
{
|
||||
log.log(Level.SEVERE, getName() + " - AppsServer error", ex);
|
||||
}
|
||||
}
|
||||
if (email == null)
|
||||
email = new EMail (this,
|
||||
getRequestEMail(), to,
|
||||
subject, message);
|
||||
if (isSmtpAuthorization())
|
||||
email.createAuthenticator (getRequestUser(), getRequestUserPW());
|
||||
return email;
|
||||
} // createEMail
|
||||
|
||||
/**
|
||||
* Create EMail from User
|
||||
* @param from optional sender
|
||||
* @param to recipient
|
||||
* @param subject sunject
|
||||
* @param message nessage
|
||||
* @return EMail
|
||||
*/
|
||||
public EMail createEMail (MUser from, MUser to,
|
||||
String subject, String message)
|
||||
{
|
||||
if (to == null)
|
||||
{
|
||||
log.warning("No To user");
|
||||
return null;
|
||||
}
|
||||
if (to.getEMail() == null || to.getEMail().length() == 0)
|
||||
{
|
||||
log.warning("No To address: " + to);
|
||||
return null;
|
||||
}
|
||||
return createEMail (from, to.getEMail(), subject, message);
|
||||
} // createEMail
|
||||
|
||||
/**
|
||||
* Create EMail from User
|
||||
* @param from optional sender
|
||||
* @param to recipient
|
||||
* @param subject sunject
|
||||
* @param message nessage
|
||||
* @return EMail
|
||||
*/
|
||||
public EMail createEMail (MUser from, String to,
|
||||
String subject, String message)
|
||||
{
|
||||
if (to == null || to.length() == 0)
|
||||
{
|
||||
log.warning("No To address");
|
||||
return null;
|
||||
}
|
||||
// No From - send from Request
|
||||
if (from == null)
|
||||
return createEMail (to, subject, message);
|
||||
// No From details - Error
|
||||
if (from.getEMail() == null
|
||||
|| from.getEMailUser() == null || from.getEMailUserPW() == null)
|
||||
{
|
||||
log.warning("From EMail incomplete: " + from + " (" + getName() + ")");
|
||||
return null;
|
||||
}
|
||||
//
|
||||
EMail email = null;
|
||||
if (isServerEMail() && Ini.isClient())
|
||||
{
|
||||
Server server = CConnection.get().getServer();
|
||||
try
|
||||
{
|
||||
if (server != null)
|
||||
{ // See ServerBean
|
||||
email = server.createEMail(getCtx(), getAD_Client_ID(),
|
||||
from.getAD_User_ID(),
|
||||
to, subject, message);
|
||||
}
|
||||
else
|
||||
log.log(Level.WARNING, "No AppsServer");
|
||||
}
|
||||
catch (RemoteException ex)
|
||||
{
|
||||
log.log(Level.SEVERE, getName() + " - AppsServer error", ex);
|
||||
}
|
||||
}
|
||||
if (email == null)
|
||||
email = new EMail (this,
|
||||
from.getEMail(),
|
||||
to,
|
||||
subject,
|
||||
message);
|
||||
if (isSmtpAuthorization())
|
||||
email.createAuthenticator (from.getEMailUser(), from.getEMailUserPW());
|
||||
return email;
|
||||
} // createEMail
|
||||
|
||||
} // MClient
|
|
@ -0,0 +1,211 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Client Info Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MClientInfo.java,v 1.2 2006/07/30 00:58:37 jjanke Exp $
|
||||
*/
|
||||
public class MClientInfo extends X_AD_ClientInfo
|
||||
{
|
||||
/**
|
||||
* Get Client Info
|
||||
* @param ctx context
|
||||
* @param AD_Client_ID id
|
||||
* @return Client Info
|
||||
*/
|
||||
public static MClientInfo get (Properties ctx, int AD_Client_ID)
|
||||
{
|
||||
return get(ctx, AD_Client_ID, null);
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get Client Info
|
||||
* @param ctx context
|
||||
* @param AD_Client_ID id
|
||||
* @param trxName optional trx
|
||||
* @return Client Info
|
||||
*/
|
||||
public static MClientInfo get (Properties ctx, int AD_Client_ID, String trxName)
|
||||
{
|
||||
Integer key = new Integer (AD_Client_ID);
|
||||
MClientInfo info = (MClientInfo)s_cache.get(key);
|
||||
if (info != null)
|
||||
return info;
|
||||
//
|
||||
String sql = "SELECT * FROM AD_ClientInfo WHERE AD_Client_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, trxName);
|
||||
pstmt.setInt (1, AD_Client_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
{
|
||||
info = new MClientInfo (ctx, rs, null);
|
||||
if (trxName == null)
|
||||
s_cache.put (key, info);
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, ex);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
}
|
||||
catch (SQLException ex1)
|
||||
{
|
||||
}
|
||||
pstmt = null;
|
||||
//
|
||||
return info;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get optionally cached client
|
||||
* @param ctx context
|
||||
* @return client
|
||||
*/
|
||||
public static MClientInfo get (Properties ctx)
|
||||
{
|
||||
return get (ctx, Env.getAD_Client_ID(ctx), null);
|
||||
} // get
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer,MClientInfo> s_cache = new CCache<Integer,MClientInfo>("AD_ClientInfo", 2);
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MClientInfo.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param ignored ignored
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MClientInfo (Properties ctx, int ignored, String trxName)
|
||||
{
|
||||
super (ctx, ignored, trxName);
|
||||
if (ignored != 0)
|
||||
throw new IllegalArgumentException("Multi-Key");
|
||||
} // MClientInfo
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MClientInfo (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MClientInfo
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param client client
|
||||
* @param AD_Tree_Org_ID org tree
|
||||
* @param AD_Tree_BPartner_ID bp tree
|
||||
* @param AD_Tree_Project_ID project tree
|
||||
* @param AD_Tree_SalesRegion_ID sr tree
|
||||
* @param AD_Tree_Product_ID product tree
|
||||
* @param AD_Tree_Campaign_ID campaign tree
|
||||
* @param AD_Tree_Activity_ID activity tree
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MClientInfo (MClient client, int AD_Tree_Org_ID, int AD_Tree_BPartner_ID,
|
||||
int AD_Tree_Project_ID, int AD_Tree_SalesRegion_ID, int AD_Tree_Product_ID,
|
||||
int AD_Tree_Campaign_ID, int AD_Tree_Activity_ID, String trxName)
|
||||
{
|
||||
super (client.getCtx(), 0, trxName);
|
||||
setAD_Client_ID(client.getAD_Client_ID()); // to make sure
|
||||
setAD_Org_ID(0);
|
||||
setIsDiscountLineAmt (false);
|
||||
//
|
||||
setAD_Tree_Menu_ID(10); // HARDCODED
|
||||
//
|
||||
setAD_Tree_Org_ID(AD_Tree_Org_ID);
|
||||
setAD_Tree_BPartner_ID(AD_Tree_BPartner_ID);
|
||||
setAD_Tree_Project_ID(AD_Tree_Project_ID);
|
||||
setAD_Tree_SalesRegion_ID(AD_Tree_SalesRegion_ID);
|
||||
setAD_Tree_Product_ID(AD_Tree_Product_ID);
|
||||
setAD_Tree_Campaign_ID(AD_Tree_Campaign_ID);
|
||||
setAD_Tree_Activity_ID(AD_Tree_Activity_ID);
|
||||
//
|
||||
m_createNew = true;
|
||||
} // MClientInfo
|
||||
|
||||
|
||||
/** Account Schema */
|
||||
private MAcctSchema m_acctSchema = null;
|
||||
/** New Record */
|
||||
private boolean m_createNew = false;
|
||||
|
||||
/**
|
||||
* Get primary Acct Schema
|
||||
* @return acct schema
|
||||
*/
|
||||
public MAcctSchema getMAcctSchema1()
|
||||
{
|
||||
if (m_acctSchema == null && getC_AcctSchema1_ID() != 0)
|
||||
m_acctSchema = new MAcctSchema (getCtx(), getC_AcctSchema1_ID(), null);
|
||||
return m_acctSchema;
|
||||
} // getMAcctSchema1
|
||||
|
||||
/**
|
||||
* Get Default Accounting Currency
|
||||
* @return currency or 0
|
||||
*/
|
||||
public int getC_Currency_ID()
|
||||
{
|
||||
if (m_acctSchema == null)
|
||||
getMAcctSchema1();
|
||||
if (m_acctSchema != null)
|
||||
return m_acctSchema.getC_Currency_ID();
|
||||
return 0;
|
||||
} // getC_Currency_ID
|
||||
|
||||
|
||||
/**
|
||||
* Overwrite Save
|
||||
* @overwrite
|
||||
* @return true if saved
|
||||
*/
|
||||
public boolean save ()
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
if (m_createNew)
|
||||
return super.save ();
|
||||
return saveUpdate();
|
||||
} // save
|
||||
|
||||
} // MClientInfo
|
|
@ -0,0 +1,291 @@
|
|||
/******************************************************************************
|
||||
* 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.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'"
|
||||
+ " AND EXISTS (SELECT * FROM AD_Column c "
|
||||
+ "WHERE t.AD_Table_ID=c.AD_Table_ID"
|
||||
+ " AND c.IsParent='Y'"
|
||||
+ " AND c.ColumnName=(SELECT ColumnName FROM AD_Column cc "
|
||||
+ "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
|
|
@ -0,0 +1,401 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Persistent Column Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MColumn.java,v 1.6 2006/08/09 05:23:49 jjanke Exp $
|
||||
*/
|
||||
public class MColumn extends X_AD_Column
|
||||
{
|
||||
/**
|
||||
* Get M_Column from Cache
|
||||
* @param ctx context
|
||||
* @param AD_Column_ID id
|
||||
* @return M_Column
|
||||
*/
|
||||
public static MColumn get (Properties ctx, int AD_Column_ID)
|
||||
{
|
||||
Integer key = new Integer (AD_Column_ID);
|
||||
MColumn retValue = (MColumn) s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MColumn (ctx, AD_Column_ID, null);
|
||||
if (retValue.get_ID () != 0)
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get Column Name
|
||||
* @param ctx context
|
||||
* @param AD_Column_ID id
|
||||
* @return Column Name or null
|
||||
*/
|
||||
public static String getColumnName (Properties ctx, int AD_Column_ID)
|
||||
{
|
||||
MColumn col = MColumn.get(ctx, AD_Column_ID);
|
||||
if (col.get_ID() == 0)
|
||||
return null;
|
||||
return col.getColumnName();
|
||||
} // getColumnName
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer,MColumn> s_cache = new CCache<Integer,MColumn>("AD_Column", 20);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Column_ID
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MColumn (Properties ctx, int AD_Column_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_Column_ID, trxName);
|
||||
if (AD_Column_ID == 0)
|
||||
{
|
||||
// setAD_Element_ID (0);
|
||||
// setAD_Reference_ID (0);
|
||||
// setColumnName (null);
|
||||
// setName (null);
|
||||
// setEntityType (null); // U
|
||||
setIsAlwaysUpdateable (false); // N
|
||||
setIsEncrypted (false);
|
||||
setIsIdentifier (false);
|
||||
setIsKey (false);
|
||||
setIsMandatory (false);
|
||||
setIsParent (false);
|
||||
setIsSelectionColumn (false);
|
||||
setIsTranslated (false);
|
||||
setIsUpdateable (true); // Y
|
||||
setVersion (Env.ZERO);
|
||||
}
|
||||
} // M_Column
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MColumn (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // M_Column
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent table
|
||||
*/
|
||||
public MColumn (MTable parent)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setAD_Table_ID (parent.getAD_Table_ID());
|
||||
setEntityType(parent.getEntityType());
|
||||
} // M_Column
|
||||
|
||||
|
||||
/**
|
||||
* Is Standard Column
|
||||
* @return true for AD_Client_ID, etc.
|
||||
*/
|
||||
public boolean isStandardColumn()
|
||||
{
|
||||
String columnName = getColumnName();
|
||||
if (columnName.equals("AD_Client_ID")
|
||||
|| columnName.equals("AD_Org_ID")
|
||||
|| columnName.equals("IsActive")
|
||||
|| columnName.startsWith("Created")
|
||||
|| columnName.startsWith("Updated") )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
} // isStandardColumn
|
||||
|
||||
/**
|
||||
* Is Virtual Column
|
||||
* @return true if virtual column
|
||||
*/
|
||||
public boolean isVirtualColumn()
|
||||
{
|
||||
String s = getColumnSQL();
|
||||
return s != null && s.length() > 0;
|
||||
} // isVirtualColumn
|
||||
|
||||
/**
|
||||
* Is the Column Encrypted?
|
||||
* @return true if encrypted
|
||||
*/
|
||||
public boolean isEncrypted()
|
||||
{
|
||||
String s = getIsEncrypted();
|
||||
return "Y".equals(s);
|
||||
} // isEncrypted
|
||||
|
||||
/**
|
||||
* Set Encrypted
|
||||
* @param IsEncrypted encrypted
|
||||
*/
|
||||
public void setIsEncrypted (boolean IsEncrypted)
|
||||
{
|
||||
setIsEncrypted (IsEncrypted ? "Y" : "N");
|
||||
} // setIsEncrypted
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getFieldLength() == 0 // LOB can be 0
|
||||
&& !DisplayType.isLOB(getAD_Reference_ID()))
|
||||
{
|
||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), "FieldLength"));
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Views are not updateable
|
||||
UPDATE AD_Column c
|
||||
SET IsUpdateable='N', IsAlwaysUpdateable='N'
|
||||
WHERE AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Table WHERE IsView='Y')
|
||||
**/
|
||||
|
||||
// Virtual Column
|
||||
if (isVirtualColumn())
|
||||
{
|
||||
if (isMandatory())
|
||||
setIsMandatory(false);
|
||||
if (isUpdateable())
|
||||
setIsUpdateable(false);
|
||||
}
|
||||
// Updateable
|
||||
if (isParent() || isKey())
|
||||
setIsUpdateable(false);
|
||||
if (isAlwaysUpdateable() && !isUpdateable())
|
||||
setIsAlwaysUpdateable(false);
|
||||
// Encrypted
|
||||
if (isEncrypted())
|
||||
{
|
||||
int dt = getAD_Reference_ID();
|
||||
if (isKey() || isParent() || isStandardColumn()
|
||||
|| isVirtualColumn() || isIdentifier() || isTranslated()
|
||||
|| DisplayType.isLookup(dt) || DisplayType.isLOB(dt)
|
||||
|| "DocumentNo".equalsIgnoreCase(getColumnName())
|
||||
|| "Value".equalsIgnoreCase(getColumnName())
|
||||
|| "Name".equalsIgnoreCase(getColumnName()))
|
||||
{
|
||||
log.warning("Encryption not sensible - " + getColumnName());
|
||||
setIsEncrypted(false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
// Update Fields
|
||||
if (!newRecord)
|
||||
{
|
||||
StringBuffer sql = new StringBuffer("UPDATE AD_Field SET Name=")
|
||||
.append(DB.TO_STRING(getName()))
|
||||
.append(", Description=").append(DB.TO_STRING(getDescription()))
|
||||
.append(", Help=").append(DB.TO_STRING(getHelp()))
|
||||
.append(" WHERE AD_Column_ID=").append(get_ID())
|
||||
.append(" AND IsCentrallyMaintained='Y'");
|
||||
int no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("afterSave - Fields updated #" + no);
|
||||
}
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* Get SQL Add command
|
||||
* @param table table
|
||||
* @return sql
|
||||
*/
|
||||
public String getSQLAdd (MTable table)
|
||||
{
|
||||
StringBuffer sql = new StringBuffer ("ALTER TABLE ")
|
||||
.append(table.getTableName())
|
||||
.append(" ADD ").append(getSQLDDL());
|
||||
return sql.toString();
|
||||
} // getSQLAdd
|
||||
|
||||
/**
|
||||
* Get SQL DDL
|
||||
* @return columnName datataype ..
|
||||
*/
|
||||
public String getSQLDDL()
|
||||
{
|
||||
StringBuffer sql = new StringBuffer (getColumnName())
|
||||
.append(" ").append(getSQLDataType());
|
||||
// Default
|
||||
if (getDefaultValue() != null && getDefaultValue().length() > 0
|
||||
// globalqss 2005-11-03
|
||||
&& (! getDefaultValue().equals("@#AD_Org_ID@"))
|
||||
&& (! getDefaultValue().equals("@#AD_Client_ID@"))
|
||||
&& (! getDefaultValue().equals("@AD_Org_ID@"))
|
||||
&& (! getDefaultValue().equals("@AD_Client_ID@"))
|
||||
// end globalqss 2005-11-03
|
||||
)
|
||||
{
|
||||
sql.append(" DEFAULT ");
|
||||
if (DisplayType.isText(getAD_Reference_ID()))
|
||||
sql.append(DB.TO_STRING(getDefaultValue()));
|
||||
else
|
||||
sql.append(getDefaultValue());
|
||||
}
|
||||
// Inline Constraint
|
||||
if (getAD_Reference_ID() == DisplayType.YesNo)
|
||||
sql.append(" CHECK (").append(getColumnName()).append(" IN ('Y','N'))");
|
||||
|
||||
// Null
|
||||
if (isMandatory())
|
||||
sql.append(" NOT NULL");
|
||||
return sql.toString();
|
||||
} // getSQLDDL
|
||||
|
||||
/**
|
||||
* Get SQL Modify command
|
||||
* @param table table
|
||||
* @param setNullOption generate null / not null statement
|
||||
* @return sql separated by ;
|
||||
*/
|
||||
public String getSQLModify (MTable table, boolean setNullOption)
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
StringBuffer sqlBase = new StringBuffer ("ALTER TABLE ")
|
||||
.append(table.getTableName())
|
||||
.append(" MODIFY ").append(getColumnName());
|
||||
|
||||
// Default
|
||||
StringBuffer sqlDefault = new StringBuffer(sqlBase)
|
||||
.append(" ").append(getSQLDataType())
|
||||
.append(" DEFAULT ");
|
||||
String defaultValue = getDefaultValue();
|
||||
if (defaultValue != null
|
||||
&& defaultValue.length() > 0
|
||||
&& defaultValue.indexOf("@") == -1) // no variables
|
||||
{
|
||||
if (DisplayType.isText(getAD_Reference_ID())
|
||||
|| getAD_Reference_ID() == DisplayType.List
|
||||
|| getAD_Reference_ID() == DisplayType.YesNo)
|
||||
{
|
||||
if (!defaultValue.startsWith("'") && !defaultValue.endsWith("'"))
|
||||
defaultValue = DB.TO_STRING(defaultValue);
|
||||
}
|
||||
sqlDefault.append(defaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlDefault.append(" NULL ");
|
||||
defaultValue = null;
|
||||
}
|
||||
sql.append(sqlDefault);
|
||||
|
||||
// Constraint
|
||||
|
||||
// Null Values
|
||||
if (isMandatory() && defaultValue != null && defaultValue.length() > 0)
|
||||
{
|
||||
StringBuffer sqlSet = new StringBuffer("UPDATE ")
|
||||
.append(table.getTableName())
|
||||
.append(" SET ").append(getColumnName())
|
||||
.append("=").append(defaultValue)
|
||||
.append(" WHERE ").append(getColumnName()).append(" IS NULL");
|
||||
sql.append(DB.SQLSTATEMENT_SEPARATOR).append(sqlSet);
|
||||
}
|
||||
|
||||
// Null
|
||||
if (setNullOption)
|
||||
{
|
||||
StringBuffer sqlNull = new StringBuffer(sqlBase);
|
||||
if (isMandatory())
|
||||
sqlNull.append(" NOT NULL");
|
||||
else
|
||||
sqlNull.append(" NULL");
|
||||
sql.append(DB.SQLSTATEMENT_SEPARATOR).append(sqlNull);
|
||||
}
|
||||
//
|
||||
return sql.toString();
|
||||
} // getSQLModify
|
||||
|
||||
/**
|
||||
* Get SQL Data Type
|
||||
* @return e.g. NVARCHAR2(60)
|
||||
*/
|
||||
private String getSQLDataType()
|
||||
{
|
||||
int dt = getAD_Reference_ID();
|
||||
if (DisplayType.isID(dt) || dt == DisplayType.Integer)
|
||||
return "NUMBER(10)";
|
||||
if (DisplayType.isDate(dt))
|
||||
return "DATE";
|
||||
if (DisplayType.isNumeric(dt))
|
||||
return "NUMBER";
|
||||
if (dt == DisplayType.Binary)
|
||||
return "BLOB";
|
||||
if (dt == DisplayType.TextLong)
|
||||
return "CLOB";
|
||||
if (dt == DisplayType.YesNo)
|
||||
return "CHAR(1)";
|
||||
if (dt == DisplayType.List)
|
||||
return "CHAR(" + getFieldLength() + ")";
|
||||
else if (!DisplayType.isText(dt))
|
||||
log.severe("Unhandled Data Type = " + dt);
|
||||
|
||||
return "NVARCHAR2(" + getFieldLength() + ")";
|
||||
} // getSQLDataType
|
||||
|
||||
/**
|
||||
* Get Table Constraint
|
||||
* @param tableName table name
|
||||
* @return table constraint
|
||||
*/
|
||||
public String getConstraint(String tableName)
|
||||
{
|
||||
if (isKey())
|
||||
return "CONSTRAINT " + tableName + "_Key PRIMARY KEY (" + getColumnName() + ")";
|
||||
/**
|
||||
if (getAD_Reference_ID() == DisplayType.TableDir
|
||||
|| getAD_Reference_ID() == DisplayType.Search)
|
||||
return "CONSTRAINT " ADTable_ADTableTrl
|
||||
+ " FOREIGN KEY (" + getColumnName() + ") REFERENCES "
|
||||
+ AD_Table(AD_Table_ID) ON DELETE CASCADE
|
||||
**/
|
||||
|
||||
return "";
|
||||
} // getConstraint
|
||||
|
||||
} // M_Column
|
|
@ -0,0 +1,161 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Column Access Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MColumnAccess.java,v 1.3 2006/07/30 00:54:54 jjanke Exp $
|
||||
*/
|
||||
public class MColumnAccess extends X_AD_Column_Access
|
||||
{
|
||||
/**
|
||||
* Persistency Constructor
|
||||
* @param ctx context
|
||||
* @param ignored ignored
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MColumnAccess (Properties ctx, int ignored, String trxName)
|
||||
{
|
||||
super(ctx, 0, trxName);
|
||||
if (ignored != 0)
|
||||
throw new IllegalArgumentException("Multi-Key");
|
||||
} // MColumnAccess
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MColumnAccess(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MColumnAccess
|
||||
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MColumnAccess[");
|
||||
sb.append("AD_Role_ID=").append(getAD_Role_ID())
|
||||
.append(",AD_Table_ID=").append(getAD_Table_ID())
|
||||
.append(",AD_Column_ID=").append(getAD_Column_ID())
|
||||
.append(",Exclude=").append(isExclude());
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Extended String Representation.
|
||||
* @param ctx context
|
||||
* @return extended info
|
||||
*/
|
||||
public String toStringX (Properties ctx)
|
||||
{
|
||||
String in = Msg.getMsg(ctx, "Include");
|
||||
String ex = Msg.getMsg(ctx, "Exclude");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(Msg.translate(ctx, "AD_Table_ID"))
|
||||
.append("=").append(getTableName(ctx)).append(", ")
|
||||
.append(Msg.translate(ctx, "AD_Column_ID"))
|
||||
.append("=").append(getColumnName(ctx))
|
||||
.append(" (").append(Msg.translate(ctx, "IsReadOnly")).append("=").append(isReadOnly())
|
||||
.append(") - ").append(isExclude() ? ex : in);
|
||||
return sb.toString();
|
||||
} // toStringX
|
||||
|
||||
/** TableName */
|
||||
private String m_tableName;
|
||||
/** ColumnName */
|
||||
private String m_columnName;
|
||||
|
||||
/**
|
||||
* Get Table Name
|
||||
* @param ctx context for translatioin
|
||||
* @return table name
|
||||
*/
|
||||
public String getTableName (Properties ctx)
|
||||
{
|
||||
if (m_tableName == null)
|
||||
getColumnName(ctx);
|
||||
return m_tableName;
|
||||
} // getTableName
|
||||
|
||||
/**
|
||||
* Get Column Name
|
||||
* @param ctx context for translatioin
|
||||
* @return column name
|
||||
*/
|
||||
public String getColumnName (Properties ctx)
|
||||
{
|
||||
if (m_columnName == null)
|
||||
{
|
||||
String sql = "SELECT t.TableName,c.ColumnName, t.AD_Table_ID "
|
||||
+ "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) "
|
||||
+ "WHERE AD_Column_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
||||
pstmt.setInt(1, getAD_Column_ID());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
m_tableName = rs.getString(1);
|
||||
m_columnName = rs.getString(2);
|
||||
if (rs.getInt(3) != getAD_Table_ID())
|
||||
log.log(Level.SEVERE, "AD_Table_ID inconsistent - Access=" + getAD_Table_ID() + " - Table=" + rs.getInt(3));
|
||||
}
|
||||
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;
|
||||
}
|
||||
// Get Clear Text
|
||||
String realName = Msg.translate(ctx, m_tableName + "_ID");
|
||||
if (!realName.equals(m_tableName + "_ID"))
|
||||
m_tableName = realName;
|
||||
m_columnName = Msg.translate(ctx, m_columnName);
|
||||
}
|
||||
return m_columnName;
|
||||
} // getColumnName
|
||||
|
||||
} // MColumnAccess
|
|
@ -0,0 +1,345 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Currency Conversion Rate Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MConversionRate.java,v 1.2 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public class MConversionRate extends X_C_Conversion_Rate
|
||||
{
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MConversionRate.class);
|
||||
|
||||
|
||||
/**
|
||||
* Convert an amount to base Currency
|
||||
* @param ctx context
|
||||
* @param CurFrom_ID The C_Currency_ID FROM
|
||||
* @param ConvDate conversion date - if null - use current date
|
||||
* @param C_ConversionType_ID conversion rate type - if 0 - use Default
|
||||
* @param Amt amount to be converted
|
||||
* @param AD_Client_ID client
|
||||
* @param AD_Org_ID organization
|
||||
* @return converted amount
|
||||
*/
|
||||
public static BigDecimal convertBase (Properties ctx,
|
||||
BigDecimal Amt, int CurFrom_ID,
|
||||
Timestamp ConvDate, int C_ConversionType_ID,
|
||||
int AD_Client_ID, int AD_Org_ID)
|
||||
{
|
||||
return convert (ctx, Amt, CurFrom_ID, MClient.get(ctx).getC_Currency_ID(),
|
||||
ConvDate, C_ConversionType_ID, AD_Client_ID, AD_Org_ID);
|
||||
} // convertBase
|
||||
|
||||
|
||||
/**
|
||||
* Convert an amount with today's default rate
|
||||
* @param ctx context
|
||||
* @param CurFrom_ID The C_Currency_ID FROM
|
||||
* @param CurTo_ID The C_Currency_ID TO
|
||||
* @param Amt amount to be converted
|
||||
* @param AD_Client_ID client
|
||||
* @param AD_Org_ID organization
|
||||
* @return converted amount
|
||||
*/
|
||||
public static BigDecimal convert (Properties ctx,
|
||||
BigDecimal Amt, int CurFrom_ID, int CurTo_ID,
|
||||
int AD_Client_ID, int AD_Org_ID)
|
||||
{
|
||||
return convert (ctx, Amt, CurFrom_ID, CurTo_ID, null, 0, AD_Client_ID, AD_Org_ID);
|
||||
} // convert
|
||||
|
||||
/**
|
||||
* Convert an amount
|
||||
* @param ctx context
|
||||
* @param CurFrom_ID The C_Currency_ID FROM
|
||||
* @param CurTo_ID The C_Currency_ID TO
|
||||
* @param ConvDate conversion date - if null - use current date
|
||||
* @param C_ConversionType_ID conversion rate type - if 0 - use Default
|
||||
* @param Amt amount to be converted
|
||||
* @param AD_Client_ID client
|
||||
* @param AD_Org_ID organization
|
||||
* @return converted amount or null if no rate
|
||||
*/
|
||||
public static BigDecimal convert (Properties ctx,
|
||||
BigDecimal Amt, int CurFrom_ID, int CurTo_ID,
|
||||
Timestamp ConvDate, int C_ConversionType_ID,
|
||||
int AD_Client_ID, int AD_Org_ID)
|
||||
{
|
||||
if (Amt == null)
|
||||
throw new IllegalArgumentException("Required parameter missing - Amt");
|
||||
if (CurFrom_ID == CurTo_ID || Amt.equals(Env.ZERO))
|
||||
return Amt;
|
||||
// Get Rate
|
||||
BigDecimal retValue = getRate (CurFrom_ID, CurTo_ID,
|
||||
ConvDate, C_ConversionType_ID,
|
||||
AD_Client_ID, AD_Org_ID);
|
||||
if (retValue == null)
|
||||
return null;
|
||||
|
||||
// Get Amount in Currency Precision
|
||||
retValue = retValue.multiply(Amt);
|
||||
int stdPrecision = MCurrency.getStdPrecision(ctx, CurTo_ID);
|
||||
if (retValue.scale() > stdPrecision)
|
||||
retValue = retValue.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
return retValue;
|
||||
} // convert
|
||||
|
||||
/**
|
||||
* Get Currency Conversion Rate
|
||||
* @param CurFrom_ID The C_Currency_ID FROM
|
||||
* @param CurTo_ID The C_Currency_ID TO
|
||||
* @param ConvDate The Conversion date - if null - use current date
|
||||
* @param ConversionType_ID Conversion rate type - if 0 - use Default
|
||||
* @param AD_Client_ID client
|
||||
* @param AD_Org_ID organization
|
||||
* @return currency Rate or null
|
||||
*/
|
||||
public static BigDecimal getRate (int CurFrom_ID, int CurTo_ID,
|
||||
Timestamp ConvDate, int ConversionType_ID, int AD_Client_ID, int AD_Org_ID)
|
||||
{
|
||||
if (CurFrom_ID == CurTo_ID)
|
||||
return Env.ONE;
|
||||
// Conversion Type
|
||||
int C_ConversionType_ID = ConversionType_ID;
|
||||
if (C_ConversionType_ID == 0)
|
||||
C_ConversionType_ID = MConversionType.getDefault(AD_Client_ID);
|
||||
// Conversion Date
|
||||
if (ConvDate == null)
|
||||
ConvDate = new Timestamp (System.currentTimeMillis());
|
||||
|
||||
// Get Rate
|
||||
String sql = "SELECT MultiplyRate "
|
||||
+ "FROM C_Conversion_Rate "
|
||||
+ "WHERE C_Currency_ID=?" // #1
|
||||
+ " AND C_Currency_ID_To=?" // #2
|
||||
+ " AND C_ConversionType_ID=?" // #3
|
||||
+ " AND ? BETWEEN ValidFrom AND ValidTo" // #4 TRUNC (?) ORA-00932: inconsistent datatypes: expected NUMBER got TIMESTAMP
|
||||
+ " AND AD_Client_ID IN (0,?)" // #5
|
||||
+ " AND AD_Org_ID IN (0,?) " // #6
|
||||
+ "ORDER BY AD_Client_ID DESC, AD_Org_ID DESC, ValidFrom DESC";
|
||||
BigDecimal retValue = null;
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, CurFrom_ID);
|
||||
pstmt.setInt(2, CurTo_ID);
|
||||
pstmt.setInt(3, C_ConversionType_ID);
|
||||
pstmt.setTimestamp(4, ConvDate);
|
||||
pstmt.setInt(5, AD_Client_ID);
|
||||
pstmt.setInt(6, AD_Org_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
retValue = rs.getBigDecimal(1);
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, "getRate", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
if (retValue == null)
|
||||
s_log.info ("getRate - not found - CurFrom=" + CurFrom_ID
|
||||
+ ", CurTo=" + CurTo_ID
|
||||
+ ", " + ConvDate
|
||||
+ ", Type=" + ConversionType_ID + (ConversionType_ID==C_ConversionType_ID ? "" : "->" + C_ConversionType_ID)
|
||||
+ ", Client=" + AD_Client_ID
|
||||
+ ", Org=" + AD_Org_ID);
|
||||
return retValue;
|
||||
} // getRate
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_Conversion_Rate_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MConversionRate (Properties ctx, int C_Conversion_Rate_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_Conversion_Rate_ID, trxName);
|
||||
if (C_Conversion_Rate_ID == 0)
|
||||
{
|
||||
// setC_Conversion_Rate_ID (0);
|
||||
// setC_Currency_ID (0);
|
||||
// setC_Currency_ID_To (null);
|
||||
super.setDivideRate (Env.ZERO);
|
||||
super.setMultiplyRate (Env.ZERO);
|
||||
setValidFrom (new Timestamp(System.currentTimeMillis()));
|
||||
}
|
||||
} // MConversionRate
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MConversionRate (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MConversionRate
|
||||
|
||||
/**
|
||||
* New Constructor
|
||||
* @param po parent
|
||||
* @param C_ConversionType_ID conversion type
|
||||
* @param C_Currency_ID currency
|
||||
* @param C_Currency_ID_To currency to
|
||||
* @param MultiplyRate multiply rate
|
||||
* @param ValidFrom valid from
|
||||
*/
|
||||
public MConversionRate (PO po,
|
||||
int C_ConversionType_ID,
|
||||
int C_Currency_ID, int C_Currency_ID_To,
|
||||
BigDecimal MultiplyRate, Timestamp ValidFrom)
|
||||
{
|
||||
this (po.getCtx(), 0, po.get_TrxName());
|
||||
setClientOrg(po);
|
||||
setC_ConversionType_ID (C_ConversionType_ID);
|
||||
setC_Currency_ID (C_Currency_ID);
|
||||
setC_Currency_ID_To (C_Currency_ID_To);
|
||||
//
|
||||
setMultiplyRate (MultiplyRate);
|
||||
setValidFrom(ValidFrom);
|
||||
} // MConversionRate
|
||||
|
||||
/**
|
||||
* Set Multiply Rate
|
||||
* Sets also Divide Rate
|
||||
* @param MultiplyRate multiply rate
|
||||
*/
|
||||
public void setMultiplyRate (BigDecimal MultiplyRate)
|
||||
{
|
||||
if (MultiplyRate == null
|
||||
|| MultiplyRate.compareTo(Env.ZERO) == 0
|
||||
|| MultiplyRate.compareTo(Env.ONE) == 0)
|
||||
{
|
||||
super.setDivideRate(Env.ONE);
|
||||
super.setMultiplyRate(Env.ONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
super.setMultiplyRate(MultiplyRate);
|
||||
double dd = 1 / MultiplyRate.doubleValue();
|
||||
super.setDivideRate(new BigDecimal(dd));
|
||||
}
|
||||
} // setMultiplyRate
|
||||
|
||||
/**
|
||||
* Set Divide Rate.
|
||||
* Sets also Multiply Rate
|
||||
* @param DivideRate divide rate
|
||||
*/
|
||||
public void setDivideRate (BigDecimal DivideRate)
|
||||
{
|
||||
if (DivideRate == null
|
||||
|| DivideRate.compareTo(Env.ZERO) == 0
|
||||
|| DivideRate.compareTo(Env.ONE) == 0)
|
||||
{
|
||||
super.setDivideRate(Env.ONE);
|
||||
super.setMultiplyRate(Env.ONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
super.setDivideRate(DivideRate);
|
||||
double dd = 1 / DivideRate.doubleValue();
|
||||
super.setMultiplyRate(new BigDecimal(dd));
|
||||
}
|
||||
} // setDivideRate
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MConversionRate[");
|
||||
sb.append(get_ID())
|
||||
.append(",Currency=").append(getC_Currency_ID())
|
||||
.append(",To=").append(getC_Currency_ID_To())
|
||||
.append(", Multiply=").append(getMultiplyRate())
|
||||
.append(",Divide=").append(getDivideRate())
|
||||
.append(", ValidFrom=").append(getValidFrom());
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
|
||||
/**
|
||||
* Before Save.
|
||||
* - Same Currency
|
||||
* - Date Range Check
|
||||
* - Set To date to 2056
|
||||
* @param newRecord new
|
||||
* @return true if OK to save
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
// From - To is the same
|
||||
if (getC_Currency_ID() == getC_Currency_ID_To())
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@C_Currency_ID@ = @C_Currency_ID@"));
|
||||
return false;
|
||||
}
|
||||
// Nothing to convert
|
||||
if (getMultiplyRate().compareTo(Env.ZERO) <= 0)
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@MultiplyRate@ <= 0"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Date Range Check
|
||||
Timestamp from = getValidFrom();
|
||||
if (getValidTo() == null)
|
||||
setValidTo (TimeUtil.getDay(2056, 1, 29)); // no exchange rates after my 100th birthday
|
||||
Timestamp to = getValidTo();
|
||||
|
||||
if (to.before(from))
|
||||
{
|
||||
SimpleDateFormat df = DisplayType.getDateFormat(DisplayType.Date);
|
||||
log.saveError("Error", df.format(to) + " < " + df.format(from));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
} // MConversionRate
|
|
@ -0,0 +1,82 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Currency Conversion Type Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MConversionType.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class MConversionType extends X_C_ConversionType
|
||||
{
|
||||
/**
|
||||
* Get Default Conversion Rate for Client/Org
|
||||
* @param AD_Client_ID client
|
||||
* @return C_ConversionType_ID or 0 if not found
|
||||
*/
|
||||
public static int getDefault (int AD_Client_ID)
|
||||
{
|
||||
// Try Cache
|
||||
Integer key = new Integer (AD_Client_ID);
|
||||
Integer ii = (Integer)s_cache.get(key);
|
||||
if (ii != null)
|
||||
return ii.intValue();
|
||||
|
||||
// Get from DB
|
||||
int C_ConversionType_ID = 0;
|
||||
String sql = "SELECT C_ConversionType_ID "
|
||||
+ "FROM C_ConversionType "
|
||||
+ "WHERE IsActive='Y'"
|
||||
+ " AND AD_Client_ID IN (0,?) " // #1
|
||||
+ "ORDER BY IsDefault DESC, AD_Client_ID DESC";
|
||||
C_ConversionType_ID = DB.getSQLValue(null, sql, AD_Client_ID);
|
||||
// Return
|
||||
s_cache.put(key, new Integer(C_ConversionType_ID));
|
||||
return C_ConversionType_ID;
|
||||
} // getDefault
|
||||
|
||||
/** Cache Client-ID */
|
||||
private static CCache<Integer,Integer> s_cache = new CCache<Integer,Integer>("C_ConversionType", 4);
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_ConversionType_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MConversionType(Properties ctx, int C_ConversionType_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_ConversionType_ID, trxName);
|
||||
} // MConversionType
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MConversionType(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MConversionType
|
||||
|
||||
} // MConversionType
|
|
@ -0,0 +1,457 @@
|
|||
/******************************************************************************
|
||||
* 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.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 ();
|
||||
if (rs.next ())
|
||||
retValue = new MCostElement (po.getCtx(), rs, po.get_TrxName());
|
||||
if (rs.next())
|
||||
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
|
||||
if (COSTELEMENTTYPE_Material.equals(getCostElementType())
|
||||
&& (newRecord || is_ValueChanged("CostingMethod")))
|
||||
{
|
||||
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
|
|
@ -0,0 +1,95 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Cost Type Model
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MCostType.java,v 1.2 2006/07/30 00:58:38 jjanke Exp $
|
||||
*/
|
||||
public class MCostType extends X_M_CostType
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param M_CostType_ID id
|
||||
* @param trxName trx
|
||||
*/
|
||||
public MCostType (Properties ctx, int M_CostType_ID, String trxName)
|
||||
{
|
||||
super (ctx, M_CostType_ID, trxName);
|
||||
} // MCostType
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName trx
|
||||
*/
|
||||
public MCostType (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MCostType
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MCostType[");
|
||||
sb.append (get_ID()).append ("-").append (getName ()).append ("]");
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* Before Delete
|
||||
* @return true if it can be deleted
|
||||
*/
|
||||
protected boolean beforeDelete ()
|
||||
{
|
||||
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID());
|
||||
for (int i = 0; i < ass.length; i++)
|
||||
{
|
||||
if (ass[i].getM_CostType_ID() == getM_CostType_ID())
|
||||
{
|
||||
log.saveError("CannotDelete", Msg.getElement(getCtx(), "C_AcctSchema_ID")
|
||||
+ " - " + ass[i].getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // beforeDelete
|
||||
|
||||
} // MCostType
|
|
@ -0,0 +1,336 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Location Country Model (Value Object)
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MCountry.java,v 1.3 2006/07/30 00:58:18 jjanke Exp $
|
||||
*/
|
||||
public final class MCountry extends X_C_Country
|
||||
implements Comparator, Serializable
|
||||
{
|
||||
/**
|
||||
* Get Country (cached)
|
||||
* @param ctx context
|
||||
* @param C_Country_ID ID
|
||||
* @return Country
|
||||
*/
|
||||
public static MCountry get (Properties ctx, int C_Country_ID)
|
||||
{
|
||||
if (s_countries == null || s_countries.size() == 0)
|
||||
loadAllCountries(ctx);
|
||||
String key = String.valueOf(C_Country_ID);
|
||||
MCountry c = (MCountry)s_countries.get(key);
|
||||
if (c != null)
|
||||
return c;
|
||||
c = new MCountry (ctx, C_Country_ID, null);
|
||||
if (c.getC_Country_ID() == C_Country_ID)
|
||||
{
|
||||
s_countries.put(key, c);
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get Default Country
|
||||
* @param ctx context
|
||||
* @return Country
|
||||
*/
|
||||
public static MCountry getDefault (Properties ctx)
|
||||
{
|
||||
if (s_countries == null || s_countries.size() == 0)
|
||||
loadAllCountries(ctx);
|
||||
return s_default;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Return Countries as Array
|
||||
* @param ctx context
|
||||
* @return MCountry Array
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static MCountry[] getCountries(Properties ctx)
|
||||
{
|
||||
if (s_countries == null || s_countries.size() == 0)
|
||||
loadAllCountries(ctx);
|
||||
MCountry[] retValue = new MCountry[s_countries.size()];
|
||||
s_countries.values().toArray(retValue);
|
||||
Arrays.sort(retValue, new MCountry(ctx, 0, null));
|
||||
return retValue;
|
||||
} // getCountries
|
||||
|
||||
/**
|
||||
* Load Countries.
|
||||
* Set Default Language to Client Language
|
||||
* @param ctx context
|
||||
*/
|
||||
private static void loadAllCountries (Properties ctx)
|
||||
{
|
||||
MClient client = MClient.get (ctx);
|
||||
MLanguage lang = MLanguage.get(ctx, client.getAD_Language());
|
||||
MCountry usa = null;
|
||||
//
|
||||
s_countries = new CCache<String,MCountry>("C_Country", 250);
|
||||
String sql = "SELECT * FROM C_Country WHERE IsActive='Y'";
|
||||
try
|
||||
{
|
||||
Statement stmt = DB.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
while(rs.next())
|
||||
{
|
||||
MCountry c = new MCountry (ctx, rs, null);
|
||||
s_countries.put(String.valueOf(c.getC_Country_ID()), c);
|
||||
// Country code of Client Language
|
||||
if (lang != null && lang.getCountryCode().equals(c.getCountryCode()))
|
||||
s_default = c;
|
||||
if (c.getC_Country_ID() == 100) // USA
|
||||
usa = c;
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
if (s_default == null)
|
||||
s_default = usa;
|
||||
s_log.fine("#" + s_countries.size()
|
||||
+ " - Default=" + s_default);
|
||||
} // loadAllCountries
|
||||
|
||||
/**
|
||||
* Set the Language for Display (toString)
|
||||
* @param AD_Language language or null
|
||||
*/
|
||||
public static void setDisplayLanguage (String AD_Language)
|
||||
{
|
||||
s_AD_Language = AD_Language;
|
||||
if (Language.isBaseLanguage(AD_Language))
|
||||
s_AD_Language = null;
|
||||
} // setDisplayLanguage
|
||||
|
||||
/** Display Language */
|
||||
private static String s_AD_Language = null;
|
||||
|
||||
/** Country Cache */
|
||||
private static CCache<String,MCountry> s_countries = null;
|
||||
/** Default Country */
|
||||
private static MCountry s_default = null;
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MCountry.class);
|
||||
// Default DisplaySequence */
|
||||
private static String DISPLAYSEQUENCE = "@C@, @P@";
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Create empty Country
|
||||
* @param ctx context
|
||||
* @param C_Country_ID ID
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCountry (Properties ctx, int C_Country_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_Country_ID, trxName);
|
||||
if (C_Country_ID == 0)
|
||||
{
|
||||
// setName (null);
|
||||
// setCountryCode (null);
|
||||
setDisplaySequence(DISPLAYSEQUENCE);
|
||||
setHasRegion(false);
|
||||
setHasPostal_Add(false);
|
||||
setIsAddressLinesLocalReverse (false);
|
||||
setIsAddressLinesReverse (false);
|
||||
}
|
||||
} // MCountry
|
||||
|
||||
/**
|
||||
* Create Country from current row in ResultSet
|
||||
* @param ctx context
|
||||
* @param rs ResultSet
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCountry (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MCountry
|
||||
|
||||
/** Translated Name */
|
||||
private String m_trlName = null;
|
||||
|
||||
/**
|
||||
* Return Name - translated if DisplayLanguage is set.
|
||||
* @return Name
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
if (s_AD_Language != null)
|
||||
{
|
||||
String nn = getTrlName();
|
||||
if (nn != null)
|
||||
return nn;
|
||||
}
|
||||
return getName();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Get Translated Name
|
||||
* @return name
|
||||
*/
|
||||
public String getTrlName()
|
||||
{
|
||||
if (m_trlName != null && s_AD_Language != null)
|
||||
{
|
||||
m_trlName = get_Translation("Name", s_AD_Language);
|
||||
if (m_trlName == null)
|
||||
s_AD_Language = null; // assume that there is no translation
|
||||
}
|
||||
return m_trlName;
|
||||
} // getTrlName
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Display Sequence
|
||||
* @return display sequence
|
||||
*/
|
||||
public String getDisplaySequence ()
|
||||
{
|
||||
String ds = super.getDisplaySequence ();
|
||||
if (ds == null || ds.length() == 0)
|
||||
ds = DISPLAYSEQUENCE;
|
||||
return ds;
|
||||
} // getDisplaySequence
|
||||
|
||||
/**
|
||||
* Get Local Display Sequence.
|
||||
* If not defined get Display Sequence
|
||||
* @return local display sequence
|
||||
*/
|
||||
public String getDisplaySequenceLocal ()
|
||||
{
|
||||
String ds = super.getDisplaySequenceLocal();
|
||||
if (ds == null || ds.length() == 0)
|
||||
ds = getDisplaySequence();
|
||||
return ds;
|
||||
} // getDisplaySequenceLocal
|
||||
|
||||
/**
|
||||
* Compare based on Name
|
||||
* @param o1 object 1
|
||||
* @param o2 object 2
|
||||
* @return -1,0, 1
|
||||
*/
|
||||
public int compare(Object o1, Object o2)
|
||||
{
|
||||
String s1 = o1.toString();
|
||||
if (s1 == null)
|
||||
s1 = "";
|
||||
String s2 = o2.toString();
|
||||
if (s2 == null)
|
||||
s2 = "";
|
||||
return s1.compareTo(s2);
|
||||
} // compare
|
||||
|
||||
/**
|
||||
* Is the region valid in the country
|
||||
* @param C_Region_ID region
|
||||
* @return true if valid
|
||||
*/
|
||||
public boolean isValidRegion(int C_Region_ID)
|
||||
{
|
||||
if (C_Region_ID == 0
|
||||
|| getC_Country_ID() == 0
|
||||
|| !isHasRegion())
|
||||
return false;
|
||||
MRegion[] regions = MRegion.getRegions(getCtx(), getC_Country_ID());
|
||||
for (int i = 0; i < regions.length; i++)
|
||||
{
|
||||
if (C_Region_ID == regions[i].getC_Region_ID())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} // isValidRegion
|
||||
|
||||
/**************************************************************************
|
||||
* Insert Countries
|
||||
* @param args none
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
/** Migration before
|
||||
UPDATE C_Country SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID<>0 OR AD_Org_ID<>0;
|
||||
UPDATE C_Region SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID<>0 OR AD_Org_ID<>0;
|
||||
IDs migration for C_Location, C_City, C_Tax (C_Country, C_Region)
|
||||
**
|
||||
// from http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1-semic.txt
|
||||
String countries = "AFGHANISTAN;AF, ALBANIA;AL, ALGERIA;DZ, AMERICAN SAMOA;AS, ANDORRA;AD, ANGOLA;AO, ANGUILLA;AI, ANTARCTICA;AQ, ANTIGUA AND BARBUDA;AG, ARGENTINA;AR,"
|
||||
+ "ARMENIA;AM, ARUBA;AW, AUSTRALIA;AU, AUSTRIA;AT, AZERBAIJAN;AZ, BAHAMAS;BS, BAHRAIN;BH, BANGLADESH;BD, BARBADOS;BB, BELARUS;BY, BELGIUM;BE, BELIZE;BZ,"
|
||||
+ "BENIN;BJ, BERMUDA;BM, BHUTAN;BT, BOLIVIA;BO, BOSNIA AND HERZEGOVINA;BA, BOTSWANA;BW, BOUVET ISLAND;BV, BRAZIL;BR, BRITISH INDIAN OCEAN TERRITORY;IO, BRUNEI DARUSSALAM;BN,"
|
||||
+ "BULGARIA;BG, BURKINA FASO;BF, BURUNDI;BI, CAMBODIA;KH, CAMEROON;CM, CANADA;CA, CAPE VERDE;CV, CAYMAN ISLANDS;KY, CENTRAL AFRICAN REPUBLIC;CF, CHAD;TD, CHILE;CL,"
|
||||
+ "CHINA;CN, CHRISTMAS ISLAND;CX, COCOS (KEELING) ISLANDS;CC, COLOMBIA;CO, COMOROS;KM, CONGO;CG, CONGO THE DEMOCRATIC REPUBLIC OF THE;CD, COOK ISLANDS;CK,"
|
||||
+ "COSTA RICA;CR, COTE D'IVOIRE;CI, CROATIA;HR, CUBA;CU, CYPRUS;CY, CZECH REPUBLIC;CZ, DENMARK;DK, DJIBOUTI;DJ, DOMINICA;DM, DOMINICAN REPUBLIC;DO, ECUADOR;EC,"
|
||||
+ "EGYPT;EG, EL SALVADOR;SV, EQUATORIAL GUINEA;GQ, ERITREA;ER, ESTONIA;EE, ETHIOPIA;ET, FALKLAND ISLANDS (MALVINAS);FK, FAROE ISLANDS;FO, FIJI;FJ,"
|
||||
+ "FINLAND;FI, FRANCE;FR, FRENCH GUIANA;GF, FRENCH POLYNESIA;PF, FRENCH SOUTHERN TERRITORIES;TF, GABON;GA, GAMBIA;GM, GEORGIA;GE, GERMANY;DE, GHANA;GH,"
|
||||
+ "GIBRALTAR;GI, GREECE;GR, GREENLAND;GL, GRENADA;GD, GUADELOUPE;GP, GUAM;GU, GUATEMALA;GT, GUINEA;GN, GUINEA-BISSAU;GW, GUYANA;GY, HAITI;HT,"
|
||||
+ "HEARD ISLAND AND MCDONALD ISLANDS;HM, HOLY SEE (VATICAN CITY STATE);VA, HONDURAS;HN, HONG KONG;HK, HUNGARY;HU, ICELAND;IS, INDIA;IN, INDONESIA;ID,"
|
||||
+ "IRAN ISLAMIC REPUBLIC OF;IR, IRAQ;IQ, IRELAND;IE, ISRAEL;IL, ITALY;IT, JAMAICA;JM, JAPAN;JP, JORDAN;JO, KAZAKHSTAN;KZ, KENYA;KE, KIRIBATI;KI, KOREA DEMOCRATIC PEOPLE'S REPUBLIC OF;KP,"
|
||||
+ "KOREA REPUBLIC OF;KR, KUWAIT;KW, KYRGYZSTAN;KG, LAO PEOPLE'S DEMOCRATIC REPUBLIC;LA, LATVIA;LV, LEBANON;LB, LESOTHO;LS, LIBERIA;LR, LIBYAN ARAB JAMAHIRIYA;LY,"
|
||||
+ "LIECHTENSTEIN;LI, LITHUANIA;LT, LUXEMBOURG;LU, MACAO;MO, MACEDONIA FORMER YUGOSLAV REPUBLIC OF;MK, MADAGASCAR;MG, MALAWI;MW, MALAYSIA;MY, MALDIVES;MV, "
|
||||
+ "MALI;ML, MALTA;MT, MARSHALL ISLANDS;MH, MARTINIQUE;MQ, MAURITANIA;MR, MAURITIUS;MU, MAYOTTE;YT, MEXICO;MX, MICRONESIA FEDERATED STATES OF;FM,"
|
||||
+ "MOLDOVA REPUBLIC OF;MD, MONACO;MC, MONGOLIA;MN, MONTSERRAT;MS, MOROCCO;MA, MOZAMBIQUE;MZ, MYANMAR;MM, NAMIBIA;NA, NAURU;NR, NEPAL;NP,"
|
||||
+ "NETHERLANDS;NL, NETHERLANDS ANTILLES;AN, NEW CALEDONIA;NC, NEW ZEALAND;NZ, NICARAGUA;NI, NIGER;NE, NIGERIA;NG, NIUE;NU, NORFOLK ISLAND;NF,"
|
||||
+ "NORTHERN MARIANA ISLANDS;MP, NORWAY;NO, OMAN;OM, PAKISTAN;PK, PALAU;PW, PALESTINIAN TERRITORY OCCUPIED;PS, PANAMA;PA, PAPUA NEW GUINEA;PG,"
|
||||
+ "PARAGUAY;PY, PERU;PE, PHILIPPINES;PH, PITCAIRN;PN, POLAND;PL, PORTUGAL;PT, PUERTO RICO;PR, QATAR;QA, REUNION;RE, ROMANIA;RO, RUSSIAN FEDERATION;RU,"
|
||||
+ "RWANDA;RW, SAINT HELENA;SH, SAINT KITTS AND NEVIS;KN, SAINT LUCIA;LC, SAINT PIERRE AND MIQUELON;PM, SAINT VINCENT AND THE GRENADINES;VC,"
|
||||
+ "SAMOA;WS, SAN MARINO;SM, SAO TOME AND PRINCIPE;ST, SAUDI ARABIA;SA, SENEGAL;SN, SEYCHELLES;SC, SIERRA LEONE;SL, SINGAPORE;SG, SLOVAKIA;SK,"
|
||||
+ "SLOVENIA;SI, SOLOMON ISLANDS;SB, SOMALIA;SO, SOUTH AFRICA;ZA, SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS;GS, SPAIN;ES, SRI LANKA;LK,"
|
||||
+ "SUDAN;SD, SURINAME;SR, SVALBARD AND JAN MAYEN;SJ, SWAZILAND;SZ, SWEDEN;SE, SWITZERLAND;CH, SYRIAN ARAB REPUBLIC;SY, TAIWAN;TW,"
|
||||
+ "TAJIKISTAN;TJ, TANZANIA UNITED REPUBLIC OF;TZ, THAILAND;TH, TIMOR-LESTE;TL, TOGO;TG, TOKELAU;TK, TONGA;TO, TRINIDAD AND TOBAGO;TT,"
|
||||
+ "TUNISIA;TN, TURKEY;TR, TURKMENISTAN;TM, TURKS AND CAICOS ISLANDS;TC, TUVALU;TV, UGANDA;UG, UKRAINE;UA, UNITED ARAB EMIRATES;AE, UNITED KINGDOM;GB,"
|
||||
+ "UNITED STATES;US, UNITED STATES MINOR OUTLYING ISLANDS;UM, URUGUAY;UY, UZBEKISTAN;UZ, VANUATU;VU, VENEZUELA;VE, VIET NAM;VN, VIRGIN ISLANDS BRITISH;VG,"
|
||||
+ "VIRGIN ISLANDS U.S.;VI, WALLIS AND FUTUNA;WF, WESTERN SAHARA;EH, YEMEN;YE, YUGOSLAVIA;YU, ZAMBIA;ZM, ZIMBABWE;ZW";
|
||||
//
|
||||
org.compiere.Adempiere.startupClient();
|
||||
StringTokenizer st = new StringTokenizer(countries, ",", false);
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String s = st.nextToken().trim();
|
||||
int pos = s.indexOf(";");
|
||||
String name = Util.initCap(s.substring(0,pos));
|
||||
String cc = s.substring(pos+1);
|
||||
System.out.println(cc + " - " + name);
|
||||
//
|
||||
MCountry mc = new MCountry(Env.getCtx(), 0);
|
||||
mc.setCountryCode(cc);
|
||||
mc.setName(name);
|
||||
mc.setDescription(name);
|
||||
mc.save();
|
||||
}
|
||||
**/
|
||||
} // main
|
||||
|
||||
} // MCountry
|
|
@ -0,0 +1,415 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Currency Model.
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MCurrency.java,v 1.3 2006/07/30 00:54:54 jjanke Exp $
|
||||
*/
|
||||
public class MCurrency extends X_C_Currency
|
||||
{
|
||||
/**
|
||||
* Currency Constructor
|
||||
* @param ctx context
|
||||
* @param C_Currency_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCurrency (Properties ctx, int C_Currency_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_Currency_ID, trxName);
|
||||
if (C_Currency_ID == 0)
|
||||
{
|
||||
setIsEMUMember (false);
|
||||
setIsEuro (false);
|
||||
setStdPrecision (2);
|
||||
setCostingPrecision (4);
|
||||
}
|
||||
} // MCurrency
|
||||
|
||||
/**
|
||||
* Currency Constructor
|
||||
* @param ctx context
|
||||
* @param ISO_Code ISO
|
||||
* @param Description Name
|
||||
* @param CurSymbol symbol
|
||||
* @param StdPrecision prec
|
||||
* @param CostingPrecision prec
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCurrency (Properties ctx, String ISO_Code,
|
||||
String Description, String CurSymbol, int StdPrecision, int CostingPrecision, String trxName)
|
||||
{
|
||||
super(ctx, 0, trxName);
|
||||
setISO_Code(ISO_Code);
|
||||
setDescription(Description);
|
||||
setCurSymbol(CurSymbol);
|
||||
setStdPrecision (StdPrecision);
|
||||
setCostingPrecision (CostingPrecision);
|
||||
setIsEMUMember (false);
|
||||
setIsEuro (false);
|
||||
} // MCurrency
|
||||
|
||||
|
||||
/** Store System Currencies **/
|
||||
private static CCache<Integer,MCurrency> s_currencies = new CCache<Integer,MCurrency>("C_Currency", 50);
|
||||
|
||||
/**
|
||||
* Get Currency
|
||||
* @param ctx Context
|
||||
* @param C_Currency_ID currency
|
||||
* @return ISO Code
|
||||
*/
|
||||
public static MCurrency get (Properties ctx, int C_Currency_ID)
|
||||
{
|
||||
// Try Cache
|
||||
Integer key = new Integer(C_Currency_ID);
|
||||
MCurrency retValue = (MCurrency)s_currencies.get(key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
|
||||
// Create it
|
||||
retValue = new MCurrency(ctx, C_Currency_ID, null);
|
||||
// Save in System
|
||||
if (retValue.getAD_Client_ID() == 0)
|
||||
s_currencies.put(key, retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get Currency Iso Code.
|
||||
* @param ctx Context
|
||||
* @param C_Currency_ID currency
|
||||
* @return ISO Code
|
||||
*/
|
||||
public static String getISO_Code (Properties ctx, int C_Currency_ID)
|
||||
{
|
||||
String contextKey = "C_Currency_" + C_Currency_ID;
|
||||
String retValue = ctx.getProperty(contextKey);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
|
||||
// Create it
|
||||
MCurrency c = get(ctx, C_Currency_ID);
|
||||
retValue = c.getISO_Code();
|
||||
ctx.setProperty(contextKey, retValue);
|
||||
return retValue;
|
||||
} // getISO
|
||||
|
||||
/**
|
||||
* Get Standard Precision.
|
||||
* @param ctx Context
|
||||
* @param C_Currency_ID currency
|
||||
* @return Standard Precision
|
||||
*/
|
||||
public static int getStdPrecision (Properties ctx, int C_Currency_ID)
|
||||
{
|
||||
MCurrency c = get(ctx, C_Currency_ID);
|
||||
return c.getStdPrecision();
|
||||
} // getStdPrecision
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "MCurrency[" + getC_Currency_ID()
|
||||
+ "-" + getISO_Code() + "-" + getCurSymbol()
|
||||
+ "," + getDescription()
|
||||
+ ",Precision=" + getStdPrecision() + "/" + getCostingPrecision();
|
||||
} // toString
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Load/link Currencies
|
||||
* @param args args
|
||||
*
|
||||
public static void main (String[] args)
|
||||
{
|
||||
System.out.println("Currency");
|
||||
Adempiere.startupClient();
|
||||
// Loop through
|
||||
for (int i = 0; i < s_table.length; i++)
|
||||
{
|
||||
/**
|
||||
System.out.println(s_table[i][I_Currency] + " - " + s_table[i][I_Name]);
|
||||
int prec = Integer.parseInt(s_table[i][I_Precision]);
|
||||
MCurrency cur = new MCurrency(Env.getCtx(), s_table[i][I_Currency],
|
||||
s_table[i][I_Name], s_table[i][I_Symbol], prec, prec+2);
|
||||
cur.save();
|
||||
System.out.println(cur);
|
||||
**
|
||||
String ISO = s_table[i][I_Currency];
|
||||
String Country = s_table[i][I_Country];
|
||||
String sql = "UPDATE C_Country SET C_Currency_ID="
|
||||
+ "(SELECT C_Currency_ID FROM C_Currency WHERE ISO_Code='" + ISO + "') "
|
||||
+ "WHERE CountryCode='" + Country + "'";
|
||||
int no = DB.executeUpdate(sql);
|
||||
System.out.println(ISO + " - " + Country + " - " + no);
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
} // main
|
||||
|
||||
|
||||
static int I_Country = 0;
|
||||
static int I_Currency = 1;
|
||||
static int I_Precision = 2;
|
||||
static int I_Symbol = 3;
|
||||
static int I_DecimalPoint = 4;
|
||||
static int I_FormatIndex = 5;
|
||||
static int I_Name = 6;
|
||||
static String[][] s_table = new String[][] {
|
||||
new String[]{"US","USD","2","$",".","0", "US Dollar"},
|
||||
new String[]{"AR","ARS","2","$",",","0", "Argentine Peso"},
|
||||
new String[]{"AS","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"CC","AUD","2","$",".","0","Australian Dollar"},
|
||||
new String[]{"CK","NZD","2","$",".","0","New Zealand Dollar"},
|
||||
new String[]{"CX","AUD","2","$",".","0","Australian Dollar"},
|
||||
new String[]{"EC","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"FM","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"GU","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"KI","AUD","2","$",".","0","Australian Dollar"},
|
||||
new String[]{"LR","LRD","2","$",".","0","Liberian Dollar"},
|
||||
new String[]{"MH","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"MP","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"MX","MXN","2","$",".","0","Mexican Peso"},
|
||||
new String[]{"NF","AUD","2","$",".","0","Australian Dollar"},
|
||||
new String[]{"NR","AUD","2","$",".","0","Australian Dollar"},
|
||||
new String[]{"NU","NZD","2","$",".","0","New Zealand Dollar"},
|
||||
new String[]{"NZ","NZD","2","$",".","0","New Zealand Dollar"},
|
||||
new String[]{"PR","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"PW","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"TC","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"TK","NZD","2","$",".","0","New Zealand Dollar"},
|
||||
new String[]{"TV","AUD","2","$",".","0","Australian Dollar"},
|
||||
new String[]{"VG","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"VI","USD","2","$",".","0","US Dollar"},
|
||||
new String[]{"UY","UYU","2","$U",",","2","Peso Uruguayo"},
|
||||
new String[]{"AM","AMD","2","",".","0","Armenian Dram"},
|
||||
new String[]{"AO","AOA","2","",".","0","Kwanza"},
|
||||
new String[]{"AZ","AZM","2","",".","0","Azerbaijanian Manat"},
|
||||
new String[]{"BO","BOB","2","",".","0","Boliviano"},
|
||||
new String[]{"CD","CDF","2","",".","0","Franc Congolais"},
|
||||
new String[]{"CZ","CZK","2","",",","3","Czech Koruna"},
|
||||
new String[]{"GE","GEL","2","",".","0","Lari"},
|
||||
new String[]{"IR","IRR","2","",".","2","Iranian Rial"},
|
||||
new String[]{"LT","LTL","2","",",","3","Lithuanian Litus"},
|
||||
new String[]{"MD","MDL","2","",".","0","Moldovan Leu"},
|
||||
new String[]{"PH","PHP","2","",".","0","Philippine Peso"},
|
||||
new String[]{"PL","PLN","2","",",","3","Zloty"},
|
||||
new String[]{"RU","RUR","2","",",","1","Russian Ruble"},
|
||||
new String[]{"SD","SDD","2","",".","0","Sudanese Dinar"},
|
||||
new String[]{"TJ","TJS","2","",".","0","Somoni"},
|
||||
new String[]{"TM","TMM","2","",".","0","Manat"},
|
||||
new String[]{"TP","TPE","0","",".","0","Timor Escudo"},
|
||||
new String[]{"UA","UAH","2","",",","3","Hryvnia"},
|
||||
new String[]{"UZ","UZS","2","",".","0","Uzbekistan Sum"},
|
||||
new String[]{"GB","GBP","2","<EFBFBD>",".","0","Pound Sterling"},
|
||||
new String[]{"CY","CYP","2","<EFBFBD>C",".","0","Cyprus Pound"},
|
||||
new String[]{"EG","EGP","2","<EFBFBD>E",".","2","Egyptian Pound"},
|
||||
new String[]{"FK","FKP","2","<EFBFBD>F",".","0","Falkland Islands Pound"},
|
||||
new String[]{"GI","GIP","2","<EFBFBD>G",".","0","Gibraltar Pound"},
|
||||
new String[]{"SH","SHP","2","<EFBFBD>S",".","0","Saint Helena Pound"},
|
||||
new String[]{"SY","SYP","2","<EFBFBD>S",".","2","Syrian Pound"},
|
||||
new String[]{"JP","JPY","0","<EFBFBD>",".","0","Yen"},
|
||||
new String[]{"GH","GHC","2","<EFBFBD>",".","0","Cedi"},
|
||||
new String[]{"SV","SVC","2","<EFBFBD>",".","0","El Salvador Colon"},
|
||||
new String[]{"AD","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"AT","EUR","2","<EFBFBD>",",","2","euro"},
|
||||
new String[]{"BE","EUR","2","<EFBFBD>",",","3","euro"},
|
||||
new String[]{"DE","EUR","2","<EFBFBD>",",","3","euro"},
|
||||
new String[]{"ES","EUR","2","<EFBFBD>",",","3","euro"},
|
||||
new String[]{"FI","EUR","2","<EFBFBD>",",","3","euro"},
|
||||
new String[]{"FR","EUR","2","<EFBFBD>",",","3","euro"},
|
||||
new String[]{"GF","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"GP","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"GR","EUR","2","<EFBFBD>",",","3","euro"},
|
||||
new String[]{"IE","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"IT","EUR","2","<EFBFBD>",",","2","euro"},
|
||||
new String[]{"LU","EUR","2","<EFBFBD>",",","3","euro"},
|
||||
new String[]{"MC","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"MQ","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"NL","EUR","2","<EFBFBD>",",","2","euro"},
|
||||
new String[]{"PM","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"PT","EUR","2","<EFBFBD>","$","3","euro"},
|
||||
new String[]{"RE","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"SM","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"VA","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"YT","EUR","2","<EFBFBD>",".","0","euro"},
|
||||
new String[]{"AU","AUD","2","A$",".","0","Australian Dollar"},
|
||||
new String[]{"AF","AFA","2","Af",".","0","Afghani"},
|
||||
new String[]{"AW","AWG","2","Af.",".","0","Aruban Guilder"},
|
||||
new String[]{"PA","PAB","2","B",".","0","Balboa"},
|
||||
new String[]{"BN","BND","2","B$",".","0","Brunei Dollar"},
|
||||
new String[]{"BS","BSD","2","B$",".","0","Bahamian Dollar"},
|
||||
new String[]{"BH","BHD","3","BD",".","2","Bahraini Dinar"},
|
||||
new String[]{"BM","BMD","2","Bd$",".","0","Bermudian Dollar"},
|
||||
new String[]{"BB","BBD","2","Bds$",".","0","Barbados Dollar"},
|
||||
new String[]{"BY","BYR","0","BR",",","3","Belarussian Ruble"},
|
||||
new String[]{"ET","ETB","2","Br",".","0","Ethiopian Birr"},
|
||||
new String[]{"VE","VEB","2","Bs",",","0","Bolivar"},
|
||||
new String[]{"TH","THB","2","Bt",".","0","Baht"},
|
||||
new String[]{"BZ","BZD","2","BZ$",".","0","Belize Dollar"},
|
||||
new String[]{"CA","CAD","2","C$",".","0","Canadian Dollar"},
|
||||
new String[]{"NI","NIO","2","C$",".","0","Cordoba Oro"},
|
||||
new String[]{"CV","CVE","2","C.V.Esc.",".","0","Cape Verde Escudo"},
|
||||
new String[]{"KM","KMF","0","CF",".","0","Comoro Franc"},
|
||||
new String[]{"BF","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
|
||||
new String[]{"BJ","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
|
||||
new String[]{"CF","XAF","0","CFAF",".","0","CFA Franc BEAC"},
|
||||
new String[]{"CG","XAF","0","CFAF",".","0","CFA Franc BEAC"},
|
||||
new String[]{"CI","XOF","0","CFAF",".","0","CFA Franc BCEA"},
|
||||
new String[]{"CM","XAF","0","CFAF",".","0","CFA Franc BEAC"},
|
||||
new String[]{"GA","XAF","0","CFAF",".","0","CFA Franc BEAC"},
|
||||
new String[]{"GQ","XAF","0","CFAF",".","0","CFA Franc BEAC"},
|
||||
new String[]{"ML","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
|
||||
new String[]{"NE","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
|
||||
new String[]{"SN","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
|
||||
new String[]{"TD","XAF","0","CFAF",".","0","CFA Franc BEAC"},
|
||||
new String[]{"TG","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
|
||||
new String[]{"NC","XPF","0","CFPF",".","0","CFP Franc"},
|
||||
new String[]{"PF","XPF","0","CFPF",".","0","CFP Franc"},
|
||||
new String[]{"WF","XPF","0","CFPF",".","0","CFP Franc"},
|
||||
new String[]{"CL","CLP","0","Ch$",",","0","Chilean Peso"},
|
||||
new String[]{"KY","KYD","2","CI$",".","0","Cayman Islands Dollar"},
|
||||
new String[]{"CO","COP","2","Col$",".","0","Colombian Peso"},
|
||||
new String[]{"KH","KHR","2","CR",".","0","Riel"},
|
||||
new String[]{"CU","CUP","2","Cu$",".","0","Cuban Peso"},
|
||||
new String[]{"GM","GMD","2","D",".","0","Dalasi"},
|
||||
new String[]{"VN","VND","2","D",",","3","Dong"},
|
||||
new String[]{"DZ","DZD","2","DA",".","2","Algerian Dinar"},
|
||||
new String[]{"ST","STD","2","Db",".","0","Dobra"},
|
||||
new String[]{"DJ","DJF","0","DF",".","0","Djibouti Franc"},
|
||||
new String[]{"AE","AED","2","Dh",".","2","UAE Dirham"},
|
||||
new String[]{"MA","MAD","2","DH",".","2","Moroccan Dirham"},
|
||||
new String[]{"YU","YUM","2","Din",".","0","Yugoslavian Dinar"},
|
||||
new String[]{"DK","DKK","2","Dkr",",","2","Danish Krone"},
|
||||
new String[]{"FO","DKK","2","Dkr",",","2","Danish Krone"},
|
||||
new String[]{"GL","DKK","2","Dkr",".","0","Danish Krone"},
|
||||
new String[]{"AG","XCD","2","EC$",".","0","East Caribbean Dollar"},
|
||||
new String[]{"AI","XCD","2","EC$",".","0","East Caribbean Dollar"},
|
||||
new String[]{"DM","XCD","2","EC$",".","0","East Caribbean Dollar"},
|
||||
new String[]{"GD","XCD","2","EC$",".","0","East Caribbean Dollar"},
|
||||
new String[]{"KN","XCD","2","EC$",".","0","East Caribbean Dollar"},
|
||||
new String[]{"LC","XCD","2","EC$",".","0","East Caribbean Dollar"},
|
||||
new String[]{"MS","XCD","2","EC$",".","0","East Caribbean Dollar"},
|
||||
new String[]{"VC","XCD","2","EC$",".","0","East Caribbean Dollar"},
|
||||
new String[]{"FJ","FJD","2","F$",".","0","Fiji Dollar"},
|
||||
new String[]{"BI","BIF","0","FBu",".","0","Burundi Franc"},
|
||||
new String[]{"MG","MGF","0","FMG",".","0","Malagasy Franc"},
|
||||
new String[]{"HU","HUF","2","Ft",",","3","Forint"},
|
||||
new String[]{"HT","HTG","2","G",".","0","Gourde"},
|
||||
new String[]{"GY","GYD","2","G$",".","0","Guyana Dollar"},
|
||||
new String[]{"HK","HKD","2","HK$",".","0","Hong Kong Dollar"},
|
||||
new String[]{"HR","HRK","2","HRK",",","2","Croatian Kuna"},
|
||||
new String[]{"IQ","IQD","3","ID",".","2","Iraqi Dinar"},
|
||||
new String[]{"IS","ISK","2","IKr",",","3","Iceland Krona"},
|
||||
new String[]{"JM","JMD","2","J$",".","0","Jamaican Dollar"},
|
||||
new String[]{"JO","JOD","3","JD",".","2","Jordanian Dinar"},
|
||||
new String[]{"MM","MMK","2","K",".","0","Kyat"},
|
||||
new String[]{"PG","PGK","2","K",".","0","Kina"},
|
||||
new String[]{"KE","KES","2","K Sh",".","0","Kenyan Shilling"},
|
||||
new String[]{"KW","KWD","3","KD",".","2","Kuwaiti Dinar"},
|
||||
new String[]{"BA","BAM","2","KM",".","0","Convertible Marks"},
|
||||
new String[]{"LA","LAK","2","KN",".","0","Kip"},
|
||||
new String[]{"ER","ERN","2","KR",".","0","Nakfa"},
|
||||
new String[]{"AL","ALL","2","L",",","1","Lek"},
|
||||
new String[]{"HN","HNL","2","L",".","0","Lempira"},
|
||||
new String[]{"RO","ROL","2","L",",","3","Leu"},
|
||||
new String[]{"SZ","SZL","2","L",".","0","Lilangeni"},
|
||||
new String[]{"LY","LYD","3","LD",".","2","Libyan Dinar"},
|
||||
new String[]{"SL","SLL","2","Le",".","0","Leone"},
|
||||
new String[]{"MT","MTL","2","Lm",".","0","Maltese Lira"},
|
||||
new String[]{"LV","LVL","2","Ls",",","3","Latvian Lats"},
|
||||
new String[]{"BG","BGL","2","Lv",",","3","Lev"},
|
||||
new String[]{"MU","MUR","2","Mau Rs",".","0","Mauritius Rupee"},
|
||||
new String[]{"MW","MWK","2","MK",".","0","Kwacha"},
|
||||
new String[]{"MK","MKD","2","MKD",".","0","Denar"},
|
||||
new String[]{"MZ","MZM","2","Mt",".","0","Metical"},
|
||||
new String[]{"AN","ANG","2","NAf.",".","0","Netherlands Antillian Guilder"},
|
||||
new String[]{"EE","EEK","2","Nfa",",","3","Kroon"},
|
||||
new String[]{"IL","ILS","2","NIS",".","2","New Israeli Sheqel"},
|
||||
new String[]{"NO","NOK","2","NKr",",","2","Norwegian Krone"},
|
||||
new String[]{"NP","NPR","2","NRs",".","0","Nepalese Rupee"},
|
||||
new String[]{"TW","TWD","2","NT$",".","0","New Taiwan Dollar"},
|
||||
new String[]{"BW","BWP","2","P",".","0","Pula"},
|
||||
new String[]{"MO","MOP","2","P",".","0","Pataca"},
|
||||
new String[]{"GT","GTQ","2","Q",".","0","Quetzal"},
|
||||
new String[]{"QA","QAR","2","QR",".","2","Qatari Rial"},
|
||||
new String[]{"LS","ZAR","2","R",".","0","Rand"},
|
||||
new String[]{"NA","ZAR","2","R",".","0","Rand"},
|
||||
new String[]{"ZA","ZAR","2","R",".","2","Rand"},
|
||||
new String[]{"BR","BRL","2","R$",",","0","Brazilian Real"},
|
||||
new String[]{"DO","DOP","2","RD$",".","0","Dominican Peso"},
|
||||
new String[]{"MV","MVR","2","Rf",".","0","Rufiyaa"},
|
||||
new String[]{"RW","RWF","0","RF",".","0","Rwanda Franc"},
|
||||
new String[]{"MY","MYR","2","RM",".","0","Malaysian Ringgit"},
|
||||
new String[]{"OM","OMR","3","RO",".","2","Rial Omani"},
|
||||
new String[]{"ID","IDR","2","Rp",",","0","Rupiah"},
|
||||
new String[]{"BT","INR","2","Rs",".","0","Indian Rupee"},
|
||||
new String[]{"IN","INR","2","Rs",".","0","Indian Rupee"},
|
||||
new String[]{"PK","PKR","2","Rs",".","0","Pakistan Rupee"},
|
||||
new String[]{"SG","SGD","2","S$",".","0","Singapore Dollar"},
|
||||
new String[]{"PE","PEN","2","S/.",",","0","Nuevo Sol"},
|
||||
new String[]{"SR","SRG","2","Sf.",".","0","Suriname Guilder"},
|
||||
new String[]{"SB","SBD","2","SI$",".","0","Solomon Islands Dollar"},
|
||||
new String[]{"SE","SEK","2","Sk",",","3","Swedish Krona"},
|
||||
new String[]{"SK","SKK","2","Sk",",","3","Slovak Koruna"},
|
||||
new String[]{"LK","LKR","2","SLRs",".","0","Sri Lanka Rupee"},
|
||||
new String[]{"SI","SIT","2","SlT",",","3","Tolar"},
|
||||
new String[]{"SO","SOS","2","So. Sh.",".","0","Somali Shilling"},
|
||||
new String[]{"SC","SCR","2","SR",".","0","Seychelles Rupee"},
|
||||
new String[]{"SA","SAR","2","SRls",".","2","Saudi Riyal"},
|
||||
new String[]{"CH","CHF","2","SwF",".","2","Swiss Franc"},
|
||||
new String[]{"LI","CHF","2","SwF",".","2","Swiss Franc"},
|
||||
new String[]{"TO","TOP","2","T$",".","0","Pa<EFBFBD>anga"},
|
||||
new String[]{"TN","TND","3","TD",".","2","Tunisian Dinar"},
|
||||
new String[]{"BD","BDT","2","Tk",".","0","Taka"},
|
||||
new String[]{"TR","TRL","0","TL",",","3","Turkish Lira"},
|
||||
new String[]{"TZ","TZS","2","TSh",".","0","Tanzanian Shilling"},
|
||||
new String[]{"TT","TTD","2","TT$",".","0","Trinidad and Tobago Dollar"},
|
||||
new String[]{"MN","MNT","2","Tug",".","0","Tugrik"},
|
||||
new String[]{"MR","MRO","2","UM",".","0","Ouguiya"},
|
||||
new String[]{"UG","UGX","2","USh",".","0","Uganda Shilling"},
|
||||
new String[]{"VU","VUV","0","VT",".","0","Vatu"},
|
||||
new String[]{"KR","KRW","0","W",".","0","Won"},
|
||||
new String[]{"WS","WST","2","WS$",".","0","Tala"},
|
||||
new String[]{"CN","CNY","2","Y",".","0","Yuan Renminbi"},
|
||||
new String[]{"YE","YER","2","YRls",".","2","Yemeni Rial"},
|
||||
new String[]{"ZW","ZWD","2","Z$",".","0","Zimbabwe Dollar"},
|
||||
new String[]{"ZM","ZMK","2","ZK",".","0","Kwacha"},
|
||||
new String[]{"CR","CRC","2","",".","0","Costa Rican Colon"},
|
||||
new String[]{"GN","GNF","0","",".","0","Guinea Franc"},
|
||||
new String[]{"GW","GWP","2","",".","0","Guinea-Bissau Peso"},
|
||||
new String[]{"KG","KGS","2","",".","0","Som"},
|
||||
new String[]{"KP","KPW","2","",".","0","North Korean Won"},
|
||||
new String[]{"KZ","KZT","2","",".","0","Tenge"},
|
||||
new String[]{"LB","LBP","2","",".","2","Lebanese Pound"},
|
||||
new String[]{"NG","NGN","2","",".","0","Naira"},
|
||||
new String[]{"PY","PYG","0","",",","0","Guarani"}
|
||||
};
|
||||
**/
|
||||
|
||||
} // MCurrency
|
|
@ -0,0 +1,91 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Currency Account Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MCurrencyAcct.java,v 1.3 2006/07/30 00:58:38 jjanke Exp $
|
||||
*/
|
||||
public class MCurrencyAcct extends X_C_Currency_Acct
|
||||
{
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger(MCurrencyAcct.class);
|
||||
|
||||
/**
|
||||
* Get Currency Account for Currency
|
||||
* @param as accounting schema default
|
||||
* @param C_Currency_ID currency
|
||||
* @return Currency Account or null
|
||||
*/
|
||||
public static MCurrencyAcct get (MAcctSchemaDefault as, int C_Currency_ID)
|
||||
{
|
||||
MCurrencyAcct retValue = null;
|
||||
String sql = "SELECT * FROM C_Currency_Acct "
|
||||
+ "WHERE C_AcctSchema_ID=? AND C_Currency_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, as.getC_AcctSchema_ID());
|
||||
pstmt.setInt(2, C_Currency_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
retValue = new MCurrencyAcct (as.getCtx(), rs, null);
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, "get", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCurrencyAcct(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MCurrencyAcct
|
||||
|
||||
} // MCurrencyAcct
|
|
@ -0,0 +1,297 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Document Type Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MDocType.java,v 1.3 2006/07/30 00:54:54 jjanke Exp $
|
||||
*/
|
||||
public class MDocType extends X_C_DocType
|
||||
{
|
||||
/**
|
||||
* Get Client Document Type with DocBaseType
|
||||
* @param ctx context
|
||||
* @param DocBaseType base document type
|
||||
* @return array of doc types
|
||||
*/
|
||||
static public MDocType[] getOfDocBaseType (Properties ctx, String DocBaseType)
|
||||
{
|
||||
ArrayList<MDocType> list = new ArrayList<MDocType>();
|
||||
String sql = "SELECT * FROM C_DocType WHERE AD_Client_ID=? AND DocBaseType=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, Env.getAD_Client_ID(ctx));
|
||||
pstmt.setString(2, DocBaseType);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add(new MDocType(ctx, rs, null));
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
MDocType[] retValue = new MDocType[list.size ()];
|
||||
list.toArray (retValue);
|
||||
return retValue;
|
||||
} // getOfDocBaseType
|
||||
|
||||
/**
|
||||
* Get Client Document Types
|
||||
* @param ctx context
|
||||
* @return array of doc types
|
||||
*/
|
||||
static public MDocType[] getOfClient (Properties ctx)
|
||||
{
|
||||
ArrayList<MDocType> list = new ArrayList<MDocType>();
|
||||
String sql = "SELECT * FROM C_DocType WHERE AD_Client_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, Env.getAD_Client_ID(ctx));
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add(new MDocType(ctx, rs, null));
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
MDocType[] retValue = new MDocType[list.size ()];
|
||||
list.toArray (retValue);
|
||||
return retValue;
|
||||
} // getOfClient
|
||||
|
||||
/**
|
||||
* Get Document Type (cached)
|
||||
* @param ctx context
|
||||
* @param C_DocType_ID id
|
||||
* @return document type
|
||||
*/
|
||||
static public MDocType get (Properties ctx, int C_DocType_ID)
|
||||
{
|
||||
Integer key = new Integer(C_DocType_ID);
|
||||
MDocType retValue = (MDocType)s_cache.get(key);
|
||||
if (retValue == null)
|
||||
{
|
||||
retValue = new MDocType (ctx, C_DocType_ID, null);
|
||||
s_cache.put(key, retValue);
|
||||
}
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Cache */
|
||||
static private CCache<Integer,MDocType> s_cache = new CCache<Integer,MDocType>("C_DocType", 20);
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MDocType.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_DocType_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDocType(Properties ctx, int C_DocType_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_DocType_ID, trxName);
|
||||
if (C_DocType_ID == 0)
|
||||
{
|
||||
// setName (null);
|
||||
// setPrintName (null);
|
||||
// setDocBaseType (null);
|
||||
// setGL_Category_ID (0);
|
||||
setDocumentCopies (0);
|
||||
setHasCharges (false);
|
||||
setIsDefault (false);
|
||||
setIsDocNoControlled (false);
|
||||
setIsSOTrx (false);
|
||||
setIsPickQAConfirm(false);
|
||||
setIsShipConfirm(false);
|
||||
setIsSplitWhenDifference(false);
|
||||
//
|
||||
setIsCreateCounter(true);
|
||||
setIsDefaultCounterDoc(false);
|
||||
setIsIndexed(true);
|
||||
}
|
||||
} // MDocType
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDocType(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MDocType
|
||||
|
||||
/**
|
||||
* New Constructor
|
||||
* @param ctx context
|
||||
* @param DocBaseType document base type
|
||||
* @param Name name
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDocType (Properties ctx, String DocBaseType, String Name, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setAD_Org_ID(0);
|
||||
setDocBaseType (DocBaseType);
|
||||
setName (Name);
|
||||
setPrintName (Name);
|
||||
setGL_Category_ID ();
|
||||
} // MDocType
|
||||
|
||||
/**
|
||||
* Set Default GL Category
|
||||
*/
|
||||
public void setGL_Category_ID()
|
||||
{
|
||||
String sql = "SELECT * FROM GL_Category WHERE AD_Client_ID=? AND IsDefault='Y'";
|
||||
int GL_Category_ID = DB.getSQLValue(get_TrxName(), sql, getAD_Client_ID());
|
||||
if (GL_Category_ID == 0)
|
||||
{
|
||||
sql = "SELECT * FROM GL_Category WHERE AD_Client_ID=?";
|
||||
GL_Category_ID = DB.getSQLValue(get_TrxName(), sql, getAD_Client_ID());
|
||||
}
|
||||
setGL_Category_ID(GL_Category_ID);
|
||||
} // setGL_Category_ID
|
||||
|
||||
|
||||
/**
|
||||
* Set SOTrx based on document base type
|
||||
*/
|
||||
public void setIsSOTrx ()
|
||||
{
|
||||
boolean isSOTrx = DOCBASETYPE_SalesOrder.equals(getDocBaseType())
|
||||
|| DOCBASETYPE_MaterialDelivery.equals(getDocBaseType())
|
||||
|| getDocBaseType().startsWith("AR");
|
||||
super.setIsSOTrx (isSOTrx);
|
||||
} // setIsSOTrx
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MDocType[");
|
||||
sb.append(get_ID()).append("-").append(getName())
|
||||
.append(",DocNoSequence_ID=").append(getDocNoSequence_ID())
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Is this a Quotation (Binding)
|
||||
* @return true if Quotation
|
||||
*/
|
||||
public boolean isQuotation()
|
||||
{
|
||||
return DOCSUBTYPESO_Quotation.equals(getDocSubTypeSO())
|
||||
&& DOCBASETYPE_SalesOrder.equals(getDocBaseType());
|
||||
} // isQuotation
|
||||
|
||||
/**
|
||||
* Is this a Proposal (Not binding)
|
||||
* @return true if proposal
|
||||
*/
|
||||
public boolean isProposal()
|
||||
{
|
||||
return DOCSUBTYPESO_Proposal.equals(getDocSubTypeSO())
|
||||
&& DOCBASETYPE_SalesOrder.equals(getDocBaseType());
|
||||
} // isProposal
|
||||
|
||||
/**
|
||||
* Is this a Proposal or Quotation
|
||||
* @return true if proposal or quotation
|
||||
*/
|
||||
public boolean isOffer()
|
||||
{
|
||||
return (DOCSUBTYPESO_Proposal.equals(getDocSubTypeSO())
|
||||
|| DOCSUBTYPESO_Quotation.equals(getDocSubTypeSO()))
|
||||
&& DOCBASETYPE_SalesOrder.equals(getDocBaseType());
|
||||
} // isOffer
|
||||
|
||||
|
||||
/**
|
||||
* Get Print Name
|
||||
* @param AD_Language language
|
||||
* @return print Name if available translated
|
||||
*/
|
||||
public String getPrintName (String AD_Language)
|
||||
{
|
||||
if (AD_Language == null || AD_Language.length() == 0)
|
||||
return super.getPrintName();
|
||||
String retValue = get_Translation ("PrintName", AD_Language);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
return super.getPrintName();
|
||||
} // getPrintName
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
} // MDocType
|
|
@ -0,0 +1,132 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Accounting Element Model.
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MElement.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class MElement extends X_C_Element
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_Element_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MElement (Properties ctx, int C_Element_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_Element_ID, trxName);
|
||||
if (C_Element_ID == 0)
|
||||
{
|
||||
// setName (null);
|
||||
// setAD_Tree_ID (0);
|
||||
// setElementType (null); // A
|
||||
setIsBalancing (false);
|
||||
setIsNaturalAccount (false);
|
||||
}
|
||||
} // MElement
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MElement (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MElement
|
||||
|
||||
/**
|
||||
* Full Constructor
|
||||
* @param client client
|
||||
* @param Name name
|
||||
* @param ElementType type
|
||||
* @param AD_Tree_ID tree
|
||||
*/
|
||||
public MElement (MClient client, String Name, String ElementType, int AD_Tree_ID)
|
||||
{
|
||||
this (client.getCtx(), 0, client.get_TrxName());
|
||||
setClientOrg(client);
|
||||
setName (Name);
|
||||
setElementType (ElementType); // A
|
||||
setAD_Tree_ID (AD_Tree_ID);
|
||||
setIsNaturalAccount(ELEMENTTYPE_Account.equals(ElementType));
|
||||
} // MElement
|
||||
|
||||
/** Tree Used */
|
||||
private X_AD_Tree m_tree = null;
|
||||
|
||||
/**
|
||||
* Get Tree
|
||||
* @return tree
|
||||
*/
|
||||
public X_AD_Tree getTree ()
|
||||
{
|
||||
if (m_tree == null)
|
||||
m_tree = new X_AD_Tree (getCtx(), getAD_Tree_ID(), get_TrxName());
|
||||
return m_tree;
|
||||
} // getTree
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
String elementType = getElementType();
|
||||
// Natural Account
|
||||
if (ELEMENTTYPE_UserDefined.equals(elementType) && isNaturalAccount())
|
||||
setIsNaturalAccount(false);
|
||||
// Tree validation
|
||||
X_AD_Tree tree = getTree();
|
||||
if (tree == null)
|
||||
return false;
|
||||
String treeType = tree.getTreeType();
|
||||
if (ELEMENTTYPE_UserDefined.equals(elementType))
|
||||
{
|
||||
if (X_AD_Tree.TREETYPE_User1.equals(treeType) || X_AD_Tree.TREETYPE_User2.equals(treeType))
|
||||
;
|
||||
else
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@TreeType@ <> @ElementType@ (U)"), false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!X_AD_Tree.TREETYPE_ElementValue.equals(treeType))
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@TreeType@ <> @ElementType@ (A)"), false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
} // MElement
|
|
@ -0,0 +1,254 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Natural Account
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MElementValue.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
|
||||
*/
|
||||
public class MElementValue extends X_C_ElementValue
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_ElementValue_ID ID or 0 for new
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MElementValue(Properties ctx, int C_ElementValue_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_ElementValue_ID, trxName);
|
||||
if (C_ElementValue_ID == 0)
|
||||
{
|
||||
// setC_Element_ID (0); // Parent
|
||||
// setName (null);
|
||||
// setValue (null);
|
||||
setIsSummary (false);
|
||||
setAccountSign (ACCOUNTSIGN_Natural);
|
||||
setAccountType (ACCOUNTTYPE_Expense);
|
||||
setIsDocControlled(false);
|
||||
setIsForeignCurrency(false);
|
||||
setIsBankAccount(false);
|
||||
//
|
||||
setPostActual (true);
|
||||
setPostBudget (true);
|
||||
setPostEncumbrance (true);
|
||||
setPostStatistical (true);
|
||||
}
|
||||
} // MElementValue
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MElementValue(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MElementValue
|
||||
|
||||
/**
|
||||
* Full Constructor
|
||||
* @param ctx context
|
||||
* @param Value value
|
||||
* @param Name name
|
||||
* @param Description description
|
||||
* @param AccountType account type
|
||||
* @param AccountSign account sign
|
||||
* @param IsDocControlled doc controlled
|
||||
* @param IsSummary summary
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MElementValue (Properties ctx, String Value, String Name, String Description,
|
||||
String AccountType, String AccountSign,
|
||||
boolean IsDocControlled, boolean IsSummary, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setValue(Value);
|
||||
setName(Name);
|
||||
setDescription(Description);
|
||||
setAccountType(AccountType);
|
||||
setAccountSign(AccountSign);
|
||||
setIsDocControlled(IsDocControlled);
|
||||
setIsSummary(IsSummary);
|
||||
} // MElementValue
|
||||
|
||||
/**
|
||||
* Import Constructor
|
||||
* @param imp import
|
||||
*/
|
||||
public MElementValue (X_I_ElementValue imp)
|
||||
{
|
||||
this (imp.getCtx(), 0, imp.get_TrxName());
|
||||
setClientOrg(imp);
|
||||
set(imp);
|
||||
} // MElementValue
|
||||
|
||||
/**
|
||||
* Set/Update Settings from import
|
||||
* @param imp import
|
||||
*/
|
||||
public void set (X_I_ElementValue imp)
|
||||
{
|
||||
setValue(imp.getValue());
|
||||
setName(imp.getName());
|
||||
setDescription(imp.getDescription());
|
||||
setAccountType(imp.getAccountType());
|
||||
setAccountSign(imp.getAccountSign());
|
||||
setIsSummary(imp.isSummary());
|
||||
setIsDocControlled(imp.isDocControlled());
|
||||
setC_Element_ID(imp.getC_Element_ID());
|
||||
//
|
||||
setPostActual(imp.isPostActual());
|
||||
setPostBudget(imp.isPostBudget());
|
||||
setPostEncumbrance(imp.isPostEncumbrance());
|
||||
setPostStatistical(imp.isPostStatistical());
|
||||
//
|
||||
// setC_BankAccount_ID(imp.getC_BankAccount_ID());
|
||||
// setIsForeignCurrency(imp.isForeignCurrency());
|
||||
// setC_Currency_ID(imp.getC_Currency_ID());
|
||||
// setIsBankAccount(imp.isIsBankAccount());
|
||||
// setValidFrom(null);
|
||||
// setValidTo(null);
|
||||
} // set
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is this a Balance Sheet Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isBalanceSheet()
|
||||
{
|
||||
String accountType = getAccountType();
|
||||
return (ACCOUNTTYPE_Asset.equals(accountType)
|
||||
|| ACCOUNTTYPE_Liability.equals(accountType)
|
||||
|| ACCOUNTTYPE_OwnerSEquity.equals(accountType));
|
||||
} // isBalanceSheet
|
||||
|
||||
/**
|
||||
* Is this an Activa Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isActiva()
|
||||
{
|
||||
return ACCOUNTTYPE_Asset.equals(getAccountType());
|
||||
} // isActive
|
||||
|
||||
/**
|
||||
* Is this a Passiva Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isPassiva()
|
||||
{
|
||||
String accountType = getAccountType();
|
||||
return (ACCOUNTTYPE_Liability.equals(accountType)
|
||||
|| ACCOUNTTYPE_OwnerSEquity.equals(accountType));
|
||||
} // isPassiva
|
||||
|
||||
/**
|
||||
* User String Representation
|
||||
* @return info value - name
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ();
|
||||
sb.append(getValue()).append(" - ").append(getName());
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Extended String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toStringX ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MElementValue[");
|
||||
sb.append(get_ID()).append(",").append(getValue()).append(" - ").append(getName())
|
||||
.append ("]");
|
||||
return sb.toString ();
|
||||
} // toStringX
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord
|
||||
* @return true if ir can be saved
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
//
|
||||
if (!newRecord && isSummary()
|
||||
&& is_ValueChanged("IsSummary"))
|
||||
{
|
||||
String sql = "SELECT COUNT(*) FROM Fact_Acct WHERE Account_ID=?";
|
||||
int no = DB.getSQLValue(get_TrxName(), sql, getC_ElementValue_ID());
|
||||
if (no != 0)
|
||||
{
|
||||
log.saveError("Error", "Already posted to");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
if (newRecord)
|
||||
insert_Tree(MTree_Base.TREETYPE_ElementValue, getC_Element_ID());
|
||||
|
||||
// Value/Name change
|
||||
if (!newRecord && (is_ValueChanged("Value") || is_ValueChanged("Name")))
|
||||
{
|
||||
MAccount.updateValueDescription(getCtx(), "Account_ID=" + getC_ElementValue_ID(),get_TrxName());
|
||||
if ("Y".equals(Env.getContext(getCtx(), "$Element_U1")))
|
||||
MAccount.updateValueDescription(getCtx(), "User1_ID=" + getC_ElementValue_ID(),get_TrxName());
|
||||
if ("Y".equals(Env.getContext(getCtx(), "$Element_U2")))
|
||||
MAccount.updateValueDescription(getCtx(), "User2_ID=" + getC_ElementValue_ID(),get_TrxName());
|
||||
}
|
||||
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* After Delete
|
||||
* @param success
|
||||
* @return deleted
|
||||
*/
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
if (success)
|
||||
delete_Tree(MTree_Base.TREETYPE_ElementValue);
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
} // MElementValue
|
|
@ -0,0 +1,108 @@
|
|||
/******************************************************************************
|
||||
* 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.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Field Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MField.java,v 1.2 2006/07/30 00:58:04 jjanke Exp $
|
||||
*/
|
||||
public class MField extends X_AD_Field
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Field_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MField (Properties ctx, int AD_Field_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_Field_ID, trxName);
|
||||
if (AD_Field_ID == 0)
|
||||
{
|
||||
// setAD_Tab_ID (0); // parent
|
||||
// setAD_Column_ID (0);
|
||||
// setName (null);
|
||||
setEntityType (ENTITYTYPE_UserMaintained); // U
|
||||
setIsCentrallyMaintained (true); // Y
|
||||
setIsDisplayed (true); // Y
|
||||
setIsEncrypted (false);
|
||||
setIsFieldOnly (false);
|
||||
setIsHeading (false);
|
||||
setIsReadOnly (false);
|
||||
setIsSameLine (false);
|
||||
// setObscureType(OBSCURETYPE_ObscureDigitsButLast4);
|
||||
}
|
||||
} // MField
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MField (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MField
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent parent
|
||||
*/
|
||||
public MField (MTab parent)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setAD_Tab_ID(parent.getAD_Tab_ID());
|
||||
} // MField
|
||||
|
||||
/**
|
||||
* Copy Constructor
|
||||
* @param parent parent
|
||||
* @param from copy from
|
||||
*/
|
||||
public MField (MTab parent, MField from)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
copyValues(from, this);
|
||||
setClientOrg(parent);
|
||||
setAD_Tab_ID(parent.getAD_Tab_ID());
|
||||
setEntityType(parent.getEntityType());
|
||||
} // M_Field
|
||||
|
||||
/**
|
||||
* Set Column Values
|
||||
* @param column column
|
||||
*/
|
||||
public void setColumn (MColumn column)
|
||||
{
|
||||
setAD_Column_ID (column.getAD_Column_ID());
|
||||
setName (column.getName());
|
||||
setDescription(column.getDescription());
|
||||
setHelp(column.getHelp());
|
||||
setDisplayLength(column.getFieldLength());
|
||||
setEntityType(column.getEntityType());
|
||||
} // setColumn
|
||||
|
||||
} // MField
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue