Search in sources :

Example 6 with AnnotationMemberValue

use of javassist.bytecode.annotation.AnnotationMemberValue in project BroadleafCommerce by BroadleafCommerce.

the class QueryConfigurationClassTransformer method prepareNamedQueries.

/**
 * Prepare the {@link NamedQueries} declaration
 *
 * @param constantPool
 * @param pool
 * @param queryArray
 * @throws NotFoundException
 */
protected void prepareNamedQueries(ConstPool constantPool, ClassPool pool, ArrayMemberValue queryArray) throws NotFoundException {
    List<MemberValue> values;
    if (queryArray.getValue() != null) {
        values = new ArrayList<MemberValue>(Arrays.asList(queryArray.getValue()));
    } else {
        values = new ArrayList<MemberValue>();
    }
    for (NamedQuery query : namedQueries) {
        Annotation namedQuery = new Annotation(NamedQuery.class.getName(), constantPool);
        StringMemberValue name = new StringMemberValue(constantPool);
        name.setValue(query.name());
        namedQuery.addMemberValue("name", name);
        StringMemberValue queryString = new StringMemberValue(constantPool);
        queryString.setValue(query.query());
        namedQuery.addMemberValue("query", queryString);
        EnumMemberValue lockMode = (EnumMemberValue) Annotation.createMemberValue(constantPool, pool.makeClass("LockModeType"));
        lockMode.setType(LockModeType.class.getName());
        lockMode.setValue(query.lockMode().toString());
        namedQuery.addMemberValue("lockMode", lockMode);
        List<AnnotationMemberValue> queryHints = new ArrayList<AnnotationMemberValue>();
        for (QueryHint hint : query.hints()) {
            prepareQueryHints(constantPool, queryHints, hint);
        }
        ArrayMemberValue hintArray = new ArrayMemberValue(constantPool);
        hintArray.setValue(queryHints.toArray(new AnnotationMemberValue[queryHints.size()]));
        namedQuery.addMemberValue("hints", hintArray);
        AnnotationMemberValue queryAnnotation = new AnnotationMemberValue(namedQuery, constantPool);
        values.add(queryAnnotation);
    }
    queryArray.setValue(values.toArray(new MemberValue[values.size()]));
}
Also used : EnumMemberValue(javassist.bytecode.annotation.EnumMemberValue) StringMemberValue(javassist.bytecode.annotation.StringMemberValue) ArrayList(java.util.ArrayList) Annotation(javassist.bytecode.annotation.Annotation) MemberValue(javassist.bytecode.annotation.MemberValue) AnnotationMemberValue(javassist.bytecode.annotation.AnnotationMemberValue) ArrayMemberValue(javassist.bytecode.annotation.ArrayMemberValue) StringMemberValue(javassist.bytecode.annotation.StringMemberValue) ClassMemberValue(javassist.bytecode.annotation.ClassMemberValue) EnumMemberValue(javassist.bytecode.annotation.EnumMemberValue) QueryHint(javax.persistence.QueryHint) AnnotationMemberValue(javassist.bytecode.annotation.AnnotationMemberValue) LockModeType(javax.persistence.LockModeType) NamedQuery(javax.persistence.NamedQuery) ArrayMemberValue(javassist.bytecode.annotation.ArrayMemberValue)

Aggregations

AnnotationMemberValue (javassist.bytecode.annotation.AnnotationMemberValue)6 StringMemberValue (javassist.bytecode.annotation.StringMemberValue)6 ArrayMemberValue (javassist.bytecode.annotation.ArrayMemberValue)5 MemberValue (javassist.bytecode.annotation.MemberValue)5 Annotation (javassist.bytecode.annotation.Annotation)4 ClassMemberValue (javassist.bytecode.annotation.ClassMemberValue)4 EnumMemberValue (javassist.bytecode.annotation.EnumMemberValue)4 ArrayList (java.util.ArrayList)3 BooleanMemberValue (javassist.bytecode.annotation.BooleanMemberValue)3 QueryHint (javax.persistence.QueryHint)3 ByteMemberValue (javassist.bytecode.annotation.ByteMemberValue)2 CharMemberValue (javassist.bytecode.annotation.CharMemberValue)2 DoubleMemberValue (javassist.bytecode.annotation.DoubleMemberValue)2 FloatMemberValue (javassist.bytecode.annotation.FloatMemberValue)2 IntegerMemberValue (javassist.bytecode.annotation.IntegerMemberValue)2 LongMemberValue (javassist.bytecode.annotation.LongMemberValue)2 ShortMemberValue (javassist.bytecode.annotation.ShortMemberValue)2 AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)1 LockModeType (javax.persistence.LockModeType)1 NamedNativeQuery (javax.persistence.NamedNativeQuery)1