Package contains the implemenatation dao classes of the application.
Package net.devmanuals.dao.daoImpl
The classes in net.devmanuals.dao.daoImpl package is used by the Hibernate API to interact with database. The structure of the net.devmanuals.dao.daoImpl package and code of each class with description is given below :
AdminDaoImpl.java
This class is used to interact with admin table.
package net.devmanuals.dao.daoImpl; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import net.devmanuals.dao.AdminDao; import net.devmanuals.model.Admin; @Repository("adminDao") public class AdminDaoImpl implements AdminDao { @Autowired private SessionFactory sessionFactory; @Override public List<Admin> validateLoginAdmin(String adminEmail, String password) { return sessionFactory .getCurrentSession() .createQuery( "from Admin where adminEmail=:adminEmail and password=:password") .setString("adminEmail", adminEmail).setString("password", password).list(); } @Override public List<Admin> getAdminByAdminEmail(String adminEmail) { return sessionFactory.getCurrentSession().createQuery( "from Admin where adminEmail=:adminEmail").setParameter( "adminEmail", adminEmail).list(); } }
LanguageDaoImpl.java
This class is used to interact with language table.
package net.devmanuals.dao.daoImpl; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import net.devmanuals.dao.LanguageDao; import net.devmanuals.model.Language; import net.devmanuals.model.User; @Repository("languageDao") public class LanguageDaoImpl implements LanguageDao { @Autowired private SessionFactory sessionFactory; public List<Language> listLanguages() { return (List<Language>) sessionFactory.getCurrentSession() .createCriteria(Language.class).list(); } @Override public List<Language> getLanguageByLanguageId(Long languageId) { return sessionFactory.getCurrentSession().createQuery( "from Language where languageId=:languageId").setParameter( "languageId", languageId).list(); } }
QuestionOptionsDaoImpl.java
This class is used to interact with question_options table.
package net.devmanuals.dao.daoImpl; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import net.devmanuals.dao.QuestionOptionsDao; import net.devmanuals.model.QuestionOptions; @Repository("questionOptionsDao") public class QuestionOptionsDaoImpl implements QuestionOptionsDao { @Autowired private SessionFactory sessionFactory; public List<QuestionOptions> listQuestionOptions() { return sessionFactory.getCurrentSession().createQuery( "from QuestionOptions where quesOpId=1").list(); } @Override public List<QuestionOptions> getQuestionOptionsByQuestionId(Long questionId) { return sessionFactory.getCurrentSession().createQuery( "from QuestionOptions where questionId=:questionId") .setParameter("questionId", questionId).list(); } @Override public List<QuestionOptions> getQuestionOptionsByQuesOpId(Long quesOpId) { return sessionFactory.getCurrentSession().createQuery( "from QuestionOptions where quesOpId=:quesOpId").setParameter( "quesOpId", quesOpId).list(); } @Override public void saveQuestionOptions(QuestionOptions questionOptions) { sessionFactory.getCurrentSession().saveOrUpdate(questionOptions); } @Override public void updateQuestionOptions(QuestionOptions questionOptions) { sessionFactory .getCurrentSession() .createQuery( "UPDATE QuestionOptions SET ansDescription=:ansDescription ,questionId=:questionId where quesOpId=:quesOpId") .setParameter("ansDescription", questionOptions.getAnsDescription()).setParameter( "questionId", questionOptions.getQuestionId()) .setParameter("quesOpId", questionOptions.getQuesOpId()) .executeUpdate(); } @Override public void deleteQuestionOptionsByQuestionId(Long questionId) { sessionFactory.getCurrentSession().createQuery( "delete from QuestionOptions where questionId=:questionId") .setParameter("questionId", questionId).executeUpdate(); } }
QuestionsDaoImpl.java
This class is used to interact with questions table.
package net.devmanuals.dao.daoImpl; import java.util.List; import org.hibernate.SessionFactory; import org.hibernate.criterion.Order; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import net.devmanuals.dao.QuestionsDao; import net.devmanuals.model.Questions; @Repository("questionsDao") public class QuestionsDaoImpl implements QuestionsDao { @Autowired private SessionFactory sessionFactory; public List<Questions> listQuestions() { return (List<Questions>) sessionFactory.getCurrentSession() .createCriteria(Questions.class).addOrder( Order.desc("questionId")).list(); } @Override public List<Questions> getQuestionsByLanguageId(Long languageId) { return sessionFactory .getCurrentSession() .createQuery( "from Questions where languageId=:languageId ORDER BY questionId DESC") .setParameter("languageId", languageId).list(); } @Override public List<Questions> getQuestionsByQuestionId(Long questionId) { return sessionFactory .getCurrentSession() .createQuery( "from Questions where questionId=:questionId ORDER BY questionId DESC") .setParameter("questionId", questionId).list(); } public void saveQuestions(Questions questions) { sessionFactory.getCurrentSession().save(questions); } @Override public void updateQuestions(Questions questions) { sessionFactory .getCurrentSession() .createQuery( "UPDATE Questions SET languageId=:languageId ,question=:question , rightOption=:rightOption where questionId=:questionId") .setParameter("languageId", questions.getLanguageId()) .setParameter("question", questions.getQuestion()) .setParameter("rightOption", questions.getRightOption()) .setParameter("questionId", questions.getQuestionId()) .executeUpdate(); } @Override public void deleteQuestions(Questions questions) { sessionFactory.getCurrentSession().createQuery( "delete from Questions where questionId=:questionId") .setParameter("questionId", questions.getQuestionId()) .executeUpdate(); } @Override public List<Questions> getTenRandomQuestionsByLanguageId(Long languageId) { return (List<Questions>) sessionFactory .getCurrentSession() .createQuery( "from Questions where languageId=:languageId order by rand()") .setParameter("languageId", languageId).setMaxResults(10) .list(); } }
UserDaoImpl.java
This class is used to interact with user table.
package net.devmanuals.dao.daoImpl; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import net.devmanuals.dao.UserDao; import net.devmanuals.model.User; @Repository("userDao") public class UserDaoImpl implements UserDao { @Autowired private SessionFactory sessionFactory; public List<User> listUsers() { return (List<User>) sessionFactory.getCurrentSession().createCriteria( User.class).list(); } @Override public void saveUser(User user) { sessionFactory.getCurrentSession().saveOrUpdate(user); } @Override public List<User> getUserByUserEmail(String userEmail) { return sessionFactory.getCurrentSession().createQuery( "from User where userEmail=:userEmail").setString("userEmail", userEmail).list(); } @Override public List<User> validateLoginUser(String userEmail, String password) { return sessionFactory.getCurrentSession().createQuery( "from User where userEmail=:userEmail and password=:password") .setString("userEmail", userEmail).setString("password", password).list(); } }
[ 0 ] Comments