odmgcollection.java
来自「用Java实现的23个常用设计模式源代码」· Java 代码 · 共 81 行
JAVA
81 行
//$Id: ODMGCollection.java,v 1.10.2.1 2003/08/03 03:23:09 oneovthafew Exp $package net.sf.hibernate.collection;import java.util.Iterator;import org.odmg.DCollection;import org.odmg.QueryInvalidException;import net.sf.hibernate.HibernateException;import net.sf.hibernate.engine.SessionImplementor;/** * All Hibernate collections actually implement the ODMG <tt>DCollection</tt> * interface and are castable to that type. However, we don't recommend that * the object model be "polluted" by using this interface, unless the * application is using the ODMG API. * * @author Gavin King */public abstract class ODMGCollection extends PersistentCollection implements DCollection { public ODMGCollection(SessionImplementor session) { super(session); } public ODMGCollection() {} //needed for SOAP libraries, etc /** * @see org.odmg.DCollection#existsElement(String) */ public boolean existsElement(String queryString) throws QueryInvalidException { //return select(queryString).hasNext(); try { return ( (Integer) getSession().filter( this, "select count(*) " + queryString ).iterator().next() ).intValue() > 0; } catch (HibernateException he) { throw new QueryInvalidException( he.getMessage() ); } } /** * @see org.odmg.DCollection#query(String) */ public DCollection query(String queryString) throws QueryInvalidException { // TODO: make this return the right collection subclass for DSet, DBag try { return new List( getSession(), (java.util.List) getSession().filter(this, queryString) ); } catch (HibernateException he) { throw new QueryInvalidException( he.getMessage() ); } } /** * @see org.odmg.DCollection#select(String) */ public Iterator select(String queryString) throws QueryInvalidException { try { return getSession().filter(this, queryString).iterator(); } catch (HibernateException he) { throw new QueryInvalidException( he.getMessage() ); } } /** * @see org.odmg.DCollection#selectElement(String) */ public Object selectElement(String queryString) throws QueryInvalidException { Iterator iter = select(queryString); return iter.hasNext() ? iter.next() : null; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?