use of org.apache.gora.util.GoraException in project gora by apache.
the class CouchDBStore method flush.
@Override
public void flush() throws GoraException {
try {
db.executeBulk(bulkDocs);
bulkDocs.clear();
db.flushBulkBuffer();
} catch (Exception e) {
throw new GoraException(e);
}
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class CouchDBStore method delete.
/**
* Deletes the object with the given key
*
* @param key the key of the object
* @return whether the object was successfully deleted
*/
@Override
public boolean delete(K key) throws GoraException {
if (key == null) {
deleteSchema();
createSchema();
return true;
}
try {
final String keyString = key.toString();
final Map<String, Object> referenceData = db.get(Map.class, keyString);
return StringUtils.isNotEmpty(db.delete(keyString, referenceData.get("_rev").toString()));
} catch (Exception e) {
throw new GoraException(e);
}
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class CouchDBStore method fromCouchDBUnion.
private Object fromCouchDBUnion(final Schema fieldSchema, final Field field, final String docf, final Object value) throws GoraException {
// schema [type0, type1]
Object result;
Schema.Type type0 = fieldSchema.getTypes().get(0).getType();
Schema.Type type1 = fieldSchema.getTypes().get(1).getType();
// or ["type","null"]
if (!type0.equals(type1) && (type0.equals(Schema.Type.NULL) || type1.equals(Schema.Type.NULL))) {
Schema innerSchema = fieldSchema.getTypes().get(1);
LOG.debug("Load from DBObject (UNION), schemaType:{}, docField:{}, storeType:{}", new Object[] { innerSchema.getType(), docf });
// Deserialize as if schema was ["type"]
result = fromDBObject(innerSchema, field, docf, value);
} else {
throw new GoraException("CouchDBStore doesn't support 3 types union field yet. Please update your mapping");
}
return result;
}
use of org.apache.gora.util.GoraException 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.util.GoraException in project gora by apache.
the class ElasticsearchStore method flush.
@Override
public void flush() throws GoraException {
try {
client.indices().refresh(new RefreshRequest(elasticsearchMapping.getIndexName()), RequestOptions.DEFAULT);
client.indices().flush(new FlushRequest(elasticsearchMapping.getIndexName()), RequestOptions.DEFAULT);
} catch (IOException ex) {
throw new GoraException(ex);
}
}
Aggregations