コード例 #1
0
  private File _call() {
    // If development
    if (ERXApplication.isDevelopmentModeSafe()) {
      parameters.put("_isDevelopmentMode", Boolean.TRUE);
    } else {
      parameters.put("_isDevelopmentMode", Boolean.FALSE);
    }

    reportFile = null;

    if (log.isDebugEnabled()) log.debug("Starting JasperReportTask: " + toString());
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {

      @SuppressWarnings("unchecked")
      NSArray<EOEnterpriseObject> objects = ec.objectsWithFetchSpecification(fetchSpecification);

      jrDataSource = new ERJRFoundationDataSource(objects);

      if (jasperCompiledReportFileName != null) {
        reportFile =
            ERJRUtilities.runCompiledReportToPDFFile(
                jasperCompiledReportFileName, frameworkName, parameters, jrDataSource);
      }

    } catch (Exception e) {
      throw new NestableRuntimeException(e);
    } finally {
      ec.unlock();
    }

    return reportFile;
  }
コード例 #2
0
  @Override
  public WOActionResults performAction() {
    log.debug("The result of the task was " + _result);
    if (_nextPage != null && _nextPageResultKey != null) {
      if (_result instanceof EOGlobalID) {

        // Inflate it to a fault
        EOEditingContext ec = ERXEC.newEditingContext();
        // Let's ensure fresh ec since we are likely coming out of a background task
        ec.setFetchTimestamp(System.currentTimeMillis());

        _result = ec.faultForGlobalID((EOGlobalID) _result, ec);
      }
      _nextPage.takeValueForKey(_result, _nextPageResultKey);
    }

    if (_nextPage != null && _nextPageValues != null) {
      for (String key : nextPageValues().allKeys()) {
        Object value = nextPageValues().valueForKey(key);
        _nextPage.takeValueForKey(value, key);
      }
    }

    if (_nextPage != null && _nextPage instanceof IERXRefreshPage) {
      ((IERXRefreshPage) _nextPage).refresh();
    }

    return _nextPage;
  }
コード例 #3
0
ファイル: Main.java プロジェクト: t-evans/memory-leak-test
  public WOActionResults createDataStore() throws IOException, MessagingException {
    File emailFile = new File("Resources/largeEmail.eml");
    javax.mail.Message message = convertEmlToMessage(emailFile);

    EOObjectStore osc = new ERXObjectStoreCoordinator(true);
    EOEditingContext ec = ERXEC.newEditingContext(osc);
    ec.lock();
    try {
      DataContainer container =
          (DataContainer)
              EOUtilities.createAndInsertInstance(ec, DataContainer.class.getSimpleName());

      DataStore dataStore =
          (DataStore) EOUtilities.createAndInsertInstance(ec, DataStore.class.getSimpleName());
      dataStore.setDataContainer(container);

      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      message.writeTo(byteStream);
      NSData rawEmail = new NSData(byteStream.toByteArray());
      dataStore.setData(rawEmail);

      ec.saveChanges();
    } finally {
      ec.unlock();
      ec.dispose();
      osc.dispose();
      ec = null;
      osc = null;
    }
    return null;
  }
コード例 #4
0
ファイル: PluginTest.java プロジェクト: hypeastrum/wonder
  protected void resetData() {
    ERXEC ec = (ERXEC) ERXEC.newEditingContext();
    ERXEOAccessUtilities.ChannelAction action =
        new ERXEOAccessUtilities.ChannelAction() {
          @Override
          protected int doPerform(EOAdaptorChannel channel) {
            try {
              ERXJDBCUtilities.executeUpdateScript(
                  channel,
                  "update city set countryID = null;\n"
                      + "update country set capitalID = null;\n"
                      + "update countrylanguage set countryID = null;\n"
                      + "delete from city;\n "
                      + "delete from countrylanguage;\n"
                      + "delete from country;");

              final String sql =
                  ERXFileUtilities.stringFromInputStream(
                      ERXFileUtilities.inputStreamForResourceNamed("world.sql", null, null));
              ERXJDBCUtilities.executeUpdateScript(channel, sql);
            } catch (SQLException e) {
              log.error(org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e), e);
              throw new NSForwardException(e);
            } catch (IOException e) {
              log.error(org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e), e);
              throw new NSForwardException(e);
            }
            return 0;
          }
        };
    action.perform(ec, model.name());
  }
