Ejemplo n.º 1
0
  /** Test of nextValue method, of class UjoSequencer. */
  public void testNextValue_2() {
    System.out.println("testNextValue_2");

    final int sequenceCache = 2;
    final OrmHandler handler = createHandler(sequenceCache);
    final MetaTable orderModel = handler.findTableModel(Order.class);
    final UjoSequencer seq = orderModel.getSequencer();
    final Session session = handler.createSession();

    long seqBeg = seq.nextValue(session);
    long seqEnd = 0;
    int count = 52;
    for (int i = 0; i < count; i++) {
      seqEnd = seq.nextValue(session);
    }
    session.close();
    assertEquals("ID sequences must be the same", seqBeg + count, seqEnd);
  }
Ejemplo n.º 2
0
  /** Test of nextValue method, of class UjoSequencer. */
  public void testNextValue_3() {
    System.out.println("testNextValue_3");

    final int sequenceCache = 3;
    final OrmHandler handler = createHandler(sequenceCache);
    final Session session = handler.createSession();

    Order orderBeg = createAndSaveOrder(session);
    Order orderEnd = null;
    int count = 53;
    for (long i = 0; i < count; i++) {
      orderEnd = createAndSaveOrder(session);
    }
    session.close();
    assertEquals(
        "ID sequences must be the same",
        orderBeg.getId().longValue() + count,
        orderEnd.getId().longValue());
  }
Ejemplo n.º 3
0
  /** Before the first: create a meta-model. Database tables will be CREATED in the first time. */
  private OrmHandler createHandler(int sequenceCache) {

    // Set the log level specifying which message levels will be logged by Ujorm:
    Logger.getLogger(Ujo.class.getPackage().getName()).setLevel(UjoLogger.ERROR);

    // Create new ORM Handler:
    OrmHandler result = new OrmHandler();

    // There are prefered default keys for a production environment:
    boolean yesIWantToChangeDefaultParameters = true;
    if (yesIWantToChangeDefaultParameters) {
      MetaParams params = new MetaParams();
      params.set(MetaParams.SEQUENCE_SCHEMA_SYMBOL, true);
      params.set(MetaParams.SEQUENCE_CACHE, sequenceCache);
      params.set(MetaParams.LOG_METAMODEL_INFO, false);
      params.setQuotedSqlNames(false);
      result.config(params);
    }

    // Load Meta-model and lock it to a read-only mode:
    result.loadDatabase(Database.class);

    return result;
  }