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

📄 testtransactionmanager.java

📁 一个在线学习系统的服务端SERVLET程序
💻 JAVA
字号:
package eols.logic.test;

import java.util.*;
import eols.bean.test.*;
import eols.logic.base.ITransaction;
import eols.storage.base.IStorage;
import eols.storage.test.TestStorageManager;

public class TestTransactionManager implements ITransaction {

	/* The storage manager used in this transaction manager */
	private IStorage iSQL = new TestStorageManager();

	/**
	 * Return the storage manager used by this
	 * transaction manager.
	 *
	 * @return The used storage manager
	 */
	public IStorage getStorageManager(){
		return iSQL;
	}

	/**
	 * Process the specified transaction. All necessary parameters are
	 * wrapped in a map which is provided by specific caller.
	 *
	 * <p>
	 * A runtime exception may be thrown out, according to specific
	 * transactions.
	 * </p>
	 *
	 * <p>
	 * In this subsystem, the parameters contains the type of the transaction,
	 * the necessary parameters of the transaction.
	 * </p>
	 *
	 * @param parameters Parameters to pass
	 * @return The handling result object
	 */
	public Object process(Map parameters){
		// Get the transaction type
		String type = (String)parameters.get("type");
		if (type == null) {
			throw new RuntimeException("The transaction type shall be specified.");
		}
		if (type.equals("CREATENEWKNOWLEDGEPOINT")) { /** Create a new knowledge point */
			KnowledgePoint newC = (KnowledgePoint)parameters.get("kp");
			if (iSQL.addRecord(newC)) {
				return new Boolean(true);
			}
			return new Boolean(false);
		}
		if (type.equals("CREATENEWQUESTION")) { /** Create a new question */
			Question newC = (Question)parameters.get("question");
			if (iSQL.addRecord(newC)) {
				return new Boolean(true);
			}
			return new Boolean(false);
		}
		if (type.equals("UPDATEKNOWLEDGEPOINT")) { /** Update the existing knowledge point */
			KnowledgePoint newC = (KnowledgePoint)parameters.get("kp");
			if (iSQL.updateRecord(null, newC)) {
				return new Boolean(true);
			}
			return new Boolean(false);
		}
		if (type.equals("UPDATEQUESTION")) { /** Update the existing question */
			Question newC = (Question)parameters.get("question");
			if (iSQL.updateRecord(null, newC)) {
				return new Boolean(true);
			}
			return new Boolean(false);
		}
                if (type.equals("SAVETESTRESULT")) {
                    List records = (List)parameters.get("results");
                    if (iSQL.addRecords(records)) {
                        return new Boolean(true);
                        }
                        return new Boolean(false);
                }
                if (type.equals("GETALLTESTSOFUSER")) {
                    return iSQL.getRecords(parameters);
                }
                if (type.equals("GETQUESTIONSOFTEST")) {
                    return iSQL.getRecords((List)parameters.get("list"));
                }
                if (type.equals("GETTESTOFUSER")) {
                    return iSQL.getRecord(parameters);
                }
		return null;
	}

}

⌨️ 快捷键说明

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