Examples of PersistenceSession


Examples of org.caffinitas.mapper.core.PersistenceSession

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "createSchema")
    public void simple() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            QueryBinder<SimpleEntity> queryBinder = session.createQueryBinder(SimpleEntity.class, null, "id in :id", null);
            queryBinder.setList("id", Arrays.asList(1, 2, 3));
            List<SimpleEntity> result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertTrue(result.isEmpty());

            // as named query

            queryBinder = session.createNamedQueryBinder(SimpleEntity.class, null, "byIds");
            queryBinder.setList("id", Arrays.asList(1, 2, 3));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertTrue(result.isEmpty());

            // insert data

            SimpleEntity inst = new SimpleEntity();
            inst.setId(1);
            inst.setStr("one");
            session.insert(inst);
            inst.setId(2);
            inst.setStr("two");
            session.insert(inst);
            inst.setId(3);
            inst.setStr("three");
            session.insert(inst);

            // again

            queryBinder = session.createQueryBinder(SimpleEntity.class, null, "id in :id", null);
            queryBinder.setList("id", Arrays.asList(1, 2, 3));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertEquals(result.size(), 3);

            // as named query

            queryBinder = session.createNamedQueryBinder(SimpleEntity.class, null, "byIds");
            queryBinder.setList("id", Arrays.asList(1, 2, 3));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertEquals(result.size(), 3);
        } finally {session.close();}
    }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

        ExecutionTracerFactory executionTracerFactory = new SingletonExecutionTracerFactory(executionTracer);

        persistenceManager = withPersistenceManagerBuilder(model).withExecutionTracerFactory(executionTracerFactory).build();

        PersistenceSession session = persistenceManager.createSession();
        try {
            session.setTracing(true);

            SimpleEntity inst = new SimpleEntity();
            inst.setId(1);

            session.insert(inst);

            Assert.assertTrue(beginModify.get());
            Assert.assertFalse(beginQuery.get());
            Assert.assertFalse(readResultSetBegin.get());
            Assert.assertFalse(readResultSetRow.get());
            Assert.assertFalse(readResultSetEnd.get());
            Assert.assertTrue(modifyWrapResultSet.get());

            beginModify.set(false);
            modifyWrapResultSet.set(false);

            session.loadOne(SimpleEntity.class, 1);

            Assert.assertFalse(beginModify.get());
            Assert.assertTrue(beginQuery.get());
            Assert.assertTrue(readResultSetBegin.get());
            Assert.assertTrue(readResultSetRow.get());
            Assert.assertTrue(readResultSetEnd.get());
            Assert.assertFalse(modifyWrapResultSet.get());

        } finally {
            session.close();
        }
    }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

        Assert.assertEquals(cols.get(0).getName(), "nt");
    }

    @Test(dependsOnMethods = "createSchema")
    public void ref_simple() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            ReferencedEntity inst = new ReferencedEntity();
            inst.setId(1);
            inst.setVal("1");
            session.insert(inst);

            ReferencedEntity loaded = session.loadOne(ReferencedEntity.class, 1);
            Assert.assertNotNull(loaded);
            Assert.assertEquals(loaded.getVal(), "1");

            NextFlatComposite compNext = new NextFlatComposite();
            compNext.setTs(new Date());
            compNext.setValA(.42d);

            SomeComposite comp = new SomeComposite();
            comp.setStr("cstr");
            comp.setVint(42);
            comp.setNext(compNext);

            SomeComposite compB = new SomeComposite();
            compB.setStr("zyx");
            compB.setVint(88);
            compB.setNext(compNext);

            ReferencingEntity ref = new ReferencingEntity();
            ref.setId(2);
            ref.setVal("v2");
            ref.setReferencedEntity(loaded);
            ref.setSomeComposite(comp);
            ref.setCompB(compB);

            session.insert(ref);

            ReferencingEntity l = session.loadOne(ReferencingEntity.class, 2);
            Assert.assertEquals(l.getId(), 2);
            Assert.assertEquals(l.getVal(), "v2");
            Assert.assertNotNull(l.getReferencedEntity());
            Assert.assertEquals(l.getReferencedEntity().getId(), 1);
            Assert.assertEquals(l.getReferencedEntity().getVal(), "1");
            Assert.assertNotNull(l.getSomeComposite());
            Assert.assertEquals(l.getSomeComposite().getStr(), "cstr");
            Assert.assertEquals(l.getSomeComposite().getVint(), 42);
            Assert.assertNotNull(l.getSomeComposite().getNext());
            Assert.assertEquals(l.getSomeComposite().getNext().getTs(), compNext.getTs());
            Assert.assertEquals(l.getSomeComposite().getNext().getValA(), .42d);
            Assert.assertNotNull(l.getCompB());
            Assert.assertEquals(l.getCompB().getStr(), "zyx");
            Assert.assertEquals(l.getCompB().getVint(), 88);
            Assert.assertNotNull(l.getCompB().getNext());
            Assert.assertEquals(l.getCompB().getNext().getTs(), compNext.getTs());
            Assert.assertEquals(l.getCompB().getNext().getValA(), .42d);

        } finally {
            session.close();
        }
    }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

    persistenceManager.close();
  }

  @Test
  public void timeUUIDPrepare() throws IOException {
    PersistenceSession persistenceSession = persistenceManager.createSession();
    Set<Long> adrs = SystemMacAddresses.inquireMacAddresses();
    StoreUUIDGeneratorConfigurer config = new StoreUUIDGeneratorConfigurer(adrs, persistenceSession);
    generator = new UUIDGenerator(4, config);
  }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

    }

    @Test(dependsOnMethods = "createSchema")
    public void composite_insertAndLoad() throws Exception {

        PersistenceSession session = persistenceManager.createSession();
        try {
            TupleEntity inst = new TupleEntity();
            inst.setId(11);
            TupleComposite comp = new TupleComposite();
            comp.setStr("string");
            comp.setNum(42);
            inst.setComp(comp);
            session.insert(inst);

            TupleEntity loaded = session.loadOne(TupleEntity.class, 11);
            Assert.assertNotNull(loaded);
            Assert.assertNotNull(loaded.getComp());
            Assert.assertEquals(loaded.getComp().getNum(), 42);
            Assert.assertEquals(loaded.getComp().getStr(), "string");
        } finally {session.close();}
    }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

        createSchemaDo(Collections.<Class<?>>singletonList(DynamicCompEntity.class));
    }

    @Test(dependsOnMethods = "createSchema")
    public void dynamic_insertAndLoad() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            DynamicCompEntity inst = new DynamicCompEntity();
            inst.setId(11);
            DynamicComposite dyn = new DynamicComposite();
            dyn.addBool(true);
            dyn.addUtf8String("Ursus");
            dyn.addInt(42);
            inst.setDyn(dyn);
            session.insert(inst);

            DynamicCompEntity loaded = session.loadOne(DynamicCompEntity.class, 11);
            Assert.assertNotNull(loaded);
            dyn = loaded.getDyn();
            Assert.assertNotNull(dyn);
            Assert.assertEquals(dyn.size(), 3);
            Assert.assertEquals(dyn.getType(0), DataType.cboolean());
            Assert.assertEquals(dyn.getType(1), DataType.text());
            Assert.assertEquals(dyn.getType(2), DataType.cint());
            Assert.assertEquals(dyn.getBool(0), true);
            Assert.assertEquals(dyn.getString(1), "Ursus");
            Assert.assertEquals(dyn.getInt(2), 42);
        } finally {session.close();}
    }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

        persistenceManager.createSchemaGenerator().generateLiveAlterDDL().execute(persistenceManager.driverSession());
    }

    @Test(dependsOnMethods = "createSchema")
    public void insert_with_ttl() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            IfNotExistsEntity inst = new IfNotExistsEntity();
            inst.setPk(2);
            inst.setCk(1);
            inst.setValue("2-1");
            session.insert(inst, new PersistOption.TTLOption(86400));
        } finally {session.close();}
    }
