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;
 import java.util.Map;
 import java.util.Set;
 
 
Property access object for module objects.

Author(s):
Michael Ruflin
 
 public class ModuleDAO {
 
Get info objects of all available module instances for an account.

Parameters:
account
Returns:
 
 
 	@SuppressWarnings("unchecked")
 	public Set<Module.InfogetModules(final UserAccountImpl account) {
 		Query query = 
 						"select module.id, module.name FROM ModuleImpl as module where module.accountId = :accountId");
 		query.setParameter("accountId"account.getId());
 		List<Object[]> results = (List<Object[]>) query.list();
 		Set<Module.Infoinfos = new TreeSet<Module.Info>();
 		for (Object[] result : results) {
 			ModuleInfoImpl info = new ModuleInfoImpl();
 			info.setAccount(account);
 			info.setId((Longresult[0]);
 			info.setName((Stringresult[1]);
 			infos.add(info);
 		}
 		return infos;
 	}

Loads a module object from the database, using the id specified in the module. If no module with given id exists in the database, a new one is created

Parameters:
moduleInfo the module to load
 
 	public ModuleImpl loadModule(ModuleInfoImpl moduleInfo) {
 				.get(ModuleImpl.classmoduleInfo.getId());
 
 		// set the account object manually
 		if (!moduleInfo.getAccount().getId().equals(module.getAccountId())) {
 			throw new RuntimeException(
 					"ModuleInfo and Module object don't belong to each other! Account id mismatch");
 		}
 		module.setAccount(moduleInfo.getAccount());
 
 		return module;
 	}

Deletes a module

Parameters:
module the module to load
 
 	public void deleteModule(final ModuleInfoImpl moduleInfo) {
		// PENDING: can't hibernate figure this out on its own?
		// TODO: Test this if removed
		// First delete all trials
		List<?> trialIds = 
						"select id from TrialImpl trial where trial.session.module.id = :id")
				.setParameter("id"moduleInfo.getId()).list();
		for (Object o : trialIds) {
			TrialImpl trial = new TrialImpl();
		}
		// then delete the sessions
		List<?> sessionIds = 
						"select id from ModuleSessionImpl session where session.module.id = :id")
				.setParameter("id"moduleInfo.getId()).list();
		for (Object o : sessionIds) {
		}
		// and finally the module itself
		ModuleImpl module = loadModule(moduleInfo);
	}
	public void addModuleProperties(final ModuleImpl impl,
			final Map<StringStringproperties) {
		Map<StringStringprops = impl.getModuleProperties();
		for (String key : properties.keySet()) {
			String value = properties.get(key);
			props.put(keyvalue);
		}
	}

Stores the module object.
	public void saveModule(ModuleImpl module) {
	}

Deletes a module object.
	public void deleteModule(Module module) {
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this. = sessionFactory;
	}
New to GrepCode? Check out our FAQ X