コード例 #1
0
 /**
  * Add all of the relevant query settings from an EJBQLParseTree to the given database query.
  *
  * @param query The query to populate
  * @param session The session to use to information such as descriptors.
  */
 public void populateQuery(DatabaseQuery query, AbstractSession session) {
   if (query.isObjectLevelReadQuery()) {
     ObjectLevelReadQuery objectQuery = (ObjectLevelReadQuery) query;
     GenerationContext generationContext = buildContext(objectQuery, session);
     populateReadQueryInternal(objectQuery, generationContext);
   } else if (query.isUpdateAllQuery()) {
     UpdateAllQuery updateQuery = (UpdateAllQuery) query;
     GenerationContext generationContext = buildContext(updateQuery, session);
     populateModifyQueryInternal(updateQuery, generationContext);
     addUpdatesToQuery(updateQuery, generationContext);
   } else if (query.isDeleteAllQuery()) {
     DeleteAllQuery deleteQuery = (DeleteAllQuery) query;
     GenerationContext generationContext = buildContext(deleteQuery, session);
     populateModifyQueryInternal(deleteQuery, generationContext);
   }
 }
コード例 #2
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);
  }
コード例 #3
0
ファイル: Acceuil.java プロジェクト: tr4ll/CommandeStation
 /** Appel lorsque l'activite passe en arriere plan */
 @Override
 public void onPause() {
   super.onPause();
   // Toast.makeText(getApplicationContext(), "onPauseAcceuil()", Toast.LENGTH_SHORT).show();
   // Fermeture de la BDD
   Log.i("CYCLE_LIFE", "On Pause Acceuil");
   query.destroy();
 }
コード例 #4
0
ファイル: Acceuil.java プロジェクト: tr4ll/CommandeStation
  public void listStation() {

    ArrayList<String> queryString =
        query.getData(new String[] {"NOM"}, null, null, null, null, "NOM", "ASC");

    // Set the ListView
    setListAdapter(
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, queryString));
  }
コード例 #5
0
 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()));
 }
コード例 #6
0
 /** 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()));
 }
コード例 #7
0
  /** 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());
  }
コード例 #8
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;
     }
   }
 }
コード例 #9
0
ファイル: Acceuil.java プロジェクト: tr4ll/CommandeStation
  private Station loadData(String nomStation) {
    Station s = null;
    // On requete la Base pour recupe les donnees sur l
    HashMap<String, String> result = new HashMap<String, String>();
    result =
        query.getDataFields(
            new String[] {
              "NOM",
              "NUMTEL",
              "DEMARRER",
              "ARRETER",
              "DEMMARERNOTF",
              "ARRETERNOTF",
              "ALARMEID",
              "ALARME_TIME",
              "ALARME_ACTION"
            },
            "NOM='" + nomStation + "'",
            null,
            null,
            null,
            "NOM",
            "ASC");

    // Recup des valeurs de la bdd
    String tel = result.get("NUMTEL");
    String dem = result.get("DEMARRER");
    String arret = result.get("ARRETER");
    String demNotif = result.get("DEMMARERNOTF");
    String arrNotif = result.get("ARRETERNOTF");
    String alarmeID = result.get("ALARMEID");
    Alarme alarme = new Alarme();
    alarme.setAction(Alarme.AlarmAction.getAlarmAction(result.get("ALARME_ACTION")));
    if (result.get("ALARME_TIME") != null) {
      Calendar cal = Calendar.getInstance();
      cal.setTimeInMillis(Long.parseLong(result.get("ALARME_TIME")));
      alarme.setScheduleAlarm(cal);
    }

    s = new Station(nomStation, tel, dem, arret);
    s.setArreterNotif(arrNotif);
    s.setDemarrerNotif(demNotif);
    s.setAlarmeId(Integer.parseInt(alarmeID));
    s.setAlarmeBean(alarme);
    return s;
  }
コード例 #10
0
 /** 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();
   }
 }
コード例 #11
0
  /** 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()));
    }
  }
コード例 #12
0
ファイル: SignUp.java プロジェクト: ChongZhang1989/IDBProject
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession(true);
    ResultSet rs = null;

    String username = request.getParameter("username");
    String password = request.getParameter("userpass");
    String password1 = request.getParameter("userpass1");
    String userssn = request.getParameter("userssn");

    if (username.equals("") || password.equals("") || password1.equals("") || userssn.equals("")) {
      Integer registerError = Integer.valueOf(1);
      session.setAttribute("registerError", registerError);
      out.println("Please fill up the form.");
      response.sendRedirect("start.html");
    } else if (!password.equals(password1)) {
      Integer registerError = Integer.valueOf(2);
      session.setAttribute("registerError", registerError);
      out.println("Your password and confirm password do not match.");
      response.sendRedirect("start.html");
    }

    try {
      rs = DatabaseQuery.getResultSet("select * from users");
      while (rs.next()) {
        if (userssn.equals(rs.getString("ssn"))) {
          Integer registerError = Integer.valueOf(3);
          session.setAttribute("registerError", registerError);
          out.println("SSN already existed");
          response.sendRedirect("start.html");
        }
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Integer max_id = null;
    try {
      rs = DatabaseQuery.getResultSet("select max(id) from users");
      if (rs.next()) {
        max_id = rs.getInt(1);
      }
      Integer user_ssn = Integer.parseInt(userssn);
      rs =
          DatabaseQuery.getResultSet(
              "insert into users (id, mid, ssn, username, password)"
                  + "values ("
                  + (max_id + 1)
                  + ", "
                  + 1
                  + ", "
                  + user_ssn
                  + ", '"
                  + username
                  + "', '"
                  + password
                  + "')");

      out.println("You are successfully registered.");
    } catch (SQLException e1) {
      // TODO Auto-generated catch block
      out.println(e1);
      out.close();
    }
  }
コード例 #13
0
ファイル: Acceuil.java プロジェクト: tr4ll/CommandeStation
  public void eraseStation(String nom) {

    query.removeRow("NOM", nom);
  }