Search in sources :

Example 81 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class SolrStore method truncateSchema.

@Override
public /**
 * Default implementation deletes and recreates the schema
 */
void truncateSchema() throws GoraException {
    try {
        server.deleteByQuery("*:*");
        server.commit();
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 82 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class SolrStore method deleteSchema.

@Override
public void deleteSchema() throws GoraException {
    // XXX should this be only in truncateSchema ???
    try {
        server.deleteByQuery("*:*");
        server.commit();
        CoreAdminRequest.unloadCore(mapping.getCoreName(), adminServer);
    } catch (Exception e) {
        if (e.getMessage().contains("No such core")) {
            // it's ok, the core is not there
            return;
        } else {
            throw new GoraException(e);
        }
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 83 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class SolrStore method exists.

@Override
public boolean exists(K key) throws GoraException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CommonParams.QT, "/get");
    params.set(CommonParams.FL, " ");
    params.set("id", key.toString());
    try {
        QueryResponse rsp = server.query(params);
        Object o = rsp.getResponse().get("doc");
        return o != null;
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrServerException(org.apache.solr.client.solrj.SolrServerException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 84 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class SolrStore method flush.

@Override
public void flush() throws GoraException {
    try {
        if (batch.size() > 0) {
            add(batch, commitWithin);
            batch.clear();
        }
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 85 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class SolrStore method put.

@Override
public void put(K key, T persistent) throws GoraException {
    Schema schema = persistent.getSchema();
    if (!persistent.isDirty()) {
        // nothing to do
        return;
    }
    SolrInputDocument doc = new SolrInputDocument();
    // add primary key
    doc.addField(mapping.getPrimaryKey(), key);
    // populate the doc
    List<Field> fields = schema.getFields();
    for (Field field : fields) {
        String sf = mapping.getSolrField(field.name());
        // mapping won't find the primary
        if (sf == null) {
            continue;
        }
        Schema fieldSchema = field.schema();
        Object v = persistent.get(field.pos());
        if (v == null) {
            continue;
        }
        v = serializeFieldValue(fieldSchema, v);
        doc.addField(sf, v);
    }
    LOG.info("Putting DOCUMENT: " + doc);
    batch.add(doc);
    if (batch.size() >= batchSize) {
        try {
            add(batch, commitWithin);
            batch.clear();
        } catch (Exception e) {
            throw new GoraException(e);
        }
    }
}
Also used : Field(org.apache.avro.Schema.Field) SolrInputDocument(org.apache.solr.common.SolrInputDocument) GoraException(org.apache.gora.util.GoraException) Schema(org.apache.avro.Schema) SolrServerException(org.apache.solr.client.solrj.SolrServerException) GoraException(org.apache.gora.util.GoraException) 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