All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openbp.server.persistence.dummy.DummyPersistenceContext Maven / Gradle / Ivy

There is a newer version: 0.9.11
Show newest version
/*
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package org.openbp.server.persistence.dummy;

import java.util.Collection;

import org.openbp.server.persistence.PersistentObject;
import org.openbp.server.persistence.BasicPersistenceContext;
import org.openbp.server.persistence.BasicPersistenceContextProvider;
import org.openbp.server.persistence.PersistenceException;
import org.openbp.server.persistence.PersistenceQuery;

/**
 * Dummy persistence context.
 *
 * @author Heiko Erhardt
 */
public class DummyPersistenceContext extends BasicPersistenceContext
{
	/**
	 * Default constructor.
	 *
	 * @param provider Persistence context provider
	 */
	public DummyPersistenceContext(final BasicPersistenceContextProvider provider)
	{
		super(provider);
	}

	//////////////////////////////////////////////////
	// @@ General
	//////////////////////////////////////////////////

	/**
	 * Determines if the given object can be managed by this persistence context.
	 *
	 * @param obj Object to check (usually an object implementing PeristentObject)
	 */
	public boolean isPersistentObject(final Object obj)
	{
		return false;
	}

	//////////////////////////////////////////////////
	// @@ Object access
	//////////////////////////////////////////////////

	/**
	 * Gets the primary key of the given object.
	 *
	 * @param obj The object
	 * @return The primary key or null if the object is not persistent or if it has not been inserted into the database yet
	 * @throws PersistenceException On error
	 */
	public Object getObjectId(final Object obj)
		throws PersistenceException
	{
		Object ret;
		if (obj instanceof PersistentObject)
			ret = ((PersistentObject) obj).getId();
		else
			ret = obj.hashCode();
		return ret;
	}

	/**
	 * Merges the (transient) given object with the current session and returns the persistent object.
	 * Reloads the object values from the database.
	 *
	 * @param obj Object to refresh
	 * @return The merged object (might be the same or another instance of the object)
	 * @throws PersistenceException On error
	 */
	public Object merge(final Object obj)
		throws PersistenceException
	{
		return obj;
	}

	/**
	 * Refreshes the given persistent object.
	 * Reloads the object values from the database.
	 *
	 * @param obj Object to refresh
	 * @return The refreshed object (might be the same or another instance of the object)
	 * @throws PersistenceException On error
	 */
	public Object refreshObject(final Object obj)
		throws PersistenceException
	{
		return obj;
	}

	/**
	 * Removes the given persistent object from the session cache.
	 *
	 * @param obj Object to evict
	 * @throws PersistenceException On error
	 */
	public void evict(final Object obj)
		throws PersistenceException
	{
	}

	/**
	 * Finds an object by its primary key.
	 *
	 * @param id Primary key
	 * @param cls Type of object to lookup (usually a class implementing PeristentObject)
	 * @return The object or null if no such object can be found
	 * @throws PersistenceException On error
	 */
	public Object findById(final Object id, final Class cls)
		throws PersistenceException
	{
		throw new PersistenceException("Operation not supported by dummy persistence context.");
	}

	/**
	 * Returns a list of the objects of a particular type that match the given criterion.
	 *
	 * @param query Query to run
	 * @return The list or null
	 * @throws PersistenceException On error
	 */
	public Collection runQuery(final PersistenceQuery query)
		throws PersistenceException
	{
		throw new PersistenceException("Operation not supported by dummy persistence context.");
	}

	//////////////////////////////////////////////////
	// @@ Object modification
	//////////////////////////////////////////////////

	/**
	 * Saves the given object to the persistent storage.
	 * According to the persistence state of the object, performs an update or insert.
	 *
	 * @param o Object to insert or update
	 * @return The updated object; usually this will be identical to the argument object,
	 * except if the object already exists in persistent storage and a merge operation needs to be performed.
	 * @throws PersistenceException On error
	 */
	public Object saveObject(final Object o)
		throws PersistenceException
	{
		return o;
	}

	/**
	 * Deletes an object from persistent storage.
	 *
	 * @param o Object to delete
	 * @throws PersistenceException On error
	 */
	public void deleteObject(final Object o)
		throws PersistenceException
	{
	}

	//////////////////////////////////////////////////
	// @@ SQL support
	//////////////////////////////////////////////////

	/**
	 * Runs the given SQL update or delete statement.
	 *
	 * @param sql An SQL update statement
	 * @return The number of rows affected.
	 * @throws PersistenceException On error
	 */
	public int executeUpdateOrDelete(String sql)
		throws PersistenceException
	{
		return 0;
	}

	/**
	 * Runs the given SQL select statement.
	 *
	 * @param sql SQL query to run
	 * @param maxResults Maximum number of result rows or 0 for unlimited
	 * @return A list of result elements (contains Object or Object[] elements, depending if this was a single column or multi-column query)
	 * @throws PersistenceException On error
	 */
	public Collection executeSelect(String sql, int maxResults)
		throws PersistenceException
	{
		throw new PersistenceException("Operation not supported by dummy persistence context.");
	}

	//////////////////////////////////////////////////
	// @@ Transaction control
	//////////////////////////////////////////////////

	public boolean isTransactionActive()
		throws PersistenceException
	{
		return false;
	}

	public void doBeginTransaction()
		throws PersistenceException
	{
	}

	public void doRollbackTransaction()
		throws PersistenceException
	{
	}

	public void doCommitTransaction()
		throws PersistenceException
	{
	}

	public void flush()
		throws PersistenceException
	{
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy