Examples of DB


Examples of org.h2.jaqu.Db

        db.update(newProd);
    }

    private void testColumnInheritanceAnnotation() {
        ProductInheritedAnnotation table = new ProductInheritedAnnotation();
        Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
        List<ProductInheritedAnnotation> inserted = ProductInheritedAnnotation.getData();
        db.insertAll(inserted);

        List<ProductInheritedAnnotation> retrieved = db.from(table).select();

        for (int j = 0; j < retrieved.size(); j++) {
            ProductInheritedAnnotation i = inserted.get(j);
            ProductInheritedAnnotation r = retrieved.get(j);
            assertEquals(i.category, r.category);
            assertEquals(i.mappedField, r.mappedField);
            assertEquals(i.unitsInStock, r.unitsInStock);
            assertEquals(i.unitPrice, r.unitPrice);
            assertEquals(i.name(), r.name());
            assertEquals(i.id(), r.id());
        }
        db.close();
    }
View Full Code Here

Examples of org.h2.jaqu.Db

    }

    private void testCreateTableIfRequiredAnnotation() {
        // tests JQTable.createTableIfRequired=false
        try {
            Db noCreateDb = Db.open("jdbc:h2:mem:", "sa", "sa");
            noCreateDb.insertAll(ProductNoCreateTable.getList());
            noCreateDb.close();
        } catch (RuntimeException r) {
            SQLException s = (SQLException) r.getCause();
            assertEquals(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, s.getErrorCode());
        }
    }
View Full Code Here

Examples of org.h2.test.db.Db

        }
        return buff.toString();
    }

    private void testInSelect() {
        Db db = new Db(conn);
        db.execute("CREATE TABLE TEST(A INT, B INT)");
        db.execute("CREATE INDEX IDX ON TEST(A)");
        db.execute("INSERT INTO TEST SELECT X/4, MOD(X, 4) FROM SYSTEM_RANGE(1, 16)");
        db.execute("UPDATE TEST SET A = NULL WHERE A = 0");
        db.execute("UPDATE TEST SET B = NULL WHERE B = 0");
        Random random = new Random();
        long seed = random.nextLong();
        println("seed: " + seed);
        for (int i = 0; i < 100; i++) {
            String column = random.nextBoolean() ? "A" : "B";
            String value = new String[] { "NULL", "0", "A", "B" }[random.nextInt(4)];
            String compare = random.nextBoolean() ? "A" : "B";
            int x = random.nextInt(3);
            String sql1 = "SELECT * FROM TEST T WHERE " + column + "+0 " +
                "IN(SELECT " + value + " FROM TEST I WHERE I." + compare + "=?) ORDER BY 1, 2";
            String sql2 = "SELECT * FROM TEST T WHERE " + column + " " +
                "IN(SELECT " + value + " FROM TEST I WHERE I." + compare + "=?) ORDER BY 1, 2";
            List<Map<String, Object>> a = db.prepare(sql1).set(x).query();
            List<Map<String, Object>> b = db.prepare(sql2).set(x).query();
            assertTrue("seed: " + seed + " sql: " + sql1 + " a: " + a + " b: " + b, a.equals(b));
        }
        db.execute("DROP TABLE TEST");
    }
View Full Code Here

Examples of org.h2.test.db.Db

        }
        db.execute("DROP TABLE TEST");
    }

    private void testGroupSorted() {
        Db db = new Db(conn);
        db.execute("CREATE TABLE TEST(A INT, B INT, C INT)");
        Random random = new Random();
        long seed = random.nextLong();
        println("seed: " + seed);
        for (int i = 0; i < 100; i++) {
            Prepared p = db.prepare("INSERT INTO TEST VALUES(?, ?, ?)");
            p.set(new String[] { null, "0", "1", "2" }[random.nextInt(4)]);
            p.set(new String[] { null, "0", "1", "2" }[random.nextInt(4)]);
            p.set(new String[] { null, "0", "1", "2" }[random.nextInt(4)]);
            p.execute();
        }
        int len = getSize(1000, 3000);
        for (int i = 0; i < len / 10; i++) {
            db.execute("CREATE TABLE TEST_INDEXED AS SELECT * FROM TEST");
            int jLen = 1 + random.nextInt(2);
            for (int j = 0; j < jLen; j++) {
                String x = "CREATE INDEX IDX" + j + " ON TEST_INDEXED(";
                int kLen = 1 + random.nextInt(2);
                for (int k = 0; k < kLen; k++) {
                    if (k > 0) {
                        x += ",";
                    }
                    x += new String[] { "A", "B", "C" }[random.nextInt(3)];
                }
                db.execute(x + ")");
            }
            for (int j = 0; j < 10; j++) {
                String x = "SELECT ";
                for (int k = 0; k < 3; k++) {
                    if (k > 0) {
                        x += ",";
                    }
                    x += new String[] { "SUM(A)", "MAX(B)", "AVG(C)", "COUNT(B)" }[random.nextInt(4)];
                    x += " S" + k;
                }
                x += " FROM ";
                String group = " GROUP BY ";
                int kLen = 1 + random.nextInt(2);
                for (int k = 0; k < kLen; k++) {
                    if (k > 0) {
                        group += ",";
                    }
                    group += new String[] { "A", "B", "C" }[random.nextInt(3)];
                }
                group += " ORDER BY 1, 2, 3";
                List<Map<String, Object>> a = db.query(x + "TEST" + group);
                List<Map<String, Object>> b = db.query(x + "TEST_INDEXED" + group);
                assertEquals(a.toString(), b.toString());
                assertTrue(a.equals(b));
            }
            db.execute("DROP TABLE TEST_INDEXED");
        }
        db.execute("DROP TABLE TEST");
    }
