![JAR search and dependency download from the Maven repository](/logo.png)
com.espertech.esper.avro.getter.AvroEventBeanGetterNestedSimple Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esper-avro Show documentation
Show all versions of esper-avro Show documentation
Complex event processing and event series analysis component
The newest version!
/*
***************************************************************************************
* Copyright (C) 2006 EsperTech, Inc. All rights reserved. *
* http://www.espertech.com/esper *
* http://www.espertech.com *
* ---------------------------------------------------------------------------------- *
* The software in this package is published under the terms of the GPL license *
* a copy of which has been included with this distribution in the license.txt file. *
***************************************************************************************
*/
package com.espertech.esper.avro.getter;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.client.EventType;
import com.espertech.esper.client.PropertyAccessException;
import com.espertech.esper.codegen.base.CodegenClassScope;
import com.espertech.esper.codegen.base.CodegenMember;
import com.espertech.esper.codegen.base.CodegenMethodScope;
import com.espertech.esper.codegen.model.expression.CodegenExpression;
import com.espertech.esper.codegen.base.CodegenMethodNode;
import com.espertech.esper.event.EventAdapterService;
import com.espertech.esper.event.EventPropertyGetterSPI;
import org.apache.avro.generic.GenericData;
import static com.espertech.esper.codegen.model.expression.CodegenExpressionBuilder.*;
public class AvroEventBeanGetterNestedSimple implements EventPropertyGetterSPI {
private final int posTop;
private final int posInner;
private final EventType fragmentType;
private final EventAdapterService eventAdapterService;
public AvroEventBeanGetterNestedSimple(int posTop, int posInner, EventType fragmentType, EventAdapterService eventAdapterService) {
this.posTop = posTop;
this.posInner = posInner;
this.fragmentType = fragmentType;
this.eventAdapterService = eventAdapterService;
}
public Object get(EventBean eventBean) throws PropertyAccessException {
return get((GenericData.Record) eventBean.getUnderlying());
}
public boolean isExistsProperty(EventBean eventBean) {
return true;
}
public Object getFragment(EventBean eventBean) throws PropertyAccessException {
if (fragmentType == null) {
return null;
}
Object value = get(eventBean);
if (value == null) {
return null;
}
return eventAdapterService.adapterForTypedAvro(value, fragmentType);
}
private CodegenMethodNode getFragmentCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) throws PropertyAccessException {
CodegenMember mSvc = codegenClassScope.makeAddMember(EventAdapterService.class, eventAdapterService);
CodegenMember mType = codegenClassScope.makeAddMember(EventType.class, fragmentType);
return codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(GenericData.Record.class, "record").getBlock()
.declareVar(Object.class, "value", underlyingGetCodegen(ref("record"), codegenMethodScope, codegenClassScope))
.ifRefNullReturnNull("value")
.methodReturn(exprDotMethod(member(mSvc.getMemberId()), "adapterForTypedAvro", ref("value"), member(mType.getMemberId())));
}
public CodegenExpression eventBeanGetCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return underlyingGetCodegen(castUnderlying(GenericData.Record.class, beanExpression), codegenMethodScope, codegenClassScope);
}
public CodegenExpression eventBeanExistsCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
}
public CodegenExpression eventBeanFragmentCodegen(CodegenExpression beanExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return underlyingFragmentCodegen(castUnderlying(GenericData.Record.class, beanExpression), codegenMethodScope, codegenClassScope);
}
public CodegenExpression underlyingGetCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return localMethod(getCodegen(codegenMethodScope, codegenClassScope), underlyingExpression);
}
public CodegenExpression underlyingExistsCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return constantTrue();
}
public CodegenExpression underlyingFragmentCodegen(CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
if (fragmentType == null) {
return constantNull();
}
return localMethod(getFragmentCodegen(codegenMethodScope, codegenClassScope), underlyingExpression);
}
private Object get(GenericData.Record record) throws PropertyAccessException {
GenericData.Record inner = (GenericData.Record) record.get(posTop);
if (inner == null) {
return null;
}
return inner.get(posInner);
}
private CodegenMethodNode getCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) {
return codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(GenericData.Record.class, "record").getBlock()
.declareVar(GenericData.Record.class, "inner", cast(GenericData.Record.class, exprDotMethod(ref("record"), "get", constant(posTop))))
.ifRefNullReturnNull("inner")
.methodReturn(exprDotMethod(ref("inner"), "get", constant(posInner)));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy