}
}
}
}
ValueAddEventProcessor vaeProcessor = valueAddEventService.getValueAddProcessor(insertIntoDesc.getEventTypeName());
EventType resultEventType;
if (isUsingWildcard)
{
if (vaeProcessor != null)
{
resultEventType = vaeProcessor.getValueAddEventType();
isRevisionEvent = true;
vaeProcessor.validateEventType(eventType);
}
else
{
EventType existingType = eventAdapterService.getExistsTypeByName(insertIntoDesc.getEventTypeName());
SelectExprProcessor existingTypeProcessor = null;
if (existingType != null)
{
// we may get away with re-casting an existing bean-event-type event to another bean-event-type
if ( (existingType instanceof BeanEventType) &&
(typeService.getEventTypes()[0] instanceof BeanEventType) &&
(selPropertyTypes.isEmpty())) {
return new EvalInsertBeanRecast(existingType, eventAdapterService, 0, typeService.getEventTypes());
}
if ( (existingType instanceof WrapperEventType) &&
(typeService.getEventTypes()[0] instanceof BeanEventType) &&
(exprEvaluators.length == 0)) {
WrapperEventType wrapperType = (WrapperEventType) existingType;
if (wrapperType.getUnderlyingEventType() instanceof BeanEventType) {
return new EvalInsertBeanWrapRecast(wrapperType, eventAdapterService, 0, typeService.getEventTypes());
}
}
existingTypeProcessor = SelectExprInsertEventBeanFactory.getInsertUnderlyingNonJoin(eventAdapterService, existingType, isUsingWildcard, typeService, exprEvaluators, columnNames, expressionReturnTypes, methodResolutionService.getEngineImportService(), insertIntoDesc, columnNamesAsProvided);
}
if (existingTypeProcessor != null) {
return existingTypeProcessor;
}
else if (existingType != null && selPropertyTypes.isEmpty() && existingType instanceof MapEventType) {
resultEventType = existingType;
return new EvalInsertCoercionMap(resultEventType, eventAdapterService);
}
else if (existingType != null && selPropertyTypes.isEmpty() && existingType instanceof ObjectArrayEventType) {
resultEventType = existingType;
return new EvalInsertCoercionObjectArray(resultEventType, eventAdapterService);
}
else if (selPropertyTypes.isEmpty() && eventType instanceof BeanEventType) {
BeanEventType beanEventType = (BeanEventType) eventType;
resultEventType = eventAdapterService.addBeanTypeByName(insertIntoDesc.getEventTypeName(), beanEventType.getUnderlyingType(), false);
}
else {
resultEventType = eventAdapterService.addWrapperType(insertIntoDesc.getEventTypeName(), eventType, selPropertyTypes, false, true);
}
}
if (singleStreamWrapper) {
if (!isRevisionEvent) {
return new EvalInsertWildcardSSWrapper(selectExprContext, resultEventType);
}
else {
return new EvalInsertWildcardSSWrapperRevision(selectExprContext, resultEventType, vaeProcessor);
}
}
if (joinWildcardProcessor == null) {
if (!isRevisionEvent) {
if (resultEventType instanceof WrapperEventType) {
return new EvalInsertWildcardWrapper(selectExprContext, resultEventType);
}
else {
return new EvalInsertWildcardBean(selectExprContext, resultEventType);
}
}
else {
if (exprEvaluators.length == 0) {
return new EvalInsertWildcardRevision(selectExprContext, resultEventType, vaeProcessor);
}
else {
EventType wrappingEventType = eventAdapterService.addWrapperType(insertIntoDesc.getEventTypeName() + "_wrapped", eventType, selPropertyTypes, false, true);
return new EvalInsertWildcardRevisionWrapper(selectExprContext, resultEventType, vaeProcessor, wrappingEventType);
}
}
}
else {
if (!isRevisionEvent) {
return new EvalInsertWildcardJoin(selectExprContext, resultEventType, joinWildcardProcessor);
}
else {
return new EvalInsertWildcardJoinRevision(selectExprContext, resultEventType, joinWildcardProcessor, vaeProcessor);
}
}
}
// not using wildcard
resultEventType = null;
if ((columnNames.length == 1) && (insertIntoDesc.getColumnNames().size() == 0))
{
EventType existingType = eventAdapterService.getExistsTypeByName(insertIntoDesc.getEventTypeName());
if (existingType != null)
{
// check if the existing type and new type are compatible
Object columnOneType = expressionReturnTypes[0];
if (existingType instanceof WrapperEventType)
{
WrapperEventType wrapperType = (WrapperEventType) existingType;
// Map and Object both supported
if (wrapperType.getUnderlyingEventType().getUnderlyingType() == columnOneType)
{
singleColumnWrapOrBeanCoercion = true;
resultEventType = existingType;
}
}
if ((existingType instanceof BeanEventType) && (columnOneType instanceof Class))
{
BeanEventType beanType = (BeanEventType) existingType;
// Map and Object both supported
if (JavaClassHelper.isSubclassOrImplementsInterface((Class) columnOneType, beanType.getUnderlyingType()))
{
singleColumnWrapOrBeanCoercion = true;
resultEventType = existingType;
}
}
}
}
if (singleColumnWrapOrBeanCoercion) {
if (!isRevisionEvent) {
if (resultEventType instanceof WrapperEventType) {
WrapperEventType wrapper = (WrapperEventType) resultEventType;
if (wrapper.getUnderlyingEventType() instanceof MapEventType) {
return new EvalInsertNoWildcardSingleColCoercionMapWrap(selectExprContext, resultEventType);
}
else if (wrapper.getUnderlyingEventType() instanceof ObjectArrayEventType) {
return new EvalInsertNoWildcardSingleColCoercionObjectArrayWrap(selectExprContext, resultEventType);
}
else if (wrapper.getUnderlyingEventType() instanceof VariantEventType) {
VariantEventType variantEventType = (VariantEventType) wrapper.getUnderlyingEventType();
vaeProcessor = valueAddEventService.getValueAddProcessor(variantEventType.getName());
return new EvalInsertNoWildcardSingleColCoercionBeanWrapVariant(selectExprContext, resultEventType, vaeProcessor);
}
else {
return new EvalInsertNoWildcardSingleColCoercionBeanWrap(selectExprContext, resultEventType);
}
}
else {
if (resultEventType instanceof BeanEventType) {
return new EvalInsertNoWildcardSingleColCoercionBean(selectExprContext, resultEventType);
}
}
}
else {
if (resultEventType instanceof MapEventType) {
return new EvalInsertNoWildcardSingleColCoercionRevisionMap(selectExprContext, resultEventType, vaeProcessor, vaeInnerEventType);
}
else if (resultEventType instanceof ObjectArrayEventType) {
return new EvalInsertNoWildcardSingleColCoercionRevisionObjectArray(selectExprContext, resultEventType, vaeProcessor, vaeInnerEventType);
}
else if (resultEventType instanceof BeanEventType) {
return new EvalInsertNoWildcardSingleColCoercionRevisionBean(selectExprContext, resultEventType, vaeProcessor, vaeInnerEventType);
}
else {
return new EvalInsertNoWildcardSingleColCoercionRevisionBeanWrap(selectExprContext, resultEventType, vaeProcessor, vaeInnerEventType);
}
}
}
if (resultEventType == null)
{
if (vaeProcessor != null)
{
// Use an anonymous type if the target is not a variant stream
if (valueAddEventService.getValueAddProcessor(insertIntoDesc.getEventTypeName()) == null) {
resultEventType = eventAdapterService.createAnonymousMapType(statementId + "_vae_" + CollectionUtil.toString(assignedTypeNumberStack, "_"), selPropertyTypes);
}
else {
String statementName = "stmt_" + statementId + "_insert";
resultEventType = eventAdapterService.addNestableMapType(statementName, selPropertyTypes, null, false, false, false, false, true);
}
}
else
{
EventType existingType = eventAdapterService.getExistsTypeByName(insertIntoDesc.getEventTypeName());
if (existingType == null) {
// The type may however be an auto-import or fully-qualified class name
Class clazz = null;
try {
clazz = this.methodResolutionService.resolveClass(insertIntoDesc.getEventTypeName());
}
catch (EngineImportException e) {
log.debug("Target stream name '" + insertIntoDesc.getEventTypeName() + "' is not resolved as a class name");
}
if (clazz != null) {
existingType = eventAdapterService.addBeanType(clazz.getName(), clazz, false, false, false);
}
}
SelectExprProcessor selectExprInsertEventBean = null;
if (existingType != null) {
selectExprInsertEventBean = SelectExprInsertEventBeanFactory.getInsertUnderlyingNonJoin(eventAdapterService, existingType, isUsingWildcard, typeService, exprEvaluators, columnNames, expressionReturnTypes, methodResolutionService.getEngineImportService(), insertIntoDesc, columnNamesAsProvided);
}
if (selectExprInsertEventBean != null) {
return selectExprInsertEventBean;
}
else
{
boolean useMap = EventRepresentationUtil.isMap(annotations, configuration, CreateSchemaDesc.AssignedType.NONE);
if (useMap) {
resultEventType = eventAdapterService.addNestableMapType(insertIntoDesc.getEventTypeName(), selPropertyTypes, null, false, false, false, false, true);
}
else {
resultEventType = eventAdapterService.addNestableObjectArrayType(insertIntoDesc.getEventTypeName(), selPropertyTypes, null, false, false, false, false, true);
}
}
}
}
if (vaeProcessor != null)
{
vaeProcessor.validateEventType(resultEventType);
vaeInnerEventType = resultEventType;
resultEventType = vaeProcessor.getValueAddEventType();
isRevisionEvent = true;
}
if (!isRevisionEvent) {
if (resultEventType instanceof MapEventType) {