Java Code Examples for org.hibernate.util.ReflectHelper#classForName()

The following examples show how to use org.hibernate.util.ReflectHelper#classForName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static CollectionType customCollection(
		String typeName,
		Properties typeParameters,
		String role,
		String propertyRef,
		boolean embedded) {
	Class typeClass;
	try {
		typeClass = ReflectHelper.classForName( typeName );
	}
	catch ( ClassNotFoundException cnfe ) {
		throw new MappingException( "user collection type class not found: " + typeName, cnfe );
	}
	CustomCollectionType result = new CustomCollectionType( typeClass, role, propertyRef, embedded );
	if ( typeParameters != null ) {
		TypeFactory.injectParameters( result.getUserType(), typeParameters );
	}
	return result;
}
 
Example 2
Source File: Array.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Class getElementClass() throws MappingException {
	if (elementClassName==null) {
		org.hibernate.type.Type elementType = getElement().getType();
		return isPrimitiveArray() ?
			( (PrimitiveType) elementType ).getPrimitiveClass() :
			elementType.getReturnedClass();
	}
	else {
		try {
			return ReflectHelper.classForName(elementClassName);
		}
		catch (ClassNotFoundException cnfe) {
			throw new MappingException(cnfe);
		}
	}
}
 
Example 3
Source File: Oracle8iDialect.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public int registerResultSetOutParameter(java.sql.CallableStatement statement,int col) throws SQLException {
	if(oracletypes_cursor_value==0) {
		try {
			Class types = ReflectHelper.classForName("oracle.jdbc.driver.OracleTypes");
			oracletypes_cursor_value = types.getField("CURSOR").getInt(types.newInstance());
		} catch (Exception se) {
			throw new HibernateException("Problem while trying to load or access OracleTypes.CURSOR value",se);
		}
	}
	//	register the type of the out param - an Oracle specific type
	statement.registerOutParameter(col, oracletypes_cursor_value);
	col++;
	return col;
}
 
Example 4
Source File: EntityType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Class determineAssociatedEntityClass() {
	try {
		return ReflectHelper.classForName( getAssociatedEntityName() );
	}
	catch ( ClassNotFoundException cnfe ) {
		return java.util.Map.class;
	}
}
 
Example 5
Source File: ClassType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object fromStringValue(String xml) throws HibernateException {
	try {
		return ReflectHelper.classForName(xml);
	}
	catch (ClassNotFoundException cnfe) {
		throw new HibernateException("could not parse xml", cnfe);
	}
}
 
Example 6
Source File: ClassType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
	String str = (String) Hibernate.STRING.get(rs, name);
	if (str == null) {
		return null;
	}
	else {
		try {
			return ReflectHelper.classForName(str);
		}
		catch (ClassNotFoundException cnfe) {
			throw new HibernateException("Class not found: " + str);
		}
	}
}
 
Example 7
Source File: SessionFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CurrentSessionContext buildCurrentSessionContext() {
	String impl = properties.getProperty( Environment.CURRENT_SESSION_CONTEXT_CLASS );
	// for backward-compatability
	if ( impl == null && transactionManager != null ) {
		impl = "jta";
	}

	if ( impl == null ) {
		return null;
	}
	else if ( "jta".equals( impl ) ) {
		if ( settings.getTransactionFactory().areCallbacksLocalToHibernateTransactions() ) {
			log.warn( "JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()" );
		}
		return new JTASessionContext( this );
	}
	else if ( "thread".equals( impl ) ) {
		return new ThreadLocalSessionContext( this );
	}
	else if ( "managed".equals( impl ) ) {
		return new ManagedSessionContext( this );
	}
	else {
		try {
			Class implClass = ReflectHelper.classForName( impl );
			return ( CurrentSessionContext ) implClass
					.getConstructor( new Class[] { SessionFactoryImplementor.class } )
					.newInstance( new Object[] { this } );
		}
		catch( Throwable t ) {
			log.error( "Unable to construct current session context [" + impl + "]", t );
			return null;
		}
	}
}
 
