BIRT运行采用自己的connection

    技术2022-05-11  12

     注:本文实现的思路不是原创,思路原文来自:

    http://birtworld.blogspot.com/2005/12/using-supplied-connection-with-birt.html

     

       本文将介绍BIRT2.2 详细的扩展与配置:

     

       在ECLIPSE中新建一个工程 new-> Bussiness Intelligence Report Tools -> Web Project 名字:MyBirt

    并设置好服务器信息(本文选用Tomcat5.5、JDK1.5)。

       建好工程以后,需要添家JDBC驱动程序到报表引擎中,本例连接ORACLE,因此将ORACLE的JDBC驱动包复制到 工程站点下的 /WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_xxxxxxx/drivers目录下。

       接下来就是继承OdaJdbcDriver类了,再此之前需要在ClassPath中Add oda-jdbc.jar 和 org.eclipse.datatools.connectivity.oda_xxxxxxxxxxxx.jar这两个包,前者位于上边提到的drivers路径的上一级,后着则在plugins下。 新建一个Class:MyJdbcDriver,指定到某个包路径下,代码如下:

    Java代码 package com.wenmin.birt.data.oda.jdbc;     import org.eclipse.birt.report.data.oda.jdbc.OdaJdbcDriver;   import java.sql.Connection;   import java.util.HashMap;   import java.util.Properties;     import org.eclipse.birt.report.data.oda.jdbc.*;   import org.eclipse.datatools.connectivity.oda.IConnection;   import org.eclipse.datatools.connectivity.oda.OdaException;     public class MyJdbcDriver extends OdaJdbcDriver    {         private Connection passedInConnection;       public static final String DATASOURCE_KEY_CONNECTION = "com.wenmin.birt.data.odb.jdbc.MyJdbcDriver";              public void setAppContext( Object context ) throws OdaException       {           HashMap ctx = (HashMap)context;           passedInConnection = (java.sql.Connection)ctx.get(DATASOURCE_KEY_CONNECTION);              }                 public IConnection getConnection(String connectionClassName) throws OdaException       {           if( passedInConnection != null){               return new appContextDBConnection();           }else{               return new org.eclipse.birt.report.data.oda.jdbc.Connection();           }       }                  private class appContextDBConnection extends org.eclipse.birt.report.data.oda.jdbc.Connection       {                                 public void open(Properties connProperties) throws OdaException           {               super.jdbcConn = passedInConnection;                                  }                      public void close( ) throws OdaException           {               if ( jdbcConn == null )               {                   return;               }               //should have call to return connection to the pool               jdbcConn = null;                                   }                                                       }   }   package com.wenmin.birt.data.oda.jdbc; import org.eclipse.birt.report.data.oda.jdbc.OdaJdbcDriver; import java.sql.Connection; import java.util.HashMap; import java.util.Properties; import org.eclipse.birt.report.data.oda.jdbc.*; import org.eclipse.datatools.connectivity.oda.IConnection; import org.eclipse.datatools.connectivity.oda.OdaException; public class MyJdbcDriver extends OdaJdbcDriver { private Connection passedInConnection; public static final String DATASOURCE_KEY_CONNECTION = "com.wenmin.birt.data.odb.jdbc.MyJdbcDriver"; public void setAppContext( Object context ) throws OdaException { HashMap ctx = (HashMap)context; passedInConnection = (java.sql.Connection)ctx.get(DATASOURCE_KEY_CONNECTION); } public IConnection getConnection(String connectionClassName) throws OdaException { if( passedInConnection != null){ return new appContextDBConnection(); }else{ return new org.eclipse.birt.report.data.oda.jdbc.Connection(); } } private class appContextDBConnection extends org.eclipse.birt.report.data.oda.jdbc.Connection { public void open(Properties connProperties) throws OdaException { super.jdbcConn = passedInConnection; } public void close( ) throws OdaException { if ( jdbcConn == null ) { return; } //should have call to return connection to the pool jdbcConn = null; } } }

     

    OK,接下来我们来打个包,利用ECLIPSE EXPORT一个 jar包,(“怎么做?”,“。。。拖下去,暴头!”)。

    本例导出包名字为:cst_driver.jar,拷贝到/WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_xxxxxxx/目录下。

          最后就是修改配置文件,第一个需要改的文件plugin.xml位于 /WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_xxxxxxx/目录下

    找到如下节点:

    Xml代码 ...   <extension           point="org.eclipse.datatools.connectivity.oda.dataSource">        <dataSource              odaVersion="3.1"              driverClass="org.eclipse.birt.report.data.oda.jdbc.OdaJdbcDriver"              defaultDisplayName="
    转载请注明原文地址: https://ibbs.8miu.com/read-700336.html

    最新回复(0)