Package jodd.db

Examples of jodd.db.DbQuery


    if (ded == null) {
      throw new DbOomException("Not an entity: " + type);
    }
    if (isPersistent(ded, entity) == false) {
      DbQuery q;
      if (keysGeneratedByDatabase == true) {
        q = query(insert(entity));
        q.setGeneratedKey();
        q.executeUpdate();
        long nextId = q.getGeneratedKey();
        setEntityId(ded, entity, nextId);
      } else {
        long nextId = generateNextId(ded);
        setEntityId(ded, entity, nextId);
        q = query(insert(entity));
        q.executeUpdate();
      }
      q.close();
    } else {
      query(DbEntitySql.updateAll(entity)).autoClose().executeUpdate();
    }
    return entity;
  }
View Full Code Here


  /**
   * Simply inserts object into the database.
   */
  public void save(Object entity) {
    DbQuery q = query(insert(entity));
    q.autoClose().executeUpdate();
  }
View Full Code Here

   * thread provided db session, but common db session.
   */
  public boolean checkDb() {
    log.debug("Check database.");
    DbSession dbSession = AppCore.ref.createDbSession();
    DbQuery query = new DbQuery(dbSession, "select count(1) from up_user_level");
    try {
      query.execute();
      log.debug("Database OK.");
        return true;
    } catch (Exception ignored) {
      return false;
    } finally {
      query.close();
      dbSession.closeSession();
    }
  }
View Full Code Here

      String q = queries[i];
      q = cleanSql(q);
      if (q.isEmpty()) {
        continue;
      }
      DbQuery query = new DbQuery(dbSession, q);
      query.executeUpdate();
      log.debug("executed query #" + (i + 1));
    }
    dbSession.closeSession();
  }
View Full Code Here

      if (q.contains("$date")) {
        q = StringUtil.replace(q, "$date", jdt.toString("YYYYMMDD"));
        jdt.addDay(1);
      }

      DbQuery query = new DbQuery(dbSession, q);
      query.executeUpdate();
      log.debug("executed query #" + (i + 1));
    }

    dbSession.closeSession();
  }
View Full Code Here

    session = new DbThreadSession(cp);

    executeUpdate("drop table WIZARD if exists");
    executeUpdate("drop table USER if exists");

    DbQuery query = new DbQuery(
        "create table USER (" +
        "USER_ID  IDENTITY," +
        "NAME    varchar(20)  not null" +
        ')');
    query.executeUpdate();

    query = new DbQuery("insert into USER values(1, 'Gandalf')");
    query.executeUpdate();

    query = new DbQuery(
        "create table WIZARD (" +
        "WIZARD_ID  IDENTITY," +
        "LEVEL    INT  not null" +
        ')');
    query.executeUpdate();

    query = new DbQuery("insert into WIZARD values(1, 7);");
    query.executeUpdate();
  }
View Full Code Here

  }

  // ---------------------------------------------------------------- helpers

  protected int executeUpdate(DbSession session, String s) {
    return new DbQuery(session, s).autoClose().executeUpdate();
  }
View Full Code Here

  protected int executeUpdate(DbSession session, String s) {
    return new DbQuery(session, s).autoClose().executeUpdate();
  }

  protected void executeUpdate(String sql) {
    new DbQuery(sql).autoClose().executeUpdate();
  }
View Full Code Here

  protected void executeUpdate(String sql) {
    new DbQuery(sql).autoClose().executeUpdate();
  }

  protected long executeCount(DbSession session, String s) {
    return new DbQuery(session, s).autoClose().executeCount();
  }
View Full Code Here

    public final void createTables() {
      DbSession session = new DbSession();

      String sql = getCreateTableSql();

      DbQuery query = new DbQuery(session, sql);
      query.executeUpdate();

      session.closeSession();
      assertTrue(query.isClosed());
    }
View Full Code Here

TOP

Related Classes of jodd.db.DbQuery

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.