* LoginAction.java - Use UserDAOImpl type for better source lookup * TermAction.ava - Use obvious serialization version - Implemented add() * UserAction.java - Use more obvious serialization version * TermDAO.java - Renamed listTermById() to getTermById() - Added Javadoc * TermDAOImpl.java - Fixed "FROM term" bug (no SQL, case-sensitive) - saveOrUpdate() now returns boolean (for TermAction) * Term.java - Now imports java.io.Serializable - Added serialization version ID - Use TermDAOImpl type for better source lookup * struts.xml - /doTermAdd now triggers add() - Added basic Term actions * user/nav.jsp - Added /listTerm link to trigger user/termList.jsp * user/termAddForm.jsp - Now functional and reusable for Rename Term * General: - Clean-up: + Renamed Object to ObjectEntity + Source formatting - Added javax.persistence and org.hibernate sources (for Javadoc) - Added PDF documentation generated from OpenDocument Text
/trunk/src/ch/ffhs/webE/dao/TermDAO.java |
---|
17,6 → 17,12 |
List<Term> listTerm(); |
/** |
* @param termName |
* @return |
*/ |
Term searchTerm(String termName); |
/** |
* Delete a term |
* |
* @param termId |
25,12 → 31,10 |
void deleteTerm(int termId); |
/** |
* Retrieves a term by ID |
* |
* @param termId |
* @return |
*/ |
Term getTermById(int termId); |
Term listTermById(int termId); |
/** |
* Executes the query to save the term |
37,7 → 41,6 |
* |
* @param term |
* Domain object to be saved |
* @return <code>true</code> if successful, <code>false</code> otherwise |
*/ |
boolean saveOrUpdate(Term term); |
void saveOrUpdate(Term term); |
} |
/trunk/src/ch/ffhs/webE/dao/TermDAOImpl.java |
---|
42,7 → 42,7 |
List<Term> term = null; |
try |
{ |
term = this.session.createQuery("from Term").list(); //$NON-NLS-1$ |
term = this.session.createQuery("FROM term").list(); //$NON-NLS-1$ |
} |
catch (Exception e) |
{ |
57,7 → 57,6 |
{ |
term = new ArrayList<Term>(); |
} |
return term; |
} |
66,19 → 65,16 |
* |
* @see ch.ffhs.webE.dao.TermDAO#saveOrUpdate(ch.ffhs.webE.domain.Term) |
*/ |
public boolean saveOrUpdate(Term term) |
public void saveOrUpdate(Term term) |
{ |
try |
{ |
term.setObjectId(term.getObjectId()); |
this.session.saveOrUpdate(term); |
return true; |
} |
catch (Exception e) |
{ |
this.transaction.rollback(); |
e.printStackTrace(); |
return false; |
} |
} |
91,8 → 87,8 |
{ |
try |
{ |
Term term = (Term) this.session.get(Term.class, termId); |
this.session.delete(term); |
Term user = (Term) this.session.get(Term.class, termId); |
this.session.delete(user); |
} |
catch (Exception e) |
{ |
101,17 → 97,43 |
} |
} |
/* |
* (non-Javadoc) |
/** |
* Returns a single user with this user name (used for login) |
* |
* @see ch.ffhs.webE.dao.TermDAO#getTermById(int) |
* @param termName |
* Term name |
* @return User: Returns a user object if something is found. If not, null is |
* returned |
*/ |
public Term getTermById(int termId) |
public Term searchTerm(String termName) |
{ |
Term term = null; |
/* Exec query */ |
try |
{ |
term = (Term) this.session |
.createQuery("FROM User " + "WHERE username = :username") //$NON-NLS-1$ //$NON-NLS-2$ |
.setParameter("username", termName).uniqueResult(); //$NON-NLS-1$ |
} |
catch (Exception e) |
{ |
/* TODO: Log error */ |
} |
return term; |
} |
/** |
* List a term by ID |
* |
* @param termId |
* @return |
*/ |
public Term listTermById(int termId) |
{ |
Term term = null; |
try |
{ |
term = (Term) this.session.get(Term.class, termId); |
} |
catch (Exception e) |
118,7 → 140,6 |
{ |
e.printStackTrace(); |
} |
return term; |
} |
} |
/trunk/src/ch/ffhs/webE/dao/UserDAOImpl.java |
---|
6,10 → 6,9 |
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; |
import ch.ffhs.webE.domain.*; |
public class UserDAOImpl implements UserDAO |
{ |
32,7 → 31,7 |
List<User> user = null; |
try |
{ |
user = this.session.createQuery("from User").list(); |
user = session.createQuery("from User").list(); |
} |
catch (Exception e) |
{ |
60,11 → 59,11 |
{ |
try |
{ |
this.session.saveOrUpdate(user); |
session.saveOrUpdate(user); |
} |
catch (Exception e) |
{ |
this.transaction.rollback(); |
transaction.rollback(); |
e.printStackTrace(); |
} |
} |
79,12 → 78,12 |
{ |
try |
{ |
User user = (User) this.session.get(User.class, userId); |
this.session.delete(user); |
User user = (User) session.get(User.class, userId); |
session.delete(user); |
} |
catch (Exception e) |
{ |
this.transaction.rollback(); |
transaction.rollback(); |
e.printStackTrace(); |
} |
} |
94,8 → 93,8 |
* |
* @param username |
* : String - entire user name |
* @return User: Returns a user object if something is found. If not, null is |
* returned |
* @return User: Returns a user object if something is found. If not, null |
* is returned |
*/ |
public User searchUsername(String username) |
{ |
104,7 → 103,7 |
// Exec query |
try |
{ |
user = (User) this.session |
user = (User) session |
.createQuery("FROM User " + "WHERE username = :username") |
.setParameter("username", username).uniqueResult(); |
} |
124,7 → 123,7 |
User user = null; |
try |
{ |
user = (User) this.session.get(User.class, userId); |
user = (User) session.get(User.class, userId); |
} |
catch (Exception e) |
{ |