implemented administration of relationship type (edit and delete are not yet working)
/trunk/src/ch/ffhs/webE/dao/UserDAOImpl.java |
---|
1,5 → 1,6 |
package ch.ffhs.webE.dao; |
import java.util.ArrayList; |
import java.util.List; |
import org.hibernate.Session; |
9,7 → 10,8 |
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget; |
import ch.ffhs.webE.domain.*; |
public class UserDAOImpl implements UserDAO { |
public class UserDAOImpl implements UserDAO |
{ |
@SessionTarget |
Session session; |
16,23 → 18,50 |
@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() { |
public List<User> listUser() |
{ |
List<User> user = null; |
try { |
try |
{ |
user = session.createQuery("from User").list(); |
} catch (Exception e) { |
} |
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 saveUser(User user) { |
try { |
public void saveUser(User user) |
{ |
try |
{ |
session.save(user); |
} catch (Exception e) { |
} |
catch (Exception e) |
{ |
transaction.rollback(); |
e.printStackTrace(); |
} |
40,13 → 69,19 |
/** |
* Used to delete a user. |
* |
* @param int userId |
*/ |
@Override |
public void deleteUser(int userId) { |
try { |
public void deleteUser(int userId) |
{ |
try |
{ |
User user = (User) session.get(User.class, userId); |
session.delete(user); |
} catch (Exception e) { |
} |
catch (Exception e) |
{ |
transaction.rollback(); |
e.printStackTrace(); |
} |
60,14 → 95,19 |
* @return User: Returns a user object if something is found. If not, null |
* is returned |
*/ |
public User searchUsername(String username) { |
public User searchUsername(String username) |
{ |
User user = null; |
try { |
//Exec query |
try |
{ |
user = (User) session |
.createQuery("FROM User " + "WHERE username = :username") |
.setParameter("username", username).uniqueResult(); |
} catch (Exception e) { |
} |
catch (Exception e) |
{ |
// TODO: Log error |
} |
return user; |
/trunk/src/ch/ffhs/webE/dao/RelationshipTypeDAO.java |
---|
0,0 → 1,15 |
package ch.ffhs.webE.dao; |
import java.util.List; |
import ch.ffhs.webE.domain.RelationshipType; |
public interface RelationshipTypeDAO { |
List<RelationshipType> listRelationshipTypes(); |
boolean saveRelationshipType(RelationshipType relType); |
boolean deleteRelationshipType(int relTypeID); |
} |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: RelationshipTypeDAOImpl.java |
=================================================================== |
--- RelationshipTypeDAOImpl.java (nonexistent) |
+++ RelationshipTypeDAOImpl.java (revision 26) |
@@ -0,0 +1,97 @@ |
+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> listRelationshipTypes() |
+ { |
+ |
+ 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 saveRelationshipType(RelationshipType relType) |
+ { |
+ try |
+ { |
+ session.save(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 |
+ { |
+ User user = (User) session.get(RelationshipType.class, relTypeID); |
+ session.delete(user); |
+ return true; |
+ } |
+ catch (Exception e) |
+ { |
+ transaction.rollback(); |
+ // TODO: Logging |
+ return false; |
+ } |
+ } |
+} |
/RelationshipTypeDAOImpl.java |
---|
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |