if (node.isDirty())
{
node.handlePreEvent();
Object entity = node.getData();
Object id = node.getEntityId();
EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
node.getDataClass());
MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
metadata.getPersistenceUnit());
EntityType entityType = metaModel.entity(metadata.getEntityClazz());
String key = getKeyAsString(id, metadata, metaModel);
if (node.isInState(RemovedState.class))
{
// create a delete request.
DeleteRequest request = new DeleteRequest(metadata.getSchema().toLowerCase(),
metadata.getTableName(), key);
bulkRequest.add(request);
}
else if (node.isUpdate())
{
Map<String, Object> values = new HashMap<String, Object>();
List<RelationHolder> relationHolders = getRelationHolders(node);
addSource(entity, values, entityType);
addRelations(relationHolders, values);
UpdateRequest request = new UpdateRequest(metadata.getSchema().toLowerCase(),
metadata.getTableName(), key).doc(values);
bulkRequest.add(request);
}
else
{
// create an insert request.
Map<String, Object> values = new HashMap<String, Object>();
List<RelationHolder> relationHolders = getRelationHolders(node);
addSource(entity, values, entityType);
addRelations(relationHolders, values);
IndexRequest request = new IndexRequest(metadata.getSchema().toLowerCase(),
metadata.getTableName(), key).source(values);
bulkRequest.add(request);
}
}