Example 8
Source File: SessionFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String getImportedClassName(String className) {
	String result = (String) imports.get(className);
	if (result==null) {
		try {
			ReflectHelper.classForName(className);
			return className;
		}
		catch (ClassNotFoundException cnfe) {
			return null;
		}
	}
	else {
		return result;
	}
}
 
Example 9
Source File: Oracle9Dialect.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public int registerResultSetOutParameter(java.sql.CallableStatement statement,int col) throws SQLException {
	if(oracletypes_cursor_value==0) {
		try {
			Class types = ReflectHelper.classForName("oracle.jdbc.driver.OracleTypes");
			oracletypes_cursor_value = types.getField("CURSOR").getInt(types.newInstance());
		} catch (Exception se) {
			throw new HibernateException("Problem while trying to load or access OracleTypes.CURSOR value",se);
		}
	}
	//	register the type of the out param - an Oracle specific type
	statement.registerOutParameter(col, oracletypes_cursor_value);
	col++;
	return col;
}
 
Example 10
Source File: IdentifierGeneratorFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Class getIdentifierGeneratorClass(String strategy, Dialect dialect) {
	Class clazz = (Class) GENERATORS.get(strategy);
	if ( "native".equals(strategy) ) clazz = dialect.getNativeIdentifierGeneratorClass();
	try {
		if (clazz==null) clazz = ReflectHelper.classForName(strategy);
	}
	catch (ClassNotFoundException e) {
		throw new MappingException("could not interpret id generator strategy: " + strategy);
	}
	return clazz;
}
 
Example 11
Source File: OptimizerFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize) {
	String optimizerClassName;
	if ( NONE.equals( type ) ) {
		optimizerClassName = NoopOptimizer.class.getName();
	}
	else if ( HILO.equals( type ) ) {
		optimizerClassName = HiLoOptimizer.class.getName();
	}
	else if ( POOL.equals( type ) ) {
		optimizerClassName = PooledOptimizer.class.getName();
	}
	else {
		optimizerClassName = type;
	}

	try {
		Class optimizerClass = ReflectHelper.classForName( optimizerClassName );
		Constructor ctor = optimizerClass.getConstructor( CTOR_SIG );
		return ( Optimizer ) ctor.newInstance( new Object[] { returnClass, new Integer( incrementSize ) } );
	}
	catch( Throwable ignore ) {
		// intentionally empty
	}

	// the default...
	return new NoopOptimizer( returnClass, incrementSize );
}
 
Example 12
Source File: ComponentEntityModeToTuplizerMapping.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ComponentTuplizer buildComponentTuplizer(String tuplizerImpl, Component component) {
	try {
		Class implClass = ReflectHelper.classForName( tuplizerImpl );
		return ( ComponentTuplizer ) implClass.getConstructor( COMPONENT_TUP_CTOR_SIG ).newInstance( new Object[] { component } );
	}
	catch( Throwable t ) {
		throw new HibernateException( "Could not build tuplizer [" + tuplizerImpl + "]", t );
	}
}
 
Example 13
Source File: EntityEntityModeToTuplizerMapping.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static EntityTuplizer buildEntityTuplizer(String className, PersistentClass pc, EntityMetamodel em) {
	try {
		Class implClass = ReflectHelper.classForName( className );
		return ( EntityTuplizer ) implClass.getConstructor( ENTITY_TUP_CTOR_SIG ).newInstance( new Object[] { em, pc } );
	}
	catch( Throwable t ) {
		throw new HibernateException( "Could not build tuplizer [" + className + "]", t );
	}
}
 
Example 14
Source File: PropertyAccessorFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static PropertyAccessor resolveCustomAccessor(String accessorName) {
	Class accessorClass;
	try {
		accessorClass = ReflectHelper.classForName(accessorName);
	}
	catch (ClassNotFoundException cnfe) {
		throw new MappingException("could not find PropertyAccessor class: " + accessorName, cnfe);
	}
	try {
		return (PropertyAccessor) accessorClass.newInstance();
	}
	catch (Exception e) {
		throw new MappingException("could not instantiate PropertyAccessor class: " + accessorName, e);
	}
}
 
Example 15
Source File: PersistentClass.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Class getProxyInterface() {
	if (proxyInterfaceName==null) return null;
	try {
		return ReflectHelper.classForName(proxyInterfaceName);
	}
	catch (ClassNotFoundException cnfe) {
		throw new MappingException("proxy class not found: " + proxyInterfaceName, cnfe);
	}
}
 