コード例 #5
0
 // CLAUSE WHERE "UV.ANUNIV || UV.PRDUNIV = ... AND UV.UVC = ...
 // AND UV.ANUNIV || UV.PRDUNIV = EIA.ANUNIV || EIA.PRDUNIV" UV o� est
 // inscris l'�tudiant
 private static EOQualifier qualForUv(String uv, String periode) {
   // ARGSUV.addObject(uv);
   NSMutableArray quals = new NSMutableArray();
   EOEditingContext myContext = ERXEC.newEditingContext();
   EOQualifier qalUv =
       EOVueInsuv.UVC
           .eq(uv)
           .and(
               EOVueInsuv.EO_ETUDIANT_INSCR_ADM
                   .dot(EOEtudiantInscrAdm.ETU_ID)
                   .eq(EOVueInsuv.ETU_ID));
   quals.addObject(qalUv);
   if (periode != null) {
     EOQualifier qualPer =
         EOQualifier.qualifierWithQualifierFormat("anUniv=%@ AND prdUniv=%@", ARGSUV);
     quals.addObject(qualPer);
   }
   EOFetchSpecification spec = null;
   if (quals.count() == 2) {
     EOQualifier qual = new EOAndQualifier(quals);
     spec = new EOFetchSpecification("EOVueInsuv", qual, null);
   } else {
     spec = new EOFetchSpecification("EOVueInsuv", qalUv, null);
   }
   spec.setUsesDistinct(true);
   NSArray uvs = myContext.objectsWithFetchSpecification(spec);
   NSMutableArray etuids = new NSMutableArray();
   for (int i = 0; i < uvs.count(); i++) {
     EOVueInsuv luv = (EOVueInsuv) uvs.objectAtIndex(i);
     Long etu_id = luv.etuId();
     etuids.addObject(etu_id);
   }
   EOQualifier fin = ETU_INSCR_ADMS.dot(EOEtudiantInscrAdm.ETU_ID).in(etuids.immutableClone());
   return fin;
 }
コード例 #6
0
  public ERJRFetchSpecificationReportTask(
      EOFetchSpecification fetchSpecification,
      String jasperCompiledReportFileName,
      String frameworkName,
      HashMap<String, Object> parameters) {
    ERXAssert.PRE.notNull(fetchSpecification);
    ERXAssert.PRE.notNull(jasperCompiledReportFileName);

    // Since it is likely the fetch spec will be used in a different
    // background thread during report generation, we need to ensure we have a schema-based
    // qualifier instead of a memory-based qualifier that might have references to EOs
    // in an RR-locked editing context
    EOFetchSpecification fs = null;
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      fs = schemaBasedFetchSpecification(fetchSpecification);
    } catch (Exception e) {
      throw new RuntimeException("Failed to convert fetchSpecification to schema-based", e);
    } finally {
      ec.unlock();
    }
    this.fetchSpecification = fs;

    this.jasperCompiledReportFileName = jasperCompiledReportFileName;
    this.frameworkName = frameworkName;
    this.parameters = parameters;

    if (this.parameters == null) {
      this.parameters = new HashMap<String, Object>();
    }
  }
コード例 #7
0
ファイル: DataCreator.java プロジェクト: hmng/wonder
 public void createDummyData() {
   ec = ERXEC.newEditingContext();
   ec.lock();
   try {
     doCreateDummyData();
   } finally {
     ec.unlock();
   }
 }
コード例 #8
0
ファイル: DataCreator.java プロジェクト: hmng/wonder
 public void createTables() {
   ec = ERXEC.newEditingContext();
   ec.lock();
   try {
     boolean dropTables = ERXProperties.booleanForKeyWithDefault("dropTables", true);
     createTables(dropTables);
   } finally {
     ec.unlock();
   }
 }
コード例 #9
0
 private void checkThreads() {
   Map<Thread, Long> requestThreads = new HashMap<>();
   synchronized (_requestThreads) {
     requestThreads.putAll(_requestThreads);
   }
   if (!requestThreads.isEmpty()) {
     int deadlocksCount = 0;
     Map<Thread, StackTraceElement[]> traces = null;
     for (Thread thread : requestThreads.keySet()) {
       Long time = requestThreads.get(thread);
       if (time != null) {
         time = System.currentTimeMillis() - time;
         if (time > _maximumRequestWarnTime / 2 && _warnTraces.get(thread) == null) {
           if (traces == null) {
             traces = Thread.getAllStackTraces();
           }
           Map<Thread, String> names = getCurrentThreadNames(traces.keySet());
           _warnTraces.put(thread, traces);
           _warnTracesNames.put(thread, names);
         }
         if (time > _maximumRequestErrorTime / 2 && _errorTraces.get(thread) == null) {
           if (traces == null) {
             traces = Thread.getAllStackTraces();
           }
           Map<Thread, String> names = getCurrentThreadNames(traces.keySet());
           _errorTraces.put(thread, traces);
           _errorTracesNames.put(thread, names);
         }
         if (time > _maximumRequestFatalTime && _fatalTraces.get(thread) == null) {
           if (traces == null) {
             traces = Thread.getAllStackTraces();
           }
           Map<Thread, String> names = getCurrentThreadNames(traces.keySet());
           _fatalTraces.put(thread, traces);
           _fatalTracesNames.put(thread, names);
           StringBuilder sb = new StringBuilder();
           sb.append("Request is taking too long, possible deadlock: ");
           sb.append(time);
           sb.append(" ms ");
           sb.append(stringFromTracesAndNames(traces, names));
           sb.append("EC info:\n");
           sb.append(ERXEC.outstandingLockDescription());
           sb.append("OSC info:\n");
           sb.append(ERXObjectStoreCoordinator.outstandingLockDescription());
           log.error(sb.toString());
           deadlocksCount++;
         }
       }
     }
     listener.deadlock(deadlocksCount);
   }
 }
