Codota Logo
EntityBag.getEntity
Code IndexAdd Codota to your IDE (free)

How to use
getEntity
method
in
com.oberasoftware.jasdb.api.session.EntityBag

Best Java code snippets using com.oberasoftware.jasdb.api.session.EntityBag.getEntity (Showing top 10 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: oberasoftware/jasdb

private void assertFind(String someRandomId) throws Exception {
  JasDBMain.start();
  log.info("START INDEX READ TEST");
  DBSession pojoDb = sessionFactory.createSession();
  EntityBag bag = pojoDb.createOrGetBag("testbag");
  try {
    log.info("Starting search for: {}", searchTestId);
    long startSearch = System.nanoTime();
    Entity entity = bag.getEntity(searchTestId);
    long endSearch = System.nanoTime();
    log.info("Search finished in: {}", (endSearch - startSearch));
    Assert.assertNotNull("An entity should have been found for id: " + searchTestId, entity);
    assertEquals(searchTestId, entity.getInternalId());
    
    log.info("Starting search for random: {}", someRandomId);
    startSearch = System.nanoTime();
    entity = bag.getEntity(someRandomId);
    endSearch = System.nanoTime();
    log.info("Search finished for random: {}", (endSearch - startSearch));
    Assert.assertNotNull("An entity should have been found", entity);
    assertEquals(someRandomId, entity.getInternalId());
  } finally {
    JasDBMain.shutdown();
  }
}
origin: oberasoftware/jasdb

@Test
public void testEntityManagerUpdate() throws JasDBException {
  DBSession session = sessionFactory.createSession();
  EntityManager entityManager = session.getEntityManager();
  String id = UUID.randomUUID().toString();
  TestEntity entity = new TestEntity(id, "Renze", "de Vries", newArrayList("programming", "model building", "biking"),
      new ImmutableMap.Builder<String, String>()
          .put("city", "Amsterdam")
          .put("street", "Secret passageway 10")
          .put("zipcode", "0000TT").build());
  assertThat(entityManager.persist(entity).getInternalId(), is(id));
  EntityBag testBag = session.createOrGetBag("TEST_BAG");
  assertThat(testBag.getSize(), is(1l));
  Entity mappedEntity = testBag.getEntity(id);
  assertThat(mappedEntity.getValue("firstName"), is("Renze"));
  assertThat(mappedEntity.getValue("lastName"), is("de Vries"));
  entity.setFirstName("Updated");
  entityManager.persist(entity);
  mappedEntity = testBag.getEntity(id);
  assertThat(mappedEntity.getValue("firstName"), is("Updated"));
  assertThat(mappedEntity.getValue("lastName"), is("de Vries"));
}
origin: oberasoftware/jasdb

@Override
public <T> T findEntity(Class<T> type, String entityId) throws JasDBStorageException {
  EntityMetadata entityMetadata = ENTITY_MAPPER.getEntityMetadata(type);
  EntityBag bag = session.getBag(entityMetadata.getBagName());
  if(bag != null) {
    Entity entity = bag.getEntity(entityId);
    return ENTITY_MAPPER.mapFrom(type, entity);
  }
  return null;
}
origin: oberasoftware/jasdb

@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"));
}
origin: oberasoftware/jasdb

@Test
public void testPersistFindPerformance() throws Exception {
  DBSession pojoDb = sessionFactory.createSession();
  EntityBag bag = pojoDb.createOrGetBag("mybag");
  List<String> entityIds = new ArrayList<>();
  for(int i=0; i<NUMBER_ENTITIES; i++) {
    SimpleEntity entity = new SimpleEntity(UUID.randomUUID().toString());
    entity.addProperty("someProperty" + i, i);
    entity.addProperty("doubleId", entity.getInternalId());
    bag.addEntity(entity);
    entityIds.add(entity.getInternalId());
  }
  try {
    for(String id : entityIds) {
      Entity entity = bag.getEntity(id);
      Assert.assertNotNull("Entity for id: " + id + " should be found", entity);
      assertEquals("Id should match expected id", id, entity.getInternalId());
      Assert.assertNotNull("There should be a property doubleId", entity.getProperty("doubleId"));
      assertEquals("Property doubleId should match expected id", id, entity.getProperty("doubleId").getFirstValueObject());
    }
  } finally {
    JasDBMain.shutdown();
  }
}
origin: oberasoftware/jasdb

