[jboss-svn-commits] JBL Code SVN: r29279 - in labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm: query and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 9 12:36:38 EDT 2009


Author: whitingjr
Date: 2009-09-09 12:36:37 -0400 (Wed, 09 Sep 2009)
New Revision: 29279

Added:
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/STMQueryImpl.java
Log:
Added query object to persistence system.

Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/STMQueryImpl.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/STMQueryImpl.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/STMQueryImpl.java	2009-09-09 16:36:37 UTC (rev 29279)
@@ -0,0 +1,149 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software 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
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package uk.ac.ncl.sdia.a8905943.stm.query;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.FlushModeType;
+import javax.persistence.NoResultException;
+import javax.persistence.NonUniqueResultException;
+import javax.persistence.Query;
+import javax.persistence.TemporalType;
+
+import org.apache.commons.jxpath.JXPathContext;
+
+public class STMQueryImpl implements Query {
+
+	private final String query;
+	private final JXPathContext xpathContext ;
+	
+	
+	@Override
+	public int executeUpdate() {
+		// FIXME executeUpdate
+		return 0;
+	}
+
+	@Override
+	public List getResultList() {
+		// FIXME getResultList
+		return null;
+	}
+
+	/**
+	 * Use this method when expecting to retrieve only one entity.
+	 */
+	@Override
+	public Object getSingleResult() 
+		throws NonUniqueResultException, NoResultException 
+	{
+		Object returnValue = null;
+		this.xpathContext.setLenient(true);
+		List selectedEntities = this.xpathContext.selectNodes(this.query);
+		if ( 1 < selectedEntities.size())
+		{
+			throw new NonUniqueResultException("The results returned from the query ["+query+"] is greater than expected single entity.");
+		}
+		else if (0 ==  selectedEntities.size())
+		{
+			throw new NoResultException("The executed query ["+this.query+"] did not return any results."); 
+		}
+		returnValue = selectedEntities.get(0);
+		return returnValue;
+	}
+
+	@Override
+	public Query setFirstResult(int startPosition) {
+		// FIXME setFirstResult
+		return null;
+	}
+
+	@Override
+	public Query setFlushMode(FlushModeType flushMode) {
+		// FIXME setFlushMode
+		return null;
+	}
+
+	@Override
+	public Query setHint(String hintName, Object value) {
+		// FIXME setHint
+		return null;
+	}
+
+	@Override
+	public Query setMaxResults(int maxResult) {
+		// FIXME setMaxResults
+		return null;
+	}
+
+	@Override
+	public Query setParameter(String name, Object value) {
+		if (null == name || null == value)
+		{
+			throw new IllegalArgumentException("When attempting to set a parameter one of the parameters is null, ["+name+"] ["+value+"].");
+		}
+		this.xpathContext.getVariables().declareVariable(name, value);
+		return this;
+	}
+
+	@Override
+	public Query setParameter(int position, Object value) {
+		// FIXME setParameter
+		return null;
+	}
+
+	@Override
+	public Query setParameter(String name, Date value, TemporalType temporalType) {
+		// FIXME setParameter
+		return null;
+	}
+
+	@Override
+	public Query setParameter(String name, Calendar value,
+			TemporalType temporalType) {
+		// FIXME setParameter
+		return null;
+	}
+
+	@Override
+	public Query setParameter(int position, Date value,
+			TemporalType temporalType) {
+		// FIXME setParameter
+		return null;
+	}
+
+	@Override
+	public Query setParameter(int position, Calendar value,
+			TemporalType temporalType) {
+		// FIXME setParameter
+		return null;
+	}
+
+	public STMQueryImpl(JXPathContext context, String expression)
+	{
+		this.xpathContext= context; 
+		this.query = expression;
+	}
+}



More information about the jboss-svn-commits mailing list