コード例 #10
0
ファイル: Main.java プロジェクト: t-evans/memory-leak-test
  public Main(WOContext context) {
    super(context);

    // The memory leak doesn't happen unless there are multiple OSCs registered with
    // ERXObjectStoreCoordinatorSynchronizer._coordinators. Using an OSC (performing a lookup, etc,
    // as below) causes the OSC to be added to the _coordinators array.
    EOEditingContext ec = ERXEC.newEditingContext(_osc);
    ec.lock();
    try {
      NSArray dcArray = EOUtilities.objectsForEntityNamed(ec, "DataContainer");
    } finally {
      ec.unlock();
      ec.dispose();
      ec = null;
    }
  }
コード例 #11
0
ファイル: ERCHelpText.java プロジェクト: hypronet/wonder
 @Override
 protected void handleUnsuccessfullQueryForKey(Object key) {
   EOEditingContext ec = ERXEC.newEditingContext();
   EOGlobalID gid = NO_GID_MARKER;
   ec.lock();
   try {
     EOEnterpriseObject eo =
         (EOEnterpriseObject)
             EOUtilities.objectsMatchingKeyAndValue(ec, ENTITY, Key.KEY, key).lastObject();
     if (eo != null) {
       gid = ec.globalIDForObject(eo);
     }
   } finally {
     ec.unlock();
   }
   cache().setObjectForKey(createRecord(gid, null), key);
 }
コード例 #12
0
  protected void connectToServer() {
    try {
      remoteObjectStore = ERDistributedObjectStore.connectToServer();
      remoteObjectStore.distributionChannel().setDelegate(this);
    } catch (ServerConnectionException e) {
      handleNoInstanceAvailable(e);
    }

    ERXEC.setDefaultParentObjectStore(remoteObjectStore);

    // Fetch the class descriptions right away to avoid bugs and performance issues from doing it on
    // demand
    NSArray<EOClassDescription> classDescriptions =
        (NSArray<EOClassDescription>)
            remoteObjectStore.invokeStatelessRemoteMethod("clientSideRequestGetClassDescriptions");
    registerClassDescriptions(classDescriptions);
  }
コード例 #13
0
 /**
  * Returns a list of the traces of open editing context locks. This is only useful if
  * er.extensions.ERXApplication.traceOpenEditingContextLocks is enabled and
  * er.extensions.ERXOpenEditingContextLocksPassword is set.
  *
  * @return list of lock traces
  */
 public WOActionResults showOpenEditingContextLockTracesAction() {
   if (canPerformActionWithPasswordKey("er.extensions.ERXOpenEditingContextLockTracesPassword")) {
     ERXStringHolder result = pageWithName(ERXStringHolder.class);
     result.setEscapeHTML(false);
     StringWriter sw = new StringWriter();
     PrintWriter pw = new PrintWriter(sw);
     pw.println("<pre>");
     pw.println(ERXEC.outstandingLockDescription());
     pw.println("</pre>");
     pw.println("<hr>");
     pw.println("<pre>");
     pw.println(ERXObjectStoreCoordinator.outstandingLockDescription());
     pw.println("</pre>");
     pw.close();
     result.setValue(sw.toString());
     return result;
   }
   return forbiddenResponse();
 }
コード例 #14
0
ファイル: Application.java プロジェクト: hypeastrum/wonder
  public static void main(String[] args) {
    Application app = new Application();
    app.connectToServer();
    try {

      EOGlobalID userGlobalID = app.distributedObjectStore().login("john", "password");
      if (userGlobalID == null) {
        System.out.println("Authentication failed.");
        System.exit(1);
      }

      EOEditingContext ec = ERXEC.newEditingContext();
      NSArray<Movie> movies = Movie.fetchAllMovies(ec);
      for (Movie movie : movies) {
        System.out.println(movie.title());
      }

    } finally {
      app.distributedObjectStore().terminateSessionOnServer();
    }
  }
