Package org.hibernate.property

Examples of org.hibernate.property.Setter


        if (objTo == null || objFrom == null) {
            return;
        }

        Getter getter = ReflectionTools.getGetter(objFrom.getClass(), propertyData);
        Setter setter = ReflectionTools.getSetter(objTo.getClass(), propertyData);
        setter.set(objTo, getter.get(objFrom), null);
    }
View Full Code Here


        if (data == null || obj == null) {
            return false;
        }

        Getter getter = ReflectionTools.getGetter(obj.getClass(), idPropertyData);
        Setter setter = ReflectionTools.getSetter(obj.getClass(), idPropertyData);

        try {
            Object subObj = ReflectHelper.getDefaultConstructor( getter.getReturnType() ).newInstance();

            boolean ret = true;
            for (IdMapper idMapper : ids.values()) {
                ret &= idMapper.mapToEntityFromMap(subObj, data);
            }

            if (ret) {
                setter.set(obj, subObj, null);
            }

            return ret;
        } catch (Exception e) {
            throw new AuditException(e);
View Full Code Here

    Long id = ( Long ) getter.get( DOM );
    assertEquals( "Not equals", new Long( 456 ), id );
  }

  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 );
  }
View Full Code Here

            }
    };
  }

  public Setter getSetter(Class theClass, final String propertyName) throws PropertyNotFoundException {
    return new Setter() {
      public Method getMethod() {
        return null;
      }

      public String getMethodName() {
View Full Code Here

        } catch (NonUniqueResultException e) {
            throw new AuditException("Many versions results for one-to-one relationship: (" + owningEntityName +
                    ", " + owningReferencePropertyName + ")");
        }

        Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
        setter.set(obj, value, null);
    }
View Full Code Here

    public void mapToEntityFromMap(Object obj, Map data) {
        if (data == null || obj == null) {
            return;
        }

        Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
        setter.set(obj, data.get(propertyData.getName()), null);
    }
View Full Code Here

        if (objTo == null || objFrom == null) {
            return;
        }

        Getter getter = ReflectionTools.getGetter(objFrom.getClass(), propertyData);
        Setter setter = ReflectionTools.getSetter(objTo.getClass(), propertyData);
        setter.set(objTo, getter.get(objFrom), null);
    }
View Full Code Here

        if (data == null || obj == null) {
            return;
        }

        Getter getter = ReflectionTools.getGetter(obj.getClass(), idPropertyData);
        Setter setter = ReflectionTools.getSetter(obj.getClass(), idPropertyData);

        try {
            Object subObj = ReflectHelper.getDefaultConstructor( getter.getReturnType() ).newInstance();
            setter.set(obj, subObj, null);

            for (IdMapper idMapper : ids.values()) {
                idMapper.mapToEntityFromMap(subObj, data);
            }
        } catch (Exception e) {
View Full Code Here

    public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) {
        if (data == null || obj == null) {
            return;
        }

        Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);

    // If all properties are null and single, then the component has to be null also.
    boolean allNullAndSingle = true;
    for (Map.Entry<PropertyData, PropertyMapper> property : delegate.getProperties().entrySet()) {
      if (data.get(property.getKey().getName()) != null || !(property.getValue() instanceof SinglePropertyMapper)) {
        allNullAndSingle = false;
        break;
      }
    }

    if (allNullAndSingle) {
      // single property, but default value need not be null, so we'll set it to null anyway
      setter.set(obj, null, null);     
    } else {
      // set the component
      try {
        Object subObj = ReflectHelper.getDefaultConstructor(
            Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
        setter.set(obj, subObj, null);
        delegate.mapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision);
      } catch (Exception e) {
        throw new AuditException(e);
      }
    }
View Full Code Here

                                   AuditReaderImplementor versionsReader, Number revision) {
        if (data == null || obj == null) {
            return;
        }

        Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
    Object value = data.get(propertyData.getName());
    // We only set a null value if the field is not primite. Otherwise, we leave it intact.
    if (value != null || !isPrimitive(setter, propertyData, obj.getClass())) {
          setter.set(obj, value, null);
    }
    }
View Full Code Here

TOP

Related Classes of org.hibernate.property.Setter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.