类org.hibernate.PropertyNotFoundException源码实例Demo

下面列出了怎么用org.hibernate.PropertyNotFoundException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: PojoInstantiator.java
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;
	}
}
 
源代码2 项目: lams   文件: ReflectHelper.java
/**
 * Retrieve the default (no arg) constructor from the given class.
 *
 * @param clazz The class for which to retrieve the default ctor.
 * @return The default constructor.
 * @throws PropertyNotFoundException Indicates there was not publicly accessible, no-arg constructor (todo : why PropertyNotFoundException???)
 */
public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws PropertyNotFoundException {
	if ( isAbstractClass( clazz ) ) {
		return null;
	}

	try {
		Constructor<T> constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
		ensureAccessibility( constructor );
		return constructor;
	}
	catch ( NoSuchMethodException nme ) {
		throw new PropertyNotFoundException(
				"Object class [" + clazz.getName() + "] must declare a default (no-argument) constructor"
		);
	}
}
 
源代码3 项目: lams   文件: ReflectHelper.java
public static Field findField(Class containerClass, String propertyName) {
	if ( containerClass == null ) {
		throw new IllegalArgumentException( "Class on which to find field [" + propertyName + "] cannot be null" );
	}
	else if ( containerClass == Object.class ) {
		throw new IllegalArgumentException( "Illegal attempt to locate field [" + propertyName + "] on Object.class" );
	}

	Field field = locateField( containerClass, propertyName );

	if ( field == null ) {
		throw new PropertyNotFoundException(
				String.format(
						Locale.ROOT,
						"Could not locate field name [%s] on class [%s]",
						propertyName,
						containerClass.getName()
				)
		);
	}

	ensureAccessibility( field );

	return field;
}
 
源代码4 项目: cacheonix-core   文件: Dom4jAccessor.java
/**
 * Create a "getter" for the named attribute
 */
public Getter getGetter(Class theClass, String propertyName) 
throws PropertyNotFoundException {
	if (nodeName==null) {
		throw new MappingException("no node name for property: " + propertyName);
	}
	if ( ".".equals(nodeName) ) {
		return new TextGetter(propertyType, factory);
	}
	else if ( nodeName.indexOf('/')>-1 ) {
		return new ElementAttributeGetter(nodeName, propertyType, factory);
	}
	else if ( nodeName.indexOf('@')>-1 ) {
		return new AttributeGetter(nodeName, propertyType, factory);
	}
	else {
		return new ElementGetter(nodeName, propertyType, factory);
	}
}
 
源代码5 项目: cacheonix-core   文件: Dom4jAccessor.java
/**
 * Create a "setter" for the named attribute
 */
public Setter getSetter(Class theClass, String propertyName) 
throws PropertyNotFoundException {
	if (nodeName==null) {
		throw new MappingException("no node name for property: " + propertyName);
	}
	if ( ".".equals(nodeName) ) {
		return new TextSetter(propertyType);
	}
	else if ( nodeName.indexOf('/')>-1 ) {
		return new ElementAttributeSetter(nodeName, propertyType);
	}
	else if ( nodeName.indexOf('@')>-1 ) {
		return new AttributeSetter(nodeName, propertyType);
	}
	else {
		return new ElementSetter(nodeName, propertyType);
	}
}
 
源代码6 项目: cacheonix-core   文件: PojoInstantiator.java
public PojoInstantiator(Component component, ReflectionOptimizer.InstantiationOptimizer optimizer) {
	this.mappedClass = component.getComponentClass();
	this.optimizer = optimizer;

	this.proxyInterface = null;
	this.embeddedIdentifier = false;

	try {
		constructor = ReflectHelper.getDefaultConstructor(mappedClass);
	}
	catch ( PropertyNotFoundException pnfe ) {
		log.info(
		        "no default (no-argument) constructor for class: " +
				mappedClass.getName() +
				" (class must be instantiated by Interceptor)"
		);
		constructor = null;
	}
}
 
源代码7 项目: cacheonix-core   文件: PojoInstantiator.java
public PojoInstantiator(PersistentClass persistentClass, ReflectionOptimizer.InstantiationOptimizer optimizer) {
	this.mappedClass = persistentClass.getMappedClass();
	this.proxyInterface = persistentClass.getProxyInterface();
	this.embeddedIdentifier = persistentClass.hasEmbeddedIdentifier();
	this.optimizer = optimizer;

	try {
		constructor = ReflectHelper.getDefaultConstructor( mappedClass );
	}
	catch ( PropertyNotFoundException pnfe ) {
		log.info(
		        "no default (no-argument) constructor for class: " +
				mappedClass.getName() +
				" (class must be instantiated by Interceptor)"
		);
		constructor = null;
	}
}
 
