private GlobalSchedulerService schedulerService;
private boolean pessimisticLocking = false;
@Override
public Object getObject() throws Exception {
RuntimeEnvironmentBuilder builder = null;
RuntimeEnvironmentBuilderFactory factory = RuntimeEnvironmentBuilder.Factory.get();
if (type.equalsIgnoreCase(TYPE_EMPTY)) {
builder = factory.newEmptyBuilder();
} else if (type.equalsIgnoreCase(TYPE_DEFAULT_IN_MEMORY)) {
builder = factory.newDefaultInMemoryBuilder();
} else if (type.equalsIgnoreCase(TYPE_DEFAULT)) {
builder = factory.newDefaultBuilder();
} else if (type.equalsIgnoreCase(TYPE_DEFAULT_KJAR)) {
if (releaseId != null) {
builder = factory.newDefaultBuilder(releaseId, kbaseName, ksessionName);
} else {
builder = factory.newDefaultBuilder(groupId, artifactId, version, kbaseName, ksessionName);
}
} else if (type.equalsIgnoreCase(TYPE_DEFAULT_KJAR_CL)) {
builder = factory.newClasspathKmoduleDefaultBuilder(kbaseName, ksessionName);
} else {
throw new IllegalArgumentException("Unknown type of environment");
}
// apply all known properties
builder
.entityManagerFactory(entityManagerFactory)
.knowledgeBase(knowledgeBase)
.classLoader(classLoader)
.schedulerService(schedulerService)
.userGroupCallback(userGroupCallback)
.registerableItemsFactory(registerableItemsFactory);
// common environment entries
builder.addEnvironmentEntry("org.kie.api.task.TaskService", taskService);
builder.addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, transactionManager);
builder.addEnvironmentEntry(EnvironmentName.TASK_USER_GROUP_CALLBACK, userGroupCallback);
builder.addEnvironmentEntry(EnvironmentName.TASK_USER_INFO, userInfo);
if (entityManager != null) {
builder.addEnvironmentEntry(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, entityManager)
.addEnvironmentEntry(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, entityManager)
.addEnvironmentEntry("IS_JTA_TRANSACTION", false)
.addEnvironmentEntry("IS_SHARED_ENTITY_MANAGER", true);
}
if( pessimisticLocking ) {
builder.addEnvironmentEntry(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
// apply configuration if any
if (configuration != null) {
for (Map.Entry<String, String> entry : configuration.entrySet()) {
builder.addConfiguration(entry.getKey(), entry.getValue());
}
}
// apply environment entries if any
if (environmentEntries != null) {
for (Map.Entry<String, Object> entry : environmentEntries.entrySet()) {
builder.addEnvironmentEntry(entry.getKey(), entry.getValue());
}
}
// apply assets if kbase was not given
if (knowledgeBase == null && assets != null) {
for (Map.Entry<Resource, ResourceType> entry : assets.entrySet()) {
builder.addAsset(entry.getKey(), entry.getValue());
}
}
return builder.get();
}