From: <one...@us...> - 2003-01-09 09:40:24
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/helpers In directory sc8-pr-cvs1:/tmp/cvs-serv8251/cirrus/hibernate/helpers Modified Files: ReflectHelper.java StringHelper.java Log Message: Mark Woon's patch to limit length of aliases Index: ReflectHelper.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/helpers/ReflectHelper.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** ReflectHelper.java 28 Dec 2002 02:25:49 -0000 1.37 --- ReflectHelper.java 9 Jan 2003 09:40:18 -0000 1.38 *************** *** 15,28 **** public final class ReflectHelper { ! private static final Class[] NO_CLASSES = new Class[0]; private static final Class[] OBJECT = new Class[] { Object.class }; private static final Method OBJECT_EQUALS; ! public static final class Setter { private Class clazz; private final Method method; private final String propertyName; ! private Setter(Class clazz, Method method, String propertyName) { this.clazz=clazz; --- 15,28 ---- public final class ReflectHelper { ! private static final Class[] NO_CLASSES = new Class[0]; private static final Class[] OBJECT = new Class[] { Object.class }; private static final Method OBJECT_EQUALS; ! public static final class Setter { private Class clazz; private final Method method; private final String propertyName; ! private Setter(Class clazz, Method method, String propertyName) { this.clazz=clazz; *************** *** 51,65 **** } catch (IllegalArgumentException iae) { ! throw new PropertyAccessException(iae, "IllegalArgumentException occurred while calling", true, clazz, propertyName); } } ! } ! public static final class Getter { private Class clazz; private final Method method; private final String propertyName; ! private Getter(Class clazz, Method method, String propertyName) { this.clazz=clazz; --- 51,70 ---- } catch (IllegalArgumentException iae) { ! if (value == null) { ! throw new PropertyAccessException(iae, "IllegalArgumentException (null value) occurred while calling", true, clazz, propertyName); ! } ! else { ! throw new PropertyAccessException(iae, "IllegalArgumentException occurred while calling", true, clazz, propertyName); ! } } } ! } ! public static final class Getter { private Class clazz; private final Method method; private final String propertyName; ! private Getter(Class clazz, Method method, String propertyName) { this.clazz=clazz; *************** *** 67,71 **** this.propertyName=propertyName; } ! public Object get(Object target) throws HibernateException { try { --- 72,76 ---- this.propertyName=propertyName; } ! public Object get(Object target) throws HibernateException { try { *************** *** 83,95 **** } } ! public Class getReturnType() { return method.getReturnType(); } ! public Method getMethod() { return method; } ! } --- 88,100 ---- } } ! public Class getReturnType() { return method.getReturnType(); } ! public Method getMethod() { return method; } ! } *************** *** 104,108 **** OBJECT_EQUALS = eq; } ! public static boolean overridesEquals(Class clazz) { Method equals; --- 109,113 ---- OBJECT_EQUALS = eq; } ! public static boolean overridesEquals(Class clazz) { Method equals; *************** *** 115,124 **** return !OBJECT_EQUALS.equals(equals); } ! public static Method getMethod(Class theClass, String methodName) throws PropertyNotFoundException { ! if (theClass==Object.class || theClass==null) throw new PropertyNotFoundException( "Could not find a setter" ); // will be swallowed ! Method result; try { --- 120,129 ---- return !OBJECT_EQUALS.equals(equals); } ! public static Method getMethod(Class theClass, String methodName) throws PropertyNotFoundException { ! if (theClass==Object.class || theClass==null) throw new PropertyNotFoundException( "Could not find a setter" ); // will be swallowed ! Method result; try { *************** *** 133,148 **** } } ! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true); return result; ! } ! public static Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException { ! if (theClass==Object.class || theClass==null) throw new PropertyNotFoundException( "Could not find a setter" ); // will be swallowed ! Method result = setter(theClass, propertyName); ! if(result==null) { try { --- 138,153 ---- } } ! if ( !ReflectHelper.isPublic(theClass, result) ) result.setAccessible(true); return result; ! } ! public static Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException { ! if (theClass==Object.class || theClass==null) throw new PropertyNotFoundException( "Could not find a setter" ); // will be swallowed ! Method result = setter(theClass, propertyName); ! if(result==null) { try { *************** *** 157,167 **** return new Setter(theClass, result, propertyName); } ! } ! private static Method setter(Class theClass, String propertyName) throws PropertyNotFoundException { ! Class returnType = getGetter(theClass, propertyName).getReturnType(); ! Method[] methods = theClass.getDeclaredMethods(); Method potentialSetter = null; --- 162,172 ---- return new Setter(theClass, result, propertyName); } ! } ! private static Method setter(Class theClass, String propertyName) throws PropertyNotFoundException { ! Class returnType = getGetter(theClass, propertyName).getReturnType(); ! Method[] methods = theClass.getDeclaredMethods(); Method potentialSetter = null; *************** *** 172,176 **** ) { String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(3) ); ! String testOldMethod = methods[i].getName().substring(3); if ( ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && --- 177,181 ---- ) { String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(3) ); ! String testOldMethod = methods[i].getName().substring(3); if ( ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && *************** *** 181,188 **** } } ! } ! return potentialSetter; } ! public static Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException { --- 186,193 ---- } } ! } ! return potentialSetter; } ! public static Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException { *************** *** 190,194 **** Method result = getter(theClass, propertyName); ! if(result==null) { try { --- 195,199 ---- Method result = getter(theClass, propertyName); ! if(result==null) { try { *************** *** 203,210 **** return new Getter(theClass, result, propertyName); } ! } ! private static Method getter(Class theClass, String propertyName) { ! Method[] methods = theClass.getDeclaredMethods(); for (int i=0; i<methods.length; i++) { --- 208,215 ---- return new Getter(theClass, result, propertyName); } ! } ! private static Method getter(Class theClass, String propertyName) { ! Method[] methods = theClass.getDeclaredMethods(); for (int i=0; i<methods.length; i++) { *************** *** 214,240 **** // try "get" if( (methods[i].getName().length() > 3) && methods[i].getName().startsWith("get") ) { ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(3) ); ! String testOldMethod = methods[i].getName().substring(3); ! if( ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && methods[i].getParameterTypes().length==0 ) return methods[i]; ! } ! // if not "get" then try "is" if( (methods[i].getName().length() > 2) && methods[i].getName().startsWith("is") ) { ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(2) ); ! String testOldMethod = methods[i].getName().substring(2); ! if( ! ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && ! methods[i].getParameterTypes().length==0 ! ) return methods[i]; } } ! } ! return null; } --- 219,245 ---- // try "get" if( (methods[i].getName().length() > 3) && methods[i].getName().startsWith("get") ) { ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(3) ); ! String testOldMethod = methods[i].getName().substring(3); ! if( ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && methods[i].getParameterTypes().length==0 ) return methods[i]; ! } ! // if not "get" then try "is" if( (methods[i].getName().length() > 2) && methods[i].getName().startsWith("is") ) { ! String testStdMethod = Introspector.decapitalize( methods[i].getName().substring(2) ); ! String testOldMethod = methods[i].getName().substring(2); ! if( ! ( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) && ! methods[i].getParameterTypes().length==0 ! ) return methods[i]; } } ! } ! return null; } *************** *** 242,246 **** return TypeFactory.hueristicType( getGetter(theClass, name).getReturnType().getName() ); } ! public static Class classForName(String name) throws ClassNotFoundException { try { --- 247,251 ---- return TypeFactory.hueristicType( getGetter(theClass, name).getReturnType().getName() ); } ! public static Class classForName(String name) throws ClassNotFoundException { try { *************** *** 251,259 **** } } ! public static boolean isPublic(Class clazz, Member member) { return Modifier.isPublic( member.getModifiers() ) && Modifier.isPublic( clazz.getModifiers() ); } ! public static Object getConstantValue(String name) { Class clazz; --- 256,264 ---- } } ! public static boolean isPublic(Class clazz, Member member) { return Modifier.isPublic( member.getModifiers() ) && Modifier.isPublic( clazz.getModifiers() ); } ! public static Object getConstantValue(String name) { Class clazz; *************** *** 271,281 **** } } ! public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotFoundException { ! if (isAbstractClass(clazz)) return null; ! try { ! Constructor constructor = clazz.getDeclaredConstructor(NO_CLASSES); if (!isPublic(clazz, constructor)) { constructor.setAccessible(true); --- 276,286 ---- } } ! public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotFoundException { ! if (isAbstractClass(clazz)) return null; ! try { ! Constructor constructor = clazz.getDeclaredConstructor(NO_CLASSES); if (!isPublic(clazz, constructor)) { constructor.setAccessible(true); *************** *** 284,294 **** } catch (NoSuchMethodException nme) { throw new PropertyNotFoundException( ! "Object class " + clazz.getName() + " must declare a default (no-argument) constructor" ); } ! } ! public static boolean isAbstractClass(Class clazz) { int modifier = clazz.getModifiers(); --- 289,299 ---- } catch (NoSuchMethodException nme) { throw new PropertyNotFoundException( ! "Object class " + clazz.getName() + " must declare a default (no-argument) constructor" ); } ! } ! public static boolean isAbstractClass(Class clazz) { int modifier = clazz.getModifiers(); Index: StringHelper.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/helpers/StringHelper.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** StringHelper.java 31 Oct 2002 14:00:28 -0000 1.17 --- StringHelper.java 9 Jan 2003 09:40:18 -0000 1.18 *************** *** 18,23 **** return buf.toString(); } ! ! public static String repeat(String string, int times) { StringBuffer buf = new StringBuffer( string.length() * times ); --- 18,23 ---- return buf.toString(); } ! ! public static String repeat(String string, int times) { StringBuffer buf = new StringBuffer( string.length() * times ); *************** *** 25,30 **** return buf.toString(); } ! ! public static String replace(String template, String placeholder, String replacement) { int loc = template.indexOf(placeholder); --- 25,30 ---- return buf.toString(); } ! ! public static String replace(String template, String placeholder, String replacement) { int loc = template.indexOf(placeholder); *************** *** 35,47 **** return new StringBuffer( template.substring(0, loc) ) .append(replacement) ! .append( replace( ! template.substring( loc + placeholder.length() ), ! placeholder, replacement ) ).toString(); } } ! ! public static String replaceOnce(String template, String placeholder, String replacement) { int loc = template.indexOf(placeholder); --- 35,47 ---- return new StringBuffer( template.substring(0, loc) ) .append(replacement) ! .append( replace( ! template.substring( loc + placeholder.length() ), ! placeholder, replacement ) ).toString(); } } ! ! public static String replaceOnce(String template, String placeholder, String replacement) { int loc = template.indexOf(placeholder); *************** *** 56,61 **** } } ! ! public static String[] split(String seperators, String list) { StringTokenizer tokens = new StringTokenizer(list, seperators); --- 56,61 ---- } } ! ! public static String[] split(String seperators, String list) { StringTokenizer tokens = new StringTokenizer(list, seperators); *************** *** 67,79 **** return result; } ! public static String unqualify(String qualifiedName) { return unqualify(qualifiedName, "."); } ! public static String unqualify(String qualifiedName, String seperator) { return qualifiedName.substring( qualifiedName.lastIndexOf(seperator) + 1 ); } ! public static String qualifier(String qualifiedName) { int loc = qualifiedName.lastIndexOf("."); --- 67,79 ---- return result; } ! public static String unqualify(String qualifiedName) { return unqualify(qualifiedName, "."); } ! public static String unqualify(String qualifiedName, String seperator) { return qualifiedName.substring( qualifiedName.lastIndexOf(seperator) + 1 ); } ! public static String qualifier(String qualifiedName) { int loc = qualifiedName.lastIndexOf("."); *************** *** 85,89 **** } } ! public static String[] suffix( String[] columns, String suffix) { if (suffix==null) return columns; --- 85,89 ---- } } ! public static String[] suffix( String[] columns, String suffix) { if (suffix==null) return columns; *************** *** 94,109 **** return qualified; } ! ! public static String suffix(String table, String suffix) { ! if (suffix==null) return table; ! char quote = table.charAt(0); ! if ( Dialect.QUOTE.indexOf(quote) > -1 ) { ! return table.substring( 0, table.length()-1 ) + suffix + quote; ! } else { ! return table + suffix; } } ! public static String[] prefix( String[] columns, String prefix) { if (prefix==null) return columns; --- 94,129 ---- return qualified; } ! ! public static String suffix(String name, String suffix) { ! ! if (suffix==null) { ! /*if (name.length() > 20) { ! return name.substring(name.length()-20); ! } ! else {*/ ! return name; ! //} ! } ! ! char quote = name.charAt(0); ! boolean nameEscaped = Dialect.QUOTE.indexOf(quote) > -1; ! StringBuffer nameBuffer = new StringBuffer(30); ! ! if (nameEscaped) { ! nameBuffer.append( name.substring(1, name.length()-1) ).append(suffix); ! } else { ! nameBuffer.append(name).append(suffix); } + if (nameBuffer.length() > 15) { + nameBuffer.delete(0, nameBuffer.length()-15); + } + if (nameEscaped) { + nameBuffer.insert(0, quote); + nameBuffer.append(quote); + } + return nameBuffer.toString(); } ! public static String[] prefix( String[] columns, String prefix) { if (prefix==null) return columns; *************** *** 119,128 **** return (loc<0) ? qualifiedName : qualifiedName.substring(0, loc); } ! public static boolean booleanValue(String tfString) { String trimmed = tfString.trim().toLowerCase(); return trimmed.equals("true") || trimmed.equals("t"); } ! public static String toString(Object[] array) { int len = array.length; --- 139,148 ---- return (loc<0) ? qualifiedName : qualifiedName.substring(0, loc); } ! public static boolean booleanValue(String tfString) { String trimmed = tfString.trim().toLowerCase(); return trimmed.equals("true") || trimmed.equals("t"); } ! public static String toString(Object[] array) { int len = array.length; *************** *** 133,137 **** return buf.append( array[len-1] ).toString(); } ! public static String[] multiply(String string, Iterator placeholders, Iterator replacements) { String[] result = new String[] { string }; --- 153,157 ---- return buf.append( array[len-1] ).toString(); } ! public static String[] multiply(String string, Iterator placeholders, Iterator replacements) { String[] result = new String[] { string }; *************** *** 158,162 **** name; } ! public static void unQuoteInPlace(String[] names) { for ( int i=0; i<names.length; i++ ) names[i] = unQuote( names[i] ); --- 178,182 ---- name; } ! public static void unQuoteInPlace(String[] names) { for ( int i=0; i<names.length; i++ ) names[i] = unQuote( names[i] ); *************** *** 167,170 **** return unquoted; } ! } --- 187,190 ---- return unquoted; } ! } |