源代码8 项目: cacheonix-core   文件: ReflectHelper.java
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);
			}
			return constructor;
		}
		catch (NoSuchMethodException nme) {
			throw new PropertyNotFoundException(
				"Object class " + clazz.getName() +
				" must declare a default (no-argument) constructor"
			);
		}

	}
 
源代码9 项目: cacheonix-core   文件: ReflectHelper.java
public static Constructor getConstructor(Class clazz, Type[] types) throws PropertyNotFoundException {
	final Constructor[] candidates = clazz.getConstructors();
	for ( int i=0; i<candidates.length; i++ ) {
		final Constructor constructor = candidates[i];
		final Class[] params = constructor.getParameterTypes();
		if ( params.length==types.length ) {
			boolean found = true;
			for ( int j=0; j<params.length; j++ ) {
				final boolean ok = params[j].isAssignableFrom( types[j].getReturnedClass() ) || (
					types[j] instanceof PrimitiveType &&
					params[j] == ( (PrimitiveType) types[j] ).getPrimitiveClass()
				);
				if (!ok) {
					found = false;
					break;
				}
			}
			if (found) {
				if ( !isPublic(clazz, constructor) ) constructor.setAccessible(true);
				return constructor;
			}
		}
	}
	throw new PropertyNotFoundException( "no appropriate constructor in class: " + clazz.getName() );
}
 
源代码10 项目: cacheonix-core   文件: AbstractQueryImpl.java
public Query setProperties(Object bean) throws HibernateException {
	Class clazz = bean.getClass();
	String[] params = getNamedParameters();
	for (int i = 0; i < params.length; i++) {
		String namedParam = params[i];
		try {
			Getter getter = ReflectHelper.getGetter( clazz, namedParam );
			Class retType = getter.getReturnType();
			final Object object = getter.get( bean );
			if ( Collection.class.isAssignableFrom( retType ) ) {
				setParameterList( namedParam, ( Collection ) object );
			}
			else if ( retType.isArray() ) {
			 	setParameterList( namedParam, ( Object[] ) object );
			}
			else {
				setParameter( namedParam, object, determineType( namedParam, retType ) );
			}
		}
		catch (PropertyNotFoundException pnfe) {
			// ignore
		}
	}
	return this;
}
 
源代码11 项目: lams   文件: PropertyAccessMixedImpl.java
protected static Field fieldOrNull(Class containerJavaType, String propertyName) {
	try {
		return ReflectHelper.findField( containerJavaType, propertyName );
	}
	catch (PropertyNotFoundException e) {
		return null;
	}
}
 
源代码12 项目: lams   文件: PropertyAccessStrategyChainedImpl.java
@Override
public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName) {
	for ( PropertyAccessStrategy candidate : chain ) {
		try {
			return candidate.buildPropertyAccess( containerJavaType, propertyName );
		}
		catch (Exception ignore) {
			// ignore
		}
	}

	throw new PropertyNotFoundException( "Could not resolve PropertyAccess for " + propertyName + " on " + containerJavaType );
}
 
源代码13 项目: lams   文件: AbstractProducedQuery.java
@Override
@SuppressWarnings("unchecked")
public QueryImplementor setProperties(Object bean) {
	Class clazz = bean.getClass();
	String[] params = getNamedParameters();
	for ( String namedParam : params ) {
		try {
			final PropertyAccess propertyAccess = BuiltInPropertyAccessStrategies.BASIC.getStrategy().buildPropertyAccess(
					clazz,
					namedParam
			);
			final Getter getter = propertyAccess.getGetter();
			final Class retType = getter.getReturnType();
			final Object object = getter.get( bean );
			if ( Collection.class.isAssignableFrom( retType ) ) {
				setParameterList( namedParam, (Collection) object );
			}
			else if ( retType.isArray() ) {
				setParameterList( namedParam, (Object[]) object );
			}
			else {
				Type type = determineType( namedParam, retType );
				setParameter( namedParam, object, type );
			}
		}
		catch (PropertyNotFoundException pnfe) {
			// ignore
		}
	}
	return this;
}
 
