'작렬허접코딩/자바'에 해당되는 글 5건

  1. [2009/11/19] WebLogic Connection Pool 사용하기
  2. [2008/12/11] RMIC 음... (3)
  3. [2008/04/04] Jakarta common-dbcp + oracle9i 사용시

WebLogic Connection Pool 사용하기

[작렬허접코딩/자바]

웹로직 짜증난다.
T3 프로토콜 때문에 다른 Servlet Container에서 사용중인 DB Connection 및 RMI 통신 부분을 사용할 수 없게 되었다.

package kr.co.jinjin.jjxweb.sql;

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.naming.*;

import kr.co.jinjin.jjxweb.conf.*;

public class WebLogicDBConnection extends AbstractDBConnection {
 private JJXWebConf xconf = null;
 private Properties poolProp = null;

 public Connection getPooledConnection(String poolName) throws Exception {
  synchronized(WebLogicDBConnection.class) {
   if(poolProp==null) {
    poolProp = new Properties();
    try {
     loadProperties();
    } catch(Exception ex) {
     ex.printStackTrace();
    }
   }
  }
 
  Connection conn = null;
  Context ctx = null;
 
  Hashtable ht = new Hashtable();
  ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  // Load t3 protocol url from properties file
  //  ex) t3://127.0.0.1:7001
  ht.put(Context.PROVIDER_URL, poolProp.getProperty(poolName));
 
  ctx = new InitialContext(ht);
  javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup(poolName);
  conn = ds.getConnection();

  return conn;
 }
 
 /**
  * Load weblogic.properties
  * @throws Exception
  */
 private void loadProperties() throws Exception {
  boolean debug = false;
  String confdir = null;
  String filename = "weblogic.properties";
  File curp = null;
  FileInputStream fis = null;
 
  try {
   xconf = JJXWebConf.getInstance();
  } catch(Exception ex) {}
  debug = new Boolean(xconf.get("debug")).booleanValue();
 
  confdir = xconf.get("homedir") + "conf" + File.separator;
  curp = new File(confdir + filename);
  if(!curp.exists())
   throw new Exception("Configuration file '/WEB-INF/conf/weblogic.properties' not found");
 
  if(debug) {
   System.out.println("# WebLogicDBConnection.loadProperties()");
   System.out.println("# Properties FileName : " + curp.getCanonicalPath());
  }
 
  try {
   //fis = new FileInputStream(curp);
   fis = new FileInputStream(curp.getCanonicalPath());
   poolProp.load(fis);
   
   if(debug)
    poolProp.list(System.out);
  } catch(Exception ex) {
   throw new Exception(ex);
  } finally {
   try {
    //if(fis!=null) fis.close();
   } catch(Exception ex) {}
  }
 }
 
}

다음은 weblogic.properties
jjxweb=t3://127.0.0.1:7011

이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/11/19 23:28 2009/11/19 23:28

RMIC 음...

[작렬허접코딩/자바]

오랜만에 RMI를 할려니 기억이 가물가물(ㅜ..ㅜ)

현재 jdk 1.5를 사용하고 있는데 rmic를 통해서 컴파일 하니 스텁만 생기고 스켈레톤이 생기지 않는다.
이게 없어도 사용할 수 있단 말인가?(정확하게 모름)
옵션을 뒤져보니 대충 다음과 같다.

D:\APP\wwwroot_jjxweb\jjxweb>rmic
Usage: rmic <options> <class names>

where <options> includes:
  -keep          Do not delete intermediate generated source files
  -keepgenerated (same as "-keep")
  -v1.1          Create stubs/skeletons for 1.1 stub protocol version
  -vcompat       Create stubs/skeletons compatible with both
                           1.1 and 1.2 stub protocol versions
  -v1.2          (default) Create stubs for 1.2 stub protocol version only
  -iiop          Create stubs for IIOP. When present, <options> also includes:

                   -always           Create stubs even when they appear current
                   -alwaysgenerate   (same as "-always")
                   -nolocalstubs     Do not create stubs optimized for same proc
