verify SingleConnectionDataSource – sybase

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

 

import javax.sql.DataSource;

 

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.springframework.beans.BeansException;

import org.springframework.context.support.AbstractApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import org.springframework.jdbc.core.JdbcTemplate;

import org.springframework.jdbc.core.RowMapper;

import org.springframework.jdbc.datasource.SingleConnectionDataSource;

 

/**

*

 * @author btan

*

 */

public class SybaseUtil {

      private static final Log log = LogFactory

                  .getLog(SybaseUtil.class.getName());

 

      static private JdbcTemplate singleConnectionHandle;

      static private JdbcTemplate handle;

 

      /**

      * @param args

      */

      public static void main(String[] args) {

            showServer();

            log(“abc ‘d’ “);

      }

 

      static public JdbcTemplate getHandle() {

            if (singleConnectionHandle != null && handle != null)

                  return handle;

            AbstractApplicationContext context = TradeEngineMain.getContext();

            if (context == null) {

                  try {

                        context = new ClassPathXmlApplicationContext(

                                    “applicationContext.xml”);

                  } catch (BeansException e) {

                        e.printStackTrace();

                        context = new ClassPathXmlApplicationContext(“dataSources.xml”);

                  }

            }

            DataSource dataSource = (DataSource) context.getBean(“mtsDataSource”);

            handle = new GenericProcedureCaller(dataSource);

 

            try {

                  dataSource = new SingleConnectionDataSource(

                              dataSource.getConnection(), true);

            } catch (SQLException e) {

                  e.printStackTrace();

                  throw new RuntimeException(e);

            }

            JdbcTemplate jt = new JdbcTemplate(dataSource);

            jt = new GenericProcedureCaller(jt);

            singleConnectionHandle = jt;

            return handle;

      }

 

      static public JdbcTemplate getSingleHandle() {

            getHandle();

            return singleConnectionHandle;

      }

 

      static public String showServer() {

            JdbcTemplate handle = getHandle();

            StringBuilder ret = new StringBuilder(“nnt == SybaseSybase Details ==”);

            ret.append(“nt ” + handle.queryForObject(“select @@servername + ‘ <– ' + @@version", String.class));

            ret.append(“nt ” + getConnectionDetails());

            ret.append(“nt ” + getSpidDetails());

            ret.append(“nn”);

            log.debug(ret);

            return ret.toString();

      }

      static private String getSpidDetails() {

            int spid = getSingleHandle().queryForInt(“sel” +

                        “ect @@spid”);

            String sql = String.format(“sp_who ‘%s'”, spid);

            String ret =”spid=” + spid + ” “;

            ret += getSingleHandle().queryForObject(sql, new RowMapper() {;

                  public String mapRow(ResultSet rs, int rowNum) throws SQLException {

                        return rs.getString(“loginame”) + ” ” + rs.getString(“hostname”);

                  }

            });

            System.err.println(ret);

            return ret;

      }

 

      static private String getConnectionDetails() {

            Connection conn3 = null;

            try {

                  conn3 = getSingleHandle().getDataSource().getConnection();

            } catch (SQLException e) {

                  throw new RuntimeException(e);

            }

            String ret = System.identityHashCode(conn3) +”=identityHash ” + conn3;

            System.err.println(ret);

            return ret;

      }

 

      static public void log(String s) {

            if (s == null || s.trim().isEmpty())

                  return;

            s = s.replaceAll(“‘”, “”);

            String insert = String.format(“insert snoop (charp1) select ‘%s'”, s);

            getSingleHandle().update(insert);

            showServer();

      }

}


This message w/attachments (message) is intended solely for the use of the intended recipient(s) and may contain information that is privileged, confidential or proprietary. If you are not an intended recipient, please notify the sender, and then please delete and destroy all copies and attachments, and be advised that any review or dissemination of, or the taking of any action in reliance on, the information contained in or attached to this message is prohibited.
Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Sender. Subject to applicable law, Sender may intercept, monitor, review and retain e-communications (EC) traveling through its networks/systems and may produce any such EC to regulators, law enforcement, in litigation and as required by law.
The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or free of errors or viruses.

References to “Sender” are references to any subsidiary of Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this EC may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link:
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you consent to the foregoing.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s