@Override
public Entity persist(Object persistableObject) throws JasDBStorageException {
  MapResult mappedResult = ENTITY_MAPPER.mapTo(persistableObject);
  String bagName = mappedResult.getBagName();
  EntityBag bag = session.createOrGetBag(bagName);
  Entity persistedEntity;
  try {
    Entity entity = mappedResult.getJasDBEntity();
    if(StringUtils.stringNotEmpty(entity.getInternalId()) && bag.getEntity(entity.getInternalId()) != null) {
      //update
      persistedEntity = bag.updateEntity(mappedResult.getJasDBEntity());
      LOG.debug("Updated entity: {} in bag: {}", persistedEntity, bagName);
    } else {
      persistedEntity = bag.addEntity(mappedResult.getJasDBEntity());
      LOG.debug("Created entity: {} in bag: {}", persistedEntity, bagName);
    }
  } catch(RuntimeJasDBException e) {
    //we do this in case we have exactly two threads at same time trying to persist
    persistedEntity = bag.updateEntity(mappedResult.getJasDBEntity());
    LOG.debug("Updated entity: {} in bag: {}", persistedEntity, bagName);
  }
  //update the ID of the passed object
  ENTITY_MAPPER.updateId(persistedEntity.getInternalId(), persistableObject);
  return persistedEntity;
}
origin: oberasoftware/jasdb

@Test
public void testPersistMultiValue() throws Exception {
  DBSession session = sessionFactory.createSession();
  EntityBag bag = session.createOrGetBag("testbag");
  try {
    Entity entity = new SimpleEntity();
    entity.addProperty("field1", "value1");
    entity.addProperty("field1", "value2");
    entity.addProperty("field1", "value3");
    entity.addProperty("number", 100L);
    entity.addProperty("number", 500L);
    bag.addEntity(entity);
    String entityId = entity.getInternalId();
    entity = bag.getEntity(entityId);
    Property property = entity.getProperty("field1");
    Assert.assertNotNull(property);
    assertEquals("The object should be multivalue", true, property.isMultiValue());
    assertEquals("There should be three properties", 3, property.getValues().size());
    assertEquals("Unexpected value", "value1", property.getValues().get(0).getValue());
    assertEquals("Unexpected value", "value2", property.getValues().get(1).getValue());
    assertEquals("Unexpected value", "value3", property.getValues().get(2).getValue());
    property = entity.getProperty("number");
    assertEquals("The object should be multivalue", true, property.isMultiValue());
    assertEquals("There should be three properties", 2, property.getValues().size());
    assertEquals("Unexpected value", 100L, property.getValues().get(0).getValue());
    assertEquals("Unexpected value", 500L, property.getValues().get(1).getValue());
  } finally {
    JasDBMain.shutdown();
  }
}
origin: oberasoftware/jasdb

Entity entity = bag.getEntity(id);
Assert.assertNotNull("Entity for id: " + id + " should be found", entity);
assertEquals("Id should match expected id", id, entity.getInternalId());
origin: oberasoftware/jasdb

entity1 = bag.getEntity(entity1.getInternalId());
assertNotNull(entity1);
assertEquals(entity1Id, entity1.getInternalId());
bag.updateEntity(entity1);
entity2 = bag.getEntity(entity2.getInternalId());
assertNotNull(entity2);
assertEquals(entity2Id, entity2.getInternalId());
EntityBag bag = pojoDb.createOrGetBag("mybag");
entity1 = bag.getEntity(entity1Id);
assertNotNull(entity1);
assertEquals(entity1Id, entity1.getInternalId());
assertEquals("My value for entity 1", entity1.getProperty("testProperty").getFirstValueObject());
entity2 = bag.getEntity(entity2Id);
assertNotNull(entity2);
assertEquals(entity2Id, entity2.getInternalId());
origin: oberasoftware/jasdb

bag = session.createOrGetBag("testbag");
Entity foundEntity = bag.getEntity(documentId);
assertEquals("Internal Doc id's should be the same", documentId, foundEntity.getInternalId());
com.oberasoftware.jasdb.api.sessionEntityBaggetEntity

Javadoc

Retrieves a specific entity from the bag

Popular methods of EntityBag

  • addEntity
    Adds an entity to the bag of entities
  • find
    Builds a query for document in the storage for a specific queryfield with optional sorting parameter
  • getEntities
    Execute a query returning all records in the bag with a given max
  • removeEntity
    Removes the entity from the bag using the id
  • updateEntity
    Updates an entity in the bag of entities
  • ensureIndex
    Ensures there is an index present on a given field in this bag, will create if not existent, will do
  • flush
    Forcibly flushes all the data in the bag to the storage
  • getDiskSize
    Returns the size on the disk of the entities
  • getSize
    Returns the amount of entities in the bag
  • persist
    Persists the provided entity, if not exists will be created, if already exists it will be updated
  • removeIndex
    Removes the index from the bag
  • removeIndex

Popular in Java

  • Parsing JSON documents to java classes using gson
  • addToBackStack (FragmentTransaction)
  • onCreateOptionsMenu (Activity)
  • runOnUiThread (Activity)
  • Path (java.nio.file)
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now