Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 34 → Rev 37

/trunk/src/ch/ffhs/webE/dao/TermDAO.java
1,28 → 1,108
package ch.ffhs.webE.dao;
 
import java.util.ArrayList;
import java.util.List;
 
import org.hibernate.Session;
import org.hibernate.Transaction;
 
import ch.ffhs.webE.domain.Term;
 
import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
 
/**
* Defines methods all term DAO implementations must implement
* Implements the Database Access Object for terms
*
* @author pelinux
* @author Thomas Lahn
*/
public interface TermDAO
public class TermDAO
{
/**
* @return
* Database session
*/
List<Term> getTerms();
@SessionTarget
Session session;
 
/**
* Database transaction
*/
@TransactionTarget
Transaction transaction;
 
/**
* Returns a list of all terms
*
* @return an ArrayList with all the terms - in case of a problem, an empty
* list is returned
*/
@SuppressWarnings("unchecked")
public List<Term> getList()
{
List<Term> term = null;
try
{
term = this.session.createQuery("from Term").list(); //$NON-NLS-1$
}
catch (Exception e)
{
e.printStackTrace();
}
 
/*
* If no term was checked, return an empty list to mitigate null pointer
* exceptions
*/
if (term == null)
{
term = new ArrayList<Term>();
}
 
return term;
}
 
/**
* Executes the query to save the term
*
* @param term
* Domain object to be saved
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
public boolean saveOrUpdate(Term term)
{
try
{
term.setObjectId(term.getObjectId());
this.session.saveOrUpdate(term);
return true;
}
catch (Exception e)
{
this.transaction.rollback();
e.printStackTrace();
return false;
}
}
 
/**
* Delete a term
*
* @param termId
* Term ID
*/
void deleteTerm(int termId);
public void delete(int termId)
{
try
{
Term term = (Term) this.session.get(Term.class, termId);
this.session.delete(term);
}
catch (Exception e)
{
this.transaction.rollback();
e.printStackTrace();
}
}
 
/**
* Retrieves a term by ID
30,14 → 110,19
* @param termId
* @return
*/
Term getTermById(int termId);
public Term getById(int termId)
{
Term term = null;
 
/**
* Executes the query to save the term
*
* @param term
* Domain object to be saved
* @return <code>true</code> if successful, <code>false</code> otherwise
*/
boolean saveOrUpdate(Term term);
}
try
{
term = (Term) this.session.get(Term.class, termId);
}
catch (Exception e)
{
e.printStackTrace();
}
 
return term;
}
}