use of org.eclipse.persistence.descriptors.DescriptorEventAdapter in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildFunctionExpressionDescriptor.
protected ClassDescriptor buildFunctionExpressionDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(FunctionExpression.class);
descriptor.setDefaultRootElement("function-expression");
descriptor.getInheritancePolicy().setParentClass(Expression.class);
// A function's base is always its first child so not persisted,
// Is fixed up to be its first child or new expression builder if no children.
// Child value expressions need their backpointer to their local base set,
// this is not persisted so must be hooked back up after loading.
descriptor.getEventManager().addListener(new DescriptorEventAdapter() {
@Override
public void postBuild(DescriptorEvent event) {
FunctionExpression expression = (FunctionExpression) event.getObject();
for (int index = 0; index < expression.getChildren().size(); index++) {
Expression child = expression.getChildren().get(index);
if (child.isValueExpression()) {
child.setLocalBase(new ExpressionBuilder());
}
}
if (expression.getChildren().size() > 0) {
expression.setBaseExpression(expression.getChildren().get(0));
} else {
expression.setBaseExpression(new ExpressionBuilder());
}
}
});
XMLDirectMapping operatorMapping = new XMLDirectMapping();
operatorMapping.setAttributeName("operator");
ExpressionOperatorConverter operatorConverter = new ExpressionOperatorConverter();
operatorConverter.addConversionValue("like", ExpressionOperator.getOperator(ExpressionOperator.Like));
operatorConverter.addConversionValue("notLike", ExpressionOperator.getOperator(ExpressionOperator.NotLike));
operatorConverter.addConversionValue("not", ExpressionOperator.getOperator(ExpressionOperator.Not));
operatorConverter.addConversionValue("isNull", ExpressionOperator.getOperator(ExpressionOperator.IsNull));
operatorConverter.addConversionValue("notNull", ExpressionOperator.getOperator(ExpressionOperator.NotNull));
operatorConverter.addConversionValue("ascending", ExpressionOperator.getOperator(ExpressionOperator.Ascending));
operatorConverter.addConversionValue("descending", ExpressionOperator.getOperator(ExpressionOperator.Descending));
// These are platform specific so not on operator.
operatorConverter.addConversionValue("upper", new ExpressionOperator(ExpressionOperator.ToUpperCase, new ArrayList<>(0)));
operatorConverter.addConversionValue("lower", new ExpressionOperator(ExpressionOperator.ToLowerCase, new ArrayList<>(0)));
// Aggregate functions
operatorConverter.addConversionValue("count", ExpressionOperator.getOperator(ExpressionOperator.Count));
operatorConverter.addConversionValue("sum", ExpressionOperator.getOperator(ExpressionOperator.Sum));
operatorConverter.addConversionValue("average", ExpressionOperator.getOperator(ExpressionOperator.Average));
operatorConverter.addConversionValue("maximum", ExpressionOperator.getOperator(ExpressionOperator.Maximum));
operatorConverter.addConversionValue("minimum", ExpressionOperator.getOperator(ExpressionOperator.Minimum));
// standardDeviation is platform specific.
operatorConverter.addConversionValue("standardDeviation", new ExpressionOperator(ExpressionOperator.StandardDeviation, new ArrayList<>(0)));
operatorConverter.addConversionValue("variance", new ExpressionOperator(ExpressionOperator.Variance, new ArrayList<>(0)));
operatorConverter.addConversionValue("distinct", ExpressionOperator.getOperator(ExpressionOperator.Distinct));
operatorMapping.setConverter(operatorConverter);
operatorMapping.setXPath("@function");
descriptor.addMapping(operatorMapping);
XMLCompositeCollectionMapping childrenMapping = new XMLCompositeCollectionMapping();
childrenMapping.useCollectionClass(NonSynchronizedVector.class);
childrenMapping.setAttributeName("children");
childrenMapping.setReferenceClass(Expression.class);
childrenMapping.setXPath(getPrimaryNamespaceXPath() + "arguments/" + getPrimaryNamespaceXPath() + "argument");
descriptor.addMapping(childrenMapping);
return descriptor;
}
use of org.eclipse.persistence.descriptors.DescriptorEventAdapter in project eclipselink by eclipse-ee4j.
the class EventListenerCollectionTest method setup.
@Override
public void setup() {
project = new EmployeeProject();
ClassDescriptor descriptor = project.getDescriptors().get(Employee.class);
descriptor.getEventManager().addListener(new DescriptorEventAdapter());
}
use of org.eclipse.persistence.descriptors.DescriptorEventAdapter in project eclipselink by eclipse-ee4j.
the class InvalidDescriptorEventCodeTest method test.
@Override
public void test() {
try {
DescriptorEventManager eManager = new DescriptorEventManager();
DescriptorEvent event = new DescriptorEvent(this);
DescriptorEventAdapter listener = new DescriptorEventAdapter();
event.setEventCode(-1);
eManager.addListener(listener);
eManager.notifyListeners(event);
} catch (EclipseLinkException exception) {
caughtException = exception;
}
}
use of org.eclipse.persistence.descriptors.DescriptorEventAdapter in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testRelationshipReadDuringClone.
public void testRelationshipReadDuringClone() {
EntityManager em = createEntityManager();
AbstractSession session = getServerSession();
ClassDescriptor departmentDesc = session.getDescriptor(Department.class);
DescriptorEventAdapter listener = new DescriptorEventAdapter() {
@Override
public void postClone(DescriptorEvent event) {
((Department) event.getObject()).getEquipment().size();
}
};
departmentDesc.getDescriptorEventManager().addListener(listener);
em.createQuery("SELECT e from Equipment e where e.department is not null").getResultList();
departmentDesc.getDescriptorEventManager().removeListener(listener);
departmentDesc.getDescriptorEventManager().initialize(session);
closeEntityManager(em);
}
use of org.eclipse.persistence.descriptors.DescriptorEventAdapter in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildRelationExpressionDescriptor.
protected ClassDescriptor buildRelationExpressionDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(RelationExpression.class);
descriptor.setDefaultRootElement("relation-expression");
descriptor.getInheritancePolicy().setParentClass(Expression.class);
// Child value expressions need their backpointer to their local base set,
// this is not persisted so must be hooked back up after loading.
descriptor.getEventManager().addListener(new DescriptorEventAdapter() {
@Override
public void postBuild(DescriptorEvent event) {
RelationExpression expression = (RelationExpression) event.getObject();
if ((expression.getFirstChild() != null) && (expression.getSecondChild() != null)) {
if (expression.getSecondChild().isValueExpression()) {
expression.getSecondChild().setLocalBase(expression.getFirstChild());
}
if (expression.getFirstChild().isValueExpression()) {
expression.getFirstChild().setLocalBase(expression.getSecondChild());
}
}
}
});
XMLDirectMapping operatorMapping = new XMLDirectMapping();
operatorMapping.setAttributeName("operator");
ObjectTypeConverter operatorConverter = new ObjectTypeConverter();
operatorConverter.addConversionValue("equal", ExpressionOperator.getOperator(ExpressionOperator.Equal));
operatorConverter.addConversionValue("notEqual", ExpressionOperator.getOperator(ExpressionOperator.NotEqual));
operatorConverter.addConversionValue("like", ExpressionOperator.getOperator(ExpressionOperator.Like));
operatorConverter.addConversionValue("notLike", ExpressionOperator.getOperator(ExpressionOperator.NotLike));
operatorConverter.addConversionValue("greaterThan", ExpressionOperator.getOperator(ExpressionOperator.GreaterThan));
operatorConverter.addConversionValue("greaterThanEqual", ExpressionOperator.getOperator(ExpressionOperator.GreaterThanEqual));
operatorConverter.addConversionValue("lessThan", ExpressionOperator.getOperator(ExpressionOperator.LessThan));
operatorConverter.addConversionValue("lessThanEqual", ExpressionOperator.getOperator(ExpressionOperator.LessThanEqual));
operatorMapping.setConverter(operatorConverter);
operatorMapping.setXPath("@operator");
descriptor.addMapping(operatorMapping);
XMLCompositeObjectMapping leftMapping = new XMLCompositeObjectMapping();
leftMapping.setAttributeName("firstChild");
leftMapping.setGetMethodName("getFirstChild");
leftMapping.setSetMethodName("setFirstChild");
leftMapping.setReferenceClass(Expression.class);
leftMapping.setXPath(getPrimaryNamespaceXPath() + "left");
descriptor.addMapping(leftMapping);
XMLCompositeObjectMapping rightMapping = new XMLCompositeObjectMapping();
rightMapping.setAttributeName("secondChild");
rightMapping.setGetMethodName("getSecondChild");
rightMapping.setSetMethodName("setSecondChild");
rightMapping.setReferenceClass(Expression.class);
rightMapping.setXPath(getPrimaryNamespaceXPath() + "right");
descriptor.addMapping(rightMapping);
return descriptor;
}
Aggregations