Beispiel #1
0
  public void init(ServletConfig servletConfig) throws ServletException {

    super.init(servletConfig);

    ServletContext sc = servletConfig.getServletContext();

    wac = WebApplicationContextUtils.getWebApplicationContext(sc);
    headerPreContent = servletConfig.getInitParameter("headerPreContent");
    headerScriptSource = servletConfig.getInitParameter("headerScriptSource");
    footerScript = servletConfig.getInitParameter("footerScript");
    try {
      boolean logResponse = "true".equalsIgnoreCase(servletConfig.getInitParameter("log-response"));
      TimeLogger.setLogResponse(logResponse);
    } catch (Exception ex) {

    }
    try {
      boolean logFullResponse =
          "true".equalsIgnoreCase(servletConfig.getInitParameter("log-full-response"));
      TimeLogger.setLogFullResponse(logFullResponse);
    } catch (Exception ex) {

    }

    String basePath = servletConfig.getServletContext().getRealPath("/");
    dispatcher = new MapDispatcher(sc);
  }
 /**
  * @see
  *     uk.ac.cam.caret.sakai.rwiki.service.api.api.dao.RWikiHistoryObjectDao#getRWikiHistoryObject(uk.ac.cam.caret.sakai.rwiki.service.api.api.model.RWikiObject,
  *     int)
  */
 public RWikiHistoryObject getRWikiHistoryObject(final RWikiObject rwo, final int revision) {
   long start = System.currentTimeMillis();
   try {
     HibernateCallback callback =
         new HibernateCallback() {
           public Object doInHibernate(Session session) throws HibernateException {
             return session
                 .createCriteria(RWikiHistoryObject.class)
                 .add(Expression.eq("rwikiobjectid", rwo.getRwikiobjectid()))
                 .add(Expression.eq("revision", Integer.valueOf(revision)))
                 .list();
           }
         };
     List found = (List) getHibernateTemplate().execute(callback);
     if (found.size() == 0) {
       if (log.isDebugEnabled()) {
         log.debug("Found " + found.size() + " objects with id " + rwo.getRwikiobjectid());
       }
       return null;
     }
     if (log.isDebugEnabled()) {
       log.debug(
           "Found "
               + found.size()
               + " objects with id "
               + rwo.getRwikiobjectid()
               + " returning most recent one.");
     }
     return (RWikiHistoryObject) proxyObject(found.get(0));
   } finally {
     long finish = System.currentTimeMillis();
     TimeLogger.printTimer(
         "RWikiHistoryObjectDaoImpl.getRWikiHistoryObject: " + rwo.getName(), start, finish);
   }
 }
 public Preference findExactByUser(final String user, final String context, final String type) {
   long start = System.currentTimeMillis();
   try {
     // there is no point in sorting by version, since there is only one
     // version in
     // this table.
     // also using like is much slower than eq
     HibernateCallback callback =
         new HibernateCallback() {
           public Object doInHibernate(Session session) throws HibernateException {
             return session
                 .createCriteria(Preference.class)
                 .add(Expression.eq("userid", user))
                 .add(Expression.eq("preftype", type))
                 .add(Expression.eq("prefcontext", context))
                 .list();
           }
         };
     List found = (List) getHibernateTemplate().execute(callback);
     if (found.size() == 0) {
       if (log.isDebugEnabled()) {
         log.debug("Found " + found.size() + " objects with name " + user);
       }
       return null;
     }
     if (log.isDebugEnabled()) {
       log.debug(
           "Found " + found.size() + " objects with name " + user + " returning most recent one.");
     }
     return (Preference) found.get(0);
   } finally {
     long finish = System.currentTimeMillis();
     TimeLogger.printTimer("PreferenceDaoImpl.findExactByUser: " + user, start, finish);
   }
 }
 public List findByUser(final String user, final String context, final String type) {
   long start = System.currentTimeMillis();
   try {
     // there is no point in sorting by version, since there is only one
     // version in
     // this table.
     // also using like is much slower than eq
     HibernateCallback callback =
         new HibernateCallback() {
           public Object doInHibernate(Session session) throws HibernateException {
             String prefcontext = context + "%";
             return session
                 .createCriteria(Preference.class)
                 .add(Expression.eq("userid", user))
                 .add(Expression.eq("preftype", type))
                 .add(Expression.like("prefcontext", prefcontext))
                 .list();
           }
         };
     return (List) getHibernateTemplate().execute(callback);
   } finally {
     long finish = System.currentTimeMillis();
     TimeLogger.printTimer("PreferenceDaoImpl.findByUser: " + user, start, finish);
   }
 }
  public int delete(final Preference pref) {

    long start = System.currentTimeMillis();
    try {
      // there is no point in sorting by version, since there is only one
      // version in
      // this table.
      // also using like is much slower than eq
      HibernateCallback callback =
          new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {

              session.delete(pref);
              return Integer.valueOf(1);
            }
          };
      return ((Integer) getHibernateTemplate().execute(callback)).intValue();
    } finally {
      long finish = System.currentTimeMillis();
      TimeLogger.printTimer("PreferenceDaoImpl.delete: " + pref, start, finish);
    }
  }
 public List findRWikiHistoryObjectsInReverse(final RWikiObject reference) {
   long start = System.currentTimeMillis();
   try {
     HibernateCallback callback =
         new HibernateCallback() {
           public Object doInHibernate(Session session) throws HibernateException {
             return session
                 .createCriteria(RWikiHistoryObject.class)
                 .add(Expression.eq("rwikiobjectid", reference.getRwikiobjectid()))
                 .addOrder(Order.desc("revision"))
                 .list();
           }
         };
     List found = (List) getHibernateTemplate().execute(callback);
     if (found.size() == 0) {
       if (log.isDebugEnabled()) {
         log.debug("Found " + found.size() + " objects with id " + reference.getRwikiobjectid());
       }
       return null;
     }
     if (log.isDebugEnabled()) {
       log.debug(
           "Found "
               + found.size()
               + " objects with id "
               + reference.getRwikiobjectid()
               + " returning most recent one.");
     }
     return new ListProxy(found, this);
   } finally {
     long finish = System.currentTimeMillis();
     TimeLogger.printTimer(
         "RWikiHistoryObjectDaoImpl.getRWikiHistoryObjects: " + reference.getName(),
         start,
         finish);
   }
 }