private static boolean isAttributeOfTypeEntity(Method method) { final Class<?> attributeTypeFromMethod = Common.getAttributeTypeFromMethod(method); return attributeTypeFromMethod != null && RawEntity.class.isAssignableFrom(attributeTypeFromMethod); }
private boolean attributeExtendsRawEntity(Method method) { Class<?> type = Common.getAttributeTypeFromMethod(method); return type != null && extendsRawEntity.test(type); }
private static boolean isAttributeOfTypeEntity(Method method) { final Class<?> attributeTypeFromMethod = Common.getAttributeTypeFromMethod(method); return attributeTypeFromMethod != null && RawEntity.class.isAssignableFrom(attributeTypeFromMethod); }
private boolean attributeExtendsRawEntity(Method method) { Class<?> type = Common.getAttributeTypeFromMethod(method); return type != null && extendsRawEntity.test(type); }
/** * @see <a href="https://studio.atlassian.com/browse/AO-325">AO-325</a> */ @Deprecated public static String[] getPolymorphicFieldNames(FieldNameConverter converter, Class<? extends RawEntity<?>> from, Class<? extends RawEntity<?>> to) { Set<String> back = new LinkedHashSet<String>(); for (Method method : from.getMethods()) { Class<?> attributeType = getAttributeTypeFromMethod(method); if (attributeType != null && attributeType.isAssignableFrom(to) && attributeType.getAnnotation(Polymorphic.class) != null) { back.add(converter.getPolyTypeName(method)); } } return back.toArray(new String[back.size()]); }
/** * @see <a href="https://studio.atlassian.com/browse/AO-325">AO-325</a> */ @Deprecated public static String[] getPolymorphicFieldNames(FieldNameConverter converter, Class<? extends RawEntity<?>> from, Class<? extends RawEntity<?>> to) { Set<String> back = new LinkedHashSet<String>(); for (Method method : from.getMethods()) { Class<?> attributeType = getAttributeTypeFromMethod(method); if (attributeType != null && attributeType.isAssignableFrom(to) && attributeType.getAnnotation(Polymorphic.class) != null) { back.add(converter.getPolyTypeName(method)); } } return back.toArray(new String[back.size()]); }
/** * @see <a href="https://studio.atlassian.com/browse/AO-325">AO-325</a> */ @Deprecated public static String[] getMappingFields(FieldNameConverter converter, Class<? extends RawEntity<?>> from, Class<? extends RawEntity<?>> to) { Set<String> back = new LinkedHashSet<String>(); for (Method method : from.getMethods()) { Class<?> attributeType = getAttributeTypeFromMethod(method); if (attributeType == null) { continue; } if (to.isAssignableFrom(attributeType)) { back.add(converter.getName(method)); } else if (attributeType.getAnnotation(Polymorphic.class) != null && attributeType.isAssignableFrom(to)) { back.add(converter.getName(method)); } } return back.toArray(new String[back.size()]); }
/** * @see <a href="https://studio.atlassian.com/browse/AO-325">AO-325</a> */ @Deprecated public static String[] getMappingFields(FieldNameConverter converter, Class<? extends RawEntity<?>> from, Class<? extends RawEntity<?>> to) { Set<String> back = new LinkedHashSet<String>(); for (Method method : from.getMethods()) { Class<?> attributeType = getAttributeTypeFromMethod(method); if (attributeType == null) { continue; } if (to.isAssignableFrom(attributeType)) { back.add(converter.getName(method)); } else if (attributeType.getAnnotation(Polymorphic.class) != null && attributeType.isAssignableFrom(to)) { back.add(converter.getName(method)); } } return back.toArray(new String[back.size()]); }
private String getPolymorphicTypeFieldName(final Method remoteMethod) { final Class<?> attributeType = getAttributeTypeFromMethod(remoteMethod); return attributeType != null && attributeType.isAssignableFrom(getType()) && attributeType.isAnnotationPresent(Polymorphic.class) ? getFieldNameConverter().getPolyTypeName(remoteMethod) : null; }
private String getPolymorphicTypeFieldName(final Method remoteMethod) { final Class<?> attributeType = getAttributeTypeFromMethod(remoteMethod); return attributeType != null && attributeType.isAssignableFrom(getType()) && attributeType.isAnnotationPresent(Polymorphic.class) ? getFieldNameConverter().getPolyTypeName(remoteMethod) : null; }
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; }
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; }
private static void parseDependencies( final FieldNameConverter fieldConverter, final Map<Class<? extends RawEntity<?>>, Set<Class<? extends RawEntity<?>>>> deps, final Set<Class<? extends RawEntity<?>>> roots, Class<? extends RawEntity<?>> clazz) { if (deps.containsKey(clazz)) { return; } final Set<Class<? extends RawEntity<?>>> individualDeps = new LinkedHashSet<Class<? extends RawEntity<?>>>(); for (final Method method : clazz.getMethods()) { final Class<?> type = Common.getAttributeTypeFromMethod(method); validateManyToManyAnnotation(method); validateOneToOneAnnotation(method); validateOneToManyAnnotation(method); if (fieldConverter.getName(method) != null && type != null && !type.equals(clazz) && RawEntity.class.isAssignableFrom(type) && !individualDeps.contains(type)) { individualDeps.add((Class<? extends RawEntity<?>>) type); addDeps(deps, clazz, individualDeps); parseDependencies(fieldConverter, deps, roots, (Class<? extends RawEntity<?>>) type); } } if (individualDeps.size() == 0) { roots.add(clazz); } else { addDeps(deps, clazz, individualDeps); } }
private static void parseDependencies( final FieldNameConverter fieldConverter, final Map<Class<? extends RawEntity<?>>, Set<Class<? extends RawEntity<?>>>> deps, final Set<Class<? extends RawEntity<?>>> roots, Class<? extends RawEntity<?>> clazz) { if (deps.containsKey(clazz)) { return; } final Set<Class<? extends RawEntity<?>>> individualDeps = new LinkedHashSet<Class<? extends RawEntity<?>>>(); for (final Method method : clazz.getMethods()) { final Class<?> type = Common.getAttributeTypeFromMethod(method); validateManyToManyAnnotation(method); validateOneToOneAnnotation(method); validateOneToManyAnnotation(method); if (fieldConverter.getName(method) != null && type != null && !type.equals(clazz) && RawEntity.class.isAssignableFrom(type) && !individualDeps.contains(type)) { individualDeps.add((Class<? extends RawEntity<?>>) type); addDeps(deps, clazz, individualDeps); parseDependencies(fieldConverter, deps, roots, (Class<? extends RawEntity<?>>) type); } } if (individualDeps.size() == 0) { roots.add(clazz); } else { addDeps(deps, clazz, individualDeps); } }
private static DDLForeignKey[] parseForeignKeys(TableNameConverter nameConverter, FieldNameConverter fieldConverter, Class<? extends RawEntity<?>> clazz) { Set<DDLForeignKey> back = new LinkedHashSet<DDLForeignKey>(); for (Method method : clazz.getMethods()) { String attributeName = fieldConverter.getName(method); Class<?> type = Common.getAttributeTypeFromMethod(method); if (type != null && attributeName != null && RawEntity.class.isAssignableFrom(type) && type.getAnnotation(Polymorphic.class) == null) { DDLForeignKey key = new DDLForeignKey(); key.setField(attributeName); key.setTable(nameConverter.getName((Class<? extends RawEntity<?>>) type)); key.setForeignField(Common.getPrimaryKeyField((Class<? extends RawEntity<?>>) type, fieldConverter)); key.setDomesticTable(nameConverter.getName(clazz)); back.add(key); } } return back.toArray(new DDLForeignKey[back.size()]); }
private static DDLForeignKey[] parseForeignKeys(TableNameConverter nameConverter, FieldNameConverter fieldConverter, Class<? extends RawEntity<?>> clazz) { Set<DDLForeignKey> back = new LinkedHashSet<DDLForeignKey>(); for (Method method : clazz.getMethods()) { String attributeName = fieldConverter.getName(method); Class<?> type = Common.getAttributeTypeFromMethod(method); if (type != null && attributeName != null && RawEntity.class.isAssignableFrom(type) && type.getAnnotation(Polymorphic.class) == null) { DDLForeignKey key = new DDLForeignKey(); key.setField(attributeName); key.setTable(nameConverter.getName((Class<? extends RawEntity<?>>) type)); key.setForeignField(Common.getPrimaryKeyField((Class<? extends RawEntity<?>>) type, fieldConverter)); key.setDomesticTable(nameConverter.getName(clazz)); back.add(key); } } return back.toArray(new DDLForeignKey[back.size()]); }
@Nullable private DDLIndexField parseIndexField(@Nullable Method method) { if (method == null) { return null; } Class<?> type = Common.getAttributeTypeFromMethod(method); String attributeName = fieldNameConverter.getName(method); AnnotationDelegate annotations = Common.getAnnotationDelegate(fieldNameConverter, method); return DDLIndexField.builder() .fieldName(attributeName) .type(SchemaGenerator.getSQLTypeFromMethod(typeManager, type, method, annotations)) .build(); }
@Nullable private DDLIndexField parseIndexField(@Nullable Method method) { if (method == null) { return null; } Class<?> type = Common.getAttributeTypeFromMethod(method); String attributeName = fieldNameConverter.getName(method); AnnotationDelegate annotations = Common.getAnnotationDelegate(fieldNameConverter, method); return DDLIndexField.builder() .fieldName(attributeName) .type(SchemaGenerator.getSQLTypeFromMethod(typeManager, type, method, annotations)) .build(); }
@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 ); }