コード例 #15
0
  /**
   * Ensures we don't have references to EOs before using this in the background thread.
   *
   * @param fs
   * @return a clone of the fetchSpecification with the EOQualifier converted to a schema-based
   *     qualifier or the same {@link EOFetchSpecification} if there is no qualifier.
   */
  private EOFetchSpecification schemaBasedFetchSpecification(
      EOFetchSpecification fetchSpecification) {

    EOQualifier q = fetchSpecification.qualifier();
    if (q != null) {

      // Clone the fetchSpec
      fetchSpecification = (EOFetchSpecification) fetchSpecification.clone();

      EOEditingContext ec = ERXEC.newEditingContext();
      ec.lock();
      try {
        EOEntity entity =
            ERXEOAccessUtilities.entityMatchingString(ec, fetchSpecification.entityName());
        // Convert the qualifier to a schema-based qualifier
        q = entity.schemaBasedQualifier(q);
        fetchSpecification.setQualifier(q);
      } finally {
        ec.unlock();
      }
    } // ~ if (q != null)
    return fetchSpecification;
  }
コード例 #16
0
 /** @param component */
 public ModuleAdminCapaciteCtrl(ModuleAdminCapacite component) {
   super(component);
   // TODO Auto-generated constructor stub
   ec = ERXEC.newEditingContext();
 }
コード例 #17
0
  @Override
  public WOResponse handleRequest(WORequest request) {
    int bufferSize = 16384;

    WOApplication application = WOApplication.application();
    application.awake();
    try {
      WOContext context = application.createContextForRequest(request);
      WOResponse response = application.createResponseInContext(context);

      String sessionIdKey = application.sessionIdKey();
      String sessionId = (String) request.formValueForKey(sessionIdKey);
      if (sessionId == null) {
        sessionId = request.cookieValueForKey(sessionIdKey);
      }
      context._setRequestSessionID(sessionId);
      if (context._requestSessionID() != null) {
        application.restoreSessionWithID(sessionId, context);
      }

      try {
        final WODynamicURL url = request._uriDecomposed();
        final String requestPath = url.requestHandlerPath();
        final Matcher idMatcher = Pattern.compile("^id/(\\d+)/").matcher(requestPath);

        final Integer requestedAttachmentID;
        String requestedWebPath;

        final boolean requestedPathContainsAnAttachmentID = idMatcher.find();
        if (requestedPathContainsAnAttachmentID) {
          requestedAttachmentID = Integer.valueOf(idMatcher.group(1));
          requestedWebPath = idMatcher.replaceFirst("/");
        } else {
          // MS: This is kind of goofy because we lookup by path, your web path needs to
          // have a leading slash on it.
          requestedWebPath = "/" + requestPath;
          requestedAttachmentID = null;
        }

        try {
          InputStream attachmentInputStream;
          String mimeType;
          String fileName;
          long length;
          String queryString = url.queryString();
          boolean proxyAsAttachment =
              (queryString != null && queryString.contains("attachment=true"));

          EOEditingContext editingContext = ERXEC.newEditingContext();
          editingContext.lock();

          try {
            ERAttachment attachment =
                fetchAttachmentFor(editingContext, requestedAttachmentID, requestedWebPath);

            if (_delegate != null && !_delegate.attachmentVisible(attachment, request, context)) {
              throw new SecurityException("You are not allowed to view the requested attachment.");
            }
            mimeType = attachment.mimeType();
            length = attachment.size().longValue();
            fileName = attachment.originalFileName();
            ERAttachmentProcessor<ERAttachment> attachmentProcessor =
                ERAttachmentProcessor.processorForType(attachment);
            if (!proxyAsAttachment) {
              proxyAsAttachment = attachmentProcessor.proxyAsAttachment(attachment);
            }
            InputStream rawAttachmentInputStream =
                attachmentProcessor.attachmentInputStream(attachment);
            attachmentInputStream = new BufferedInputStream(rawAttachmentInputStream, bufferSize);
          } finally {
            editingContext.unlock();
          }

          response.setHeader(mimeType, "Content-Type");
          response.setHeader(String.valueOf(length), "Content-Length");

          if (proxyAsAttachment) {
            response.setHeader("attachment; filename=\"" + fileName + "\"", "Content-Disposition");
          }

          response.setStatus(200);
          response.setContentStream(attachmentInputStream, bufferSize, length);
        } catch (SecurityException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(403);
        } catch (NoSuchElementException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(404);
        } catch (FileNotFoundException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(404);
        } catch (IOException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(500);
        }

        return response;
      } finally {
        if (context._requestSessionID() != null) {
          WOApplication.application().saveSessionForContext(context);
        }
      }
    } finally {
      application.sleep();
    }
  }