X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.support.hibernate%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fhibernate%2Fprocess%2FSlcExecutionDaoHibernate.java;fp=runtime%2Forg.argeo.slc.support.hibernate%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fhibernate%2Fprocess%2FSlcExecutionDaoHibernate.java;h=0000000000000000000000000000000000000000;hb=868102c0f0220e12eca836b6ec9b3a2b9a3441e4;hp=f581f9261de1203f9381f339ee60963836c4a5ad;hpb=a5b25ca3e5efc8de3571993f6bfc1671c0e2f3ba;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.hibernate/src/main/java/org/argeo/slc/hibernate/process/SlcExecutionDaoHibernate.java b/runtime/org.argeo.slc.support.hibernate/src/main/java/org/argeo/slc/hibernate/process/SlcExecutionDaoHibernate.java deleted file mode 100644 index f581f9261..000000000 --- a/runtime/org.argeo.slc.support.hibernate/src/main/java/org/argeo/slc/hibernate/process/SlcExecutionDaoHibernate.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * 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.argeo.slc.hibernate.process; - -import java.sql.SQLException; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.SlcException; -import org.argeo.slc.dao.process.SlcExecutionDao; -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.process.SlcExecutionStep; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.springframework.orm.hibernate3.HibernateCallback; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -public class SlcExecutionDaoHibernate extends HibernateDaoSupport implements - SlcExecutionDao { - private final static Log log = LogFactory - .getLog(SlcExecutionDaoHibernate.class); - - public void create(SlcExecution slcExecution) { - getHibernateTemplate().save(slcExecution); - } - - public void update(final SlcExecution slcExecution) { - getHibernateTemplate().update(slcExecution); - } - - public void merge(final SlcExecution slcExecution) { - getHibernateTemplate().merge(slcExecution); - } - - public SlcExecution getSlcExecution(String uuid) { - return (SlcExecution) getHibernateTemplate().get(SlcExecution.class, - uuid); - } - - @SuppressWarnings("unchecked") - public List listSlcExecutions() { - return (List) getHibernateTemplate().loadAll( - SlcExecution.class); - } - - public void addSteps(final String slcExecutionId, - final List additionalSteps) { - getHibernateTemplate().execute(new HibernateCallback() { - - public Object doInHibernate(Session session) - throws HibernateException, SQLException { - SlcExecution slcExecution = getSlcExecution(session, - slcExecutionId); - slcExecution.getSteps().addAll(additionalSteps); - session.update(slcExecution); - return slcExecution; - } - }); - - } - - @SuppressWarnings("unchecked") - public List tailSteps(final String slcExecutionId, - final Integer nbrOfSteps) { - return (List) getHibernateTemplate().execute( - new HibernateCallback() { - - public Object doInHibernate(Session session) - throws HibernateException, SQLException { - SlcExecution slcExecution = getSlcExecution(session, - slcExecutionId); - // TODO: do a query count() instead? - int stepCount = slcExecution.getSteps().size(); - if (stepCount > nbrOfSteps) { - return session.createFilter( - slcExecution.getSteps(), "") - .setFirstResult(stepCount - nbrOfSteps) - .setMaxResults(nbrOfSteps).list(); - } else { - return slcExecution.getSteps(); - } - } - }); - } - - @SuppressWarnings("unchecked") - public List tailSteps(final String slcExecutionId, - final String slcExecutionStepId) { - Object[] values = { slcExecutionStepId, slcExecutionId }; - List indexes = getHibernateTemplate().findByNamedQuery( - SlcExecutionStep.class.getName() + ".stepIndex", values); - - Integer index = indexes.get(0); - if (log.isTraceEnabled()){ - log.trace(indexes.size()); - log.trace("Index " + index + " for step " + slcExecutionStepId - + " in process " + slcExecutionId); - } - Object[] values2 = { slcExecutionId, index }; - return getHibernateTemplate().findByNamedQuery( - SlcExecutionStep.class.getName() + ".stepsAfter", values2); - } - - protected SlcExecution getSlcExecution(Session session, - String slcExecutionId) { - SlcExecution slcExecution = (SlcExecution) session.get( - SlcExecution.class, slcExecutionId); - - if (slcExecution == null) - throw new SlcException("Could not find SLC execution " - + slcExecutionId); - - return slcExecution; - } - -}