Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 Michael Ruflin, Andr´┐Ż Locher, Claudia von Bastian. This file is part of Tatool. Tatool 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 3 of the License, or (at your option) any later version. Tatool 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 Tatool. If not, see <http://www.gnu.org/licenses/>. /
 
 package ch.tatool.app.service.impl;
 
 import java.util.List;
 
 
Property access object for module objects.

Author(s):
Michael Ruflin
 
 public class TrialDAO {
 
 
 	Logger logger = LoggerFactory.getLogger(TrialDAO.class);

Get a list of all sessions.
 
 	@SuppressWarnings("unchecked")
 	public List<TrialloadAllTrials(final ModuleImpl module) {
 		String queryString = "select trial from TrialImpl trial where trial.session.module = :module";
 				queryString);
 		query.setParameter("module"module);
 		return (List<Trial>) query.list();
 	}

Get all trials for a given session.
 
 	@SuppressWarnings("unchecked")
 	public List<TrialgetTrials(final ModuleSession moduleSession) {
 		Query query = .getCurrentSession().createQuery("select trial from TrialImpl trial where trial.session = :session order by trial.id");
 		query.setParameter("session"moduleSession);
 		List<Trialtrials = (List<Trial>) query.list();
 		// make sure we set the moduleSession correctly
 		for (Trial t : trials) {
 			t.setSession(moduleSession);
 		}
 		return trials;
 	}

Get all trials for a given session.
 
 	@SuppressWarnings("unchecked")
 	public List<TrialgetTrials(final ModuleImpl modulefinal ModuleSession moduleSessionfinal String elementNameLikefinal String propertyNameLikefinal int offsetfinal int maxResults) {
 		if (elementNameLike == null && propertyNameLike == null) {
 			throw new RuntimeException(
 					"Either elementName or propertyName needs to be non-null");
 		}
 
 		if (moduleSession != null) {
 		}
 
 		StringBuilder q = new StringBuilder();
 		q.append("select distinct(trial) from TrialImpl trial ");
 		q.append(" join trial.entriesImpl as entry where ");
 		if (moduleSession != null) {
 			q.append(" trial.session = :session ");
 		} else {
 			q.append(" trial.session.module = :module ");
 		}
 		if (elementNameLike != null) {
 			q.append(" and entry.nodeId like :elementName");
 		}
 		if (propertyNameLike != null) {
 			q.append(" and entry.name like :propName");
		}
		// sort reverse
		q.append(" order by trial.id DESC");
		// create the query and set the various parameters
		if (moduleSession != null) {
			query.setParameter("session"moduleSession);
else {
			query.setParameter("module"module);
		}
		if (elementNameLike != null) {
			query.setParameter("elementName"elementNameLike);
		}
		if (propertyNameLike != null) {
			query.setParameter("propName"propertyNameLike);
		}
		// limit results if requested
		if (offset > 0) {
			query.setFirstResult(offset);
		}
		if (maxResults > -1) {
			query.setMaxResults(maxResults);
		}
		List<Trialtrials = (List<Trial>) query.list();
		// make sure we set the moduleSession correctly
		if (moduleSession != null) {
			for (Trial t : trials) {
				t.setSession(moduleSession);
			}
		}
		return trials;
	}

Get the last trial index for a given session.
	@SuppressWarnings("unchecked")
	public int getLastTrialIndex(final ModuleSession moduleSession) {
						"select max(trial.index) from TrialImpl trial where trial.session = :session");
		query.setParameter("session"moduleSession);
		List<Integerindex = (List<Integer>) query.list();
		if (index != null && index.isEmpty()) {
			return 0;
else {
			return index.get(0);
		}
	}

Persist a trial.
	public void saveTrial(Module moduleModuleSession sessionTrial trial) {
		ModuleSessionImpl sessionImpl = (ModuleSessionImplsession;
		if (trial.getId() == null) {
			trial.setSession(session);
			sessionImpl.getTrials().add(trial);
			trial.setIndex(sessionImpl.getTrials().indexOf(trial));
else {
		}
	}

Delete a trial object.
	public void deleteTrial(Module moduleModuleSession sessionTrial trial) {
		Iterator<Trialit = ((ModuleSessionImplsession).getTrials()
		while (it.hasNext()) {
			Trial t = it.next();
			if (t.getId().equals(trial.getId())) {
				it.remove();
			}
		}
	}
	@SuppressWarnings("unchecked")
	public List<TrialgetTrials(ModuleSession sessionNode nodeint maxResults) {
		List<Trialtrials = null;
		DetachedCriteria criteria = DetachedCriteria.forClass(Trial.class);
		// limit the session
		if (session != null) {
			criteria.add(Property.forName("session").eq(session));
		}
		// limit the element
		if (node != null) {
			criteria.add(Property.forName("nodeId").eq(node.getId()));
		}
		// get the last trial as first
		criteria.addOrder(Order.desc("id"));
		// find the trials
		return trials;
	}

Get all distinct trial property names for a module.

Returns:
An array with [0] containing the item name, [1] the property name
	@SuppressWarnings("unchecked")
		StringBuilder queryString = new StringBuilder();
		queryString
				.append("Select distinct(entry.nodeId), entry.name")
				.append(" from TrialImpl trial left join trial.entriesImpl entry")
				.append(" where trial.session.module = :module")
				.append(" and entry.nodeId is not NULL")
				.append(" order by entry.nodeId, entry.name");
		// put together the complete query
				queryString.toString());
		query.setParameter("module"module);
		// and get the results
		return (List<Object[]>) query.list();
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this. = sessionFactory;
	}
New to GrepCode? Check out our FAQ X