@Override public String getName(Method method) { return fncSupplier.get().getName(method); }
Method getCounterPartMethod() { final String name = converter.getName(method); final Class<?> clazz = method.getDeclaringClass(); for (Method other : clazz.getMethods()) { final String otherName = converter.getName(other); if (!other.equals(method) && otherName != null && otherName.equals(name)) { return other; } } return null; }
Method getCounterPartMethod() { final String name = converter.getName(method); final Class<?> clazz = method.getDeclaringClass(); for (Method other : clazz.getMethods()) { final String otherName = converter.getName(other); if (!other.equals(method) && otherName != null && otherName.equals(name)) { return other; } } return null; }
public static String getPrimaryKeyField(Class<? extends RawEntity<?>> type, FieldNameConverter converter) { final Iterable<Method> methods = MethodFinder.getInstance().findAnnotatedMethods(PrimaryKey.class, type); if (Iterables.isEmpty(methods)) { throw new RuntimeException("Entity " + type.getSimpleName() + " has no primary key field"); } return converter.getName(methods.iterator().next()); }
public static String getPrimaryKeyField(Class<? extends RawEntity<?>> type, FieldNameConverter converter) { final Iterable<Method> methods = MethodFinder.getInstance().findAnnotatedMethods(PrimaryKey.class, type); if (Iterables.isEmpty(methods)) { throw new RuntimeException("Entity " + type.getSimpleName() + " has no primary key field"); } return converter.getName(methods.iterator().next()); }
/** * @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()]); }
String name = fieldNameConverter.getName(method); if (name != null) { if (accessorByFieldName.containsKey(name)) { 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)", method, mutatorByFieldName.get(name), name)); mutatorByFieldName.put(fieldNameConverter.getName(method), method);
String name = fieldNameConverter.getName(method); if (name != null) { if (accessorByFieldName.containsKey(name)) { 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)", method, mutatorByFieldName.get(name), name)); mutatorByFieldName.put(fieldNameConverter.getName(method), method);
/** * Gets all the names of fields of an entity that correspond to a value field. This means fields that are stored as * values in the database as opposed to fields (IDs) that define a relationship to another table in the database. * * @param entityInfo the entity to look up the methods from * @return the set of names found */ public static ImmutableSet<String> getValueFieldsNames(final EntityInfo<? extends RawEntity<?>, ?> entityInfo, final FieldNameConverter converter) { List<String> valueFieldsNames = new ArrayList<String>(); for (FieldInfo fieldInfo : entityInfo.getFields()) { // filter out just the value fields - we need to remove any entities from polymorphic relationships if (!Entity.class.isAssignableFrom(fieldInfo.getJavaType())) { // apply the name converter if we have a getter if (fieldInfo.hasAccessor()) { valueFieldsNames.add(converter.getName(fieldInfo.getAccessor())); } } } return ImmutableSet.copyOf(valueFieldsNames); }
/** * Gets all the names of fields of an entity that correspond to a value field. This means fields that are stored as * values in the database as opposed to fields (IDs) that define a relationship to another table in the database. * * @param entityInfo the entity to look up the methods from * @return the set of names found */ public static ImmutableSet<String> getValueFieldsNames(final EntityInfo<? extends RawEntity<?>, ?> entityInfo, final FieldNameConverter converter) { List<String> valueFieldsNames = new ArrayList<String>(); for (FieldInfo fieldInfo : entityInfo.getFields()) { // filter out just the value fields - we need to remove any entities from polymorphic relationships if (!Entity.class.isAssignableFrom(fieldInfo.getJavaType())) { // apply the name converter if we have a getter if (fieldInfo.hasAccessor()) { valueFieldsNames.add(converter.getName(fieldInfo.getAccessor())); } } } return ImmutableSet.copyOf(valueFieldsNames); }
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(); }
public static String getFieldName(EntityManager em, Class<? extends RawEntity<?>> entityType, String methodName) { return em.getProvider().shorten(em.getFieldNameConverter().getName(findMethod(entityType, methodName))); }