Example 16
Source File: PersistentClass.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Class getMappedClass() throws MappingException {
	if (className==null) return null;
	try {
		return ReflectHelper.classForName(className);
	}
	catch (ClassNotFoundException cnfe) {
		throw new MappingException("entity class not found: " + className, cnfe);
	}
}
 
Example 17
Source File: Component.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Class getComponentClass() throws MappingException {
	try {
		return ReflectHelper.classForName(componentClassName);
	}
	catch (ClassNotFoundException cnfe) {
		throw new MappingException("component class not found: " + componentClassName, cnfe);
	}
}
 
Example 18
Source File: SessionFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Return the names of all persistent (mapped) classes that extend or implement the
 * given class or interface, accounting for implicit/explicit polymorphism settings
 * and excluding mapped subclasses/joined-subclasses of other classes in the result.
 */
public String[] getImplementors(String className) throws MappingException {

	final Class clazz;
	try {
		clazz = ReflectHelper.classForName(className);
	}
	catch (ClassNotFoundException cnfe) {
		return new String[] { className }; //for a dynamic-class
	}

	ArrayList results = new ArrayList();
	Iterator iter = entityPersisters.values().iterator();
	while ( iter.hasNext() ) {
		//test this entity to see if we must query it
		EntityPersister testPersister = (EntityPersister) iter.next();
		if ( testPersister instanceof Queryable ) {
			Queryable testQueryable = (Queryable) testPersister;
			String testClassName = testQueryable.getEntityName();
			boolean isMappedClass = className.equals(testClassName);
			if ( testQueryable.isExplicitPolymorphism() ) {
				if ( isMappedClass ) {
					return new String[] {className}; //NOTE EARLY EXIT
				}
			}
			else {
				if (isMappedClass) {
					results.add(testClassName);
				}
				else {
					final Class mappedClass = testQueryable.getMappedClass( EntityMode.POJO );
					if ( mappedClass!=null && clazz.isAssignableFrom( mappedClass ) ) {
						final boolean assignableSuperclass;
						if ( testQueryable.isInherited() ) {
							Class mappedSuperclass = getEntityPersister( testQueryable.getMappedSuperclass() ).getMappedClass( EntityMode.POJO);
							assignableSuperclass = clazz.isAssignableFrom(mappedSuperclass);
						}
						else {
							assignableSuperclass = false;
						}
						if ( !assignableSuperclass ) {
							results.add( testClassName );
						}
					}
				}
			}
		}
	}
	return (String[]) results.toArray( new String[ results.size() ] );
}
 
Example 19
Source File: TypeFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Uses heuristics to deduce a Hibernate type given a string naming the type or Java class.
 * Return an instance of <tt>org.hibernate.type.Type</tt>.
 */
public static Type heuristicType(String typeName, Properties parameters)
		throws MappingException {
	Type type = TypeFactory.basic( typeName );
	if ( type == null ) {
		Class typeClass;
		try {
			typeClass = ReflectHelper.classForName( typeName );
		}
		catch (ClassNotFoundException cnfe) {
			typeClass = null;
		}
		if ( typeClass != null ) {
			if ( Type.class.isAssignableFrom( typeClass ) ) {
				try {
					type = (Type) typeClass.newInstance();
				}
				catch (Exception e) {
					throw new MappingException( 
							"Could not instantiate Type: " + typeClass.getName(),
							e 
						);
				}
				injectParameters(type, parameters);
			}
			else if ( CompositeUserType.class.isAssignableFrom( typeClass ) ) {
				type = new CompositeCustomType( typeClass, parameters );
			}
			else if ( UserType.class.isAssignableFrom( typeClass ) ) {
				type = new CustomType( typeClass, parameters );
			}
			else if ( Lifecycle.class.isAssignableFrom( typeClass ) ) {
				type = Hibernate.entity( typeClass );
			}
			else if ( Serializable.class.isAssignableFrom( typeClass ) ) {
				type = Hibernate.serializable( typeClass );
			}
		}
	}
	return type;

}