@SuppressWarnings("unchecked") public List<MessageBundleProperty> search( String searchQuery, String module, String baseName, String locale) { List<String> values = new ArrayList<String>(); StringBuffer queryString = new StringBuffer(""); try { if (searchQuery != null && searchQuery.length() > 0) { queryString.append("(defaultValue like ? OR value like ? OR propertyName = ?)"); values.add("%" + searchQuery + "%"); values.add("%" + searchQuery + "%"); values.add(searchQuery); } if (module != null && module.length() > 0) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("moduleName = ? "); values.add(module); } if (baseName != null && baseName.length() > 0) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("baseName = ?"); values.add(baseName); } if (locale != null && locale.length() > 0) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("locale = ?"); values.add(locale); } if (queryString.length() > 0) { queryString.insert(0, "from MessageBundleProperty where "); } else { queryString.insert(0, "from MessageBundleProperty"); } return getHibernateTemplate().find(queryString.toString(), values.toArray()); } catch (Exception e) { logger.error("problem searching the message bundle data", e); } return new ArrayList<MessageBundleProperty>(); }
@Override public List<Forum> getForumsOfaUser(int userId) { // TODO Auto-generated method stub List<Forum> forums = new ArrayList<Forum>(); Session session = sessionFactory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); Query query = session.createQuery("from Subscription where userId = :userId"); query.setString("userId", String.valueOf(userId)); List<Subscription> userSubscribedGroups = query.list(); for (Subscription subsc : userSubscribedGroups) { query = session.createQuery("from Forum where forumId = :forumId"); query.setParameter("forumId", subsc.getForumId()); // add this to a list variable query.uniqueResult(); forums.add((Forum) query.uniqueResult()); } } catch (HibernateException e) { if (tx != null) { tx.rollback(); e.printStackTrace(); } } finally { session.close(); } return forums; }
public List<Team> getTeams() { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); List result = null; try { Transaction transaction = session.beginTransaction(); result = session.createQuery("from Team").list(); session.flush(); transaction.commit(); } catch (HibernateException e) { e.printStackTrace(); } finally { if (session.isOpen()) { session.close(); } } List<Team> teams = new ArrayList<Team>(); for (Object o : result) { if (o instanceof Team) { teams.add((Team) o); } } return teams; }
public List<Activity> getActivities(Event parent) { List<Activity> result = new ArrayList<Activity>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object event = session .createQuery("from Event as event where event.idevent= " + parent.getIdevent()) .uniqueResult(); transaction.commit(); if (event != null) { Event eventEntity = (Event) event; Collection<Activity> activityList = eventEntity.getActivities(); for (Activity activity : activityList) { result.add(activity); } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
/** * queues up a call to add or update message bundle data * * @param baseName * @param moduleName * @param bundleData * @param loc */ protected void queueBundle( String baseName, String moduleName, Map<String, String> bundleData, Locale loc) { SaveOrUpdateCall call = new SaveOrUpdateCall(); call.baseName = baseName; call.moduleName = moduleName; call.bundleData = bundleData; call.loc = loc; queue.add(call); }
public List<ActivityPartnerRequest> getAllActivityPartnerRequestForUser(User user) { List<ActivityPartnerRequest> result = new ArrayList<ActivityPartnerRequest>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction = session.beginTransaction(); List list = session .createQuery("from ActivityPartnerRequest apr where apr.iduser=" + user.getIduser()) .list(); transaction.commit(); if (list != null && list.size() > 0) { for (Object o : list) { result.add((ActivityPartnerRequest) o); } } return result; }
public List<Event> getEvent(String name) { List<Event> result = new ArrayList<Event>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from Event as event where event.name='" + name + "'").list(); transaction.commit(); for (Object o : list) { result.add((Event) o); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public List<User> getUsers() { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); List<User> result = new ArrayList<User>(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from User").list(); transaction.commit(); for (Object o : list) { User user = (User) o; result.add(user); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public List<Logo> getLogos() { List<Logo> result = new ArrayList<Logo>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from Logo").list(); transaction.commit(); for (Object o : list) { Logo logo = (Logo) o; result.add(logo); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public List<User> getUsersForTeam(Team team) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction = session.beginTransaction(); List list = session .createQuery( "from TeamUserSelection as teamUserSelection where teamUserSelection.idteam= " + team.getId()) .list(); transaction.commit(); if (list != null) { List<User> result = new ArrayList<User>(); for (Object o : list) { User user = getUser(((TeamUserSelection) o).getIduser()); result.add(user); } return result; } return null; }
public List<Activity> getActivities() { List<Activity> result = new ArrayList<Activity>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from Activity").list(); transaction.commit(); for (Object o : list) { Activity activity = (Activity) o; result.add(activity); } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
@SuppressWarnings("unchecked") public List<PostAndReply> getPostsAndReplies(int forumId) { // TODO Auto-generated method stub Session session = sessionFactory.openSession(); Transaction tx = null; List<Post> postArr = new ArrayList<Post>(); List<PostAndReply> prArray = new ArrayList<PostAndReply>(); try { tx = session.beginTransaction(); Query query = session.createQuery("from Post where forumId = :forumId order by createdDate desc"); query.setParameter("forumId", forumId); postArr = query.list(); System.out.println("No of posts.." + postArr.size()); for (Post post : postArr) { int postId = post.getPostId(); System.out.println("Post id----" + postId); List<Reply> replies = getRepliesToPost(postId); User user = getUser(post.getCreatedBy()); String postCreatorName = user.getFirstname() + ' ' + user.getLastname(); PostAndReply pr = new PostAndReply(); pr.setPost(post); pr.setReplies(replies); pr.setPostCreatorName(postCreatorName); prArray.add(pr); // System.out.println("Post - Description----"+post.getDescription()); // System.out.println("No of Replies----"+replies.size()); } } catch (HibernateException e) { if (tx != null) { tx.rollback(); e.printStackTrace(); } } finally { session.close(); } return prArray; }
public List<Location> getLocations() { List<Location> result = new ArrayList<Location>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from Location").list(); transaction.commit(); if (list != null) { for (Object o : list) { Location location = (Location) o; result.add(location); } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public List<ClassificationType> getClassificationTypes() { List<ClassificationType> result = new ArrayList<ClassificationType>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from ClassificationType").list(); transaction.commit(); if (list != null) { for (Object o : list) { ClassificationType classificationType = (ClassificationType) o; result.add(classificationType); } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public List<User> getUserForActivity(Activity activity) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); List<User> result = new ArrayList<User>(); try { Transaction transaction = session.beginTransaction(); String queryString = "select user from User as user where " + activity.getIdactivity() + " in elements (user.activities)"; List users = session.createQuery(queryString).list(); transaction.commit(); for (Object user : users) { result.add((User) user); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public List<User> getUserForEvent(Event selectedEvent) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); List<User> result = new ArrayList<User>(); try { Transaction transaction = session.beginTransaction(); String queryString = "select user from User as user where " + selectedEvent.getIdevent() + " in elements (user.events) order by user.firstname"; List users = session.createQuery(queryString).list(); transaction.commit(); for (Object user : users) { result.add((User) user); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public int getSearchCount(String searchQuery, String module, String baseName, String locale) { List<String> values = new ArrayList<String>(); List<NullableType> types = new ArrayList<NullableType>(); StringBuffer queryString = new StringBuffer(""); try { if (searchQuery != null && searchQuery.length() > 0) { queryString.append("(defaultValue like ? OR value like ? OR propertyName = ?)"); values.add("%" + searchQuery + "%"); values.add("%" + searchQuery + "%"); values.add(searchQuery); types.add(Hibernate.STRING); types.add(Hibernate.STRING); types.add(Hibernate.STRING); } if (module != null && module.length() > 0) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("moduleName = ? "); values.add(module); types.add(Hibernate.STRING); } if (baseName != null && baseName.length() > 0) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("baseName = ?"); values.add(baseName); types.add(Hibernate.STRING); } if (locale != null && locale.length() > 0) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("locale = ?"); values.add(locale); types.add(Hibernate.STRING); } if (queryString.length() > 0) { queryString.insert(0, "select count(*) from MessageBundleProperty where "); } else { queryString.insert(0, "select count(*) from MessageBundleProperty"); } Integer count = null; try { Query query = getSession().createQuery(queryString.toString()); query.setParameters(values.toArray(), (Type[]) types.toArray(new Type[types.size()])); count = (Integer) query.uniqueResult(); } catch (HibernateException e) { throw new RuntimeException(e.getMessage(), e); } return count.intValue(); } catch (Exception e) { logger.error("problem searching the message bundle data", e); } return 0; }