View Full Code Here

Examples of org.camunda.bpm.engine.impl.db.PersistenceSession

  private final static Logger log = Logger.getLogger(SchemaOperationsProcessEngineBuild.class.getName());

  public Object execute(CommandContext commandContext) {
    String databaseSchemaUpdate = Context.getProcessEngineConfiguration().getDatabaseSchemaUpdate();
    PersistenceSession persistenceSession = commandContext.getSession(PersistenceSession.class);
    if (ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)) {
      try {
        persistenceSession.dbSchemaDrop();
      } catch (RuntimeException e) {
        // ignore
      }
    }
    if ( ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP.equals(databaseSchemaUpdate)
      || ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)
      || ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_CREATE.equals(databaseSchemaUpdate)
      ) {
      persistenceSession.dbSchemaCreate();
    } else if (ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE.equals(databaseSchemaUpdate)) {
      persistenceSession.dbSchemaCheckVersion();
    } else if (ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE.equals(databaseSchemaUpdate)) {
      persistenceSession.dbSchemaUpdate();
    }


    DbEntityManager entityManager = commandContext.getSession(DbEntityManager.class);
    checkHistoryLevel(entityManager);
View Full Code Here

Examples of org.camunda.bpm.engine.impl.db.PersistenceSession

      ((ProcessEngineImpl)processEngine)
        .getProcessEngineConfiguration()
        .getCommandExecutorTxRequired()
        .execute(new Command<Object>() {
          public Object execute(CommandContext commandContext) {
            PersistenceSession persistenceSession = commandContext.getSession(PersistenceSession.class);
            persistenceSession.dbSchemaDrop();
            persistenceSession.dbSchemaCreate();
            SchemaOperationsProcessEngineBuild.dbCreateHistoryLevel(commandContext.getDbEntityManager());
            return null;
          }
        });
View Full Code Here

Examples of org.camunda.bpm.engine.impl.db.PersistenceSession

      log.info("dropping and recreating db");

      CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutorTxRequired();
      commandExecutor.execute(new Command<Object>() {
        public Object execute(CommandContext commandContext) {
          PersistenceSession persistenceSession = commandContext.getSession(PersistenceSession.class);
          persistenceSession.dbSchemaDrop();
          persistenceSession.dbSchemaCreate();
          return null;
        }
      });

      if (exception != null) {
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.