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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations