private void initialize(String[] aliases) { PropertyAccessor propertyAccessor = new ChainedPropertyAccessor( new PropertyAccessor[] { PropertyAccessorFactory.getPropertyAccessor( resultClass, null ), PropertyAccessorFactory.getPropertyAccessor( "field" ) } ); this.aliases = new String[ aliases.length ]; setters = new Setter[ aliases.length ]; for ( int i = 0; i < aliases.length; i++ ) { String alias = aliases[ i ]; if ( alias != null ) { this.aliases[ i ] = alias; setters[ i ] = propertyAccessor.getSetter( resultClass, alias ); } } isInitialized = true; }
@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 ); }
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; }
public void testCompanyElementGeneration() throws Throwable { Setter idSetter = PropertyAccessorFactory.getPropertyAccessor( generateIdProperty(), EntityMode.DOM4J ) .getSetter( null, null ); Setter nameSetter = PropertyAccessorFactory.getPropertyAccessor( generateNameProperty(), EntityMode.DOM4J ) .getSetter( null, null ); Setter textSetter = PropertyAccessorFactory.getPropertyAccessor( generateTextProperty(), EntityMode.DOM4J ) .getSetter( null, null ); Setter accountIdSetter = PropertyAccessorFactory.getPropertyAccessor( generateAccountIdProperty(), EntityMode.DOM4J ) .getSetter( null, null ); Element root = generateRootTestElement(); idSetter.set( root, new Long( 123 ), getSFI() ); textSetter.set( root, "description...", getSFI() ); nameSetter.set( root, "JBoss", getSFI() ); accountIdSetter.set( root, new Long( 456 ), getSFI() ); assertTrue( "DOMs not equal", new NodeComparator().compare( DOM, root ) == 0 ); }
public ValueGenerationPlan( String propertyName, IdentifierGenerator subGenerator, Setter injector) { this.propertyName = propertyName; this.subGenerator = subGenerator; this.injector = injector; }
@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 ); }
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 ); }
@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 Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { return new EntityPropertyAccessor().getSetter( mappedEntity.getMappedClass(), mappedProperty.getName()); }
/** * Comunica que se ha cambiado de bean, para que los {@link NestedSetter}, * creen una nueva instancia en vez de reutilizarla actual. */ private void resetNestedSetter() { NestedObjectHolder noh = new NestedObjectHolder(); for (Setter s : setters) { if (s instanceof NestedSetter) { NestedSetter nSetter = (NestedSetter) s; nSetter.setHolder(noh); } } }
/** * * @param primary * @param duplicated * @param currentAlias */ private void handleDuplicate(Object primary, Object duplicated) { for (Setter s : setters) { if (s instanceof NestedSetter) { NestedSetter ns = (NestedSetter) s; ns.join(primary, duplicated); } } }
private void initialize(String[] newAlias) { PropertyAccessor propertyAccessor = new ChainedPropertyAccessor( new PropertyAccessor[] { PropertyAccessorFactory.getPropertyAccessor( resultClass, null), PropertyAccessorFactory.getPropertyAccessor("field") }); this.aliases = new String[newAlias.length]; setters = new Setter[newAlias.length]; for (int i = 0; i < newAlias.length; i++) { String alias = newAlias[i]; if (alias != null) { this.aliases[i] = alias; // Diferencia con AliasToBeanResultTransformer if (alias.indexOf('.') > 0) { // found nested setters[i] = new NestedSetter(resultClass, alias); } else { // ------------------------------------------- setters[i] = propertyAccessor.getSetter(resultClass, alias); // Diferencia con AliasToBeanResultTransformer } // ------------------------------------------- } } isInitialized = true; }
@Override protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { if (!"property".equals(mappedProperty.getPropertyAccessorName())) { mappedProperty.setPropertyAccessorName(OptionAwareDirectPropertyAccessor.class.getName()); } return super.buildPropertySetter(mappedProperty, mappedEntity); }
@Override public Setter getSetter(final Class theClass, final String propertyName) throws PropertyNotFoundException { final Field field = find(OptionAwareDirectPropertyAccessor_.fieldName.andThen(equalTo(propertyName)), fields(theClass)).get(); final boolean isOption = Option.class.isAssignableFrom(field.getType()); return new Setter() { @Override public void set(Object target, Object value, SessionFactoryImplementor factory) throws HibernateException { try { field.setAccessible(true); field.set(target, isOption ? Option.of(value) : value); } catch (Exception e) { throw new PropertyAccessException(e, "could not set a field value by reflection", true, theClass, propertyName); } } @Override public String getMethodName() { return null; } @Override public Method getMethod() { return null; } }; }
/** * @param theClass Target class in which the value is to be set * @param propertyName Target property name * @return returns Setter class instance */ private static Setter createSetter(Class theClass, String propertyName) { CollectionPropertySetter result = getSetterOrNull(theClass, propertyName); if (result == null) { throw new PropertyNotFoundException( "Could not find a setter for property " + propertyName + " in class " + theClass.getName()); } return result; }
private Setter injector(Property property, Class attributeDeclarer) { return property.getPropertyAccessor( attributeDeclarer ) .getSetter( attributeDeclarer, property.getName() ); }
public Setter getSetter(Class clazz) throws PropertyNotFoundException, MappingException { return getPropertyAccessor(clazz).getSetter(clazz, name); }
@Override protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { return buildPropertyAccessor(mappedProperty).getSetter( null, mappedProperty.getName() ); }
@Override protected Setter buildPropertySetter(AttributeBinding mappedProperty) { return buildPropertyAccessor( mappedProperty ).getSetter( 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 Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { return mappedProperty.getSetter( mappedEntity.getMappedClass() ); }
@Override protected Setter buildPropertySetter(AttributeBinding mappedProperty) { return getSetter( mappedProperty ); }
private Setter getSetter(AttributeBinding mappedProperty) throws PropertyNotFoundException, MappingException { return getPropertyAccessor( mappedProperty ).getSetter( mappedProperty.getContainer().getClassReference(), mappedProperty.getAttribute().getName() ); }
protected Setter buildSetter(Component component, Property prop) { return prop.getSetter( component.getComponentClass() ); }
protected Setter buildSetter(Component component, Property prop) { return buildPropertyAccessor(prop).getSetter( null, prop.getName() ); }
@Override protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { return mappedProperty.getSetter(mappedEntity.getMappedClass()); }
@Override protected ProxyFactory buildProxyFactory(PersistentClass thePersistentClass, Getter idGetter, Setter idSetter) { final Class<?> mappedClass = thePersistentClass.getMappedClass(); Check.isNotNull(mappedClass, "Mapped class of entity " + thePersistentClass.getEntityName() + " is null"); // determine the id getter and setter methods from the proxy interface // (if // any) // determine all interfaces needed by the resulting proxy final HashSet<Object> proxyInterfaces = new HashSet<Object>(); proxyInterfaces.add(HibernateProxy.class); final Class<?> proxyInterface = thePersistentClass.getProxyInterface(); 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); } final Iterator<?> iter = thePersistentClass.getSubclassIterator(); while (iter.hasNext()) { final Subclass subclass = (Subclass) iter.next(); final Class<?> subclassProxy = subclass.getProxyInterface(); final Class<?> subclassClass = subclass.getMappedClass(); if (subclassProxy != null && !subclassClass.equals(subclassProxy)) { if (proxyInterface == null || !proxyInterface.isInterface()) { throw new MappingException("proxy must be either an interface, or the class itself: " + subclass.getEntityName()); } proxyInterfaces.add(subclassProxy); } } final Method idGetterMethod = idGetter == null ? null : idGetter.getMethod(); final Method idSetterMethod = idSetter == null ? null : idSetter.getMethod(); final Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idGetterMethod); final Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idSetterMethod); ProxyFactory pf = buildProxyFactoryInternal(thePersistentClass, idGetter, idSetter); try { pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, thePersistentClass.hasEmbeddedIdentifier() ? (CompositeType) thePersistentClass .getIdentifier().getType() : null); } catch (final HibernateException he) { log.warn("could not create proxy factory for:" + getEntityName(), he); pf = null; } return pf; }
public Setter getSetter(Class arg0, String arg1) throws PropertyNotFoundException { return new NoopSetter(); }
/** * Constructs a new AbstractEntityTuplizer instance. * * @param entityMetamodel The "interpreted" information relating to the mapped entity. * @param mappingInfo The parsed "raw" mapping data relating to the given entity. */ public AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) { this.entityMetamodel = entityMetamodel; if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) { idGetter = buildPropertyGetter( mappingInfo.getIdentifierProperty(), mappingInfo ); idSetter = buildPropertySetter( mappingInfo.getIdentifierProperty(), mappingInfo ); } else { idGetter = null; idSetter = null; } propertySpan = entityMetamodel.getPropertySpan(); getters = new Getter[propertySpan]; setters = new Setter[propertySpan]; Iterator iter = mappingInfo.getPropertyClosureIterator(); boolean foundCustomAccessor=false; int i=0; while ( iter.hasNext() ) { //TODO: redesign how PropertyAccessors are acquired... Property property = (Property) iter.next(); getters[i] = buildPropertyGetter(property, mappingInfo); setters[i] = buildPropertySetter(property, mappingInfo); if ( !property.isBasicPropertyAccessor() ) foundCustomAccessor = true; i++; } hasCustomAccessors = foundCustomAccessor; instantiator = buildInstantiator( mappingInfo ); if ( entityMetamodel.isLazy() ) { proxyFactory = buildProxyFactory( mappingInfo, idGetter, idSetter ); if (proxyFactory == null) { entityMetamodel.setLazy( false ); } } else { proxyFactory = null; } Component mapper = mappingInfo.getIdentifierMapper(); identifierMapperType = mapper==null ? null : (AbstractComponentType) mapper.getType(); }
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { return buildPropertyAccessor(mappedProperty).getSetter( null, mappedProperty.getName() ); }
protected ProxyFactory buildProxyFactoryInternal(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { // TODO : YUCK!!! finx after HHH-1907 is complete return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); // return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); }