Package org.apache.cayenne.query

Examples of org.apache.cayenne.query.SelectQuery


      if(ca != null)
        return ca.getToCommand();

      // No aliases found; check for the real command
      Expression expression = ExpressionFactory.matchExp(Command.NAME_PROPERTY, command);
      SelectQuery query = new SelectQuery(Command.class, expression);
      return (Command)DataObjectUtils.objectForQuery(DatabaseContext.getContext(), query);
    } catch(Exception e) {
      return null;
    }
  }
View Full Code Here


   * @param access Minimum access
   * @return List of commands
   */
  @SuppressWarnings("unchecked")
  public static List<Command> getCommands(int access) {
    SelectQuery query = new SelectQuery(Command.class);
    List<Command> commands = DatabaseContext.getContext().performQuery(query);
    List<Command> ret = new ArrayList<Command>(commands.size());
    for(Command c : commands)
      if(c.getAccess() <= access)
        ret.add(c);
View Full Code Here

   * @return List of commands
   */
  @SuppressWarnings("unchecked")
  public static List<Command> getCommands(String category, int access) {
    Expression expression = ExpressionFactory.likeIgnoreCaseExp(Command.CMDGROUP_PROPERTY, category);
    SelectQuery query = new SelectQuery(Command.class, expression);
    List<Command> commands = DatabaseContext.getContext().performQuery(query);
    List<Command> ret = new ArrayList<Command>(commands.size());
    for(Command c : commands)
      if(c.getAccess() <= access)
        ret.add(c);
View Full Code Here

   * @return The CommandAlias, or NULL if the command alias is not in the database
   */
  public static CommandAlias get(String command) {
    try {
      Expression expression = ExpressionFactory.matchExp(CommandAlias.ALIAS_PROPERTY, command);
      SelectQuery query = new SelectQuery(CommandAlias.class, expression);
      return (CommandAlias)DataObjectUtils.objectForQuery(DatabaseContext.getContext(), query);
    } catch(Exception e) {
      Out.exception(e);
      return null;
    }
View Full Code Here

   * @return The BNLogin, or NULL if the user is not in the database
   */
  public static BNLogin get(BNetUser user) {
    try {
      Expression expr = ExpressionFactory.likeIgnoreCaseExp(BNLogin.LOGIN_PROPERTY, user.getFullAccountName());
      SelectQuery query = new SelectQuery(BNLogin.class, expr);
      return (BNLogin)DataObjectUtils.objectForQuery(DatabaseContext.getContext(), query);
    } catch(Exception e) {
      return null;
    }
  }
View Full Code Here

   * @param num The number of people to search for
   * @return A <code>List&lt;BNLogin></code>
   */
  @SuppressWarnings("unchecked")
  public static List<BNLogin> getLastSeen(int num) {
    SelectQuery query = new SelectQuery(BNLogin.class);
    query.addOrdering(BNLogin.LAST_SEEN_PROPERTY, false);
    query.setFetchLimit(num);
    return DatabaseContext.getContext().performQuery(query);
  }
View Full Code Here

   * @return A <code>List&lt;BNLogin></code> of users matching the pattern
   */
  @SuppressWarnings("unchecked")
  public static List<BNLogin> search(String pattern) {
    Expression expr = ExpressionFactory.likeIgnoreCaseExp(BNLogin.LOGIN_PROPERTY, "%" + pattern + "%");
    SelectQuery query = new SelectQuery(BNLogin.class, expr);
    query.addOrdering(BNLogin.LAST_SEEN_PROPERTY, false);
    return DatabaseContext.getContext().performQuery(query);
  }
View Full Code Here

      return;

    // If the schema was not rebuilt...
    if(schemaValid) {
      // Search for any account in the DB
      SelectQuery query = new SelectQuery(Account.class);
      List<?> accounts = DatabaseContext.getContext().performQuery(query);
      // Only open the wizard if there are no accounts
      if(accounts.size() > 0)
        return;
    }
View Full Code Here

        defaultMaxAge = rank.getExpireDays();
    }

    boolean debugEnabled = Out.isDebug(DatabaseContext.class);

    for(BNLogin login : (List<BNLogin>)context.performQuery(new SelectQuery(BNLogin.class))) {
      long age = login.getLastSeen().getTime();
      age = System.currentTimeMillis() - age;
      age /= 86400000l; // convert to days

      long maxAge = defaultMaxAge;
      Account account = login.getAccount();
      if(account != null) {
        Rank rank = account.getRank();
        if(rank != null)
          maxAge = rank.getExpireDays();
      }

      if(maxAge == 0)
        continue;
      if(age <= maxAge)
        continue;

      if(account != null)
        try {
          Mail.send(null, account, "Your login [ " + login.getLogin() + " ] has been removed due to inactivity (" + age + " days)");
        } catch (Exception e) {
          Out.exception(e);
          break;
        }

      if(debugEnabled)
        Out.debugAlways(DatabaseContext.class, "Removing " + login.getLogin() + " due to inactivity (" + age + " days)");
      context.deleteObject(login);
      Thread.yield();
    }

    try {
      context.commitChanges();
    } catch(Exception e) {
      context.rollbackChanges();
      Out.exception(e);
    }

    for(Account account : (List<Account>)context.performQuery(new SelectQuery(Account.class))) {
      // Only consider users with no BnLogins
      if(account.getBnLogins().size() != 0)
        continue;

      // Only consider users with positive access; banlisted users shouldn't expire
View Full Code Here

        cal.set(2002, 1, 1);

        test.setCalendarField(cal);
        context.commitChanges();

        SelectQuery q = new SelectQuery(CalendarEntity.class);
        CalendarEntity testRead = (CalendarEntity) context.performQuery(q).get(0);
        assertNotNull(testRead.getCalendarField());
        assertEquals(cal, testRead.getCalendarField());

        test.setCalendarField(null);
View Full Code Here

TOP

Related Classes of org.apache.cayenne.query.SelectQuery

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.