#304 - ElasticSearch integration part 1 / doc store integration

This commit is contained in:
Robin Bygrave committed 2016-03-01 15:36:44 +13:00
1 parent cb1fe297d6
commit 8d3b4a0407
209 files changed
+6736 -573

No files matched your search

@@ -29,4 +29,5 @@ public interface LoadManyBuffer {
void configureQuery(SpiQuery<?> query);
boolean isUseDocStore();
}
@@ -144,7 +144,7 @@ public class LoadManyRequest extends LoadRequest {
query.setLazyLoadForParents(many);
List<Object> idList = getParentIdList(batchSize);
many.addWhereParentIdIn(query, idList);
many.addWhereParentIdIn(query, idList, loadContext.isUseDocStore());
query.setPersistenceContext(loadContext.getPersistenceContext());
@@ -1,6 +1,7 @@
package com.avaje.ebeaninternal.api;
import com.avaje.ebean.TransactionCallback;
import com.avaje.ebean.annotation.DocStoreEvent;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebean.config.PersistBatch;
import com.avaje.ebean.event.changelog.BeanChange;
@@ -59,6 +60,26 @@ public class ScopedTransaction implements SpiTransaction {
}
}
@Override
public DocStoreEvent getDocStoreUpdateMode() {
return transaction.getDocStoreUpdateMode();
}
@Override
public void setDocStoreUpdateMode(DocStoreEvent indexUpdateMode) {
transaction.setDocStoreUpdateMode(indexUpdateMode);
}
@Override
public int getDocStoreBulkBatchSize() {
return transaction.getDocStoreBulkBatchSize();
}
@Override
public void setDocStoreUpdateBatchSize(int batchSize) {
transaction.setDocStoreUpdateBatchSize(batchSize);
}
@Override
public String getLogPrefix() {
return transaction.getLogPrefix();
@@ -83,6 +83,11 @@ public interface SpiEbeanServer extends EbeanServer, BeanLoader, BeanCollectionL
*/
BeanDescriptor<?> getBeanDescriptorById(String className);
/**
* Return BeanDescriptor using it's unique doc store queueId.
*/
BeanDescriptor<?> getBeanDescriptorByQueueId(String queueId);
/**
* Return BeanDescriptors mapped to this table.
*/
@@ -3,6 +3,9 @@ package com.avaje.ebeaninternal.api;
import com.avaje.ebean.Expression;
import com.avaje.ebean.event.BeanQueryRequest;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.expression.ElasticExpressionContext;
import java.io.IOException;
/**
@@ -10,6 +13,11 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
*/
public interface SpiExpression extends Expression {
/**
* Write the expression as an elastic search expression.
*/
void writeElastic(ElasticExpressionContext context) throws IOException;
/**
* Process "Many" properties populating ManyWhereJoins.
* <p>
@@ -16,10 +16,12 @@ import com.avaje.ebeaninternal.server.autotune.ProfilingListener;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.deploy.TableJoin;
import com.avaje.ebeaninternal.server.expression.ElasticExpressionContext;
import com.avaje.ebeaninternal.server.query.CancelableQuery;
import com.avaje.ebeaninternal.server.querydefn.NaturalKeyBindParam;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;
import java.util.Set;
@@ -128,6 +130,26 @@ public interface SpiQuery<T> extends Query<T> {
}
}
/**
* Write the query as an elastic search query.
*/
void writeElastic(ElasticExpressionContext context) throws IOException;
/**
* Return true if AutoTune should be attempted on this query.
*/
boolean isAutoTunable();
/**
* Return the bean descriptor for this query.
*/
BeanDescriptor<T> getBeanDescriptor();
/**
* Return true if this query should be executed against the doc store.
*/
boolean isUseDocStore();
/**
* Return the PersistenceContextScope that this query should use.
* <p>
@@ -276,18 +298,13 @@ public interface SpiQuery<T> extends Query<T> {
/**
* Return the lazy loading 'many' property.
*/
BeanPropertyAssocMany<?> getLazyLoadForParentsProperty();
BeanPropertyAssocMany<?> getLazyLoadMany();
/**
* Set the load mode (+lazy or +query) and the load description.
*/
void setLoadDescription(String loadMode, String loadDescription);
/**
* Set the BeanDescriptor for the root type of this query.
*/
void setBeanDescriptor(BeanDescriptor<?> desc);
/**
* Return the joins required to support predicates on the many properties.
*/
@@ -639,9 +656,9 @@ public interface SpiQuery<T> extends Query<T> {
*/
boolean isDisableReadAudit();
/**
* Return true if this is a query executing in the background.
*/
/**
* Return true if this is a query executing in the background.
*/
boolean isFutureFetch();
/**
@@ -4,6 +4,7 @@ import java.sql.Connection;
import java.util.List;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.annotation.DocStoreEvent;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebean.event.changelog.BeanChange;
import com.avaje.ebean.event.changelog.ChangeSet;
@@ -20,7 +21,7 @@ import com.avaje.ebeaninternal.server.persist.BatchControl;
public interface SpiTransaction extends Transaction {
/**
* Return the string prefix with the transactin id and label used in logging.
* Return the string prefix with the transaction id and label used in logging.
*/
String getLogPrefix();
@@ -102,6 +103,20 @@ public interface SpiTransaction extends Transaction {
*/
Boolean isUpdateAllLoadedProperties();
/**
* Return the batchSize specifically set for this transaction or 0.
* <p>
* Returning 0 implies to use the system wide default batch size.
* </p>
*/
DocStoreEvent getDocStoreUpdateMode();
/**
* Return the batch size to us for ElasticSearch Bulk API calls
* as a result of this transaction.
*/
int getDocStoreBulkBatchSize();
/**
* Return the batchSize specifically set for this transaction or 0.
* <p>
@@ -157,12 +172,12 @@ public interface SpiTransaction extends Transaction {
boolean isBatchThisRequest(PersistRequest.Type type);
/**
* Return the queue used to batch up persist requests.
* Return the BatchControl used to batch up persist requests.
*/
BatchControl getBatchControl();
/**
* Set the queue used to batch up persist requests. There should only be one
* Set the BatchControl used to batch up persist requests. There should only be one
* PersistQueue set per transaction.
*/
void setBatchControl(BatchControl control);
@@ -1,5 +1,6 @@
package com.avaje.ebeaninternal.api;
import com.avaje.ebeanservice.docstore.api.DocStoreUpdates;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.transaction.DeleteByIdMap;
@@ -120,4 +121,16 @@ public class TransactionEvent implements Serializable {
}
}
/**
* Add any relevant PersistRequestBean's to DocStoreUpdates for later processing.
*/
public void addDocStoreUpdates(DocStoreUpdates docStoreUpdates) {
List<PersistRequestBean<?>> persistRequestBeans = getPersistRequestBeans();
if (persistRequestBeans != null) {
for (int i=0; i< persistRequestBeans.size(); i++) {
persistRequestBeans.get(i).addDocStoreUpdates(docStoreUpdates);
}
}
}
}