persistencemanager.java

来自「软件设计课做的一个类似Hibernate的O/R Mapping的框架」· Java 代码 · 共 70 行

JAVA
70
字号
package cn.edu.nju.software.sd.torm;

import cn.edu.nju.software.sd.torm.cfg.Configuration;
import cn.edu.nju.software.sd.torm.PersistenceException;

public abstract class PersistenceManager {

	protected static Configuration configuration = null;

	private static PersistenceManager manager = null;

	/**
	 * You must subclass the PersistenceManager to implement the abstract
	 * methods.
	 * 
	 * @return the implementation of the PersistenceManager
	 */
	public static PersistenceManager getInstance() {
		synchronized (PersistenceManager.class) {
			if (manager == null) {

				configuration = new Configuration().configure();

				manager = configuration.createPersistenceManager();
			}
		}
		return manager;
	}

	/**
	 * Delete the object from the database;
	 * 
	 * @param obj
	 *            object to be delete from the database;
	 * @throws PersistenceException
	 */
	public abstract void delete(Object obj) throws PersistenceException;

	/**
	 * Insert a new object into the database, the persistence manager will
	 * generate the object identifier for the object.
	 * 
	 * @param obj
	 * @throws PersistenceException
	 */
	public abstract void insert(Object obj) throws PersistenceException;

	/**
	 * Update an object in the database
	 * 
	 * @param obj
	 * @throws PersistenceException
	 */
	public abstract void update(Object obj) throws PersistenceException;

	/**
	 * Given the class and the object-identifier, the object will be load from
	 * the database
	 * 
	 * @param clazz
	 *            the class of the object
	 * @param id
	 *            the object-identifier of the object
	 * @return the object in the database
	 * @throws PersistenceException
	 */
	public abstract Object load(Class clazz, int id)
			throws PersistenceException;
}

⌨️ 快捷键说明

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