Remove a lot of old dead code

master
Vitaliy Filippov 2015-12-21 00:49:05 +03:00
parent 133fc66358
commit 9a3aba6ed7
14 changed files with 127 additions and 1846 deletions

View File

@ -35,8 +35,6 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.glassfish.openesb.databasebc.model.runtime.DBConnectionInfo;
/**
* author
@ -79,7 +77,6 @@ public class EndpointBean implements Serializable {
private String mTableName = null;
private EndpointStatus mEndpointStatus;
private List mrecordList = new ArrayList();
private DBConnectionInfo mDBConnectionInfo;
// throttling related info
private int maxConcurrencyLimit = -1;
@ -193,14 +190,6 @@ public class EndpointBean implements Serializable {
public String getTableName() {
return mTableName;
}
public void setDBInfo(DBConnectionInfo dbInfo){
this.mDBConnectionInfo = dbInfo;
}
public DBConnectionInfo getDBInfo(){
return this.mDBConnectionInfo;
}
public void setMaxConcurrencyLimit(int maxConcurrencyLimit){
this.maxConcurrencyLimit = maxConcurrencyLimit;

View File

@ -72,13 +72,13 @@ import javax.xml.parsers.ParserConfigurationException;
import com.sun.jbi.internationalization.Messages;
import org.glassfish.openesb.databasebc.model.metadata.DBMetaData;
import org.glassfish.openesb.databasebc.model.runtime.DBConnectionInfo;
import org.glassfish.openesb.databasebc.model.runtime.DatabaseModel;
import org.glassfish.openesb.databasebc.model.runtime.DatabaseModelImpl;
import org.glassfish.openesb.databasebc.model.runtime.Db2DataAccess;
import org.glassfish.openesb.databasebc.model.runtime.DerbyDataAccess;
import org.glassfish.openesb.databasebc.model.runtime.OracleDataAccess;
import org.glassfish.openesb.databasebc.model.runtime.SqlServerDataAccess;
import org.glassfish.openesb.databasebc.model.runtime.MysqlDataAccess;
import com.sun.jbi.nms.exchange.ExchangePattern;
import com.sun.jbi.common.qos.messaging.MessagingChannel;
@ -91,16 +91,6 @@ import net.java.hulp.measure.Probe;
* author : Venkat P Process requests received from the External Database
*/
public class InboundMessageProcessor implements Runnable, MessageExchangeReplyListener, RedeliveryListener {
private static final String DERBY_PROD_NAME = "DERBY";
private static final String ORACLE_PROD_NAME = "ORACLE";
private static final String SQLSERVER_PROD_NAME = "SQLSERVER";
private static final String DB2_PROD_NAME = "DB2";
private static final String JDBC_PROD_NAME = "JDBC";
private static final Messages mMessages = Messages.getMessages(InboundMessageProcessor.class);
private static final Logger mLogger = Messages.getLogger(InboundMessageProcessor.class);
@ -137,16 +127,11 @@ public class InboundMessageProcessor implements Runnable, MessageExchangeReplyLi
private String mMarkColumnValue = null;
private String mPKType = null;
private String mFlagColumnType = null;
private String mSchemaName = null;
private String mXAEnabled = null;
private String mTableName = null;
private String mDbName = null;
private String mPollingPostProcessing = null;
@ -356,14 +341,15 @@ public class InboundMessageProcessor implements Runnable, MessageExchangeReplyLi
getTransactionManager().begin();
}
DatabaseModel dbDataAccessObject = getDataAccessObject(meta);
mSelectSQL = dbDataAccessObject.generateSelectQuery(mSelectSQL, mTableName);
epb.setTableName(mTableName);
connection = getDatabaseConnection(jndiName);
if (mDbName == null){
mDbName = connection.getMetaData().getDatabaseProductName().toLowerCase();
if (mSelectSQL == null || mSelectSQL.trim().equals("")) {
DatabaseModel dbDataAccessObject = getDataAccessObject(connection);
int numberOfRecords = meta.getJDBCOperationInput().getNumberOfRecords();
mSelectSQL = dbDataAccessObject.generateSelectQuery(mTableName, numberOfRecords);
}
String dbName = connection.getMetaData().getDatabaseProductName().toLowerCase();
if (epb.isClustered()) {
connection.setAutoCommit(false);
// In cluster environment, adding a simple "FOR UPDATE" to the poll query is enough
@ -398,7 +384,7 @@ public class InboundMessageProcessor implements Runnable, MessageExchangeReplyLi
normalizer.setInboundExchangeProcessRecordsMap(mMapInboundExchangesProcessRecords);
normalizer.setRecordsProcessedList(mProcessedList);
inMsg = normalizer.normalizeSelectInbound(rs, exchange, meta, epb, mPKName,mDbName);
inMsg = normalizer.normalizeSelectInbound(rs, exchange, meta, epb, mPKName, dbName);
rowCount = normalizer.mRowCount;
if(normalizationMeasurement != null){
@ -502,13 +488,8 @@ public class InboundMessageProcessor implements Runnable, MessageExchangeReplyLi
List<String> bind = new ArrayList<String>();
if (lSelectSQL.indexOf("$WHERE") >= 0) {
if (mMarkColumnName != null && !mMarkColumnName.equals("")) {
if (mFlagColumnType != null) {
where = "("+mMarkColumnName+" != ? OR "+mMarkColumnName+" IS NULL)";
bind.add(mMarkColumnValue);
} else {
final String msg = InboundMessageProcessor.mMessages.getString("DBBC_E00638.IMP_Error_IVALID_ColumnName") + mMarkColumnName;
throw new MessagingException(msg, new NamingException());
}
where = "("+mMarkColumnName+" != ? OR "+mMarkColumnName+" IS NULL)";
bind.add(mMarkColumnValue);
}
lSelectSQL = lSelectSQL.replace("$WHERE", where.equals("") ? "1=1" : where);
}
@ -543,90 +524,20 @@ public class InboundMessageProcessor implements Runnable, MessageExchangeReplyLi
return rs;
}
/**
* @return
* @throws MessagingException
*/
public DatabaseModel getDataAccessObject(OperationMetaData meta) throws MessagingException {
DatabaseModel objDataAccess = null;
String jndiName = null;
String prdtName = null;
String catalog = null;
jndiName = epb.getValue(EndpointBean.JDBC_DATABASE_JNDI_NAME);
Connection connection = null;
ResultSet rs = null;
try {
connection = getDatabaseConnection(jndiName);
prdtName = DBMetaData.getDBType(connection);
rs = connection.getMetaData().getColumns(catalog, mSchemaName, mTableName, "%");
int noofColCounter = -1;
while (rs.next()) {
noofColCounter++;
final String colName = rs.getString("COLUMN_NAME");
if (colName.equalsIgnoreCase(meta.getJDBCSql().getPKName())) {
final String defaultValue = rs.getString("COLUMN_DEF");
final int sqlTypeCode = rs.getInt("DATA_TYPE");
final String sqlType = DBMetaData.getSQLTypeDescription(sqlTypeCode);
mPKType = sqlType;
}
if (colName.equalsIgnoreCase(meta.getJDBCSql().getMarkColumnName())) {
final String defaultValue = rs.getString("COLUMN_DEF");
final int sqlTypeCode = rs.getInt("DATA_TYPE");
final String sqlType = DBMetaData.getSQLTypeDescription(sqlTypeCode);
mFlagColumnType = sqlType;
}
}
if(noofColCounter < 0 ){
final String msg = InboundMessageProcessor.mMessages.getString("DBBC_E00636.IMP_Table_NotExist");
throw new MessagingException(msg, new NamingException());
}
if (mPKType == null) {
final String msg = InboundMessageProcessor.mMessages.getString("DBBC_E00637.IMP_PrimaryKey_Error");
throw new MessagingException(msg, new NamingException());
}
if (prdtName.equalsIgnoreCase(InboundMessageProcessor.DERBY_PROD_NAME)) {
return objDataAccess = DerbyDataAccess.getInstance();
} else if (prdtName.equalsIgnoreCase(InboundMessageProcessor.ORACLE_PROD_NAME)) {
return objDataAccess = OracleDataAccess.getInstance();
} else if (prdtName.equalsIgnoreCase(InboundMessageProcessor.DB2_PROD_NAME)) {
return objDataAccess = Db2DataAccess.getInstance();
} else if (prdtName.equalsIgnoreCase(InboundMessageProcessor.SQLSERVER_PROD_NAME)) {
return objDataAccess = SqlServerDataAccess.getInstance();
} else if (prdtName.equalsIgnoreCase(InboundMessageProcessor.JDBC_PROD_NAME)) {
return objDataAccess = DatabaseModelImpl.getInstance();
} else {
return objDataAccess = new DatabaseModelImpl();
}
} catch (final NamingException ex) {
final String msg = InboundMessageProcessor.mMessages.getString("DBBC_E00635.IMP_Error_Lookup") + jndiName;
mLogger.log(Level.SEVERE, msg, ex);
throw new MessagingException(msg, ex);
} catch (final SQLException ex) {
final String msg = InboundMessageProcessor.mMessages.getString("DBBC_E00639.IMP_Failed_Executing_SQL") +
"Reason: " + ex.getLocalizedMessage() + " SQLState: " + ex.getSQLState() + " ErrorCode: " + ex.getErrorCode();
mLogger.log(Level.SEVERE, msg, ex);
throw new MessagingException(msg, ex);
} catch (final Exception ex) {
final String msg = InboundMessageProcessor.mMessages.getString("DBBC_E00639.IMP_Failed_Executing_SQL");
throw new MessagingException(msg, ex);
} finally {
try {
if (rs != null) {
rs.close();
}
}catch(SQLException se){
mLogger.log(Level.SEVERE, mMessages.getString("DBBC_E11109.IMP_EXCEPTION_WHILE_CLOSING_THE_RS"), se);
}
try{
if (connection != null) {
connection.close();
}
}catch(SQLException se){
mLogger.log(Level.SEVERE, mMessages.getString("DBBC_E11111.IMP_EXCEPTION_WHILE_CLOSING_THE_CONNECTION"), se);
}
public DatabaseModel getDataAccessObject(Connection connection) throws SQLException {
String prdtName = DBMetaData.getDBType(connection);
if (prdtName == DBMetaData.DERBY) {
return DerbyDataAccess.getInstance();
} else if (prdtName == DBMetaData.ORACLE) {
return OracleDataAccess.getInstance();
} else if (prdtName == DBMetaData.DB2) {
return Db2DataAccess.getInstance();
} else if (prdtName == DBMetaData.SQLSERVER) {
return SqlServerDataAccess.getInstance();
} else if (prdtName == DBMetaData.MYSQL) {
return MysqlDataAccess.getInstance();
} else {
return DatabaseModelImpl.getInstance();
}
}

View File

@ -108,7 +108,7 @@ public class JDBCDenormalizer {
* @throws MessagingException
*/
protected void denormalizeOutbound(final NormalizedMessage normalizedMessage,
String dbName, final String jndiName, final OperationMetaData opMetaData, final PreparedStatement ps)
final String jndiName, final OperationMetaData opMetaData, final PreparedStatement ps)
throws MessagingException {
if (opMetaData != null) {
final JDBCOperationInput mJdbcOperationInput = opMetaData.
@ -120,7 +120,7 @@ public class JDBCDenormalizer {
Element element =
transformMessage(normalizedMessage, opMetaData);
if (element != null)
populatePreparedStatement(element, dbName, jndiName, opMetaData, ps);
populatePreparedStatement(element, jndiName, opMetaData, ps);
} catch (final SQLException ex) {
final String msg =
JDBCDenormalizer.mMessages.getString(
@ -411,7 +411,7 @@ public class JDBCDenormalizer {
* @throws MessagingException
* @throws Exception
*/
private void populatePreparedStatement(final Element tableElem, String dbName, String jndiName,
private void populatePreparedStatement(final Element tableElem, String jndiName,
final OperationMetaData opMetaData, final PreparedStatement ps)
throws SQLException, MessagingException, Exception {
/*

View File

@ -56,7 +56,6 @@ import javax.xml.parsers.ParserConfigurationException;
import com.sun.jbi.internationalization.Messages;
import javax.transaction.xa.XAResource;
import org.glassfish.openesb.databasebc.model.runtime.DBConnectionInfo;
import javax.sql.*;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@ -87,7 +86,6 @@ public class OutboundMessageProcessor implements Runnable {
private MessageExchange mExchange;
private JDBCComponentContext mContext;
private Map mInboundExchanges;
DBConnectionInfo dbConnectionInfo;
XAConnection xaConnection = null;
private String mXAEnabled = null;
Connection connection = null;
@ -128,7 +126,6 @@ public class OutboundMessageProcessor implements Runnable {
final DocumentBuilderFactory docBuilderFact = DocumentBuilderFactory.
newInstance();
mDocBuilder = docBuilderFact.newDocumentBuilder();
dbConnectionInfo = new DBConnectionInfo();
}
/**
@ -1623,8 +1620,7 @@ public class OutboundMessageProcessor implements Runnable {
eBean.getUniqueName(),
JDBCBindingLifeCycle.PERF_CAT_DENORMALIZATION);
denormalizer.denormalizeOutbound(nMsg, getDBName(eBean, nMsg), jndiName,
opMetaData, ps);
denormalizer.denormalizeOutbound(nMsg, jndiName, opMetaData, ps);
if (denormalizationMeasurement != null)
denormalizationMeasurement.end();
@ -1677,8 +1673,7 @@ public class OutboundMessageProcessor implements Runnable {
eBean.getUniqueName(),
JDBCBindingLifeCycle.PERF_CAT_DENORMALIZATION);
denormalizer.denormalizeOutbound(nMsg, getDBName(eBean, nMsg), jndiName,
opMetaData, ps);
denormalizer.denormalizeOutbound(nMsg, jndiName, opMetaData, ps);
if (denormalizationMeasurement != null)
denormalizationMeasurement.end();
@ -1737,8 +1732,7 @@ public class OutboundMessageProcessor implements Runnable {
eBean.getUniqueName(),
JDBCBindingLifeCycle.PERF_CAT_DENORMALIZATION);
denormalizer.denormalizeOutbound(nMsg, getDBName(eBean, nMsg), jndiName,
opMetaData, ps);
denormalizer.denormalizeOutbound(nMsg, jndiName, opMetaData, ps);
if (denormalizationMeasurement != null)
denormalizationMeasurement.end();
@ -2047,26 +2041,6 @@ public class OutboundMessageProcessor implements Runnable {
}
}
private String getDBName(EndpointBean eBean, NormalizedMessage nMsg)
throws javax.naming.NamingException, java.sql.SQLException {
if (eBean.getValue(EndpointBean.JDBC_DATABASE_JNDI_NAME) == null || eBean.
getValue(EndpointBean.JDBC_DATABASE_JNDI_NAME).equals(""))
return dbConnectionInfo.getDataBaseName(eBean.getValue(
EndpointBean.JDBC_DATABASE_URL), null, null);
else {
String jndiName = eBean.getValue(
EndpointBean.JDBC_DATABASE_JNDI_NAME);
if (nMsg.getProperty(
JDBCComponentContext.NM_PROP_DATABASEBC_CONNECTION_JNDI_NAME) != null)
jndiName = nMsg.getProperty(
JDBCComponentContext.NM_PROP_DATABASEBC_CONNECTION_JNDI_NAME).
toString();
return dbConnectionInfo.getDataBaseName(null, null,
(DataSource) getDataSourceFromContext(jndiName));
}
}
private void setErrorInExchange(MessageExchange ex, String faultCode,
String faultDetail, Exception e) {
ex.setError(e);

View File

@ -121,6 +121,9 @@ public final class DBMetaData {
/** Database OTD type for Oracle */
public static final String ORACLE = "ORACLE"; // NOI18N
/** Database OTD type for MySQL */
public static final String MYSQL = "MYSQL"; // NOI18N
/** Database OTD type for SQL Server */
public static final String SQLSERVER = "SQLSERVER"; // NOI18N
@ -232,26 +235,11 @@ public final class DBMetaData {
// String used in java.sql.DatabaseMetaData to indicate system tables.
private static final String VIEW = "VIEW"; // NOI18N
//private Connection dbconn; // db connection
//private DatabaseMetaData dbmeta; // db metadata
//private String errMsg; // error message
//private boolean checkPrepStmtMetaData = true; // indicates driver does not
// fully support finding prepared
// statement metadata
//private boolean errPrepStmtParameters = false; // error getting prep. stmt. parameters
//private boolean errPrepStmtResultSetColumns = false; // error getting prep. stmt. resultset
// columns
private static final Logger mLogger = Logger.getLogger(DBMetaData.class.getName());
private static final Messages mMessages = Messages.getMessages(DBMetaData.class);
/**
* Gets the primary keys for a table.
*
@ -334,75 +322,6 @@ public final class DBMetaData {
}
}
/**
* Establishes a connection to the database.
*
* @param conn JDBC connection
* @throws Exception DOCUMENT ME!
*/
/*public void connectDB(final Connection conn) throws Exception {
this.errMsg = "";
if (conn == null) {
throw new IllegalArgumentException("Connection can't be null.");
}
this.dbconn = conn;
this.getDBMetaData();
}*/
/**
* Disconnects from the database.
*
* @throws Exception DOCUMENT ME!
*/
/*public void disconnectDB() throws Exception {
this.errMsg = "";
// close connection to database
try {
if (this.dbconn != null && !this.dbconn.isClosed()) {
this.dbconn.close();
this.dbconn = null;
}
} catch (final SQLException e) {
e.printStackTrace();
this.errMsg = e.getLocalizedMessage();
throw e;
}
}*/
/*private void getDBMetaData() throws Exception {
this.errMsg = "";
// get the metadata
try {
this.dbmeta = this.dbconn.getMetaData();
} catch (final SQLException e) {
e.printStackTrace();
this.errMsg = e.getLocalizedMessage();
throw e;
}
}*/
/**
* Returns the database product name
*
* @return String database product name
* @throws Exception DOCUMENT ME!
*/
/*public String getDBName() throws Exception {
String dbname = "";
this.errMsg = "";
// get the database product name
try {
dbname = this.dbmeta.getDatabaseProductName();
} catch (final SQLException e) {
e.printStackTrace();
this.errMsg = e.getLocalizedMessage();
throw e;
}
return dbname;
}*/
/**
* Returns the database OTD type.
*
@ -410,7 +329,7 @@ public final class DBMetaData {
* @return String Database OTD type
* @throws Exception DOCUMENT ME!
*/
public static String getDBType(final Connection conn) throws Exception {
public static String getDBType(final Connection conn) throws SQLException {
String dbtype = "";
// get the database type based on the product name converted to lowercase
@ -430,6 +349,9 @@ public final class DBMetaData {
} else if (dbname.indexOf("orac") > -1) {
// Oracle
dbtype = DBMetaData.ORACLE;
} else if (dbname.indexOf("mysql") > -1 || dbname.indexOf("mariadb") > -1) {
// MySQL
dbtype = DBMetaData.MYSQL;
} else if (dbname.indexOf("derby") > -1) {
// derby
dbtype = DBMetaData.DERBY;

View File

@ -1,233 +0,0 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
* If applicable add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced with
* your own identifying information: Portions Copyright
* [year] [name of copyright owner]
*/
/*
* @(#)DBConnectionInfo.java
*
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
*
* END_HEADER - DO NOT EDIT
*/
package org.glassfish.openesb.databasebc.model.runtime;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import javax.sql.XADataSource;
import javax.jbi.component.ComponentContext;
import javax.xml.transform.*;
import org.glassfish.openesb.databasebc.EndpointBean;
/*
* This class encapsulates the DBConnection parameters
* while obtaining the connection and will help in identifying
* the
*/
public class DBConnectionInfo {
private String dbUrl;
private String serverName;
private int portNumber;
private String databaseOrSchemaName;
private String username;
private String password;
private int dbType;
private String driverName;
private String mjndiName;
public static final String JDBCDEF_TAG = "connectiondef";
DBConnectionInfo dbConnectionInfo;
private String XAEnabled = null;
public void buildConnectionInfo(String dbUrl) {
//Url format: jdbc:derby://localhost:1527/testDB;create=true
if (dbUrl.startsWith("jdbc:derby://")) {
dbType = DataBases.DERBY.ordinal();
dbUrl = dbUrl.substring("jdbc:derby://".length(), dbUrl.length());
final String[] array1 = dbUrl.split("/");
final String[] array2 = array1[0].split(":");
serverName = array2[0];
portNumber = Integer.valueOf(array2[1]).intValue();
databaseOrSchemaName = array1[1];
} else if (dbUrl.startsWith("jdbc:oracle:thin:@")) {
//jdbc:oracle:thin:@<server>[:<1521>]:<database_name>
dbType = DataBases.ORACLE.ordinal();
}else if (dbUrl.startsWith("jdbc:Seebeyond:db2://")) {
//jdbc:Seebeyond:db2://localhost:1433;DatabaseName=db2
dbType = DataBases.DB2.ordinal();
dbUrl = dbUrl.substring("jdbc:Seebeyond:db2://".length(), dbUrl.length());
final String[] array1 = dbUrl.split(";");
final String[] array2 = array1[0].split(":");
serverName = array2[0];
portNumber = Integer.valueOf(array2[1]).intValue();
databaseOrSchemaName = array1[1];
}else if (dbUrl.startsWith("jdbc:SeeBeyond:sqlserver://")) {
//jdbc:SeeBeyond:sqlserver://rpoon-xp.stc.com:1433;DatabaseName=dgdb
dbType = DataBases.SQLSERVER.ordinal();
dbUrl = dbUrl.substring("jdbc:SeeBeyond:sqlserver://".length(), dbUrl.length());
final String[] array1 = dbUrl.split(";");
final String[] array2 = array1[0].split(":");
serverName = array2[0];
portNumber = Integer.valueOf(array2[1]).intValue();
final String[] array3 = array1[1].split("=");
databaseOrSchemaName = array3[1];
}
}
/*
* This gets the database name based on either the dbUrl or XADataSource or DataSource
* that is available
* @param dbUrl
* @param xads
* @param ds
* @return String
* @throws SQLException
*/
public String getDataBaseName(final String dbUrl, final XADataSource xads, final DataSource ds)
throws SQLException {
Connection conn = null;
String dbName = null;
if (xads != null) {
conn = xads.getXAConnection().getConnection();
dbName = conn.getMetaData().getDatabaseProductName();
conn.close();
return dbName;
}
if (ds != null) {
conn = ds.getConnection();
dbName = conn.getMetaData().getDatabaseProductName();
conn.close();
return dbName;
}
if (dbUrl.contains("derby")) {
return "DERBY";
} else if (dbUrl.contains("oracle")) {
return "ORACLE";
}else if (dbUrl.contains("sqlserver")) {
return "SQLSERVER";
} else if (dbUrl.contains("db2")) {
return "DB2";
}
return null;
}
public String getDatabaseOrSchemaName() {
return databaseOrSchemaName;
}
public void setDatabaseOrSchemaName(final String databaseOrSchemaName) {
this.databaseOrSchemaName = databaseOrSchemaName;
}
public int getDbType() {
return dbType;
}
public void setDbType(final int dbType) {
this.dbType = dbType;
}
public String getDbUrl() {
return dbUrl;
}
public void setDbUrl(final String dbUrl) {
this.dbUrl = dbUrl;
}
public String getPassword() {
return password;
}
public void setPassword(final String password) {
this.password = password;
}
public int getPortNumber() {
return portNumber;
}
public void setPortNumber(final int portNumber) {
this.portNumber = portNumber;
}
public String getServerName() {
return serverName;
}
public void setServerName(final String serverName) {
this.serverName = serverName;
}
public String getUsername() {
return username;
}
public void setUsername(final String username) {
this.username = username;
}
public String getDriverName() {
return driverName;
}
public void setDriverName(final String driverName) {
this.driverName = driverName;
}
public String getJNDIName(){
return this.mjndiName;
}
public Object CreateDataSource(final ComponentContext componentContext,
final String jndiname, final EndpointBean epb, final String XAEnabled) throws Exception {
dbConnectionInfo = epb.getDBInfo();
final String dbURL = dbConnectionInfo.getDbUrl();
final String driverClass = dbConnectionInfo.getDriverName();
dbConnectionInfo.buildConnectionInfo(dbURL);
dbConnectionInfo.getDataBaseName(dbURL, null, null);
final String dbName = dbConnectionInfo.getDataBaseName(dbURL, null, null);
final DataBases dataBases = DataBases.valueOf(dbName);
dataBases.setDBConnectionInfo(dbConnectionInfo);
Object objDataSource = dataBases.buildDataSource();
this.mjndiName = dataBases.createAndBindJNDIDS(componentContext,objDataSource,jndiname,XAEnabled);
return objDataSource;
}
public String getXAEnabled() {
return XAEnabled;
}
public void setXAEnabled(String enabled) {
XAEnabled = enabled;
}
}

View File

@ -1,301 +0,0 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
* If applicable add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced with
* your own identifying information: Portions Copyright
* [year] [name of copyright owner]
*/
/*
* @(#)DataBases.java
*
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
*
* END_HEADER - DO NOT EDIT
*/
package org.glassfish.openesb.databasebc.model.runtime;
import com.sun.jbi.internationalization.Messages;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jbi.component.ComponentContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.*;
import javax.sql.XADataSource;
public enum DataBases {
DERBY,ORACLE,DB2,SQLSERVER,VSAM,MYSQL;
DBConnectionInfo mdbConnectionInfo = null;
private static final Logger mLogger = Logger.getLogger(DataBases.class.getName());
private static final Messages mMessages = Messages.getMessages(DataBases.class);
public int dbType() {
return ordinal();
}
@Override
public String toString() {
switch (this) {
case DERBY:
return "DERBY";
case ORACLE:
return "ORACLE";
case DB2:
return "DB2";
case SQLSERVER:
return "SQLSERVER";
case VSAM:
return "VSAM";
case MYSQL:
return "MYSQL";
}
return null;
}
public Class getXADataSourceClass() throws ClassNotFoundException {
switch (this) {
case DERBY:
return Class.forName("org.apache.derby.jdbc.ClientXADataSource");
case ORACLE:
return Class.forName("oracle.jdbc.xa.client.OracleXADataSource");
case DB2:
return Class.forName("com.ibm.db2.jdbc.DB2XADataSource");
case SQLSERVER:
return Class.forName("com.ddtek.jdbcx.sqlserver.SQLServerDataSource");
}
return null;
}
public Class getDataSourceClass() throws ClassNotFoundException {
switch (this) {
case DERBY:
return Class.forName("org.apache.derby.jdbc.ClientDataSource");
case ORACLE:
return Class.forName("oracle.jdbc.pool.OracleDataSource");
case DB2:
return Class.forName("com.SeeBeyond.db2.jdbcx.db2.DB2DataSource");
case SQLSERVER:
return Class.forName("com.SeeBeyond.sqlserver.jdbcx.sqlserver.SQLServerDataSource");
}
return null;
}
public Object buildDataSource() throws ClassNotFoundException , Exception{
Class dsClass = null;
if (mdbConnectionInfo.getXAEnabled().equalsIgnoreCase("XATransaction"))
dsClass = getXADataSourceClass();
else
dsClass = getDataSourceClass();
return buildDataSource(dsClass);
}
public Object buildDataSource(final Class dsclass) throws ClassNotFoundException, Exception {
try {
final Object dataSourceInstance = dsclass.newInstance();
final Class[] stringParam = new Class[] {String.class};
final Class[] intParam = new Class[]{int.class};
if (this == DERBY) {
dsclass.getMethod("setServerName", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getServerName() });
dsclass
.getMethod("setPortNumber", new Class[] { int.class })
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getPortNumber() });
dsclass.getMethod("setDatabaseName", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getDatabaseOrSchemaName() });
dsclass.getMethod("setUser", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getUsername() });
dsclass.getMethod("setPassword", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getPassword() });
} else if (this == ORACLE) {
dsclass.getMethod("setURL", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getDbUrl()});
dsclass.getMethod("setUser", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getUsername() });
dsclass.getMethod("setPassword", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getPassword() });
} else if (this == DB2) {
dsclass.getMethod("setServerName", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getServerName()});
dsclass.getMethod("setPortNumber", intParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getPortNumber()});
dsclass.getMethod("setDatabaseName", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getDatabaseOrSchemaName()});
dsclass.getMethod("setUser", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getUsername() });
dsclass.getMethod("setPassword", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getPassword() });
} else if (this == SQLSERVER) {
dsclass.getMethod("setServerName", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getServerName()});
dsclass.getMethod("setPortNumber", intParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getPortNumber()});
dsclass.getMethod("setDatabaseName", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getDatabaseOrSchemaName()});
dsclass.getMethod("setUser", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getUsername() });
dsclass.getMethod("setPassword", stringParam)
.invoke(dataSourceInstance,
new Object[] { mdbConnectionInfo.getPassword() });
}
return dataSourceInstance;
} catch (final IllegalAccessException iae) {
mLogger.log(Level.SEVERE,"Illegal Access Exception While Dealing with Driver class",iae);
} catch (final NoSuchMethodException nsme) {
mLogger.log(Level.SEVERE,"No Such Method Exception While Dealing with Driver class",nsme);
} catch (final InvocationTargetException ite) {
mLogger.log(Level.SEVERE,"Invocation Target Exception While Dealing with Driver class",ite);
} catch (final InstantiationException ie) {
mLogger.log(Level.SEVERE," Exception While Instantiating the Driver class",ie);
}
return null;
}
/*public Object buildXADataSource() {
try {
final Class dsclass = getXADataSourceClass();
final Object dataSourceInstance = dsclass.newInstance();
final Class[] stringParam = new Class[] { String.class };
final Class[] stringParams = new Class[] {String.class,String.class};
if (this == DERBY) {
dsclass.getMethod("setServerName", stringParam)
.invoke(dataSourceInstance,
new Object[] { dbConnectionInfo.getServerName() });
dsclass.getMethod("setPortNumber", new Class[] { int.class })
.invoke(dataSourceInstance,
new Object[] { dbConnectionInfo.getPortNumber() });
dsclass.getMethod("setDatabaseName", stringParam)
.invoke(dataSourceInstance,
new Object[] { dbConnectionInfo.getDatabaseOrSchemaName() });
dsclass.getMethod("setUser", stringParam)
.invoke(dataSourceInstance,
new Object[] { dbConnectionInfo.getUsername() });
dsclass.getMethod("setPassword", stringParam)
.invoke(dataSourceInstance,
new Object[] { dbConnectionInfo.getPassword() });
} else if (this == ORACLE) {
dsclass.getMethod("setURL", stringParam).invoke(dataSourceInstance,
new Object[] { dbConnectionInfo.getDbUrl()});
dsclass.getMethod("setUser", stringParam)
.invoke(dataSourceInstance,
new Object[] { dbConnectionInfo.getUsername() });
dsclass.getMethod("setPassword", stringParam)
.invoke(dataSourceInstance,
new Object[] { dbConnectionInfo.getPassword() });
}
return dataSourceInstance;
} catch (final ClassNotFoundException cnfe) {
cnfe.getMessage();
} catch (final IllegalAccessException iae) {
} catch (final NoSuchMethodException nsme) {
} catch (final InvocationTargetException ite) {
} catch (final InstantiationException ie) {
}
return null;
}
*/
public void setDBConnectionInfo(final DBConnectionInfo dbConnectionInfo) {
this.mdbConnectionInfo = dbConnectionInfo;
}
public DataBases getValue(final String value) {
if (value.equalsIgnoreCase("DERBY")) {
return DERBY;
} else if (value.equalsIgnoreCase("ORACLE")) {
return ORACLE;
} else if (value.equalsIgnoreCase("VSAM")) {
return VSAM;
} else if (value.equalsIgnoreCase("DB2")) {
return DB2;
} else if (value.equalsIgnoreCase("SQLSERVER")) {
return SQLSERVER;
} else if (value.equalsIgnoreCase("MYSQL")) {
return MYSQL;
} else {
return null;
}
}
public DatabaseModel getDatabaseModel() {
switch (this) {
case DERBY:
return DerbyDataAccess.getInstance();
case ORACLE:
return OracleDataAccess.getInstance();
case DB2:
return Db2DataAccess.getInstance();
case SQLSERVER:
return SqlServerDataAccess.getInstance();
}
return DatabaseModelImpl.getInstance();
}
public String createAndBindJNDIDS(final ComponentContext componentContext,
Object datasource, final String jndiname, final String xaEnabled)
throws NamingException {
final InitialContext namingContext = componentContext.getNamingContext();
if(mdbConnectionInfo.getXAEnabled().equalsIgnoreCase("XATransaction")){
datasource =(XADataSource)datasource;
}else{
datasource =(DataSource)datasource;
}
if(lookup(jndiname,namingContext)){
namingContext.bind(jndiname, datasource);
}
return jndiname;
}
public boolean lookup(final String jndiname,final InitialContext namingContext) throws NamingException{
try{
namingContext.lookup(jndiname);
}catch(javax.naming.NameNotFoundException e){
return true;
}
return false;
}
}

