Package ru.yandex.strictweb.ajaxtools.orm

Examples of ru.yandex.strictweb.ajaxtools.orm.ORMManager


    }
   
    void doRequests(HttpServletRequest request, HttpServletResponse response, Reader input) throws ServletException, IOException {
      preventCaching(response);
     
    ORMManager orm = ormManagerProvider != null ? ormManagerProvider.getORMManager() : null;
   
        Presentation present = getPresentation(request, response);
       
    try {
      if(null!=orm) orm.begin();

      response.setCharacterEncoding("utf-8");
     
            if(authorityProvider != null) {
                authorityProvider.checkRequest(request);
            }
           
      List<AjaxRequestResult> results = new ArrayList<AjaxRequestResult>();
           
      final EntityManager em = orm == null ? null : orm.get();
     
     
      XmlRePresentation.EntityFinder ef = new XmlRePresentation.EntityFinder() {
        public Object find(Class clazz, Object primaryKey) {
            if(em == null) return createFakeEntity(clazz, primaryKey);
          return em.find(clazz, primaryKey);
        }
      };
     
      JsonRePresentation rep = new JsonRePresentation(ef).reset(input);
     
      if(rep.lexer.yylex() != Yytoken.TYPE_LEFT_SQUARE) throw new ParseException("request args should be passed as array");
     
      for(int i=0;;i++) {
          AjaxRequestResult result = new AjaxRequestResult();
                   
          try {       
                String beanName = getStringFromJsonArray("Bean name expected", rep);
                if(beanName==null) break;
               
                String methodName = getStringFromJsonArray("Method name expected", rep);
                if(methodName==null) break;
               
                rep.lexer.yylex();
                  if(rep.lexer.type != Yytoken.TYPE_COMMA) {
                      throw new ParseException("Method " + methodName + " args expected as array");
                  }
                             
                    if(!doAction(beanName, methodName, rep, request, result)) break;
           
            if(orm != null) orm.commit();
   
          }catch(Throwable e) {
            if(e.getClass().getCanonicalName().equals("org.eclipse.jetty.continuation.ContinuationThrowable")) {
              throw e;
            }
            e.printStackTrace();
            if(null!=orm) orm.rollback();
            result.setError(e);
            if(e instanceof ParseException) {
                results.add(result);
                break;
            }
          }
         
          results.add(result);
      }
      present.present(response.getWriter(), results);
    }catch(Throwable e) {
      if(e.getClass().getCanonicalName().equals("org.eclipse.jetty.continuation.ContinuationThrowable")) {
        throw (Error)e;
      }
      e.printStackTrace();
      if(null!=orm) orm.rollback();

      try {
                present.present(response.getWriter(), e);
            } catch (Throwable e1) {
                response.sendError(500, e.getMessage());
            }
    } finally {
      if(null!=orm) orm.close();
    }
  }
View Full Code Here

TOP

Related Classes of ru.yandex.strictweb.ajaxtools.orm.ORMManager

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.