@Deprecated public static void closeQuietly(Connection connection) { Common.closeQuietly(connection); }
private static String where(String where, final FieldNameConverter fnc) { if (fnc instanceof FieldNameProcessor) { final Matcher matcher = SqlUtils.WHERE_CLAUSE.matcher(where); final StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, convert(fnc, matcher.group(1))); } matcher.appendTail(sb); return sb.toString(); } else { return where; } }
@Override protected String getName(String entityClassCanonicalName) { return Common.convertDowncaseName(Common.convertSimpleClassName(entityClassCanonicalName)); } }
public static Class<?> getAttributeTypeFromMethod(Method method) { if (isAnnotatedAsRelational(method)) { return null; } if (isMutator(method)) { return getMutatorParameterType(method); } if (isAccessor(method)) { return getAccessorReturnType(method); } return null; }
private RawEntity[] fetchManyToMany(final Method method, final ManyToMany annotation) throws SQLException, NoSuchMethodException { final Class remoteType = method.getReturnType().getComponentType(); final Class throughType = annotation.value(); final String whereClause = Common.where(annotation, getFieldNameConverter()); final Preload preloadAnnotation = (Preload) remoteType.getAnnotation(Preload.class); final Method reverseMethod = throughType.getMethod(annotation.reverse()); final Method throughMethod = throughType.getMethod(annotation.through()); final String reversePolymorphicTypeFieldName = getAttributeTypeFromMethod(reverseMethod).isAnnotationPresent(Polymorphic.class) ? getFieldNameConverter().getPolyTypeName(reverseMethod) : null; final String remotePolymorphicTypeFieldName = getAttributeTypeFromMethod(throughMethod).isAnnotationPresent(Polymorphic.class) ? getFieldNameConverter().getPolyTypeName(throughMethod) : null; final String returnField = getFieldNameConverter().getName(throughMethod); final Set<String> selectFields = new LinkedHashSet<String>(); } else { if (preloadAnnotation != null) { selectFields.addAll(preloadValue(preloadAnnotation, getFieldNameConverter())); } else { selectFields.addAll(Common.getValueFieldsNames(manager.resolveEntityInfo(remoteType), getFieldNameConverter())); final String remotePrimaryKeyField = Common.getPrimaryKeyField(remoteType, getFieldNameConverter()); if (!selectFields.isEmpty()) { final String remoteTable = provider.withSchema(getTableNameConverter().getName(remoteType)); stmt.setString(2, manager.getPolymorphicTypeMapper().convert(entityInfo.getEntityType())); final TypeInfo<K> primaryKeyType = Common.getPrimaryKeyType(provider.getTypeManager(), (Class<? extends RawEntity<K>>) remoteType); final ResultSet res = stmt.executeQuery(); try {
List<String> attributes = new LinkedList<String>(); for (Method method : Common.getValueFieldsMethods(clazz, fieldConverter)) { String attributeName = fieldConverter.getName(method); final Class<?> type = Common.getAttributeTypeFromMethod(method); final AnnotationDelegate annotations = Common.getAnnotationDelegate(fieldConverter, method);
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 boolean attributeExtendsRawEntity(Method method) { Class<?> type = Common.getAttributeTypeFromMethod(method); return type != null && extendsRawEntity.test(type); }
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()]); }
@Override protected String getName(String entityClassCanonicalName) { return convertSimpleClassName(entityClassCanonicalName); } }
private boolean isIndexed(Method method) { final AnnotationDelegate annotations = Common.getAnnotationDelegate(fieldNameConverter, method); final Indexed indexed = annotations.getAnnotation(Indexed.class); return indexed != null; }
public static boolean fuzzyCompare(TypeManager typeManager, Object a, Object b) { if (a == null && b == null) { return true; } else if (a == null || b == null) { // implicitly, one or other is null, not both return false; } Object array = null; Object other = null; if (a.getClass().isArray()) { array = a; other = b; } else if (b.getClass().isArray()) { array = b; other = a; } if (array != null) { for (int i = 0; i < Array.getLength(array); i++) { if (fuzzyCompare(typeManager, Array.get(array, i), other)) { return true; } } } return typeManager.getType(a.getClass()).getLogicalType().valueEquals(a, b) || typeManager.getType(b.getClass()).getLogicalType().valueEquals(b, a); }
@Override public String convertName(String name) { return Common.convertDowncaseName(name); } }
/** * <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)); }
@Override public T pullFromDatabase(EntityManager manager, ResultSet res, Class<T> type, String columnName) throws SQLException { return Common.createPeer(manager, type, primaryKeyTypeInfo.getLogicalType().pullFromDatabase(manager, res, primaryKeyClass, columnName)); }
private RawEntity[] fetchManyToMany(final Method method, final ManyToMany annotation) throws SQLException, NoSuchMethodException { final Class remoteType = method.getReturnType().getComponentType(); final Class throughType = annotation.value(); final String whereClause = Common.where(annotation, getFieldNameConverter()); final Preload preloadAnnotation = (Preload) remoteType.getAnnotation(Preload.class); final Method reverseMethod = throughType.getMethod(annotation.reverse()); final Method throughMethod = throughType.getMethod(annotation.through()); final String reversePolymorphicTypeFieldName = getAttributeTypeFromMethod(reverseMethod).isAnnotationPresent(Polymorphic.class) ? getFieldNameConverter().getPolyTypeName(reverseMethod) : null; final String remotePolymorphicTypeFieldName = getAttributeTypeFromMethod(throughMethod).isAnnotationPresent(Polymorphic.class) ? getFieldNameConverter().getPolyTypeName(throughMethod) : null; final String returnField = getFieldNameConverter().getName(throughMethod); final Set<String> selectFields = new LinkedHashSet<String>(); } else { if (preloadAnnotation != null) { selectFields.addAll(preloadValue(preloadAnnotation, getFieldNameConverter())); } else { selectFields.addAll(Common.getValueFieldsNames(manager.resolveEntityInfo(remoteType), getFieldNameConverter())); final String remotePrimaryKeyField = Common.getPrimaryKeyField(remoteType, getFieldNameConverter()); if (!selectFields.isEmpty()) { final String remoteTable = provider.withSchema(getTableNameConverter().getName(remoteType)); stmt.setString(2, manager.getPolymorphicTypeMapper().convert(entityInfo.getEntityType())); final TypeInfo<K> primaryKeyType = Common.getPrimaryKeyType(provider.getTypeManager(), (Class<? extends RawEntity<K>>) remoteType); final ResultSet res = stmt.executeQuery(); try {
public static Class<?> getAttributeTypeFromMethod(Method method) { if (isAnnotatedAsRelational(method)) { return null; } if (isMutator(method)) { return getMutatorParameterType(method); } if (isAccessor(method)) { return getAccessorReturnType(method); } return null; }
List<String> attributes = new LinkedList<String>(); for (Method method : Common.getValueFieldsMethods(clazz, fieldConverter)) { String attributeName = fieldConverter.getName(method); final Class<?> type = Common.getAttributeTypeFromMethod(method); final AnnotationDelegate annotations = Common.getAnnotationDelegate(fieldConverter, method);
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 boolean isAttributeOfTypeEntity(Method method) { final Class<?> attributeTypeFromMethod = Common.getAttributeTypeFromMethod(method); return attributeTypeFromMethod != null && RawEntity.class.isAssignableFrom(attributeTypeFromMethod); }