Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.java.ao.schema.info;
  
  import net.java.ao.Common;
 
 import java.util.Map;
 import java.util.Set;

A EntityInfoResolver which creates new EntityInfo instances on every invocation of resolve(java.lang.Class)
 
 public class SimpleEntityInfoResolver implements EntityInfoResolver
 {
 
     private final NameConverters nameConverters;
     private final TypeManager typeManager;
 
     public SimpleEntityInfoResolver(NameConverters nameConvertersTypeManager typeManager) {
         this. = nameConverters;
         this. = typeManager;
     }
 
     @Override
     public <T extends RawEntity<K>, K> EntityInfo<T, K> resolve(Class<T> type)
     {
         final FieldNameConverter fieldNameConverter = .getFieldNameConverter();
 
         final Map<StringMethodaccessorByFieldName = Maps.newHashMap();
         final Map<StringMethodmutatorByFieldName = Maps.newHashMap();
 
         // First find all the methods
         for (Method method : type.getMethods())
         {
             if (method.isAnnotationPresent(Ignore.class))
             {
                 continue;
             }
 
             if (Common.isAccessor(method))
             {
                 String name = fieldNameConverter.getName(method);
                 if (name != null)
                 {
                     if (accessorByFieldName.containsKey(name))
                     {
                         throw new IllegalArgumentException(String.format("Invalid Entity definition. Both %s and %s generate the same table name (%s)"methodaccessorByFieldName.get(name), name));
                     }
                     accessorByFieldName.put(namemethod);
                 }
             }
             else if (Common.isMutator(method))
             {
                 String name = fieldNameConverter.getName(method);
                 if (name != null)
                 {
                     if (mutatorByFieldName.containsKey(name))
                     {
                         throw new IllegalArgumentException(String.format("Invalid Entity definition. Both %s and %s generate the same table name (%s)"methodmutatorByFieldName.get(name), name));
                     }
                     mutatorByFieldName.put(fieldNameConverter.getName(method), method);
                 }
             }
         }
 
         Set<FieldInfofields = Sets.newHashSet();
 
         for (String fieldName : Sets.union(accessorByFieldName.keySet(), mutatorByFieldName.keySet()))
         {
             fields.add(createFieldInfo(fieldNameaccessorByFieldName.get(fieldName), mutatorByFieldName.get(fieldName)));
         }
 
         return new ImmutableEntityInfo<T, K>(
                 type,
                 .getTableNameConverter().getName(type),
                 fields
         );
     }
 
     @SuppressWarnings("unchecked")
     private FieldInfo createFieldInfo(String fieldNameMethod accessorMethod mutator)
     {
         Class fieldType = Common.getAttributeTypeFromMethod(Objects.firstNonNull(accessormutator));
        AnnotationDelegate annotations = getAnnotations(accessormutator);
        Generator generatorAnnotation = annotations.getAnnotation(Generator.class);
        return new ImmutableFieldInfo(
                fieldName,
                fieldType.isAnnotationPresent(Polymorphic.class) ? .getFieldNameConverter().getPolyTypeName(Objects.firstNonNull(accessormutator)) : null,
                accessor,
                mutator,
                fieldType,
                .getType(fieldType),
                annotations.isAnnotationPresent(PrimaryKey.class),
                !annotations.isAnnotationPresent(NotNull.class),
                annotations.isAnnotationPresent(Transient.class),
                annotations.isAnnotationPresent(AutoIncrement.class),
                annotations.isAnnotationPresent(Default.class),
                generatorAnnotation != null ? generatorAnnotation.value() : null
        );
    }
    private AnnotationDelegate getAnnotations(Method accessorMethod mutator)
    {
        return accessor != null ? new AnnotationDelegate(accessormutator) : new AnnotationDelegate(mutatoraccessor);
    }
New to GrepCode? Check out our FAQ X