|
16 | 16 |
|
17 | 17 | import groovy.lang.GroovyObject; |
18 | 18 | import org.apache.commons.lang.StringUtils; |
19 | | -import org.hibernate.type.TypeFactory; |
20 | 19 |
|
| 20 | +import java.io.Serializable; |
| 21 | +import java.math.BigDecimal; |
| 22 | +import java.math.BigInteger; |
21 | 23 | import java.net.URI; |
22 | 24 | import java.net.URL; |
23 | | -import java.util.Collections; |
24 | | -import java.util.Map; |
| 25 | +import java.sql.Blob; |
| 26 | +import java.sql.Clob; |
| 27 | +import java.sql.Time; |
| 28 | +import java.sql.Timestamp; |
| 29 | +import java.util.*; |
25 | 30 |
|
26 | 31 | /** |
27 | 32 | * Utility methods used in configuring the Grails Hibernate integration |
@@ -110,7 +115,7 @@ public static void configureDomainClassRelationships(GrailsClass[] domainClasses |
110 | 115 | /** |
111 | 116 | * Returns the ORM frameworks mapping file name for the specified class name |
112 | 117 | * |
113 | | - * @param className |
| 118 | + * @param className The class name of the mapped file |
114 | 119 | * @return The mapping file name |
115 | 120 | */ |
116 | 121 | public static String getMappingFileName(String className) { |
@@ -154,11 +159,62 @@ public static Map getMappedByMap(Class domainClass) { |
154 | 159 | public static boolean isBasicType(GrailsDomainClassProperty prop) { |
155 | 160 | if(prop == null)return false; |
156 | 161 | Class propType = prop.getType(); |
157 | | - return TypeFactory.basic(propType.getName()) != null || |
158 | | - propType == URL.class || |
159 | | - propType == URI.class; |
| 162 | + return isBasicType(propType); |
| 163 | + } |
| 164 | + |
| 165 | + private static final Set BASIC_TYPES; |
| 166 | + |
| 167 | + static { |
| 168 | + Set basics = new HashSet(); |
| 169 | + basics.add( boolean.class.getName()); |
| 170 | + basics.add( long.class.getName()); |
| 171 | + basics.add( short.class.getName()); |
| 172 | + basics.add( int.class.getName()); |
| 173 | + basics.add( byte.class.getName()); |
| 174 | + basics.add( float.class.getName()); |
| 175 | + basics.add( double.class.getName()); |
| 176 | + basics.add( char.class.getName()); |
| 177 | + basics.add( Boolean.class.getName()); |
| 178 | + basics.add( Long.class.getName()); |
| 179 | + basics.add( Short.class.getName()); |
| 180 | + basics.add( Integer.class.getName()); |
| 181 | + basics.add( Byte.class.getName()); |
| 182 | + basics.add( Float.class.getName()); |
| 183 | + basics.add( Double.class.getName()); |
| 184 | + basics.add( Character.class.getName()); |
| 185 | + basics.add( String.class.getName()); |
| 186 | + basics.add( java.util.Date.class.getName()); |
| 187 | + basics.add( Time.class.getName()); |
| 188 | + basics.add( Timestamp.class.getName()); |
| 189 | + basics.add( java.sql.Date.class.getName()); |
| 190 | + basics.add( BigDecimal.class.getName()); |
| 191 | + basics.add( BigInteger.class.getName()); |
| 192 | + basics.add( Locale.class.getName()); |
| 193 | + basics.add( Calendar.class.getName()); |
| 194 | + basics.add( GregorianCalendar.class.getName()); |
| 195 | + basics.add( java.util.Currency.class.getName()); |
| 196 | + basics.add( TimeZone.class.getName()); |
| 197 | + basics.add( Object.class.getName()); |
| 198 | + basics.add( Class.class.getName()); |
| 199 | + basics.add( byte[].class.getName()); |
| 200 | + basics.add( Byte[].class.getName()); |
| 201 | + basics.add( char[].class.getName()); |
| 202 | + basics.add( Character[].class.getName()); |
| 203 | + basics.add( Blob.class.getName()); |
| 204 | + basics.add( Clob.class.getName()); |
| 205 | + basics.add( Serializable.class.getName() ); |
| 206 | + basics.add( URI.class.getName() ); |
| 207 | + basics.add( URL.class.getName() ); |
| 208 | + |
| 209 | + BASIC_TYPES = Collections.unmodifiableSet( basics ); |
160 | 210 | } |
161 | 211 |
|
162 | | - |
163 | | - |
| 212 | + public static boolean isBasicType(Class propType) { |
| 213 | + if(propType.isArray()) { |
| 214 | + return isBasicType(propType.getComponentType()); |
| 215 | + } |
| 216 | + return BASIC_TYPES.contains(propType.getName()); |
| 217 | + } |
| 218 | + |
| 219 | + |
164 | 220 | } |
0 commit comments