View File

@ -36,10 +36,5 @@ package org.glassfish.openesb.databasebc.model.runtime;
*
*/
public interface DatabaseModel {
public String createQualifiedQuery(String souTable, String tarTable,
String flagName, String MarkColumnValue, String pkName, String Operation,String FlagColumnType)
throws Exception;
public String generateSelectQuery(String query, String tableName)
throws Exception;
public String generateSelectQuery(String tableName, int rowCount);
}

View File

@ -44,219 +44,15 @@ public class DatabaseModelImpl implements DatabaseModel {
private static final Logger mLogger = Messages.getLogger(DatabaseModelImpl.class);
public DatabaseModelImpl(){
}
private static final DatabaseModelImpl instance = new DatabaseModelImpl();
public static final DatabaseModelImpl getInstance(){
return instance;
}
//@Override
public String createQualifiedQuery(final String souTable, final String tarTable,
final String flagName, final String markcolumnValue, final String pkName, final String operation,
final String FlagColumnType)
throws Exception {
String Sql = null;
try {
if (operation.equals("UPDATE")) {
if(FlagColumnType.equalsIgnoreCase("LONGVARCHAR") || FlagColumnType.equalsIgnoreCase("CHAR")
|| FlagColumnType.equalsIgnoreCase("VARCHAR")){
Sql = "update " + souTable + " set " + flagName + " = " +
"'"+markcolumnValue+"'"+ " where " + pkName;
}else{
Sql = "update " + souTable + " set " + flagName + " = " +
markcolumnValue + " where " + pkName;
}
} else if (operation.equals("DELETE")) {
Sql = "delete from " + souTable + " where " + pkName;
} else if (operation.equals("INSERT")) {
Sql = "insert into " + tarTable + " select * from " + souTable +
" where " + pkName;
} else if (operation.equals("SELECT")) {
Sql = "select * from " + souTable;
}
} catch (final Exception e) {
mLogger.log(Level.SEVERE,mMessages.getString("Derby_Create_Query"),e);
throw new Exception(mMessages.getString("Derby_Create_Query"), e);
}
return Sql;
return instance;
}
//@Override
public String generateSelectQuery(final String selectSql, final String TableName)
throws Exception {
String Sql = null;
if( (selectSql == null)
|| selectSql.trim().equals("") ) {
Sql = "select * from " + TableName;
return Sql;
} else {
return selectSql;
}
public String generateSelectQuery(final String TableName, final int rowCount) {
return "SELECT * FROM " + TableName + " WHERE $WHERE FOR UPDATE";
}
}
//public class DerbyDataAccess implements DatabaseModel{
// private String mtabName = null;
// private String mtrigName = null;
// private TableColumn[] mcolumns = null;
// private String mSchemaName = null;
// private String mMarkColumnName = null;
// private String mstageFlag = null;
// private static final Messages mMessages = Messages.getMessages(DerbyDataAccess.class);
// private static Logger mLogger = Messages.getLogger(DerbyDataAccess.class);
/**
* @param souTable
* @param schemaName
* @param flagName
*/
// public void init(Table souTable,String schemaName,String flagName,String stageFlag){
// mMarkColumnName = flagName;
// mstageFlag = stageFlag;
// setTableName(souTable.getName());
// setTriggerName(souTable.getName());
// mcolumns = souTable.getColumns();
// this.mSchemaName = schemaName;
// }
/**
* @throws Exception
*/
// public String createTableQuery() throws Exception {
// StringBuffer sb = new StringBuffer();
// sb.append("create table ");
// sb.append(" ");
// sb.append(getTableName());
// sb.append(" ");
// sb.append("(");
// for (int i = 0; i < this.mcolumns.length; i++) {
// sb.append("\"" + this.mcolumns[i].getName() + "\"");
// sb.append(" ");
// sb.append(this.mcolumns[i].getSqlType());
// if ((this.mcolumns[i].getNumericPrecision() != 0)
// && ((this.mcolumns[i].getSqlType())
// .equalsIgnoreCase("VARCHAR"))) {
// sb.append("(");
// sb.append(this.mcolumns[i].getNumericPrecision());
// sb.append(")");
// }
// sb.append(" ");
// if (this.mcolumns[i].getIsPrimaryKey()) {
// sb.append("primary key");
// }
// sb.append(" ");
// if (this.mcolumns[i].getIsNullable()) {
// sb.append("not null");
// }
// if ((i == (this.mcolumns.length - 1)))
// sb.append(")");
// else
// sb.append(",");
// }
// mLogger.log(Level.INFO, mMessages.getString("Derby_Create_SQL") + sb.toString());
// return sb.toString();
// }
/**
* @param source
* @throws Exception
*/
// public String createTriggerQuery(String source) throws Exception {
// StringBuffer sb = new StringBuffer();
// sb.append("CREATE TRIGGER ");
// sb.append(" ");
// sb.append(getTriggerName());
// sb.append(" ");
// sb.append("AFTER INSERT ON");
// sb.append(" ");
// sb.append(source);
// sb.append(" ");
// sb.append("REFERENCING NEW AS UPDATEDROW FOR EACH ROW MODE DB2SQL");
// sb.append(" ");
// sb.append("INSERT INTO");
// sb.append(" ");
// sb.append(getTableName());
// sb.append(" ");
// sb.append("VALUES");
// sb.append(" ");
// sb.append("(");
// for (int i = 0; i < this.mcolumns.length; i++) {
// sb.append("UPDATEDROW.");
// sb.append("\"");
// sb.append(this.mcolumns[i].getName());
// sb.append("\"");
// if ((i == (this.mcolumns.length - 1)))
// sb.append(")");
// else
// sb.append(",");
// }
// mLogger.log(Level.INFO, mMessages.getString("Derby_Create_SQL") + sb.toString());
// return sb.toString();
// }
//
// public String getTableName(){
// return (getSchemaName()+"."+this.mtabName);
// }
//
// public String getTriggerName(){
// return (getSchemaName()+"."+this.mtrigName);
// }
//
// public String getSchemaName(){
// return "\""+this.mSchemaName+"\"";
// }
//
// public void setTableName(String tabSource){
// mLogger.log(Level.INFO, "Flag Name" + mMarkColumnName);
// if(mMarkColumnName != null && mMarkColumnName != "" && mstageFlag.equalsIgnoreCase("Yes"))
// this.mtabName = "\""+tabSource+"_jdbc_StaggingTable"+"\"";
// else
// this.mtabName = "\""+tabSource+"\"";
// }
//
// public void setTriggerName(String trigName){
// if(mMarkColumnName != null && mMarkColumnName != "" && mstageFlag.equalsIgnoreCase("Yes"))
// this.mtrigName = "\""+trigName+"_jdbc_staggingTrigger"+"\"";
// else
// this.mtabName = "\""+trigName+"\"";
// }
/**
* @param souTable
* @param flagName
* @param pkName
* @param operation
* @throws Exception
*/
// public String createQualifiedQuery(String souTable, String flagName,
// String pkName, String operation) throws Exception {
// String Sql = null;
//
// try {
// if (operation.equals("UPDATE")) {
// Sql = "update " + souTable + " set " + flagName + " = 0 where"
// + souTable + "." + pkName;
// } else if (operation.equals("DELETE")) {
// Sql = "delete from " + souTable + " where " + souTable + "."
// + pkName ;
// } else if (operation.equals("INSERT")) {
// Sql = "insert into " + "\"" + souTable + "\"" + "." + "\""
// + flagName + "_jdbc_StaggingTable" + "\""
// + " select * from " + pkName;
// }
// } catch (Exception e) {
// throw new Exception( mMessages.getString("Derby_Create_Query"), e);
// }
// return Sql;
// }
//}

View File

@ -43,222 +43,18 @@ import java.util.logging.Logger;
public class Db2DataAccess implements DatabaseModel {
private static final Messages mMessages = Messages.getMessages(Db2DataAccess.class);
private static final Logger mLogger = Messages.getLogger(Db2DataAccess.class);
private Db2DataAccess(){
}
private static final Db2DataAccess instance = new Db2DataAccess();
private Db2DataAccess(){
}
public static final Db2DataAccess getInstance(){
return instance;
return instance;
}
//@Override
public String createQualifiedQuery(final String souTable, final String tarTable,
final String flagName, final String markcolumnValue, final String pkName, final String operation,
final String FlagColumnType)
throws Exception {
String Sql = null;
try {
if (operation.equals("UPDATE")) {
if(FlagColumnType.equalsIgnoreCase("LONGVARCHAR") || FlagColumnType.equalsIgnoreCase("CHAR")
|| FlagColumnType.equalsIgnoreCase("VARCHAR")){
Sql = "update " + souTable + " set " + flagName + " = " +
"'"+markcolumnValue+"'"+ " where " + souTable + "." + pkName;
}else{
Sql = "update " + souTable + " set " + flagName + " = " +
markcolumnValue + " where " + souTable + "." + pkName;
}
} else if (operation.equals("DELETE")) {
Sql = "delete from " + souTable + " where " + souTable + "." +
pkName;
} else if (operation.equals("INSERT")) {
Sql = "insert into " + tarTable + " select * from " + souTable +
" where " + souTable + "." + pkName;
} else if (operation.equals("SELECT")) {
Sql = "select * from " + "\"" + souTable + "\"";
}
} catch (final Exception e) {
mLogger.log(Level.SEVERE,mMessages.getString("Derby_Create_Query"),e);
throw new Exception(Db2DataAccess.mMessages.getString("Derby_Create_Query"), e);
}
return Sql;
}
//@Override
public String generateSelectQuery(final String selectSql, final String TableName)
throws Exception {
String Sql = null;
if( (selectSql == null)
|| selectSql.trim().equals("") ) {
Sql = "select * from " + TableName;
return Sql;
} else {
return selectSql;
}
public String generateSelectQuery(final String tableName, final int rowCount) {
return "SELECT * FROM " + tableName + " WHERE $WHERE" +
(rowCount > 0 ? " FETCH FIRST "+rowCount+" ROWS ONLY" : "") + " FOR UPDATE";
}
}
//public class Db2DataAccess implements DatabaseModel{
// private String mtabName = null;
// private String mtrigName = null;
// private TableColumn[] mcolumns = null;
// private String mSchemaName = null;
// private String mMarkColumnName = null;
// private String mstageFlag = null;
// private static final Messages mMessages = Messages.getMessages(Db2DataAccess.class);
// private static Logger mLogger = Messages.getLogger(Db2DataAccess.class);
/**
* @param souTable
* @param schemaName
* @param flagName
*/
// public void init(Table souTable,String schemaName,String flagName,String stageFlag){
// mMarkColumnName = flagName;
// mstageFlag = stageFlag;
// setTableName(souTable.getName());
// setTriggerName(souTable.getName());
// mcolumns = souTable.getColumns();
// this.mSchemaName = schemaName;
// }
/**
* @throws Exception
*/
// public String createTableQuery() throws Exception {
// StringBuffer sb = new StringBuffer();
// sb.append("create table ");
// sb.append(" ");
// sb.append(getTableName());
// sb.append(" ");
// sb.append("(");
// for (int i = 0; i < this.mcolumns.length; i++) {
// sb.append("\"" + this.mcolumns[i].getName() + "\"");
// sb.append(" ");
// sb.append(this.mcolumns[i].getSqlType());
// if ((this.mcolumns[i].getNumericPrecision() != 0)
// && ((this.mcolumns[i].getSqlType())
// .equalsIgnoreCase("VARCHAR"))) {
// sb.append("(");
// sb.append(this.mcolumns[i].getNumericPrecision());
// sb.append(")");
// }
// sb.append(" ");
// if (this.mcolumns[i].getIsPrimaryKey()) {
// sb.append("primary key");
// }
// sb.append(" ");
// if (this.mcolumns[i].getIsNullable()) {
// sb.append("not null");
// }
// if ((i == (this.mcolumns.length - 1)))
// sb.append(")");
// else
// sb.append(",");
// }
// mLogger.log(Level.INFO, mMessages.getString("Derby_Create_SQL") + sb.toString());
// return sb.toString();
// }
/**
* @param source
* @throws Exception
*/
// public String createTriggerQuery(String source) throws Exception {
// StringBuffer sb = new StringBuffer();
// sb.append("CREATE TRIGGER ");
// sb.append(" ");
// sb.append