@Override protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) { ProxyFactory pf = new MapProxyFactory(); try { //TODO: design new lifecycle for ProxyFactory pf.postInstantiate( getEntityName(), null, null, null, null, null ); } catch ( HibernateException he ) { LOG.unableToCreateProxyFactory( getEntityName(), he ); pf = null; } return pf; }
@Override protected ProxyFactory buildProxyFactory(EntityBinding mappingInfo, Getter idGetter, Setter idSetter) { ProxyFactory pf = new MapProxyFactory(); try { //TODO: design new lifecycle for ProxyFactory pf.postInstantiate( getEntityName(), null, null, null, null, null ); } catch ( HibernateException he ) { LOG.unableToCreateProxyFactory(getEntityName(), he); pf = null; } return pf; }
protected AbstractComponentTuplizer(Component component) { propertySpan = component.getPropertySpan(); getters = new Getter[propertySpan]; setters = new Setter[propertySpan]; Iterator iter = component.getPropertyIterator(); boolean foundCustomAccessor=false; int i = 0; while ( iter.hasNext() ) { Property prop = ( Property ) iter.next(); getters[i] = buildGetter( component, prop ); setters[i] = buildSetter( component, prop ); if ( !prop.isBasicPropertyAccessor() ) { foundCustomAccessor = true; } i++; } hasCustomAccessors = foundCustomAccessor; instantiator = buildInstantiator( component ); }
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; }
protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) { ProxyFactory pf = new MapProxyFactory(); try { //TODO: design new lifecycle for ProxyFactory pf.postInstantiate( getEntityName(), null, null, null, null, null ); } catch ( HibernateException he ) { log.warn( "could not create proxy factory for:" + getEntityName(), he ); pf = null; } return pf; }
protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) { HashSet proxyInterfaces = new HashSet(); proxyInterfaces.add( HibernateProxy.class ); proxyInterfaces.add( Element.class ); ProxyFactory pf = new Dom4jProxyFactory(); try { pf.postInstantiate( getEntityName(), Element.class, proxyInterfaces, null, null, mappingInfo.hasEmbeddedIdentifier() ? (AbstractComponentType) mappingInfo.getIdentifier().getType() : null ); } catch ( HibernateException he ) { log.warn( "could not create proxy factory for:" + getEntityName(), he ); pf = null; } return pf; }
@Override public Getter getVersionGetter() { if ( getEntityMetamodel().isVersioned() ) { return getGetter( getEntityMetamodel().getVersionPropertyIndex() ); } return null; }
private static Getter getGetter(Property mappingProperty) { if ( mappingProperty == null || !mappingProperty.getPersistentClass().hasPojoRepresentation() ) { return null; } PropertyAccessor pa = PropertyAccessorFactory.getPropertyAccessor( mappingProperty, EntityMode.POJO ); return pa.getGetter( mappingProperty.getPersistentClass().getMappedClass(), mappingProperty.getName() ); }
private static Getter getGetter(AttributeBinding mappingProperty) { if ( mappingProperty == null || mappingProperty.getContainer().getClassReference() == null ) { return null; } PropertyAccessor pa = PropertyAccessorFactory.getPropertyAccessor( mappingProperty, EntityMode.POJO ); return pa.getGetter( mappingProperty.getContainer().getClassReference(), mappingProperty.getAttribute().getName() ); }
/** * Return an IdentifierValue for the specified unsaved-value. If none is specified, * guess the unsaved value by instantiating a test instance of the class and * reading it's version property value, or if that is not possible, using the java default * value for the type * * @param versionUnsavedValue The mapping defined unsaved value * @param versionGetter The version attribute getter * @param versionType The mapping type for the version * @param constructor The constructor for the entity * * @return The appropriate VersionValue */ public static VersionValue getUnsavedVersionValue( String versionUnsavedValue, Getter versionGetter, VersionType versionType, Constructor constructor) { if ( versionUnsavedValue == null ) { if ( constructor!=null ) { final Object defaultValue = versionGetter.get( instantiate( constructor ) ); // if the version of a newly instantiated object is not the same // as the version seed value, use that as the unsaved-value return versionType.isEqual( versionType.seed( null ), defaultValue ) ? VersionValue.UNDEFINED : new VersionValue( defaultValue ); } else { return VersionValue.UNDEFINED; } } else if ( "undefined".equals( versionUnsavedValue ) ) { return VersionValue.UNDEFINED; } else if ( "null".equals( versionUnsavedValue ) ) { return VersionValue.NULL; } else if ( "negative".equals( versionUnsavedValue ) ) { return VersionValue.NEGATIVE; } else { // this should not happen since the DTD prevents it throw new MappingException( "Could not parse version unsaved-value: " + versionUnsavedValue ); } }
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 ); } }
@Override protected ProxyFactory buildProxyFactory(PersistentClass thePersistentClass, Getter idGetter, Setter idSetter) { ProxyFactory pf = new MapProxyFactory(); try { pf.postInstantiate(getEntityName(), null, null, null, null, null); } catch (final HibernateException he) { log.warn("could not create proxy factory for:" + getEntityName(), he); pf = null; } return pf; }
protected AbstractComponentTuplizer(Component component) { propertySpan = component.getPropertySpan(); getters = new Getter[propertySpan]; setters = new Setter[propertySpan]; Iterator iter = component.getPropertyIterator(); boolean foundCustomAccessor=false; int i = 0; while ( iter.hasNext() ) { Property prop = ( Property ) iter.next(); getters[i] = buildGetter( component, prop ); setters[i] = buildSetter( component, prop ); if ( !prop.isBasicPropertyAccessor() ) { foundCustomAccessor = true; } i++; } hasCustomAccessors = foundCustomAccessor; String[] getterNames = new String[propertySpan]; String[] setterNames = new String[propertySpan]; Class[] propTypes = new Class[propertySpan]; for ( int j = 0; j < propertySpan; j++ ) { getterNames[j] = getters[j].getMethodName(); setterNames[j] = setters[j].getMethodName(); propTypes[j] = getters[j].getReturnType(); } instantiator = buildInstantiator( component ); }
public static VersionValue getUnsavedVersionValue( String versionUnsavedValue, Getter versionGetter, VersionType versionType, Constructor constructor) { if ( versionUnsavedValue == null ) { if ( constructor!=null ) { Object defaultValue = versionGetter.get( instantiate(constructor) ); // if the version of a newly instantiated object is not the same // as the version seed value, use that as the unsaved-value return versionType.isEqual( versionType.seed( null ), defaultValue ) ? VersionValue.UNDEFINED : new VersionValue( defaultValue ); } else { return VersionValue.UNDEFINED; } } else if ( "undefined".equals( versionUnsavedValue ) ) { return VersionValue.UNDEFINED; } else if ( "null".equals( versionUnsavedValue ) ) { return VersionValue.NULL; } else if ( "negative".equals( versionUnsavedValue ) ) { return VersionValue.NEGATIVE; } else { // this should not happen since the DTD prevents it throw new MappingException( "Could not parse version unsaved-value: " + versionUnsavedValue ); } }
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); } }
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { // allows defining a custom proxy factory, which is responsible for // generating lazy proxies for a given entity. // // Here we simply use the default... return super.buildProxyFactory( persistentClass, idGetter, idSetter ); }
public void testStringElementExtraction() throws Throwable { Property property = generateNameProperty(); Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J ) .getGetter( null, null ); String name = ( String ) getter.get( DOM ); assertEquals( "Not equals", "JBoss", name ); }
public void testStringTextExtraction() throws Throwable { Property property = generateTextProperty(); Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J ) .getGetter( null, null ); String name = ( String ) getter.get( DOM ); assertEquals( "Not equals", "description...", name ); }
public void testLongAttributeExtraction() throws Throwable { Property property = generateIdProperty(); Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J ) .getGetter( null, null ); Long id = ( Long ) getter.get( DOM ); assertEquals( "Not equals", new Long( 123 ), id ); }
public void testLongElementAttributeExtraction() throws Throwable { Property property = generateAccountIdProperty(); Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J ) .getGetter( null, null ); Long id = ( Long ) getter.get( DOM ); assertEquals( "Not equals", new Long( 456 ), id ); }
@Override protected ProxyFactory buildProxyFactory(PersistentClass pc, Getter arg1,Setter arg2) { CFCHibernateProxyFactory pf = new CFCHibernateProxyFactory(); pf.postInstantiate(pc); return pf; }
/** * {@inheritDoc} */ @Override protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { fixPropertyAccessors(persistentClass); return super.buildProxyFactory(persistentClass, idGetter, idSetter); }
/** * {@inheritDoc} */ @Override protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { return new EntityPropertyAccessor().getGetter( mappedEntity.getMappedClass(), mappedProperty.getName()); }
@Override protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { if (!"property".equals(mappedProperty.getPropertyAccessorName())) { mappedProperty.setPropertyAccessorName(OptionAwareDirectPropertyAccessor.class.getName()); } return super.buildPropertyGetter(mappedProperty, mappedEntity); }
public Getter getGetter(Class clazz) throws PropertyNotFoundException, MappingException { return getPropertyAccessor(clazz).getGetter( clazz, name ); }
@Override public Getter getIdentifierGetter() { return idGetter; }
@Override public Getter getGetter(int i) { return getters[i]; }
@Override protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { return buildPropertyAccessor(mappedProperty).getGetter( null, mappedProperty.getName() ); }
@Override protected Getter buildPropertyGetter(AttributeBinding mappedProperty) { return buildPropertyAccessor( mappedProperty ).getGetter( null, mappedProperty.getAttribute().getName() ); }
protected ProxyFactory buildProxyFactoryInternal(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { // TODO : YUCK!!! fix after HHH-1907 is complete return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); // return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); }
@Override protected ProxyFactory buildProxyFactory(EntityBinding entityBinding, Getter idGetter, Setter idSetter) { // determine the id getter and setter methods from the proxy interface (if any) // determine all interfaces needed by the resulting proxy HashSet<Class> proxyInterfaces = new HashSet<Class>(); proxyInterfaces.add( HibernateProxy.class ); Class mappedClass = entityBinding.getEntity().getClassReference(); Class proxyInterface = entityBinding.getProxyInterfaceType().getValue(); if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) { if ( ! proxyInterface.isInterface() ) { throw new MappingException( "proxy must be either an interface, or the class itself: " + getEntityName() ); } proxyInterfaces.add( proxyInterface ); } if ( mappedClass.isInterface() ) { proxyInterfaces.add( mappedClass ); } for ( EntityBinding subEntityBinding : entityBinding.getPostOrderSubEntityBindingClosure() ) { final Class subclassProxy = subEntityBinding.getProxyInterfaceType().getValue(); final Class subclassClass = subEntityBinding.getClassReference(); if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) { if ( ! subclassProxy.isInterface() ) { throw new MappingException( "proxy must be either an interface, or the class itself: " + subEntityBinding.getEntity().getName() ); } proxyInterfaces.add( subclassProxy ); } } for ( AttributeBinding property : entityBinding.attributeBindings() ) { Method method = getGetter( property ).getMethod(); if ( method != null && Modifier.isFinal( method.getModifiers() ) ) { LOG.gettersOfLazyClassesCannotBeFinal(entityBinding.getEntity().getName(), property.getAttribute().getName()); } method = getSetter( property ).getMethod(); if ( method != null && Modifier.isFinal( method.getModifiers() ) ) { LOG.settersOfLazyClassesCannotBeFinal(entityBinding.getEntity().getName(), property.getAttribute().getName()); } } Method idGetterMethod = idGetter==null ? null : idGetter.getMethod(); Method idSetterMethod = idSetter==null ? null : idSetter.getMethod(); Method proxyGetIdentifierMethod = idGetterMethod==null || proxyInterface==null ? null : ReflectHelper.getMethod(proxyInterface, idGetterMethod); Method proxySetIdentifierMethod = idSetterMethod==null || proxyInterface==null ? null : ReflectHelper.getMethod(proxyInterface, idSetterMethod); ProxyFactory pf = buildProxyFactoryInternal( entityBinding, idGetter, idSetter ); try { pf.postInstantiate( getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, entityBinding.getHierarchyDetails().getEntityIdentifier().isEmbedded() ? ( CompositeType ) entityBinding .getHierarchyDetails() .getEntityIdentifier() .getValueBinding() .getHibernateTypeDescriptor() .getResolvedTypeMapping() : null ); } catch ( HibernateException he ) { LOG.unableToCreateProxyFactory(getEntityName(), he); pf = null; } return pf; }
protected ProxyFactory buildProxyFactoryInternal(EntityBinding entityBinding, Getter idGetter, Setter idSetter) { // TODO : YUCK!!! fix after HHH-1907 is complete return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); // return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); }
@Override protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { return mappedProperty.getGetter( mappedEntity.getMappedClass() ); }
@Override protected Getter buildPropertyGetter(AttributeBinding mappedProperty) { return getGetter( mappedProperty ); }
private Getter getGetter(AttributeBinding mappedProperty) throws PropertyNotFoundException, MappingException { return getPropertyAccessor( mappedProperty ).getGetter( mappedProperty.getContainer().getClassReference(), mappedProperty.getAttribute().getName() ); }
public Getter getGetter(int i) { return getters[i]; }
protected Getter buildGetter(Component component, Property prop) { return prop.getGetter( component.getComponentClass() ); }