congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
EntityBag.updateEntity
Code IndexAdd Tabnine to your IDE (free)

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

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

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 testRandomPersistUpdate() throws Exception {
  String[] cities = new String[] {"Amsterdam", "Rotterdam", "Utrecht", "Groningen", "Haarlem", "Den Haag", "Maastricht", "Eindhoven"};
  int testSize = 1000;
  DBSession session = sessionFactory.createSession();
  EntityBag bag = session.createOrGetBag("testbag");
  bag.ensureIndex(new SimpleIndexField("city", new StringKeyType()), false);
  bag.ensureIndex(new SimpleIndexField("itemId", new LongKeyType()), true);
  try {
    Map<String, Integer> cityCounts = generateCities(testSize, bag);
    assertCityIndexes(bag, cities, cityCounts);
    for(int i=200; i<400; i++) {
      QueryExecutor executor = bag.find(QueryBuilder.createBuilder().field("itemId").value((long)i));
      QueryResult result = executor.execute();
      for(Entity entity : result) {
        String city = entity.getProperty("city").getFirstValueObject().toString();
        entity.setProperty("city", "unknown");
        bag.updateEntity(entity);
        changeCityCount(city, cityCounts, false);
        changeCityCount("unknown", cityCounts, true);
      }
    }
    assertCityIndexes(bag, cities, cityCounts);
  } finally {
    JasDBMain.shutdown();
  }
}
origin: oberasoftware/jasdb

@Test
public void testRandomPersistUpdateBigRecordUpdate() throws Exception {
  String htmlData = ResourceUtil.getContent("datasets/htmlpage.data", "UTF-8");
  int testSize = 1000;
  DBSession session = sessionFactory.createSession();
  EntityBag bag = session.createOrGetBag("testbag");
  bag.ensureIndex(new SimpleIndexField("city", new StringKeyType()), false);
  bag.ensureIndex(new SimpleIndexField("itemId", new LongKeyType()), true);
  try {
    Map<String, Integer> cityCounts = generateCities(testSize, bag);
    assertCityIndexes(bag, cities, cityCounts);
    for(int i=200; i<400; i++) {
      QueryExecutor executor = bag.find(QueryBuilder.createBuilder().field("itemId").value((long)i));
      QueryResult result = executor.execute();
      for(Entity entity : result) {
        String city = entity.getProperty("city").getFirstValueObject().toString();
        entity.setProperty("city", "unknown");
        entity.setProperty("bigdatafield", htmlData);
        bag.updateEntity(entity);
        changeCityCount(city, cityCounts, false);
        changeCityCount("unknown", cityCounts, true);
      }
    }
    assertCityIndexes(bag, cities, cityCounts);
  } finally {
    JasDBMain.shutdown();
  }
}
origin: oberasoftware/jasdb

assertEquals(entity1Id, entity1.getInternalId());
entity1.addProperty("testProperty", "My value for entity 1");
bag.updateEntity(entity1);
assertEquals(entity2Id, entity2.getInternalId());
entity2.addProperty("someProp", "Value 1 smaller");
bag.updateEntity(entity2);
origin: oberasoftware/jasdb

bag.updateEntity(new SimpleEntity(controllerEntityId).addProperty("controllerId", "Renzes-MacBook-Pro-2.local")
    .addProperty("plugins", "7158f3ec-681f-4d9b-9ab1-6ab6c60288e3").addProperty("type", "controller"));
bag.updateEntity(new SimpleEntity(pluginEntityId)
    .addProperty("controllerId", "Renzes-MacBook-Pro-2.local").addProperty("pluginId", "zwave")
    .addProperty("name", "ZWave provider").addProperty("type", "plugin"));
com.oberasoftware.jasdb.api.sessionEntityBagupdateEntity

Javadoc

Updates an entity in the bag of entities

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
  • getEntity
    Retrieves a specific entity from the bag
  • removeEntity
    Removes the entity from the bag using the id
  • 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

  • Updating database using SQL prepared statement
  • onCreateOptionsMenu (Activity)
  • runOnUiThread (Activity)
  • putExtra (Intent)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Menu (java.awt)
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now