ess

  -idl           Create IDL. When present, <options> also includes:

                   -noValueMethods   Do not generate methods for valuetypes
                   -always           Create IDL even when it appears current
                   -alwaysgenerate   (same as "-always")

  -g             Generate debugging info
  -nowarn        Generate no warnings
  -nowrite       Do not write compiled classes to the file system
  -verbose       Output messages about what the compiler is doing
  -classpath <path>      Specify where to find input class files
  -bootclasspath <path>  Override location of bootstrap class files
  -extdirs <path>        Override location of installed extensions
  -d <directory>         Specify where to place generated class files
  -J<runtime flag>       Pass argument to the java interpreter

그래서 다음과 같이 실행하니 스텁과 스켈레톤이 잘 생긴다.
rmic -vcompat -verbose -classpath .; package.WebReportFactoryImpl

이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/12/11 18:27 2008/12/11 18:27
TAG. ,

Jakarta common-dbcp + oracle9i 사용시

[작렬허접코딩/자바]
문제점이 있다.

common-dbcp + 오라클 9i 이상을 함께 사용할 때 Oracle의 CLOB 컬럼을 읽어올 때 문제가 발생한다.
에러 내용은 다음과 같다.

org.apache.tomcat.dbcp.dbcp.DelegatingResultSet
        at kr.co.jinjin.jjxweb.sql.DBActor.getCLOB(Unknown Source)
        at kr.co.jinjin.jjxweb.BaseJob.readClob(Unknown Source)
        at kr.co.jinjin.jjxweb.Job.doAct(Unknown Source)
        at kr.co.jinjin.servlet.jjxwebservlet.doPost(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
        at java.lang.Thread.run(Thread.java:595)

다음은 8i에서 CLOB를 읽어오기 위해 처리하던 부분이다.
public String getCLOB(String poolName,
   String tableName,
   String clobColumnName,
   String sqlstr) throws Exception {
 
  Connection con = null;
  Statement stmt = null;
  ResultSet rs = null;
  Reader m_reader = null;
  char[] m_buffer = null;
 
  StringBuffer readedStr = null;
  StringBuffer qry = new StringBuffer();
 
  qry.append("SELECT " + clobColumnName + " FROM " + tableName);
  qry.append((!sqlstr.trim().toUpperCase().startsWith("WHERE") ? " WHERE " : " ") + sqlstr);
 
  try {
   con = dbcon.getPooledConnection(poolName);
   stmt = con.createStatement();
   rs = stmt.executeQuery(qry.toString());
   
   if(rs.next()) {
    // 문제 발생시키는 놈 Class Casting이 안된다.
    CLOB clob = ((OracleResultSet)rs).getCLOB(clobColumnName);
   
    m_reader = clob.getCharacterStream();
    readedStr = new StringBuffer();
    m_buffer = new char[BUFFER_LENGTH];
   
    int readedIndex = 0;
    while ((readedIndex = m_reader.read(m_buffer)) != -1)  {
     for (int i=0; i<readedIndex; i++) {
      //System.out.print(buffer[i]);
      readedStr.append(new String(m_buffer, 0, readedIndex));
      m_buffer = new char[BUFFER_LENGTH];
     }
    }
   }
   
  } catch(Exception e) {
   throw new Exception("[Exception] DBActor.getCLOB()  : [" + tableName + "." + clobColumnName + "] " + e.getMessage());
  } finally {
   try {
    dbcon.release(rs, stmt, con);
    if(m_reader != null) m_reader.close();
   } catch(Exception e) {
    e.printStackTrace();
   }
  }
 
  return readedStr.toString();
 }

그럼 어떻게 처리해야 하나?
일반적인 varchar2 컬럼을 읽어오듯이
SELECT NORMAL_COL, CLOB_COL FROM MYTABLE WHERE....
이렇게 읽어오니 모든 데이터가 잘도 읽힌다.
참 환장하겠다.
이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/04/04 22:50 2008/04/04 22:50