Package org.springframework.orm.hibernate3

Examples of org.springframework.orm.hibernate3.HibernateTemplate


        else
            return null;
    }

    public void saveSong(Song song) {
    HibernateTemplate ht = getHibernateTemplate();
        try {
            ht.saveOrUpdate(song);
            song = (Song) ht.get(Song.class, song.getId());
        } catch (Exception e) {
            log.error(song.toString(), e);
        }

    ht.flush();
  }
View Full Code Here


//    protected String[] getConfigLocations() {
//        return new String [] {"/WEB-INF/classes/applicationContext.xml"};
//    }
 
  public void saveObject(Object o) {
    HibernateTemplate ht = getHibernateTemplate();
        try {
            ht.saveOrUpdate(o);
        } catch (DataIntegrityViolationException e) {
            log.warn("DataIntegrityViolationException while saveOrUpdate(): \n\t" + e.getMessage() + "\n\t" + o.toString());
        }
    }
View Full Code Here

  public User getUser(Integer id) {
    return (User) getObject(User.class, id);
  }

    public User getUser(String username) {
        HibernateTemplate ht = getHibernateTemplate();
        User user = (User)ht.find("from User user where user.username = '"+username+"'");
        return (user);
    }
View Full Code Here

        User user = (User)ht.find("from User user where user.username = '"+username+"'");
        return (user);
    }

    public void saveUser(User user) {
    HibernateTemplate ht = getHibernateTemplate();
    ht.saveOrUpdate(user);
    user = (User) ht.get(User.class, user.getId());
    ht.flush();
  }
View Full Code Here

  @Transactional(readOnly = false)
  public boolean moveScheduleActionUp(ScheduleAction action)
  {
    synchronized (ScheduleAction.class)
    {
      HibernateTemplate htl = getHibernateTemplate();

      if (action.getPosition() > 1)
      {
        List<ScheduleAction> prevActions = htl.find(
                "from ScheduleAction where scheduleId = ? and position = ?", new Object[]
                {
                        action.getScheduleId(), action.getPosition() - 1
                });

        if (prevActions.size() > 0)
        {
          prevActions.get(0).setPosition(action.getPosition());
          htl.update(prevActions.get(0));
        }

        action.setPosition(action.getPosition() - 1);
        htl.update(action);

        return true;
      }

      return false;
View Full Code Here

  @Transactional(readOnly = false)
  public boolean moveScheduleActionDown(ScheduleAction action)
  {
    synchronized (ScheduleAction.class)
    {
      HibernateTemplate htl = getHibernateTemplate();
      Integer maxPosition = (Integer) htl.find("select max(position) from ScheduleAction where scheduleId = ?",
              action.getScheduleId()).get(0);

      if (action.getPosition() < maxPosition)
      {
        List<ScheduleAction> nextActions = htl.find(
                "from ScheduleAction where scheduleId = ? and position = ?", new Object[]
                {
                        action.getScheduleId(), action.getPosition() + 1
                });

        if (nextActions.size() > 0)
        {
          nextActions.get(0).setPosition(action.getPosition());
          htl.update(nextActions.get(0));
        }

        action.setPosition(action.getPosition() + 1);
        htl.update(action);

        return true;
      }

      return false;
View Full Code Here

  @Transactional(readOnly = false)
  public boolean moveScheduleActionToFront(ScheduleAction action)
  {
    synchronized (ScheduleAction.class)
    {
      HibernateTemplate htl = getHibernateTemplate();
      List<ScheduleAction> prevActions = htl.find("from ScheduleAction where scheduleId = ? and position < ?",
              new Object[]
              {
                      action.getScheduleId(), action.getPosition()
              });

      for (ScheduleAction prevAction : prevActions)
      {
        prevAction.setPosition(prevAction.getPosition() + 1);
        htl.update(prevAction);
      }

      if (action.getPosition() != 1)
      {
        action.setPosition(1);
        htl.update(action);

        return true;
      }

      return false;
View Full Code Here

  @Transactional(readOnly = false)
  public boolean moveScheduleActionToEnd(ScheduleAction action)
  {
    synchronized (ScheduleAction.class)
    {
      HibernateTemplate htl = getHibernateTemplate();
      Integer maxPosition = (Integer) htl.find("select max(position) from ScheduleAction where scheduleId = ?",
              action.getScheduleId()).get(0);
      List<ScheduleAction> nextActions = htl.find("from ScheduleAction where scheduleId = ? and position > ?",
              new Object[]
              {
                      action.getScheduleId(), action.getPosition()
              });

      for (ScheduleAction nextAction : nextActions)
      {
        nextAction.setPosition(nextAction.getPosition() - 1);
        htl.update(nextAction);
      }

      if (action.getPosition() != maxPosition)
      {
        action.setPosition(maxPosition);
        htl.update(action);

        return true;
      }

      return false;
View Full Code Here

  /**
   * @see de.iritgo.aktera.authentication.defaultauth.entity.UserDAO#findGroupsByUser(de.iritgo.aktera.authentication.defaultauth.entity.AkteraUser)
   */
  public List<AkteraGroup> findGroupsByUser(AkteraUser user)
  {
    HibernateTemplate htl = getHibernateTemplate();
    List<AkteraGroup> groups = new LinkedList();
    List<AkteraGroupEntry> entries = htl.find("from AkteraGroupEntry where userId = ?", user.getId());

    for (AkteraGroupEntry entry : entries)
    {
      AkteraGroup group = (AkteraGroup) htl.get(AkteraGroup.class, entry.getGroupId());

      groups.add(group);
    }

    return groups;
View Full Code Here

  /**
   * @see de.iritgo.aktera.authentication.defaultauth.entity.UserDAO#findUsersByGroup(de.iritgo.aktera.authentication.defaultauth.entity.AkteraGroup)
   */
  public List<AkteraUser> findUsersByGroup(AkteraGroup group)
  {
    HibernateTemplate htl = getHibernateTemplate();
    List<AkteraUser> users = new LinkedList();
    List<AkteraGroupEntry> entries = htl.find("from AkteraGroupEntry where groupId = ?", group.getId());
    for (AkteraGroupEntry entry : entries)
    {
      AkteraUser user = (AkteraUser) htl.get(AkteraUser.class, entry.getUserId());

      users.add(user);
    }
    return users;
  }
View Full Code Here

TOP

Related Classes of org.springframework.orm.hibernate3.HibernateTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.