@RequestMapping(value = "/{instanceId}/{bag}") public String findAll(@PathVariable String instanceId, @PathVariable String bag, Model model) throws JasDBException { DBSession session = sessionFactory.createSession(instanceId); EntityBag entityBag = session.getBag(bag); PageResult result = new PageResult(); model.addAttribute("page", result); if(entityBag != null) { QueryResult queryResult = entityBag.getEntities(DEFAULT_PAGE_SIZE); result.setEntities(loadEntities(queryResult)); } else { result.setMessage(String.format("Unable to load Bag: %s on instance: %s as it does not exist", bag, instanceId)); } return "data/query"; }
private void testReadBag() throws Exception { JasDBMain.start(); DBSession pojoDb = sessionFactory.createSession(); EntityBag bag = pojoDb.createOrGetBag("testbag"); try { long startTime = System.currentTimeMillis(); QueryResult result = bag.getEntities(); int foundEntities = getResultSize(result); long endTime = System.currentTimeMillis(); log.info("Took: {} ms. to read: {} entities from 'testbag'", (endTime - startTime), foundEntities); assertEquals("Unexpected number of entities found", NUMBER_ENTITIES + 1, foundEntities); result = bag.getEntities(20); foundEntities = getResultSize(result); assertEquals("Unexpected number of entities found", 20, foundEntities); } finally { JasDBMain.shutdown(); } }
@Test public void testCreateAndInsertEntities() throws JasDBException, IOException { DBSession session = sessionFactory.createSession(); session.addInstance(MY_INSTANCE); EntityBag bag = session.createOrGetBag(MY_INSTANCE, BAG_1); bag.addEntity(new SimpleEntity().addProperty("test", "value")); QueryResult result = bag.getEntities(); assertThat(result.size(), is(1l)); Entity entity = result.next(); assertThat(entity, notNullValue()); assertThat(entity.getProperty("test").getFirstValue().toString(), is("value")); }
@Test public void testInsertOrUpdatePersist() throws JasDBException { DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("insertOrUpdateBag"); SimpleEntity entity = new SimpleEntity(); entity.addProperty("Test", "value1"); String id = bag.persist(entity).getInternalId(); assertThat(bag.getEntities().size(), is(1L)); assertThat(bag.getEntity(id).getProperty("Test").getFirstValueObject(), is("value1")); SimpleEntity updatedEntity = new SimpleEntity(id); updatedEntity.addProperty("AnotherProperty", "AnotherValue"); bag.persist(updatedEntity); assertThat(bag.getEntities().size(), is(1L)); assertThat(bag.getEntity(id).getProperty("AnotherProperty").getFirstValueObject(), is("AnotherValue")); }
for(Entity en : bag.getEntities()) { log.debug("Loaded entity: {}", en.getInternalId()); recordsFound++;