源代码14 项目: lams   文件: PojoInstantiator.java
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;
	}
}
 
源代码15 项目: lams   文件: ReflectHelper.java
/**
 * Retrieve a constructor for the given class, with arguments matching the specified Hibernate mapping
 * {@link Type types}.
 *
 * @param clazz The class needing instantiation
 * @param types The types representing the required ctor param signature
 * @return The matching constructor.
 * @throws PropertyNotFoundException Indicates we could not locate an appropriate constructor (todo : again with PropertyNotFoundException???)
 */
public static Constructor getConstructor(Class clazz, Type[] types) throws PropertyNotFoundException {
	final Constructor[] candidates = clazz.getConstructors();
	Constructor constructor = null;
	int numberOfMatchingConstructors = 0;
	for ( final Constructor candidate : candidates ) {
		final Class[] params = candidate.getParameterTypes();
		if ( params.length == types.length ) {
			boolean found = true;
			for ( int j = 0; j < params.length; j++ ) {
				final boolean ok = types[j] == null || params[j].isAssignableFrom( types[j].getReturnedClass() ) || (
						types[j] instanceof PrimitiveType &&
								params[j] == ( (PrimitiveType) types[j] ).getPrimitiveClass()
				);
				if ( !ok ) {
					found = false;
					break;
				}
			}
			if ( found ) {
				numberOfMatchingConstructors ++;
				ensureAccessibility( candidate );
				constructor = candidate;
			}
		}
	}

	if ( numberOfMatchingConstructors == 1 ) {
		return constructor;
	}
	throw new PropertyNotFoundException( "no appropriate constructor in class: " + clazz.getName() );

}
 
源代码16 项目: lams   文件: ReflectHelper.java
public static Method findGetterMethod(Class containerClass, String propertyName) {
	Class checkClass = containerClass;
	Method getter = null;

	// check containerClass, and then its super types (if any)
	while ( getter == null && checkClass != null ) {
		if ( checkClass.equals( Object.class ) ) {
			break;
		}

		getter = getGetterOrNull( checkClass, propertyName );

		// if no getter found yet, check all implemented interfaces
		if ( getter == null ) {
			getter = getGetterOrNull( checkClass.getInterfaces(), propertyName );
		}

		checkClass = checkClass.getSuperclass();
	}


	if ( getter == null ) {
		throw new PropertyNotFoundException(
				String.format(
						Locale.ROOT,
						"Could not locate getter method for property [%s#%s]",
						containerClass.getName(),
						propertyName
				)
		);
	}

	ensureAccessibility( getter );

	return getter;
}
 
源代码17 项目: lams   文件: ReflectHelper.java
public static Method getterMethodOrNull(Class containerJavaType, String propertyName) {
	try {
		return findGetterMethod( containerJavaType, propertyName );
	}
	catch (PropertyNotFoundException e) {
		return null;
	}
}
 
源代码18 项目: lams   文件: ReflectHelper.java
public static Method findSetterMethod(final Class containerClass, final String propertyName, final Class propertyType) {
	final Method setter = setterMethodOrNull( containerClass, propertyName, propertyType );
	if ( setter == null ) {
		throw new PropertyNotFoundException(
				String.format(
						Locale.ROOT,
						"Could not locate setter method for property [%s#%s]",
						containerClass.getName(),
						propertyName
				)
		);
	}
	return setter;
}
 
源代码19 项目: lams   文件: ComponentType.java
@Override
public int getPropertyIndex(String name) {
	String[] names = getPropertyNames();
	for ( int i = 0, max = names.length; i < max; i++ ) {
		if ( names[i].equals( name ) ) {
			return i;
		}
	}
	throw new PropertyNotFoundException(
			"Unable to locate property named " + name + " on " + getReturnedClass().getName()
	);
}
 
源代码20 项目: lams   文件: CompositeCustomType.java
@Override
public int getPropertyIndex(String name) {
	String[] names = getPropertyNames();
	for ( int i = 0, max = names.length; i < max; i++ ) {
		if ( names[i].equals( name ) ) {
			return i;
		}
	}
	throw new PropertyNotFoundException(
			"Unable to locate property named " + name + " on " + getReturnedClass().getName()
	);
}
 
