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

📄 inputdatadboperator.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/* 
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program 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 General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */ 
 
package eti.bi.alphaminer.patch.standard.operation.operator;


import java.util.Vector;


import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningInputStream;
import com.prudsys.pdm.Input.MiningStoredData;
import com.prudsys.pdm.Input.Relational.MiningSqlSource;
import com.prudsys.pdm.Input.Relational.MiningSqlStream;
import com.prudsys.pdm.Transform.Special.CopyMiningStream;

import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.InputOperator;
import eti.bi.alphaminer.vo.BIData;
import eti.bi.alphaminer.vo.BIObject;
import eti.bi.alphaminer.vo.IBIData;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.exception.SysException;
import eti.bi.util.ValueValidator;

/**
 * @author jyung
 *
 */

public class InputDataDBOperator extends InputOperator {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final String SOURCE_TYPE_ParameterValue = "Source Type";

	private final String ODBC_ParameterValue = "ODBC";

	private final String DB2_ParameterValue = "DB2";

	private final String MYSQL_ParameterValue = "MYSQL";

	private final String ORACLE_ParameterValue = "ORACLE";

	private final String MSSQL_ParameterValue = "MSSQL";

	private final String POSTGRE_ParameterValue = "POSTGRE";

	private final String HOST_ParameterValue = "HOST";

	private final String PORT_ParameterValue = "PORT";

	private final String DSN_ParameterValue = "DSN";

	private final String DBName_ParameterValue = "DB Name";

	private final String url_ParameterValue = "DB url";

	private final String DBUser_ParameterValue = "DB User";

	private final String pwd_ParameterValue = "DB Password";

	private final String dbDriver_ParameterValue = "DB Driver";

	private final String table_ParameterValue = "DB Table";

	private final String query_ParameterValue = "DB Query";
	
	private final String option_ParameterValue = "OPTION";

	/**
	 * Creates an Operator.
	 * @param a_CaseID ID of the Case containing the node represented 
	 * by this Operator.
	 * @param a_CaseWindow CaseWindow in which this Operator to be added.
	 */	
	public InputDataDBOperator(String a_CaseID, INodeInfo aNodeInfo, ICaseHandler aCaseHandler) {
		super(a_CaseID, aNodeInfo, aCaseHandler);
	}
	
	/**
	 * Set node id and update operator text of the DecisionTreeOperator at the same time.
	 * @param a_NodeID ID of the node
	 */
	public void setNodeID(String a_NodeID) {
		setLabel(getDescription() + " [" + a_NodeID + "]");
		super.setNodeID(a_NodeID);
	}
	
	/**
	 * Set node id and update operator text of the DecisionTreeOperator at the same time.
	 * @param a_NodeID ID of the node
	 */
	public void setDescription(String a_Description) {
		m_Description = a_Description;
		setLabel(m_Description + " [" + m_NodeID + "]");
	}
	
	public void setDataDBOperatorText(String a_filename){
		setDescription(a_filename);
	}
	
	public void setMiningStoredData(MiningInputStream a_MiningInputData)
			throws MiningException, SysException {
		IBIData aBIData = getOutputBIObject().getBIData();

		// If the mining input data is null, reset the BIData and clear temp
		// data
		if (a_MiningInputData == null) {
			aBIData.setMiningStoredData(null);
			return;
		}

		MiningStoredData miningStoredData = new MiningStoredData();
		try {
			(new CopyMiningStream()).transform(a_MiningInputData,
					miningStoredData);
			miningStoredData.reset();
			aBIData.setMiningStoredData(miningStoredData);
			aBIData.writeTempBIData();
		} catch (MiningException me) {
			if (aBIData != null) {
				aBIData.setMiningStoredData(null);
			}
			throw me;
		}
	}

	/*
	 * public void loadTempBIData() throws MiningException { try { if
	 * (!m_OutputBIData.loadTempBIData()) { // If the temp data file could not
	 * be loaded, get the metadata form the parameter BICase a_Case =
	 * CaseHandler.getInstance().getCase(m_CaseID, false); OperatorNode node =
	 * (OperatorNode) a_Case.getNode(NodeFactory.OPERATOR, m_NodeID); String
	 * filename = node.getParameterValue("Source location"); if (filename!=null) {
	 * m_OutputBIData.setMetaData(MiningDataSpecification.getMiningDataSpecification(filename)); } } }
	 * catch (Exception me) { throw new MiningException("Error in loading
	 * temporary data: " + me.getMessage()); } }
	 */