View Full Code Here

Examples of org.h2.test.db.Db

        select * from test1 where
        b in(null, 0) and a in(2, null, null)
        order by 1, 2, 3;
     */
    private void testIn() throws SQLException {
        Db db = new Db(conn);
        db.execute("create table test0(a int, b int, c int)");
        db.execute("create index idx_1 on test0(a)");
        db.execute("create index idx_2 on test0(b, a)");
        db.execute("create table test1(a int, b int, c int)");
        db.execute("insert into test0 select x / 100, mod(x / 10, 10), mod(x, 10) from system_range(0, 999)");
        db.execute("update test0 set a = null where a = 9");
        db.execute("update test0 set b = null where b = 9");
        db.execute("update test0 set c = null where c = 9");
        db.execute("insert into test1 select * from test0");

        // this failed at some point
        Prepared p = db.prepare("select * from test0 where b in(" +
                "select a from test1 where a <? and a not in(" +
                "select c from test1 where b <=10 and a in(" +
                "select a from test1 where b =1 or b =2 and b not in(2))) or c <>a) " +
                "and c in(0, 10) and c in(10, 0, 0) order by 1, 2, 3");
        p.set(1);
        p.execute();

        Random seedGenerator = new Random();
        String[] columns = new String[] { "a", "b", "c" };
        String[] values = new String[] { null, "0", "0", "1", "2", "10", "a", "?" };
        String[] compares = new String[] { "in(", "not in(", "=", "=", ">",
                "<", ">=", "<=", "<>", "in(select", "not in(select" };
        int size = getSize(100, 1000);
        for (int i = 0; i < size; i++) {
            long seed = seedGenerator.nextLong();
            println("seed: " + seed);
            Random random = new Random(seed);
            ArrayList<String> params = New.arrayList();
            String condition = getRandomCondition(random, params, columns, compares, values);
            //   System.out.println(condition + " " + params);
            PreparedStatement prep0 = conn.prepareStatement(
                    "select * from test0 where " + condition
                    + " order by 1, 2, 3");
            PreparedStatement prep1 = conn.prepareStatement(
                    "select * from test1 where " + condition
                    + " order by 1, 2, 3");
            for (int j = 0; j < params.size(); j++) {
                prep0.setString(j + 1, params.get(j));
                prep1.setString(j + 1, params.get(j));
            }
            ResultSet rs0 = prep0.executeQuery();
            ResultSet rs1 = prep1.executeQuery();
            assertEquals("seed: " + seed + " " + condition, rs0, rs1);
            if (params.size() > 0) {
                for (int j = 0; j < params.size(); j++) {
                    String value = values[random.nextInt(values.length - 2)];
                    params.set(j, value);
                    prep0.setString(j + 1, value);
                    prep1.setString(j + 1, value);
                }
                assertEquals("seed: " + seed + " " + condition, rs0, rs1);
            }
        }
        db.execute("drop table test0, test1");
    }
View Full Code Here

