Search in sources :

Example 41 with GoraException

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);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) DocumentNotFoundException(org.ektorp.DocumentNotFoundException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 42 with GoraException

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);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) DocumentNotFoundException(org.ektorp.DocumentNotFoundException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 43 with GoraException

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;
}
Also used : GoraException(org.apache.gora.util.GoraException) Schema(org.apache.avro.Schema)

Example 44 with GoraException

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;
}
Also used : Field(org.apache.avro.Schema.Field) GoraException(org.apache.gora.util.GoraException) PersistentBase(org.apache.gora.persistency.impl.PersistentBase) Schema(org.apache.avro.Schema) BeanFactoryImpl(org.apache.gora.persistency.impl.BeanFactoryImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 45 with GoraException

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);
    }
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) GoraException(org.apache.gora.util.GoraException) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) IOException(java.io.IOException)

Aggregations

GoraException (org.apache.gora.util.GoraException)174 IOException (java.io.IOException)119 ArrayList (java.util.ArrayList)30 Schema (org.apache.avro.Schema)25 SQLException (java.sql.SQLException)17 HashMap (java.util.HashMap)17 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 PreparedStatement (java.sql.PreparedStatement)11 Map (java.util.Map)11 PersistentBase (org.apache.gora.persistency.impl.PersistentBase)9 SolrServerException (org.apache.solr.client.solrj.SolrServerException)9 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)8 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)8 Field (org.apache.avro.Schema.Field)8 KuduException (org.apache.kudu.client.KuduException)8 ResultSet (com.datastax.driver.core.ResultSet)7 SimpleStatement (com.datastax.driver.core.SimpleStatement)7 SAXBuilder (org.jdom.input.SAXBuilder)7 InputStream (java.io.InputStream)6