Exemplo n.º 1
0
  /** INTERNAL: Answers the session to be used for the given query. */
  protected AbstractSession getSessionForQuery(DatabaseQuery query) {
    if (query.hasSessionName()) {
      return getSessionForName(query.getSessionName());
    }

    Class queryClass;
    if (query.getDescriptor() != null) {
      queryClass = query.getDescriptor().getJavaClass();
    } else {
      queryClass = query.getReferenceClass();
      if (queryClass == null) {
        throw QueryException.unnamedQueryOnSessionBroker(query);
      }
    }
    return getSessionForClass(queryClass);
  }
 public void occurred(String operationName, DatabaseQuery query) {
   if (this.profileWeight < SessionProfiler.NORMAL) {
     return;
   }
   occurred(operationName);
   occurred(
       COUNTER
           + query.getMonitorName()
           + ":"
           + operationName.substring(COUNTER.length(), operationName.length()));
 }
 /** INTERNAL: Start the operation timing. */
 public void startOperationProfile(String operationName, DatabaseQuery query, int weight) {
   if (this.profileWeight < weight) {
     return;
   }
   startOperationProfile(operationName);
   startOperationProfile(
       TIMER
           + query.getMonitorName()
           + ":"
           + operationName.substring(TIMER.length(), operationName.length()));
 }
  /** INTERNAL: Prepare the receiver for execution in a session. */
  protected void prepare() throws QueryException {

    if (getObject() != null) { // Prepare can be called without the object set yet.
      checkDescriptor(getObject(), getSession());
      setObject(getDescriptor().getObjectBuilder().unwrapObject(getObject(), getSession()));
    }

    super.prepare();

    // It will only get to prepare if check database if required.
    getQueryMechanism().prepareDoesExist(getDoesExistField());
  }
Exemplo n.º 5
0
 /**
  * INTERNAL: Prepare the query from the prepared query. This allows a dynamic query to prepare
  * itself directly from a prepared query instance. This is used in the JPQL parse cache to allow
  * preparsed queries to be used to prepare dynamic queries. This only copies over properties that
  * are configured through JPQL.
  */
 public void prepareFromQuery(DatabaseQuery query) {
   super.prepareFromQuery(query);
   if (query.isReadAllQuery()) {
     ReadAllQuery readQuery = (ReadAllQuery) query;
     this.containerPolicy = readQuery.containerPolicy;
     if (readQuery.hasHierarchicalExpressions()) {
       this.orderSiblingsByExpressions = readQuery.getOrderSiblingsByExpressions();
       this.connectByExpression = readQuery.getConnectByExpression();
       this.startWithExpression = readQuery.getStartWithExpression();
     }
     if (readQuery.hasBatchReadAttributes()) {
       this.batchReadAttributeExpressions = readQuery.batchReadAttributeExpressions;
       this.batchReadMappingQueries = readQuery.batchReadMappingQueries;
       this.batchReadAttributes = readQuery.batchReadAttributes;
     }
   }
 }
 /** INTERNAL: Monitoring is done on the endOperation only. */
 public Object profileExecutionOfQuery(DatabaseQuery query, Record row, AbstractSession session) {
   if (this.profileWeight < SessionProfiler.HEAVY) {
     return session.internalExecuteQuery(query, (AbstractRecord) row);
   }
   startOperationProfile(TIMER + query.getMonitorName());
   startOperationProfile(TIMER + query.getClass().getSimpleName());
   occurred(COUNTER + query.getClass().getSimpleName());
   occurred(COUNTER + query.getMonitorName());
   try {
     return session.internalExecuteQuery(query, (AbstractRecord) row);
   } finally {
     endOperationProfile(TIMER + query.getMonitorName());
     endOperationProfile(TIMER + query.getClass().getSimpleName());
     checkDumpTime();
   }
 }
  /** INTERNAL: Prepare the receiver for execution in a session. */
  public void prepareForExecution() throws QueryException {
    super.prepareForExecution();

    if (getObject() == null) {
      throw QueryException.objectToModifyNotSpecified(this);
    }
    setObject(this.descriptor.getObjectBuilder().unwrapObject(getObject(), getSession()));

    if (this.descriptor == null) {
      setDescriptor(getSession().getDescriptor(getObject().getClass()));
    }

    if (getPrimaryKey() == null) {
      setPrimaryKey(
          this.descriptor
              .getObjectBuilder()
              .extractPrimaryKeyFromObject(getObject(), getSession()));
    }

    if ((getTranslationRow() == null) || (getTranslationRow().isEmpty())) {
      setTranslationRow(
          this.descriptor.getObjectBuilder().buildRowForTranslation(getObject(), getSession()));
    }
  }