@Override public KeyType getKeyType() { return new LongKeyType(); }
@Override public void openWriter() throws JasDBStorageException { this.keyInfo = new KeyInfoImpl(new SimpleIndexField("__ID", new UUIDKeyType()), new SimpleIndexField("RECORD_POINTER", new LongKeyType())); this.index = new BTreeIndex(indexLocation, keyInfo); this.writer.openWriter(); this.index.openIndex(); }
EntityBag bag = pojoDb.createOrGetBag("inverted"); bag.ensureIndex(new SimpleIndexField("field1", new StringKeyType()), false); bag.ensureIndex(new SimpleIndexField("field5", new LongKeyType()), false, new SimpleIndexField("field6", new LongKeyType())); bag.ensureIndex(new SimpleIndexField("field6", new LongKeyType()), false); bag.ensureIndex(new SimpleIndexField("age", new LongKeyType()), false); bag.ensureIndex(new SimpleIndexField("city", new StringKeyType()), false); bag.ensureIndex(new SimpleIndexField("embed.embeddedProperty", new StringKeyType()), false); bag.ensureIndex(new SimpleCompositeIndexField(new SimpleIndexField("age", new LongKeyType()), new SimpleIndexField("mainCity", new StringKeyType())), false);
@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(); } }
@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(); } }
@Test public void testPersisterRemove() throws Exception { int testSize = 1000; DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("testbag"); bag.ensureIndex(new SimpleIndexField("city", new StringKeyType(100)), false); bag.ensureIndex(new SimpleIndexField("testField", new LongKeyType()), true); Random rnd = new Random(); for(int i=0; i<testSize; i++) { int cityIdx = rnd.nextInt(SimpleBaseTest.possibleCities.length); String city = SimpleBaseTest.possibleCities[cityIdx]; SimpleEntity entity = new SimpleEntity(); entity.addProperty("city", city); entity.addProperty("testField", (long)i); bag.addEntity(entity); } for(String city : SimpleBaseTest.possibleCities) { QueryResult result = bag.find(QueryBuilder.createBuilder().field("city").value(city)).execute(); for(Entity foundEntity : result) { Long testFieldValue = foundEntity.getProperty("testField").getFirstValueObject(); bag.removeEntity(foundEntity); assertFalse("There should no longer be a result", bag.find(QueryBuilder.createBuilder().field("testField").value(testFieldValue)).execute().hasNext()); } result = bag.find(QueryBuilder.createBuilder().field("city").value(city)).execute(); assertEquals("There should no longer be any entity", (long) 0, result.size()); } }
@Test public void testNotEqualsMultiIndexes() throws Exception { try { DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("websites"); bag.ensureIndex(new SimpleIndexField("url", new StringKeyType()), false); bag.ensureIndex( new SimpleCompositeIndexField( new SimpleIndexField("stepid", new StringKeyType()), new SimpleIndexField("workflow", new LongKeyType()) ),false); bag.addEntity(new SimpleEntity().addProperty("url", "").addProperty("stepid", 1L).addProperty("workflow", 1L)); bag.addEntity(new SimpleEntity().addProperty("url", "").addProperty("stepid", 1L).addProperty("workflow", 1L)); bag.addEntity(new SimpleEntity().addProperty("url", "").addProperty("stepid", 1L).addProperty("workflow", 1L)); bag.addEntity(new SimpleEntity().addProperty("url", "http://someurl.nl/1").addProperty("stepid", 1L).addProperty("workflow", 1L)); bag.addEntity(new SimpleEntity().addProperty("url", "http://someurl.nl/2").addProperty("stepid", 1L).addProperty("workflow", 1L)); QueryResult r = bag.find(QueryBuilder.createBuilder() .field("stepid").value(1L) .field("workflow").value(1L) .field("url").notEquals("")).execute(); assertThat(r.size(), is(2L)); } finally { JasDBMain.shutdown(); } }