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

📄 dummydatasource.java

📁 Mandarax是一个规则引擎的纯Java实现。它支持多类型的事实和基于反映的规则
💻 JAVA
字号:
/*
 * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package test.org.mandarax.zkb;

import java.io.PrintWriter;
import java.sql.SQLException;

/**
 * "Simulation" of a data source, not functional but with some properties a real
 * implementaton probably has.
 * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
 * @version 3.4 <7 March 05>
 * @since 2.2
 */
public class DummyDataSource implements javax.sql.DataSource,java.io.Serializable  {

    private Class       driver        = null;
    private String      connectString = "";
    private String      userName      = "";
    private String      password      = "";
    private int         loginTimeout  = 1000;
    private PrintWriter logWriter     = null;

    /**
     * Constructor.
     */
    public DummyDataSource() {
        super ();
        try {
        	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
        catch (Exception x) {
        	x.printStackTrace();
        }	
    }

    /**
     * Get a database connection.
     * @return a database connection
     */
    public java.sql.Connection getConnection() throws java.sql.SQLException {
        return java.sql.DriverManager.getConnection("jdbc:odbc:test");
    }

    /**
     * Get a database connection.
     * @return a database connection
     * @param userName a user name
     * @param password a password
     */
    public java.sql.Connection getConnection(String userName, String password) throws java.sql.SQLException {
        return java.sql.DriverManager.getConnection("jdbc:odbc:test",userName,password);
    }

    /**
     * Get a connect string.
     * @return a string
     */
    public java.lang.String getConnectString() {
        return connectString;
    }

    /**
     * Get tehn login toimeout.
     */
    public int getLoginTimeout() throws SQLException {
        return loginTimeout;
    }

    /**
     * Get the log writer.
     */
    public PrintWriter getLogWriter() throws SQLException {
        return logWriter;
    }

    /**
     * Get the password.
     * @return the database password
     */
    public String getPassword() {
        return password;
    }

    /**
     * Get the user name for the database
     * @return the user name
     */
    public String getUserName() {
        return userName;
    }

    /**
     * Set the connect string.
     * @param newConnectString java.lang.String
     */
    public void setConnectString(java.lang.String newConnectString) {
        connectString = newConnectString;
    }

    /**
     * Set the login timeout.
     * @param millis the time in milli seconds
     */
    public void setLoginTimeout(int millis) throws SQLException {
        loginTimeout = millis;
    }

    /**
     * Set the log writer.
     * @param writer a writer
     */
    public void setLogWriter(PrintWriter writer) throws SQLException {
        logWriter = writer;
    }

    /**
     * Set a new password.
     * @param newPassword a password
     */
    public void setPassword(String newPassword) {
        password = newPassword;
    }

    /**
     * Set a user name.
     * @param newUserName the user name
     */
    public void setUserName(String newUserName) {
        userName = newUserName;
    }

    /**
     * Get a database driver class.
     * @return a database driver
     */
    public Class getDriver() {
        return driver;
    }

    /**
     * Set a new driver class.
     * @param newDriver a jdbc driver class
     */
    public void setDriver(Class newDriver) {
        driver = newDriver;
    }

    /**
     * Convert the object to a string.
     * @return a string representation of this object
     */
    public String toString() {
        return "data source dummy implementation for XKB testing only";
    }

    /**
     * Compares objects.
     * @return a boolean
     * @param obj another object
     */
    public boolean equals(Object obj) {
        if(obj instanceof DummyDataSource) {
            DummyDataSource ds     = (DummyDataSource) obj;
            boolean         result = true;

            result = result && (driver == ds.driver);
            result = result && (loginTimeout == ds.loginTimeout);
            result = result && ((connectString == null)
                                ? ds.connectString == null
                                : connectString.equals (ds.connectString));
            result = result && ((userName == null)
                                ? ds.userName == null
                                : userName.equals (ds.userName));
            result = result && ((password == null)
                                ? ds.password == null
                                : password.equals (ds.password));
            result = result && ((logWriter == null)
                                ? ds.logWriter == null
                                : logWriter.equals (ds.logWriter));

            return result;
        }

        return false;
    }

    /**
     * Get the hash code of the object.
     * @return a hash code
     */
    public int hashCode() {
        return(connectString == null)
              ? 0
              : connectString.hashCode ();
    }
}

⌨️ 快捷键说明

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