	public boolean hasResult() {
		if (m_OutputBIObject != null) {
			return (m_OutputBIObject.hasResult(BIObject.DATA));
		} else {
			return false;
		}
	}

	public void execute(IOperatorNode a_OperatorNode, Vector a_Parents)
			throws MiningException, SysException {

		/* Get parameter from user input */
		String type = (String) a_OperatorNode
				.getParameterValue(SOURCE_TYPE_ParameterValue);

		/* Get input bi object from parent node */
		// No parent node //
		/* Prepare output mining data */
		// Do not create new outputBIData here as the property pane has alreayd created one
		//>> Added by Joyce 2005/02/25
		if (m_OutputBIObject.getBIData() == null){
			BIData aOutputBIData = new BIData(getCaseID(), getNodeID());
			m_OutputBIObject.setBIData(aOutputBIData);	
		}
		//>>
		IBIData aOutputBIData = m_OutputBIObject.getBIData();

		if (type == null) {
			throw new MiningException(
					"Please specify required information for input data source");
		} else if ((type.equals(ODBC_ParameterValue)
				|| (type.equals(DB2_ParameterValue))
				|| (type.equals(MYSQL_ParameterValue))
				|| (type.equals(ORACLE_ParameterValue))
				|| (type.equals(MSSQL_ParameterValue)) || (type
				.equals(POSTGRE_ParameterValue)))) {
			//			String url = (String)
			// a_OperatorNode.getParameterValue(url_ParameterValue);
			//			String dbName = (String)
			// a_OperatorNode.getParameterValue(DBUser_ParameterValue);
			//			String dbPassword = (String)
			// a_OperatorNode.getParameterValue(pwd_ParameterValue);
			//			String dbDriver = (String)
			// a_OperatorNode.getParameterValue(dbDriver_ParameterValue);
			//			
			//==
			@SuppressWarnings("unused") String dbengine, host, port, dsn, dbName, dbUrl, dbUser, dbPwd, dbDriver, dbTable, dbQuery;

			dbengine = ODBC_ParameterValue; // will change later
			host = (String) a_OperatorNode
					.getParameterValue(HOST_ParameterValue);
			port = (String) a_OperatorNode
					.getParameterValue(PORT_ParameterValue);
			dsn = (String) a_OperatorNode.getParameterValue(DSN_ParameterValue);
			dbName = (String) a_OperatorNode
					.getParameterValue(DBName_ParameterValue);
			dbUrl = (String) a_OperatorNode
					.getParameterValue(url_ParameterValue);
			dbUser = (String) a_OperatorNode
					.getParameterValue(DBUser_ParameterValue);
			dbPwd = (String) a_OperatorNode
					.getParameterValue(pwd_ParameterValue);
			dbDriver = (String) a_OperatorNode
					.getParameterValue(dbDriver_ParameterValue);
			dbTable = (String) a_OperatorNode
					.getParameterValue(table_ParameterValue);
			dbQuery = (String) a_OperatorNode
					.getParameterValue(query_ParameterValue);

			String option = null;
			option = (String) a_OperatorNode.getParameterValue(option_ParameterValue);
			//==

			MiningSqlSource a_Source = new MiningSqlSource(dbUrl, dbUser,
					dbPwd, dbDriver);
			a_Source.getConnection();

			String ls_sql = "";
			if (option.toUpperCase().equals("TABLE")) {
				String dbTableName = (String) a_OperatorNode.getParameterValue(table_ParameterValue);
				 
				// MySQL is not allowed to have special characters and double quote "" in the tablename
            	// Access is allowed to have soecial characters in table name, a double quote is needed in this case
            	if (ValueValidator.containSpecialChar(dbTableName))
            	{
            		ls_sql = "select * from " + "\"" + dbTableName + "\"";
            	}else
            	{
        			ls_sql = "select * from " + dbTableName;
            	}
			} else 
			{
				ls_sql = dbQuery;
				
			}
			//MiningInputStream a_Input = new MiningSqlStream(a_Source, ls_sql);
			MiningSqlStream a_Input = new MiningSqlStream(a_Source, ls_sql);
			//a_Input.getMetaData().getName();
			setMiningStoredData(a_Input);
			a_Input.close();

		}
		a_OperatorNode.setParameterValue("Temporary data", aOutputBIData
				.getTempBIDataPath());
	}
}

⌨️ 快捷键说明

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