Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 37 → Rev 35

/trunk/src/ch/ffhs/webE/dao/RelationshipDAO.java
File deleted
\ No newline at end of file
Property changes:
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
Index: HistoryDAO.java
===================================================================
--- HistoryDAO.java (revision 37)
+++ HistoryDAO.java (nonexistent)
@@ -1,88 +0,0 @@
-/**
- *
- */
-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.History;
-
-import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
-import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
-
-/**
- * @author pelinux
- *
- */
-public class HistoryDAO
-{
- /**
- * Database session
- */
- @SessionTarget
- Session session;
-
- /**
- * Database transaction
- */
- @TransactionTarget
- Transaction transaction;
-
- /**
- * Executes the query to save the history record
- *
- * @param history
- * Domain object to be saved
- * @return <code>true</code> if successful, <code>false</code> otherwise
- */
- public boolean saveOrUpdate(History history)
- {
- try
- {
- history.setId(history.getId());
- this.session.saveOrUpdate(history);
- return true;
- }
- catch (Exception e)
- {
- this.transaction.rollback();
- e.printStackTrace();
- return false;
- }
- }
-
- /**
- * 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<History> getList()
- {
- List<History> history = null;
- try
- {
- history = this.session.createQuery("from History").list(); //$NON-NLS-1$
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- /*
- * If no term was checked, return an empty list to mitigate null pointer
- * exceptions
- */
- if (history == null)
- {
- history = new ArrayList<History>();
- }
-
- return history;
- }
-}
/HistoryDAO.java
Property changes:
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
Index: RelationshipDAOImpl.java
===================================================================
--- RelationshipDAOImpl.java (nonexistent)
+++ RelationshipDAOImpl.java (revision 35)
@@ -0,0 +1,130 @@
+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.Relationship;
+
+import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
+import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
+
+/**
+ * Implements the Database Access Object for terms
+ *
+ * @author Thomas Lahn
+ */
+public class RelationshipDAOImpl
+{
+ /**
+ * Database session
+ */
+ @SessionTarget
+ Session session;
+
+ /**
+ * Database transaction
+ */
+ @TransactionTarget
+ Transaction transaction;
+
+ /**
+ * Creates a list of all relationships
+ *
+ * @return an ArrayList with all the relationshops - in case of a problem, an
+ * empty list is returned
+ */
+ @SuppressWarnings("unchecked")
+ public List<Relationship> getRelationshipList()
+ {
+ List<Relationship> relationship = null;
+ try
+ {
+ relationship = this.session.createQuery("from Relationship").list(); //$NON-NLS-1$
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ /*
+ * If no relationship was checked, return an empty list to mitigate null
+ * pointer exceptions
+ */
+ if (relationship == null)
+ {
+ relationship = new ArrayList<Relationship>();
+ }
+
+ return relationship;
+ }
+
+ /**
+ * Executes the query to save the relationship
+ *
+ * @param relationship
+ * Domain object to be saved
+ * @return <code>true</code> if successful, <code>false</code> otherwise
+ */
+ public boolean saveOrUpdate(Relationship relationship)
+ {
+ try
+ {
+ relationship.setObjectId(relationship.getObjectId());
+ this.session.saveOrUpdate(relationship);
+ return true;
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Delete a relationship
+ *
+ * @param id
+ * Relationship ID
+ */
+ public void deleteRelationship(int id)
+ {
+ try
+ {
+ Relationship relationship = (Relationship) this.session.get(
+ Relationship.class, id);
+ this.session.delete(relationship);
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Retrieves a relationship by ID
+ *
+ * @param id
+ * Term ID
+ * @return The relationship with this <var>id</var>
+ */
+ public Relationship getRelationshipById(int id)
+ {
+ Relationship relationship = null;
+
+ try
+ {
+ relationship = (Relationship) this.session.get(Relationship.class, id);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return relationship;
+ }
+}
\ No newline at end of file
/RelationshipDAOImpl.java
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: RelationshipTypeDAO.java
===================================================================
--- RelationshipTypeDAO.java (revision 37)
+++ RelationshipTypeDAO.java (revision 35)
@@ -1,130 +1,16 @@
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.RelationshipType;
-import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
-import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
+public interface RelationshipTypeDAO {
-/**
- * Data Access Object class for {@link RelationshipType}s
- *
- * @author Thomas Lahn
- */
-public class RelationshipTypeDAO
-{
+ List<RelationshipType> getRelTypes();
- /**
- * Hibernate session target
- */
- @SessionTarget
- Session session;
+ boolean deleteRelationshipType(int relTypeID);
+
+ RelationshipType getRelTypeById(int relTypeID);
- /**
- * Hibernate transaction target
- */
- @TransactionTarget
- Transaction transaction;
-
- /**
- * Gets a list of all the relationshipTypes in the database.
- *
- * @return List of all the users. In case of a problem, an empty list is
- * returned.
- */
- @SuppressWarnings("unchecked")
- public List<RelationshipType> getList()
- {
-
- List<RelationshipType> relType = null;
-
- try
- {
- relType = this.session.createQuery("from RelationshipType").list(); //$NON-NLS-1$
- }
- catch (Exception e)
- {
- // TODO: Logging
- }
-
- if (relType == null)
- {
- relType = new ArrayList<RelationshipType>();
- }
-
- return relType;
- }
-
- /**
- * Saves or updates a relationship type
- *
- * @param relType
- * A filled domain object
- * @return Boolean indicating success or error in saving the relationshipType
- */
- public boolean saveOrUpdate(RelationshipType relType)
- {
- try
- {
- this.session.saveOrUpdate(relType);
- return true;
- }
- catch (Exception e)
- {
- this.transaction.rollback();
- return false;
- // TODO: Logging
- }
- }
-
- /**
- * Delete a relationship type
- *
- * @param relTypeId
- * Relationship type ID
- * @return boolean indicating success or error in the query execution
- */
- public boolean delete(int relTypeId)
- {
- try
- {
- RelationshipType relType = (RelationshipType) this.session.get(
- RelationshipType.class, relTypeId);
- this.session.delete(relType);
- return true;
- }
- catch (Exception e)
- {
- this.transaction.rollback();
- // TODO: Logging
- return false;
- }
- }
-
- /**
- * Used to get a relationship type by ID
- *
- * @param relTypeID
- * @return
- */
- public RelationshipType getById(int relTypeID)
- {
- RelationshipType relType = null;
- try
- {
- relType = (RelationshipType) this.session.get(RelationshipType.class,
- relTypeID);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- // TODO: Logging
- }
- return relType;
- }
+ boolean saveOrUpdateRelType(RelationshipType relType);
}
/trunk/src/ch/ffhs/webE/dao/RelationshipTypeDAOImpl.java
0,0 → 1,118
package ch.ffhs.webE.dao;
 
import java.util.ArrayList;
import java.util.List;
 
import org.hibernate.Session;
import org.hibernate.Transaction;
 
import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
import ch.ffhs.webE.domain.*;
 
public class RelationshipTypeDAOImpl implements RelationshipTypeDAO
{
 
@SessionTarget
Session session;
@TransactionTarget
Transaction transaction;
 
/**
* Gets a list of all the relationshipTypes in the database.
*
* @return List of all the users. In case of a problem, an empty list is
* returned.
*/
@SuppressWarnings("unchecked")
@Override
public List<RelationshipType> getRelTypes()
{
 
List<RelationshipType> relType = null;
 
try
{
relType = session.createQuery("from RelationshipType").list();
}
catch (Exception e)
{
// TODO: Logging
}
 
if (relType == null)
{
relType = new ArrayList<RelationshipType>();
}
 
return relType;
}
 
/**
* used to save a relationship type
*
* @param RelationshipType
* relType: A filled DAO
* @return Boolean indicating success or error in saving the
* relationshipType
*/
@Override
public boolean saveOrUpdateRelType(RelationshipType relType)
{
try
{
session.saveOrUpdate(relType);
return true;
}
catch (Exception e)
{
transaction.rollback();
return false;
// TODO: Logging
}
}
 
/**
* Used to delete a relationship type.
*
* @param int RelationshipType ID
* @return boolean indicating success or error in the query execution
*/
@Override
public boolean deleteRelationshipType(int relTypeID)
{
try
{
RelationshipType relType = (RelationshipType) session.get(
RelationshipType.class, relTypeID);
session.delete(relType);
return true;
}
catch (Exception e)
{
transaction.rollback();
// TODO: Logging
return false;
}
}
 
/**
* Used to get a relationship type by ID
*/
@Override
public RelationshipType getRelTypeById(int relTypeID)
{
RelationshipType relType = null;
try
{
relType = (RelationshipType) session.get(RelationshipType.class,
relTypeID);
}
catch (Exception e)
{
e.printStackTrace();
// TODO: Logging
}
return relType;
}
}
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: TermDAO.java
===================================================================
--- TermDAO.java (revision 37)
+++ TermDAO.java (revision 35)
@@ -1,66 +1,37 @@
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;
-
/**
- * Implements the Database Access Object for terms
+ * Defines methods all term DAO implementations must implement
*
- * @author Thomas Lahn
+ * @author pelinux
*/
-public class TermDAO
+public interface TermDAO
{
/**
- * Database session
+ * @return
*/
- @SessionTarget
- Session session;
+ List<Term> getTerms();
/**
- * Database transaction
+ * Delete a term
+ *
+ * @param termId
+ * Term ID
*/
- @TransactionTarget
- Transaction transaction;
+ void deleteTerm(int termId);
/**
- * Returns a list of all terms
+ * Retrieves a term by ID
*
- * @return an ArrayList with all the terms - in case of a problem, an empty
- * list is returned
+ * @param termId
+ * @return
*/
- @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();
- }
+ Term getTermById(int termId);
- /*
- * 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
*
@@ -68,61 +39,5 @@
* 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
- */
- 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
- *
- * @param termId
- * @return
- */
- public Term getById(int termId)
- {
- Term term = null;
-
- try
- {
- term = (Term) this.session.get(Term.class, termId);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- return term;
- }
-}
\ No newline at end of file
+ boolean saveOrUpdate(Term term);
+}
/trunk/src/ch/ffhs/webE/dao/TermDAOImpl.java
0,0 → 1,124
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;
 
/**
* Implements the Database Access Object for terms
*
* @author Thomas Lahn
*/
public class TermDAOImpl implements TermDAO
{
/**
* Database session
*/
@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> getTerms()
{
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;
}
 
/*
* (non-Javadoc)
*
* @see ch.ffhs.webE.dao.TermDAO#saveOrUpdate(ch.ffhs.webE.domain.Term)
*/
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;
}
}
 
/*
* (non-Javadoc)
*
* @see ch.ffhs.webE.dao.TermDAO#deleteTerm(int)
*/
public void deleteTerm(int termId)
{
try
{
Term term = (Term) this.session.get(Term.class, termId);
this.session.delete(term);
}
catch (Exception e)
{
this.transaction.rollback();
e.printStackTrace();
}
}
 
/*
* (non-Javadoc)
*
* @see ch.ffhs.webE.dao.TermDAO#getTermById(int)
*/
public Term getTermById(int termId)
{
Term term = null;
 
try
{
term = (Term) this.session.get(Term.class, termId);
}
catch (Exception e)
{
e.printStackTrace();
}
 
return term;
}
}
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: UserDAOImpl.java
===================================================================
--- UserDAOImpl.java (nonexistent)
+++ UserDAOImpl.java (revision 35)
@@ -0,0 +1,135 @@
+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.User;
+
+import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
+import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
+
+public class UserDAOImpl implements UserDAO
+{
+
+ @SessionTarget
+ Session session;
+ @TransactionTarget
+ Transaction transaction;
+
+ /**
+ * Creates a list of all the registered users
+ *
+ * @return an ArrayList with all the users - in case of a problem, an empty
+ * list is returned
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<User> listUser()
+ {
+ List<User> user = null;
+ try
+ {
+ user = this.session.createQuery("from User").list();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ // If no user was checked, return an empty list to mitigate null pointer
+ // exceptions
+ if (user == null)
+ {
+ user = new ArrayList<User>();
+ }
+ return user;
+ }
+
+ /**
+ * Executes the query to save the user
+ *
+ * @param User
+ * Domain object to be saved
+ * @return void
+ */
+ @Override
+ public void saveOrUpdateUser(User user)
+ {
+ try
+ {
+ this.session.saveOrUpdate(user);
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Used to delete a user.
+ *
+ * @param int userId
+ */
+ @Override
+ public void deleteUser(int userId)
+ {
+ try
+ {
+ User user = (User) this.session.get(User.class, userId);
+ this.session.delete(user);
+ }
+ catch (Exception e)
+ {
+ this.transaction.rollback();
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Returns a single user with this user name (used for login)
+ *
+ * @param username
+ * : String - entire user name
+ * @return User: Returns a user object if something is found. If not, null is
+ * returned
+ */
+ public User searchUsername(String username)
+ {
+ User user = null;
+
+ // Exec query
+ try
+ {
+ user = (User) this.session
+ .createQuery("FROM User " + "WHERE username = :username")
+ .setParameter("username", username).uniqueResult();
+ }
+ catch (Exception e)
+ {
+ // TODO: Log error
+ }
+ return user;
+ }
+
+ /**
+ * Used to list a single user by Id.
+ */
+ @Override
+ public User listUserById(int userId)
+ {
+ User user = null;
+ try
+ {
+ user = (User) this.session.get(User.class, userId);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return user;
+ }
+}
\ No newline at end of file
/UserDAOImpl.java
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: UserDAO.java
===================================================================
--- UserDAO.java (revision 37)
+++ UserDAO.java (revision 35)
@@ -1,134 +1,19 @@
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.User;
-import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
-import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
-
-public class UserDAO
+public interface UserDAO
{
- @SessionTarget
- Session session;
- @TransactionTarget
- Transaction transaction;
+ List<User> listUser();
- /**
- * Creates a list of all the registered users
- *
- * @return an ArrayList with all the users - in case of a problem, an empty
- * list is returned
- */
- @SuppressWarnings("unchecked")
- public List<User> getList()
- {
- List<User> user = null;
- try
- {
- user = this.session.createQuery("from User").list();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ User searchUsername(String username);
- // If no user was checked, return an empty list to mitigate null pointer
- // exceptions
- if (user == null)
- {
- user = new ArrayList<User>();
- }
- return user;
- }
+ void deleteUser(int userId);
- /**
- * Executes the query to save the user
- *
- * @param user
- * Domain object to be saved
- * @return void
- */
- public void saveOrUpdate(User user)
- {
- try
- {
- this.session.saveOrUpdate(user);
- }
- catch (Exception e)
- {
- this.transaction.rollback();
- e.printStackTrace();
- }
- }
+ User listUserById(int userId);
- /**
- * Used to delete a user.
- *
- * @param userId
- */
- public void delete(int userId)
- {
- try
- {
- User user = (User) this.session.get(User.class, userId);
- this.session.delete(user);
- }
- catch (Exception e)
- {
- this.transaction.rollback();
- e.printStackTrace();
- }
- }
-
- /**
- * Returns a single user with this user name (used for login)
- *
- * @param username
- * : String - entire user name
- * @return User: Returns a user object if something is found. If not, null is
- * returned
- */
- public User getByUsername(String username)
- {
- User user = null;
-
- // Exec query
- try
- {
- user = (User) this.session
- .createQuery("FROM User " + "WHERE username = :username")
- .setParameter("username", username).uniqueResult();
- }
- catch (Exception e)
- {
- // TODO: Log error
- }
- return user;
- }
-
- /**
- * Used to list a single user by Id.
- *
- * @param userId
- * @return
- */
- public User getById(int userId)
- {
- User user = null;
- try
- {
- user = (User) this.session.get(User.class, userId);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return user;
- }
-}
\ No newline at end of file
+ void saveOrUpdateUser(User user);
+}