Examples of org.iq80.leveldb.DB

  public WriteOptions getWriteOptions() {
    return writeOptions;
  }

  public DB getTable(String tableName) throws IOException {
    DB db = tables.get(tableName);
    if (db == null) {
      synchronized (tables) {
        db = tables.get(tableName);
        if (db == null) {
          db = openTable(tableName);
View Full Code Here

Examples of org.mapdb.DB

  extends TestSupport
{
  @Test
  public void createDatabase() throws Exception {
    File file = util.createTempFile("db");
    DB db = DBMaker.newFileDB(file).make();
    try {
      log("Database: {}, file: {}", db, file);
    }
    finally {
      db.close();
    }
  }
View Full Code Here

Examples of org.olat.core.commons.persistence.DB

        duration = System.currentTimeMillis() - lastTime.getTime();
      } else {
        duration = currentTime.getTime() - lastTime.getTime();
      }
     
      DB db = DBFactory.getInstanceForClosing();
      if (db!=null && db.isError()) {
        // then we would run into an ERROR when we'd do more with this DB
        // hence we just issue a log.info here with the details
        //@TODO: lower to log_.info once we checked that it doesn't occur very often (best for 6.4)
        log_.warn("log: DB is in Error state therefore the UserActivityLoggerImpl cannot update the simpleDuration of log_id "+lastLogObj.getKey()+" with value "+duration+", loggingObject: "+lastLogObj);
      } else {
        DBQuery update = DBFactory.getInstance().createQuery(
            "update org.olat.core.logging.activity.LoggingObject set simpleDuration = :duration where log_id = :logid");
        update.setLong("duration", duration);
        update.setLong("logid", lastLogObj.getKey());
        // we have to do FlushMode.AUTO (which is the default anyway)
        update.executeUpdate(FlushMode.AUTO);
      }
    }
   
    // store the current logging object in the session - for duration calculation at next log
    session_.putEntry(USESS_KEY_USER_ACTIVITY_LOGGING_LAST_LOG, logObj);

    if (resourceInfos!=null && resourceInfos.size()!=0) {
      // this should be the normal case - we do have LoggingResourceables which we can log
      // alongside the log message
     
      // check if we have more than 4 - if we do, issue a log and remove the middle ones
      if (resourceInfos.size()>4) {
        log_.warn("More than 4 resource infos set on a user activity log. Can only have 4. Having: "+resourceInfos.size());
        int diff = resourceInfos.size()-4;
        for(int i=0; i<diff; i++) {
          resourceInfos.remove(3);
        }
      }
     
      // get the target resourceable
      ILoggingResourceable ri = resourceInfos.get(resourceInfos.size()-1);
      logObj.setTargetResourceInfo(ri);
     
      // now set parent - if applicable
      if (resourceInfos.size()>1) {
        ri = resourceInfos.get(resourceInfos.size()-2);
        logObj.setParentResourceInfo(ri);
      }
     
      // and set the grand parent - if applicable
      if (resourceInfos.size()>2) {
        ri = resourceInfos.get(resourceInfos.size()-3);
        logObj.setGrandParentResourceInfo(ri);
      }
     
      // and set the great grand parent - if applicable
      if (resourceInfos.size()>3) {
        ri = resourceInfos.get(resourceInfos.size()-4);
        logObj.setGreatGrandParentResourceInfo(ri);
      }
    }
   
    // fill the remaining fields
    logObj.setBusinessPath(businessPath_);
    logObj.setSourceClass(callingClass.getCanonicalName());
    logObj.setSimpleDuration(-1);
    logObj.setResourceAdminAction(actionType.equals(ActionType.admin)?true:false);
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
   
    //prepate the user properties, set them at once
    List<String> tmpUserProperties = new ArrayList<String>(12);
    for(Iterator<String> iterator = userProperties_.iterator(); iterator.hasNext();) {
      tmpUserProperties.add(identity.getUser().getPropertyOrIdentityEnvAttribute(iterator.next(), locale));
    }
    logObj.setUserProperties(tmpUserProperties);
   
    // and store it
    DB db = DBFactory.getInstanceForClosing();
    if (db!=null && db.isError()) {
      // then we would run into an ERROR when we'd do more with this DB
      // hence we just issue a log.info here with the details
      //@TODO: lower to log_.info once we checked that it doesn't occur very often (best for 6.4)
      log_.warn("log: DB is in Error state therefore the UserActivityLoggerImpl cannot store the following logging action into the loggingtable: "+logObj);
    } else {
View Full Code Here

Examples of org.olat.core.commons.persistence.DB

   */
  private void updateUserLocaleAndLogout(UserRequest ureq, String localeKey) {
    User currUser = ureq.getIdentity().getUser();
    // direct DB calls have to be made here because the
    // user manager is not available in the core
    DB db = DBFactory.getInstance();
    currUser = (User) db.loadObject(currUser);
    currUser.getPreferences().setLanguage(localeKey);
    db.saveObject(currUser);
    DispatcherAction.redirectToDefaultDispatcher(ureq.getHttpResp());
  }
View Full Code Here

Examples of org.olat.core.commons.persistence.DB

    if (rating == null) {
      // Original rating has been deleted in the meantime. Don't delete it again.
      return 0;
    }
    // Delete this rating and finish
    DB db = DBFactory.getInstance();
    db.deleteObject(rating);
    return 1;

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.