源代码21 项目: lams   文件: AnyType.java
@Override
public int getPropertyIndex(String name) {
	if ( PROPERTY_NAMES[0].equals( name ) ) {
		return 0;
	}
	else if ( PROPERTY_NAMES[1].equals( name ) ) {
		return 1;
	}

	throw new PropertyNotFoundException( "Unable to locate property named " + name + " on AnyType" );
}
 
源代码22 项目: cacheonix-core   文件: BasicPropertyAccessor.java
private static Setter createSetter(Class theClass, String propertyName) 
throws PropertyNotFoundException {
	BasicSetter result = getSetterOrNull(theClass, propertyName);
	if (result==null) {
		throw new PropertyNotFoundException( 
				"Could not find a setter for property " + 
				propertyName + 
				" in class " + 
				theClass.getName() 
			);
	}
	return result;
}
 
源代码23 项目: cacheonix-core   文件: BasicPropertyAccessor.java
public static Getter createGetter(Class theClass, String propertyName) 
throws PropertyNotFoundException {
	BasicGetter result = getGetterOrNull(theClass, propertyName);
	if (result==null) {
		throw new PropertyNotFoundException( 
				"Could not find a getter for " + 
				propertyName + 
				" in class " + 
				theClass.getName() 
		);
	}
	return result;

}
 
源代码24 项目: cacheonix-core   文件: DirectPropertyAccessor.java
private static Field getField(Class clazz, String name) throws PropertyNotFoundException {
	if ( clazz==null || clazz==Object.class ) {
		throw new PropertyNotFoundException("field not found: " + name); 
	}
	Field field;
	try {
		field = clazz.getDeclaredField(name);
	}
	catch (NoSuchFieldException nsfe) {
		field = getField( clazz, clazz.getSuperclass(), name );
	}
	if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
	return field;
}
 
源代码25 项目: cacheonix-core   文件: DirectPropertyAccessor.java
private static Field getField(Class root, Class clazz, String name) throws PropertyNotFoundException {
	if ( clazz==null || clazz==Object.class ) {
		throw new PropertyNotFoundException("field [" + name + "] not found on " + root.getName()); 
	}
	Field field;
	try {
		field = clazz.getDeclaredField(name);
	}
	catch (NoSuchFieldException nsfe) {
		field = getField( root, clazz.getSuperclass(), name );
	}
	if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
	return field;
}
 
源代码26 项目: cacheonix-core   文件: ChainedPropertyAccessor.java
public Getter getGetter(Class theClass, String propertyName)
		throws PropertyNotFoundException {
	Getter result = null;
	for (int i = 0; i < chain.length; i++) {
		PropertyAccessor candidate = chain[i];
		try {
			result = candidate.getGetter(theClass, propertyName);
			return result;
		} catch (PropertyNotFoundException pnfe) {
			// ignore
		}
	}
	throw new PropertyNotFoundException("Could not find getter for " + propertyName + " on " + theClass);
}
 
源代码27 项目: cacheonix-core   文件: ChainedPropertyAccessor.java
public Setter getSetter(Class theClass, String propertyName)
		throws PropertyNotFoundException {
	Setter result = null;
	for (int i = 0; i < chain.length; i++) {
		PropertyAccessor candidate = chain[i];
		try {
			result = candidate.getSetter(theClass, propertyName);
			return result;
		} catch (PropertyNotFoundException pnfe) {
			//
		}
	}
	throw new PropertyNotFoundException("Could not find setter for " + propertyName + " on " + theClass);
}
 
源代码28 项目: cacheonix-core   文件: ReflectHelper.java
private static Getter getter(Class clazz, String name) throws MappingException {
	try {
		return BASIC_PROPERTY_ACCESSOR.getGetter(clazz, name);
	}
	catch (PropertyNotFoundException pnfe) {
		return DIRECT_PROPERTY_ACCESSOR.getGetter(clazz, name);
	}
}
 
源代码29 项目: lams   文件: Property.java
public Getter getGetter(Class clazz) throws PropertyNotFoundException, MappingException {
	return getPropertyAccessStrategy( clazz ).buildPropertyAccess( clazz, name ).getGetter();
}
 
源代码30 项目: lams   文件: Property.java
public Setter getSetter(Class clazz) throws PropertyNotFoundException, MappingException {
	return getPropertyAccessStrategy( clazz ).buildPropertyAccess( clazz, name ).getSetter();
}
 
 类所在包
 同包方法