⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postgresdatasource.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
字号:
//// PostgresDataSource.java//// jmettraux@openwfe.org//// generated with // jtmpl 1.0.04 31.10.2002 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.sql.ds;import openwfe.org.MapUtils;import openwfe.org.ServiceException;import openwfe.org.ApplicationContext;import org.postgresql.jdbc3.Jdbc3SimpleDataSource;/** * no comment * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Date: 2005/05/17 16:40:16 $ * <br>$Id: PostgresDataSource.java,v 1.6 2005/05/17 16:40:16 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public class PostgresDataSource    extends OwfeDataSource{    private final static org.apache.log4j.Logger log = org.apache.log4j.Logger        .getLogger(PostgresDataSource.class.getName());    //    // CONSTANTS (definitions)    /**     * This datasource usually requires a 'user' attribute to be defined.     */    public final static String P_USER = "user";    /**     * This datasource usually requires a 'pass' attribute to be defined.     */    public final static String P_PASS = "pass";    private final static String CON_VALIDITY_SQL_CODE        = "select 1";    //    // FIELDS    //    // CONSTRUCTORS    public void init         (final String serviceName,          final ApplicationContext context,          final java.util.Map serviceParams)    throws         ServiceException    {        super.init(serviceName, context, serviceParams);        final String url = MapUtils.getMandatoryString(getParams(), P_URL);        final String user = MapUtils.getMandatoryString(getParams(), P_USER);        final String pass = MapUtils.getMandatoryString(getParams(), P_PASS);        final Jdbc3SimpleDataSource ds = new Jdbc3SimpleDataSource();        setUpDataSource(ds, url, user, pass);        setDataSource(ds);    }    //    // METHODS    protected void setUpDataSource         (final Jdbc3SimpleDataSource source,          String url,          final String user,         final String pass)    throws         ServiceException    {        source.setUser(user);        source.setPassword(pass);        if ( ! url.startsWith("jdbc:postgresql:"))        {            throw new ServiceException                ("url '"+url+"' should begin with 'jdbc:postgresql:'");        }        url = url.substring(16);        if ( ! url.startsWith("//"))        {            //            // database directly expressed            log.debug("DatabaseName >"+url+"<");            source.setDatabaseName(url);            return;        }        url = url.substring(2); // skip '//'        String[] ss = url.split("/");        String hostAndPort = ss[0];        String databaseName = ss[1];        log.debug("DatabaseName >"+databaseName+"<");        source.setDatabaseName(databaseName);        if (hostAndPort.indexOf(":") > -1)        {            ss = hostAndPort.split(":");            log.debug("ServerName >"+ss[0]+"<");            source.setServerName(ss[0]);            int port = -1;            try            {                port = Integer.parseInt(ss[1]);            }            catch (NumberFormatException nfe)            {                throw new ServiceException                    ("invalid port number '"+ss[1]+"'", nfe);            }            log.debug("PortNumber >"+port+"<");            source.setPortNumber(port);        }        else        {            log.debug("ServerName >"+hostAndPort+"<");            source.setServerName(hostAndPort);        }    }    //    // METHODS from OwfeDataSource    /**     * This method when implemented has to return a piece of SQL code     * that will be run against any database for connection     * validity checking.     */    public String getConnectionValiditySqlCode ()    {        return CON_VALIDITY_SQL_CODE;    }    //    // METHODS from Service}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -