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> listRelationships() |
{ |
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; |
} |
} |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: RelationshipTypeDAOImpl.java |
=================================================================== |
--- RelationshipTypeDAOImpl.java (revision 33) |
+++ RelationshipTypeDAOImpl.java (revision 34) |
@@ -26,7 +26,7 @@ |
*/ |
@SuppressWarnings("unchecked") |
@Override |
- public List<RelationshipType> listRelationshipTypes() |
+ public List<RelationshipType> getRelTypes() |
{ |
List<RelationshipType> relType = null; |
@@ -100,7 +100,7 @@ |
* Used to get a relationship type by ID |
*/ |
@Override |
- public RelationshipType listRelTypeById(int relTypeID) |
+ public RelationshipType getRelTypeById(int relTypeID) |
{ |
RelationshipType relType = null; |
try |