private AnnotationDelegate getAnnotations(Method accessor, Method mutator) { return accessor != null ? new AnnotationDelegate(accessor, mutator) : new AnnotationDelegate(mutator, accessor); }
private boolean isIndexed(Method method) { final AnnotationDelegate annotations = Common.getAnnotationDelegate(fieldNameConverter, method); final Indexed indexed = annotations.getAnnotation(Indexed.class); return indexed != null; }
public boolean apply(Method m) { final AnnotationDelegate annotations = getAnnotationDelegate(converter, m); return !annotations.isAnnotationPresent(Ignore.class) && !annotations.isAnnotationPresent(OneToOne.class) && !annotations.isAnnotationPresent(OneToMany.class) && !annotations.isAnnotationPresent(ManyToMany.class); } });
@SuppressWarnings("unchecked") private FieldInfo createFieldInfo(String fieldName, Method accessor, Method mutator) { Class fieldType = Common.getAttributeTypeFromMethod(MoreObjects.firstNonNull(accessor, mutator)); AnnotationDelegate annotations = getAnnotations(accessor, mutator); Generator generatorAnnotation = annotations.getAnnotation(Generator.class); return new ImmutableFieldInfo( fieldName, fieldType.isAnnotationPresent(Polymorphic.class) ? nameConverters.getFieldNameConverter().getPolyTypeName(MoreObjects.firstNonNull(accessor, mutator)) : null, accessor, mutator, fieldType, typeManager.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 ); }
@SuppressWarnings("unchecked") private FieldInfo createFieldInfo(String fieldName, Method accessor, Method mutator) { Class fieldType = Common.getAttributeTypeFromMethod(MoreObjects.firstNonNull(accessor, mutator)); AnnotationDelegate annotations = getAnnotations(accessor, mutator); Generator generatorAnnotation = annotations.getAnnotation(Generator.class); return new ImmutableFieldInfo( fieldName, fieldType.isAnnotationPresent(Polymorphic.class) ? nameConverters.getFieldNameConverter().getPolyTypeName(MoreObjects.firstNonNull(accessor, mutator)) : null, accessor, mutator, fieldType, typeManager.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 ); }
field.setNotNull(annotations.isAnnotationPresent(NotNull.class) || annotations.isAnnotationPresent(Unique.class) || annotations.isAnnotationPresent(PrimaryKey.class)); field.setUnique(annotations.isAnnotationPresent(Unique.class)); if (annotations.isAnnotationPresent(Default.class)) { final Object defaultValue = convertStringDefaultValue(annotations.getAnnotation(Default.class).value(), sqlType, method); if (type.isEnum() && ((Integer) defaultValue) > EnumUtils.size((Class<? extends Enum>) type) - 1) { throw new ActiveObjectsConfigurationException("There is no enum value of '" + type + "'for which the ordinal is " + defaultValue); field.setJdbcType(java.sql.Types.VARCHAR); if (annotations.getAnnotation(NotNull.class) != null) { field.setNotNull(true);
public boolean apply(Method m) { final AnnotationDelegate annotations = getAnnotationDelegate(converter, m); return !annotations.isAnnotationPresent(Ignore.class) && !annotations.isAnnotationPresent(OneToOne.class) && !annotations.isAnnotationPresent(OneToMany.class) && !annotations.isAnnotationPresent(ManyToMany.class); } });
private boolean isIndexed(Method method) { final AnnotationDelegate annotations = Common.getAnnotationDelegate(fieldNameConverter, method); final Indexed indexed = annotations.getAnnotation(Indexed.class); return indexed != null; }
private AnnotationDelegate getAnnotations(Method accessor, Method mutator) { return accessor != null ? new AnnotationDelegate(accessor, mutator) : new AnnotationDelegate(mutator, accessor); }
field.setNotNull(annotations.isAnnotationPresent(NotNull.class) || annotations.isAnnotationPresent(Unique.class) || annotations.isAnnotationPresent(PrimaryKey.class)); field.setUnique(annotations.isAnnotationPresent(Unique.class)); if (annotations.isAnnotationPresent(Default.class)) { final Object defaultValue = convertStringDefaultValue(annotations.getAnnotation(Default.class).value(), sqlType, method); if (type.isEnum() && ((Integer) defaultValue) > EnumUtils.size((Class<? extends Enum>) type) - 1) { throw new ActiveObjectsConfigurationException("There is no enum value of '" + type + "'for which the ordinal is " + defaultValue); field.setJdbcType(java.sql.Types.VARCHAR); if (annotations.getAnnotation(NotNull.class) != null) { field.setNotNull(true);
private static boolean isAutoIncrement(Class<?> type, AnnotationDelegate annotations, TypeInfo<?> dbType) { final boolean isAutoIncrement = annotations.isAnnotationPresent(AutoIncrement.class); if (isAutoIncrement && (!AUTO_INCREMENT_LEGAL_TYPES.contains(dbType.getJdbcWriteType()) || type.isEnum())) { throw new ActiveObjectsConfigurationException(AutoIncrement.class.getName() + " is not supported for type: " + dbType); } return isAutoIncrement; }
public static List<String> getSearchableFields(EntityManager manager, Class<? extends RawEntity<?>> type) { List<String> back = new ArrayList<String>(); for (Method m : type.getMethods()) { Searchable annot = getAnnotationDelegate(manager.getNameConverters().getFieldNameConverter(), m).getAnnotation(Searchable.class); if (annot != null) { Class<?> attributeType = Common.getAttributeTypeFromMethod(m); String name = manager.getNameConverters().getFieldNameConverter().getName(m); // don't index Entity fields if (name != null && !RawEntity.class.isAssignableFrom(attributeType) && !back.contains(name)) { back.add(name); } } } return back; }
/** * <b>Note</b>: this method leads to the creation and quick discard of * large numbers of {@link AnnotationDelegate} objects. Need to * do some research to determine whether or not this is actually * a problem. * * @deprecated All annotation information should be resolved upfront using {@link net.java.ao.schema.info.EntityInfo} */ @Deprecated public static AnnotationDelegate getAnnotationDelegate(FieldNameConverter converter, Method method) { return new AnnotationDelegate(method, findCounterpart(converter, method)); }
private static boolean isAutoIncrement(Class<?> type, AnnotationDelegate annotations, TypeInfo<?> dbType) { final boolean isAutoIncrement = annotations.isAnnotationPresent(AutoIncrement.class); if (isAutoIncrement && (!AUTO_INCREMENT_LEGAL_TYPES.contains(dbType.getJdbcWriteType()) || type.isEnum())) { throw new ActiveObjectsConfigurationException(AutoIncrement.class.getName() + " is not supported for type: " + dbType); } return isAutoIncrement; }
public static List<String> getSearchableFields(EntityManager manager, Class<? extends RawEntity<?>> type) { List<String> back = new ArrayList<String>(); for (Method m : type.getMethods()) { Searchable annot = getAnnotationDelegate(manager.getNameConverters().getFieldNameConverter(), m).getAnnotation(Searchable.class); if (annot != null) { Class<?> attributeType = Common.getAttributeTypeFromMethod(m); String name = manager.getNameConverters().getFieldNameConverter().getName(m); // don't index Entity fields if (name != null && !RawEntity.class.isAssignableFrom(attributeType) && !back.contains(name)) { back.add(name); } } } return back; }
/** * <b>Note</b>: this method leads to the creation and quick discard of * large numbers of {@link AnnotationDelegate} objects. Need to * do some research to determine whether or not this is actually * a problem. * * @deprecated All annotation information should be resolved upfront using {@link net.java.ao.schema.info.EntityInfo} */ @Deprecated public static AnnotationDelegate getAnnotationDelegate(FieldNameConverter converter, Method method) { return new AnnotationDelegate(method, findCounterpart(converter, method)); }
private static boolean isPrimaryKey(AnnotationDelegate annotations, DDLField field) { final boolean isPrimaryKey = annotations.isAnnotationPresent(PrimaryKey.class); if (isPrimaryKey && !field.getType().isAllowedAsPrimaryKey()) { throw new ActiveObjectsConfigurationException(PrimaryKey.class.getName() + " is not supported for type: " + field.getType()); } return isPrimaryKey; }
public static TypeInfo<?> getSQLTypeFromMethod(TypeManager typeManager, Class<?> type, Method method, AnnotationDelegate annotations) { TypeQualifiers qualifiers = qualifiers(); StringLength lengthAnno = annotations.getAnnotation(StringLength.class); if (lengthAnno != null) { final int length = lengthAnno.value(); if (length > MAX_STRING_LENGTH) { throw new ActiveObjectsConfigurationException("@StringLength must be <= " + MAX_STRING_LENGTH + " or UNLIMITED").forMethod(method); } try { qualifiers = qualifiers.stringLength(length); } catch (ActiveObjectsConfigurationException e) { throw new ActiveObjectsConfigurationException(e.getMessage()).forMethod(method); } } return typeManager.getType(type, qualifiers); }
private static boolean isPrimaryKey(AnnotationDelegate annotations, DDLField field) { final boolean isPrimaryKey = annotations.isAnnotationPresent(PrimaryKey.class); if (isPrimaryKey && !field.getType().isAllowedAsPrimaryKey()) { throw new ActiveObjectsConfigurationException(PrimaryKey.class.getName() + " is not supported for type: " + field.getType()); } return isPrimaryKey; }
public static TypeInfo<?> getSQLTypeFromMethod(TypeManager typeManager, Class<?> type, Method method, AnnotationDelegate annotations) { TypeQualifiers qualifiers = qualifiers(); StringLength lengthAnno = annotations.getAnnotation(StringLength.class); if (lengthAnno != null) { final int length = lengthAnno.value(); if (length > MAX_STRING_LENGTH) { throw new ActiveObjectsConfigurationException("@StringLength must be <= " + MAX_STRING_LENGTH + " or UNLIMITED").forMethod(method); } try { qualifiers = qualifiers.stringLength(length); } catch (ActiveObjectsConfigurationException e) { throw new ActiveObjectsConfigurationException(e.getMessage()).forMethod(method); } } return typeManager.getType(type, qualifiers); }