use of org.apache.gora.persistency.impl.BeanFactoryImpl in project gora by apache.
the class MemStoreTest method testMemStoreDeleteByQueryFields.
@Test
public void testMemStoreDeleteByQueryFields() throws Exception {
DataStore<String, WebPage> store = new MemStore<>();
BeanFactory<String, WebPage> beanFactory = new BeanFactoryImpl<>(String.class, WebPage.class);
store.setBeanFactory(beanFactory);
Query<String, WebPage> query;
// test 5 - delete all with some fields
WebPageDataCreator.createWebPageData(store);
query = store.newQuery();
query.setFields("outlinks", "parsedContent", "content");
Query<String, WebPage> newQuery = store.newQuery();
newQuery.setStartKey(SORTED_URLS[0]);
newQuery.setEndKey(SORTED_URLS[9]);
newQuery.setFields("outlinks", "parsedContent", "content");
DataStoreTestUtil.assertNumResults(newQuery, URLS.length);
store.deleteByQuery(query);
store.deleteByQuery(query);
// don't you love that HBase sometimes does not delete arbitrarily
store.deleteByQuery(query);
store.flush();
DataStoreTestUtil.assertNumResults(store.newQuery(), URLS.length);
// assert that data is deleted
for (String SORTED_URL : SORTED_URLS) {
WebPage page = store.get(SORTED_URL);
assertNotNull(page);
assertNotNull(page.getUrl());
assertEquals(page.getUrl().toString(), SORTED_URL);
assertEquals("Map of Outlinks should have a size of '0' as the deleteByQuery " + "not only removes the data but also the data structure.", 0, page.getOutlinks().size());
assertEquals(0, page.getParsedContent().size());
if (page.getContent() != null) {
LOG.info("url:" + page.getUrl().toString());
LOG.info("limit:" + page.getContent().limit());
} else {
assertNull(page.getContent());
}
}
// test 6 - delete some with some fields
WebPageDataCreator.createWebPageData(store);
query = store.newQuery();
query.setFields("url");
String startKey = SORTED_URLS[NUM_KEYS];
String endKey = SORTED_URLS[SORTED_URLS.length - NUM_KEYS];
query.setStartKey(startKey);
query.setEndKey(endKey);
DataStoreTestUtil.assertNumResults(store.newQuery(), URLS.length);
store.deleteByQuery(query);
store.deleteByQuery(query);
// don't you love that HBase sometimes does not delete arbitrarily
store.deleteByQuery(query);
store.flush();
DataStoreTestUtil.assertNumResults(store.newQuery(), URLS.length);
// assert that data is deleted
for (int i = 0; i < URLS.length; i++) {
WebPage page = store.get(URLS[i]);
assertNotNull(page);
if (URLS[i].compareTo(startKey) < 0 || URLS[i].compareTo(endKey) > 0) {
// not deleted
DataStoreTestUtil.assertWebPage(page, i);
} else {
// deleted
assertNull(page.getUrl());
assertNotNull(page.getOutlinks());
assertNotNull(page.getParsedContent());
assertNotNull(page.getContent());
assertTrue(page.getOutlinks().size() > 0);
assertTrue(page.getParsedContent().size() > 0);
}
}
}
use of org.apache.gora.persistency.impl.BeanFactoryImpl in project gora by apache.
the class CouchDBStore method fromCouchDBRecord.
private Object fromCouchDBRecord(final Schema fieldSchema, final String docf, final Object value) throws GoraException {
final Object innerValue = ((Map) value).get(docf);
if (innerValue == null) {
return null;
}
Class<?> clazz = null;
try {
clazz = ClassLoadingUtils.loadClass(fieldSchema.getFullName());
} catch (ClassNotFoundException e) {
throw new GoraException(e);
}
final PersistentBase record = (PersistentBase) new BeanFactoryImpl(keyClass, clazz).newPersistent();
for (Field recField : fieldSchema.getFields()) {
Schema innerSchema = recField.schema();
record.put(recField.pos(), fromDBObject(innerSchema, recField, recField.name(), innerValue));
}
return record;
}
use of org.apache.gora.persistency.impl.BeanFactoryImpl in project gora by apache.
the class JCacheGoraDataStoreTest method testGetWithFields.
@Test
public void testGetWithFields() throws Exception {
DataStore<String, WebPage> store = super.webPageStore;
BeanFactory<String, WebPage> beanFactory = new BeanFactoryImpl<>(String.class, WebPage.class);
store.setBeanFactory(beanFactory);
WebPageDataCreator.createWebPageData(store);
String[] interestFields = new String[2];
interestFields[0] = "url";
interestFields[1] = "content";
WebPage page = store.get(URLS[1], interestFields);
assertNotNull(page);
assertNotNull(page.getUrl());
assertEquals(page.getUrl().toString(), URLS[1]);
assertNotNull(page.getContent());
assertEquals("Map of Outlinks should have a size of '0' as it is omitted at retrieval", 0, page.getOutlinks().size());
assertEquals("Map of Parsed Content should have a size of '0' as it is omitted at retrieval", 0, page.getParsedContent().size());
}
use of org.apache.gora.persistency.impl.BeanFactoryImpl in project gora by apache.
the class JCacheGoraDataStoreTest method testDeleteByQueryFields.
@Test
public void testDeleteByQueryFields() throws Exception {
DataStore<String, WebPage> store = super.webPageStore;
BeanFactory<String, WebPage> beanFactory = new BeanFactoryImpl<>(String.class, WebPage.class);
store.setBeanFactory(beanFactory);
Query<String, WebPage> query;
WebPageDataCreator.createWebPageData(store);
query = store.newQuery();
query.setFields("outlinks", "parsedContent", "content");
Query<String, WebPage> newQuery = store.newQuery();
newQuery.setStartKey(SORTED_URLS[0]);
newQuery.setEndKey(SORTED_URLS[9]);
newQuery.setFields("outlinks", "parsedContent", "content");
DataStoreTestUtil.assertNumResults(newQuery, URLS.length);
store.deleteByQuery(query);
store.deleteByQuery(query);
store.deleteByQuery(query);
store.flush();
DataStoreTestUtil.assertNumResults(store.newQuery(), URLS.length);
for (String SORTED_URL : SORTED_URLS) {
WebPage page = store.get(SORTED_URL);
assertNotNull(page);
assertNotNull(page.getUrl());
assertEquals(page.getUrl().toString(), SORTED_URL);
assertEquals("Map of Outlinks should have a size of '0' as the deleteByQuery " + "not only removes the data but also the data structure.", 0, page.getOutlinks().size());
assertEquals(0, page.getParsedContent().size());
if (page.getContent() != null) {
LOG.info("url:" + page.getUrl().toString());
LOG.info("limit:" + page.getContent().limit());
} else {
assertNull(page.getContent());
}
}
WebPageDataCreator.createWebPageData(store);
query = store.newQuery();
query.setFields("url");
String startKey = SORTED_URLS[NUM_KEYS];
String endKey = SORTED_URLS[SORTED_URLS.length - NUM_KEYS];
query.setStartKey(startKey);
query.setEndKey(endKey);
DataStoreTestUtil.assertNumResults(store.newQuery(), URLS.length);
store.deleteByQuery(query);
store.deleteByQuery(query);
store.deleteByQuery(query);
store.flush();
DataStoreTestUtil.assertNumResults(store.newQuery(), URLS.length);
for (int i = 0; i < URLS.length; i++) {
WebPage page = store.get(URLS[i]);
assertNotNull(page);
if (URLS[i].compareTo(startKey) < 0 || URLS[i].compareTo(endKey) > 0) {
DataStoreTestUtil.assertWebPage(page, i);
} else {
assertNull(page.getUrl());
assertNotNull(page.getOutlinks());
assertNotNull(page.getParsedContent());
assertNotNull(page.getContent());
assertTrue(page.getOutlinks().size() > 0);
assertTrue(page.getParsedContent().size() > 0);
}
}
}
use of org.apache.gora.persistency.impl.BeanFactoryImpl in project gora by apache.
the class MongoStore method fromMongoRecord.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object fromMongoRecord(final Schema fieldSchema, final String docf, final DBObject rec) {
Object result;
BSONDecorator innerBson = new BSONDecorator(rec);
Class<?> clazz = null;
try {
clazz = ClassLoadingUtils.loadClass(fieldSchema.getFullName());
} catch (ClassNotFoundException e) {
}
PersistentBase record = (PersistentBase) new BeanFactoryImpl(keyClass, clazz).newPersistent();
for (Field recField : fieldSchema.getFields()) {
Schema innerSchema = recField.schema();
DocumentFieldType innerStoreType = mapping.getDocumentFieldType(innerSchema.getName());
String innerDocField = mapping.getDocumentField(recField.name()) != null ? mapping.getDocumentField(recField.name()) : recField.name();
String fieldPath = docf + "." + innerDocField;
LOG.debug("Load from DBObject (RECORD), field:{}, schemaType:{}, docField:{}, storeType:{}", new Object[] { recField.name(), innerSchema.getType(), fieldPath, innerStoreType });
record.put(recField.pos(), fromDBObject(innerSchema, innerStoreType, recField, innerDocField, innerBson));
}
result = record;
return result;
}
Aggregations