public Class fromString(String string) { if ( string == null ) { return null; } try { return ReflectHelper.classForName( string ); } catch ( ClassNotFoundException e ) { throw new HibernateException( "Unable to locate named class " + string ); } }
private void readObject(java.io.ObjectInputStream stream) throws ClassNotFoundException, IOException { stream.defaultReadObject(); constructor = ReflectHelper.getDefaultConstructor( mappedClass ); }
@Override public void postInstantiate( String entityName, Class persistentClass, Set<Class> interfaces, Method getIdentifierMethod, Method setIdentifierMethod, CompositeType componentIdType) throws HibernateException { this.entityName = entityName; this.persistentClass = persistentClass; this.interfaces = toArray( interfaces ); this.getIdentifierMethod = getIdentifierMethod; this.setIdentifierMethod = setIdentifierMethod; this.componentIdType = componentIdType; this.overridesEquals = ReflectHelper.overridesEquals( persistentClass ); this.proxyClass = byteBuddyProxyHelper.buildProxy( persistentClass, this.interfaces ); }
@SuppressWarnings("unchecked") private void checkEqualsAndHashCode(Class javaType) { if ( !ReflectHelper.overridesEquals( javaType ) || !ReflectHelper.overridesHashCode( javaType ) ) { log.unknownJavaTypeNoEqualsHashCode( javaType ); } }
public PojoInstantiator(Class componentClass, ReflectionOptimizer.InstantiationOptimizer optimizer) { this.mappedClass = componentClass; this.isAbstract = ReflectHelper.isAbstractClass( mappedClass ); this.optimizer = optimizer; this.embeddedIdentifier = false; try { constructor = ReflectHelper.getDefaultConstructor(mappedClass); } catch ( PropertyNotFoundException pnfe ) { LOG.noDefaultConstructor(mappedClass.getName()); constructor = null; } }
public PropertyAccessBasicImpl( PropertyAccessStrategyBasicImpl strategy, Class containerJavaType, final String propertyName) { this.strategy = strategy; final Method getterMethod = ReflectHelper.findGetterMethod( containerJavaType, propertyName ); this.getter = new GetterMethodImpl( containerJavaType, propertyName, getterMethod ); final Method setterMethod = ReflectHelper.findSetterMethod( containerJavaType, propertyName, getterMethod.getReturnType() ); this.setter = new SetterMethodImpl( containerJavaType, propertyName, setterMethod ); }
public static DatasourceConnectionProviderImpl buildDataSourceConnectionProvider(String dbName) { try { Class dataSourceClass = ReflectHelper.classForName( DATA_SOURCE, ConnectionProviderBuilder.class ); DataSource actualDataSource = (DataSource) dataSourceClass.newInstance(); ReflectHelper.findSetterMethod( dataSourceClass, "URL", String.class ).invoke( actualDataSource, String.format( URL, dbName ) ); ReflectHelper.findSetterMethod( dataSourceClass, "user", String.class ).invoke( actualDataSource, USER ); ReflectHelper.findSetterMethod( dataSourceClass, "password", String.class ) .invoke( actualDataSource, PASS );
@Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { try { String stringValue = javaTypeDescriptor.unwrap( value, String.class, options ); Class clazz= ReflectHelper.classForName( "org.postgresql.util.PGobject", this.getClass()); Object holder = clazz.newInstance(); ReflectHelper.setterMethodOrNull( clazz, "type", String.class ).invoke( holder, "inet" ); ReflectHelper.setterMethodOrNull( clazz, "value", String.class ).invoke( holder, stringValue ); st.setObject( index, holder ); } catch (ClassNotFoundException|IllegalAccessException|InstantiationException|InvocationTargetException e) { throw new IllegalArgumentException( e ); } }
@Override public void setText(String s) { // for some reason the antlr.CommonAST initialization routines force // this method to get called twice. The first time with an empty string if ( StringHelper.isNotEmpty( s ) ) { constantExpression = s; constantValue = ReflectHelper.getConstantValue( s, factory ); heuristicType = factory.getTypeResolver().heuristicType( constantValue.getClass().getName() ); super.setText( s ); } }
/** * Determine if the given class defines an {@link Object#equals} override. * * @param clazz The class to check * @return True if clazz defines an equals override. */ public static boolean overridesEquals(Class clazz) { Method equals; try { equals = extractEqualsMethod( clazz ); } catch ( NoSuchMethodException nsme ) { return false; //its an interface so we can't really tell anything... } return !OBJECT_EQUALS.equals( equals ); }
/** * Determine if the given class defines a {@link Object#hashCode} override. * * @param clazz The class to check * @return True if clazz defines an hashCode override. */ public static boolean overridesHashCode(Class clazz) { Method hashCode; try { hashCode = extractHashCodeMethod( clazz ); } catch ( NoSuchMethodException nsme ) { return false; //its an interface so we can't really tell anything... } return !OBJECT_HASHCODE.equals( hashCode ); }
@Test public void test_setMethod_nestedInterfaces() { assertNotNull( ReflectHelper.findSetterMethod( C.class, "id", Integer.class ) ); }
public PojoInstantiator( Class mappedClass, ReflectionOptimizer.InstantiationOptimizer optimizer, boolean embeddedIdentifier) { this.mappedClass = mappedClass; this.optimizer = optimizer; this.embeddedIdentifier = embeddedIdentifier; this.isAbstract = ReflectHelper.isAbstractClass( mappedClass ); try { constructor = ReflectHelper.getDefaultConstructor(mappedClass); } catch ( PropertyNotFoundException pnfe ) { LOG.noDefaultConstructor( mappedClass.getName() ); constructor = null; } }
private void handleDotStructure(AST dotStructureRoot) { final String expression = ASTUtil.getPathText( dotStructureRoot ); final Object constant = ReflectHelper.getConstantValue( expression, factory ); if ( constant != null ) { dotStructureRoot.setFirstChild( null ); dotStructureRoot.setType( HqlTokenTypes.JAVA_CONSTANT ); dotStructureRoot.setText( expression ); } } }
private void checkCompositeIdentifier() { if ( getIdentifier() instanceof Component ) { Component id = (Component) getIdentifier(); if ( !id.isDynamic() ) { final Class idClass = id.getComponentClass(); if ( idClass != null ) { final String idComponentClassName = idClass.getName(); if ( !ReflectHelper.overridesEquals( idClass ) ) { LOG.compositeIdClassDoesNotOverrideEquals( idComponentClassName ); } if ( !ReflectHelper.overridesHashCode( idClass ) ) { LOG.compositeIdClassDoesNotOverrideHashCode( idComponentClassName ); } if ( !Serializable.class.isAssignableFrom( idClass ) ) { throw new MappingException( "Composite-id class must implement Serializable: " + idComponentClassName ); } } } } }
@Test @TestForIssue( jiraKey = "HHH-11202") public void testProtectedMethodSetter() throws Exception { final AnEntity entity = new AnEntity( new PK( 1L ) ); final Getter getter = new GetterMethodImpl( AnEntity.class, "pk", ReflectHelper.findGetterMethod( AnEntity.class, "pk" ) ); final Setter setter = new SetterMethodImpl( AnEntity.class, "pk", ReflectHelper.findSetterMethod( AnEntity.class, "pk", PK.class ) ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject( setter ); final ObjectInputStream ois = new ObjectInputStream( new ByteArrayInputStream( baos.toByteArray() ) ); final Setter setterClone = (Setter) ois.readObject(); final PK pkNew = new PK( 2L ); setterClone.set( entity, pkNew, null ); assertSame( pkNew, getter.get( entity ) ); } }
/** * Determine if the given class defines an {@link Object#equals} override. * * @param clazz The class to check * @return True if clazz defines an equals override. */ public static boolean overridesEquals(Class clazz) { Method equals; try { equals = extractEqualsMethod( clazz ); } catch ( NoSuchMethodException nsme ) { return false; //its an interface so we can't really tell anything... } return !OBJECT_EQUALS.equals( equals ); }
/** * Determine if the given class defines a {@link Object#hashCode} override. * * @param clazz The class to check * @return True if clazz defines an hashCode override. */ public static boolean overridesHashCode(Class clazz) { Method hashCode; try { hashCode = extractHashCodeMethod( clazz ); } catch ( NoSuchMethodException nsme ) { return false; //its an interface so we can't really tell anything... } return !OBJECT_HASHCODE.equals( hashCode ); }
@TestForIssue(jiraKey = "HHH-12090") @Test public void test_setMethod_nestedInterfaces_on_superclasses() { assertNotNull( ReflectHelper.findSetterMethod( E.class, "id", String.class ) ); } }
private Class locateOracleTypesClass() { try { return ReflectHelper.classForName( ORACLE_TYPES_CLASS_NAME ); } catch (ClassNotFoundException e) { try { return ReflectHelper.classForName( DEPRECATED_ORACLE_TYPES_CLASS_NAME ); } catch (ClassNotFoundException e2) { throw new HibernateException( String.format( "Unable to locate OracleTypes class using either known FQN [%s, %s]", ORACLE_TYPES_CLASS_NAME, DEPRECATED_ORACLE_TYPES_CLASS_NAME ), e ); } } }