java类javax.persistence.Embedded的实例源码

ACustomIdDao.java 文件源码 项目:invesdwin-context-persistence 阅读 37 收藏 0 点赞 0 评论 0
private boolean determineDeleteInBatchSupported(final Class<?> genericType) {
    final MutableBoolean deleteInBatchSupported = new MutableBoolean(true);
    Reflections.doWithFields(genericType, new FieldCallback() {
        @Override
        public void doWith(final Field field) {
            if (!deleteInBatchSupported.getValue()) {
                return;
            } else if (Reflections.getAnnotation(field, ElementCollection.class) != null) {
                //element collections are mapped as separate tables, thus the values would cause a foreign key constraint violation
                deleteInBatchSupported.setValue(false);
            } else if (Reflections.getAnnotation(field, Embedded.class) != null) {
                //check embedded types for the same constraints
                if (!determineDeleteInBatchSupported(field.getType())) {
                    deleteInBatchSupported.setValue(false);
                }
            }
        }
    });
    return deleteInBatchSupported.getValue();
}
AdminAuditableListener.java 文件源码 项目:metaworks_framework 阅读 29 收藏 0 点赞 0 评论 0
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalCreatedField = auditable.getClass().getDeclaredField("dateCreated");
            Field temporalUpdatedField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalCreatedField, auditable);
            setAuditValueTemporal(temporalUpdatedField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AdminAuditableListener.java 文件源码 项目:metaworks_framework 阅读 36 收藏 0 点赞 0 评论 0
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AuditableListener.java 文件源码 项目:metaworks_framework 阅读 31 收藏 0 点赞 0 评论 0
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateCreated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AuditableListener.java 文件源码 项目:metaworks_framework 阅读 34 收藏 0 点赞 0 评论 0
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AdminAuditableListener.java 文件源码 项目:SparkCommerce 阅读 32 收藏 0 点赞 0 评论 0
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalCreatedField = auditable.getClass().getDeclaredField("dateCreated");
            Field temporalUpdatedField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalCreatedField, auditable);
            setAuditValueTemporal(temporalUpdatedField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AdminAuditableListener.java 文件源码 项目:SparkCommerce 阅读 41 收藏 0 点赞 0 评论 0
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AuditableListener.java 文件源码 项目:SparkCommerce 阅读 35 收藏 0 点赞 0 评论 0
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateCreated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AuditableListener.java 文件源码 项目:SparkCommerce 阅读 34 收藏 0 点赞 0 评论 0
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AdminAuditableListener.java 文件源码 项目:blcdemo 阅读 33 收藏 0 点赞 0 评论 0
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), getAuditableFieldName());
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalCreatedField = auditable.getClass().getDeclaredField("dateCreated");
            Field temporalUpdatedField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalCreatedField, auditable);
            setAuditValueTemporal(temporalUpdatedField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AdminAuditableListener.java 文件源码 项目:blcdemo 阅读 35 收藏 0 点赞 0 评论 0
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), getAuditableFieldName());
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AuditableListener.java 文件源码 项目:blcdemo 阅读 33 收藏 0 点赞 0 评论 0
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateCreated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
AuditableListener.java 文件源码 项目:blcdemo 阅读 37 收藏 0 点赞 0 评论 0
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
EntityClass.java 文件源码 项目:org.fastnate 阅读 39 收藏 0 点赞 0 评论 0
/**
 * Builds the property for the given attribute.
 *
 * @param attribute
 *            the attribute to inspect
 * @param columnMetadata
 *            the attached (or overriden) column metadata
 * @param override
 *            the AssociationOverride found for this attribute
 * @return the property that represents the attribute or {@code null} if not persistent
 */
<X> Property<X, ?> buildProperty(final AttributeAccessor attribute, final Column columnMetadata,
        final AssociationOverride override) {
    if (attribute.isPersistent()) {
        if (CollectionProperty.isCollectionProperty(attribute)) {
            return new CollectionProperty<>(this, attribute, override);
        } else if (MapProperty.isMapProperty(attribute)) {
            return new MapProperty<>(this, attribute, override);
        } else if (EntityProperty.isEntityProperty(attribute)) {
            return new EntityProperty<>(this.context, getTable(), attribute, override);
        } else if (attribute.isAnnotationPresent(Embedded.class)) {
            return new EmbeddedProperty<>(this, attribute);
        } else if (attribute.isAnnotationPresent(Version.class)) {
            return new VersionProperty<>(this.context, this.table, attribute, columnMetadata);
        } else {
            return new PrimitiveProperty<>(this.context, this.table, attribute, columnMetadata);
        }
    }
    return null;
}
AllProcessor.java 文件源码 项目:easyjweb 阅读 36 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
private void resovleEmbed(List<Map> fields, List<Map> complexFields,
        Field field) {
    if (field.isAnnotationPresent(Embedded.class)) {
        for (Field f : field.getType().getDeclaredFields()) {
            if ((field.getName().equals("status"))
                    || field.getName().equals("serialVersionUID")) {
                continue;
            }
            if (resovleGenerAnno(field)) {
                continue;
            }
            if (isSimpleType(f.getType())) {
                fields.add(parseField(f));
            }
        }
        complexFields.remove(complexFields.size() - 1);
    }
}
DbUtil.java 文件源码 项目:cosmic 阅读 38 收藏 0 点赞 0 评论 0
public static Field findField(final Class<?> clazz, final String columnName) {
    for (final Field field : clazz.getDeclaredFields()) {
        if (field.getAnnotation(Embedded.class) != null || field.getAnnotation(EmbeddedId.class) != null) {
            findField(field.getClass(), columnName);
        } else {
            if (columnName.equals(DbUtil.getColumnName(field))) {
                return field;
            }
        }
    }
    return null;
}
TemporalTimestampListener.java 文件源码 项目:metaworks_framework 阅读 35 收藏 0 点赞 0 评论 0
private void setTimestamps(Field[] fields, Object entity) throws Exception {
    Calendar cal = null;
    for (Field field : fields) {
        Class<?> type = field.getType();
        Temporal temporalAnnotation = field.getAnnotation(Temporal.class);

        if (temporalAnnotation != null) {
            if (field.isAnnotationPresent(Column.class)) {
                field.setAccessible(true);
                try {
                    if (TemporalType.TIMESTAMP.equals(temporalAnnotation.value()) && (field.isAnnotationPresent(AutoPopulate.class))) {
                        if (field.get(entity) == null || field.getAnnotation(AutoPopulate.class).autoUpdateValue()) {
                            if (type.isAssignableFrom(Date.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal.getTime());
                            } else if (type.isAssignableFrom(Calendar.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal);
                            }
                        }
                    }
                } finally {
                    field.setAccessible(false);
                }
            }
        } else if (field.isAnnotationPresent(Embedded.class)) {
            field.setAccessible(true);
            try {
                // Call recursively
                setTimestamps(field.getType().getDeclaredFields(), field.get(entity));
            } finally {
                field.setAccessible(false);
            }
        }
    }
}
Statistics.java 文件源码 项目:alex 阅读 39 收藏 0 点赞 0 评论 0
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner", column = @Column(name = "duration_learner")),
        @AttributeOverride(name = "eqOracle", column = @Column(name = "duration_eqOracle"))
})
public DetailedStatistics getDuration() {
    return duration;
}
Statistics.java 文件源码 项目:alex 阅读 39 收藏 0 点赞 0 评论 0
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner", column = @Column(name = "mqs_learner")),
        @AttributeOverride(name = "eqOracle", column = @Column(name = "mqs_eqOracle"))
})
public DetailedStatistics getMqsUsed() {
    return mqsUsed;
}
Statistics.java 文件源码 项目:alex 阅读 40 收藏 0 点赞 0 评论 0
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner", column = @Column(name = "symbolsUsed_learner")),
        @AttributeOverride(name = "eqOracle", column = @Column(name = "symbolsUsed_eqOracle"))
})
public DetailedStatistics getSymbolsUsed() {
    return symbolsUsed;
}
TemporalTimestampListener.java 文件源码 项目:SparkCommerce 阅读 38 收藏 0 点赞 0 评论 0
private void setTimestamps(Field[] fields, Object entity) throws Exception {
    Calendar cal = null;
    for (Field field : fields) {
        Class<?> type = field.getType();
        Temporal temporalAnnotation = field.getAnnotation(Temporal.class);

        if (temporalAnnotation != null) {
            if (field.isAnnotationPresent(Column.class)) {
                field.setAccessible(true);
                try {
                    if (TemporalType.TIMESTAMP.equals(temporalAnnotation.value()) && (field.isAnnotationPresent(AutoPopulate.class))) {
                        if (field.get(entity) == null || field.getAnnotation(AutoPopulate.class).autoUpdateValue()) {
                            if (type.isAssignableFrom(Date.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal.getTime());
                            } else if (type.isAssignableFrom(Calendar.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal);
                            }
                        }
                    }
                } finally {
                    field.setAccessible(false);
                }
            }
        } else if (field.isAnnotationPresent(Embedded.class)) {
            field.setAccessible(true);
            try {
                // Call recursively
                setTimestamps(field.getType().getDeclaredFields(), field.get(entity));
            } finally {
                field.setAccessible(false);
            }
        }
    }
}
SuperTripSubQuery.java 文件源码 项目:amos-ss15-proj2 阅读 35 收藏 0 点赞 0 评论 0
@Embedded
@AttributeOverrides({
        @AttributeOverride(name= RouteLocation.COLUMN_LAT, column = @Column(name = "sLat")),
        @AttributeOverride(name= RouteLocation.COLUMN_LNG, column = @Column(name = "sLng"))
})
public RouteLocation getStartLocation() {
    return startLocation;
}
SuperTripSubQuery.java 文件源码 项目:amos-ss15-proj2 阅读 33 收藏 0 点赞 0 评论 0
@Embedded
@AttributeOverrides({
        @AttributeOverride(name= RouteLocation.COLUMN_LAT, column = @Column(name = "eLat")),
        @AttributeOverride(name= RouteLocation.COLUMN_LNG, column = @Column(name = "eLng"))
})
public RouteLocation getDestinationLocation() {
    return destinationLocation;
}
TemporalTimestampListener.java 文件源码 项目:blcdemo 阅读 31 收藏 0 点赞 0 评论 0
private void setTimestamps(Field[] fields, Object entity) throws Exception {
    Calendar cal = null;
    for (Field field : fields) {
        Class<?> type = field.getType();
        Temporal temporalAnnotation = field.getAnnotation(Temporal.class);

        if (temporalAnnotation != null) {
            if (field.isAnnotationPresent(Column.class)) {
                field.setAccessible(true);
                try {
                    if (TemporalType.TIMESTAMP.equals(temporalAnnotation.value()) && (field.isAnnotationPresent(AutoPopulate.class))) {
                        if (field.get(entity) == null || field.getAnnotation(AutoPopulate.class).autoUpdateValue()) {
                            if (type.isAssignableFrom(Date.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal.getTime());
                            } else if (type.isAssignableFrom(Calendar.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal);
                            }
                        }
                    }
                } finally {
                    field.setAccessible(false);
                }
            }
        } else if (field.isAnnotationPresent(Embedded.class)) {
            field.setAccessible(true);
            try {
                // Call recursively
                setTimestamps(field.getType().getDeclaredFields(), field.get(entity));
            } finally {
                field.setAccessible(false);
            }
        }
    }
}
BeanMappingUtils.java 文件源码 项目:petit 阅读 41 收藏 0 点赞 0 评论 0
/**
 * Adds an extended property to the BeanMapping. 
 * 
 * @param props
 * @param name
 * @param type
 * @param columnMapping
 * @return
 */
public static <B> Property<B, Object> initExtendedProperty(Map<String, Property<B, Object>> props, String name, Class<B> type, String columnMapping) {
    PropertyDescriptor pd = BeanMappingReflectionUtils.getPropertyDescriptor(type, name);

    if (!isPropertyReadableAndWritable(pd)) {
        return null;
    }

    List<Annotation> ans = BeanMappingReflectionUtils.readAnnotations(type, pd.getName());

    Column column = BeanMappingReflectionUtils.getAnnotation(ans, Column.class);

    ReflectionProperty<B, Object> prop = new ReflectionProperty<B, Object>(name,
            (Class<Object>) pd.getPropertyType(), inferColumn(columnMapping != null ? columnMapping : name, column), pd.getWriteMethod(),
            pd.getReadMethod());

    if (column != null) {
        prop.readOnly(true);
    }

    if (BeanMappingReflectionUtils.getAnnotation(ans, Id.class) != null) {
        prop.setIdProperty(true);
    }

    if (useAdditionalConfiguration()) {
        prop.getConfiguration().setAnnotations(ans);
        if (Collection.class.isAssignableFrom(pd.getPropertyType())) {
            prop.getConfiguration().setCollectionTypeArguments(
                    ((ParameterizedType) pd.getReadMethod().getGenericReturnType()).getActualTypeArguments());
        }
    }

    if (BeanMappingReflectionUtils.getAnnotation(ans, Embedded.class) != null) {
        props.putAll(getCompositeProperties(prop, ans));
    } else {
        props.put(prop.name(), prop);
    }

    return prop;
}
DbUtil.java 文件源码 项目:cloudstack 阅读 44 收藏 0 点赞 0 评论 0
public static Field findField(Class<?> clazz, String columnName) {
    for (Field field : clazz.getDeclaredFields()) {
        if (field.getAnnotation(Embedded.class) != null || field.getAnnotation(EmbeddedId.class) != null) {
            findField(field.getClass(), columnName);
        } else {
            if (columnName.equals(DbUtil.getColumnName(field))) {
                return field;
            }
        }
    }
    return null;
}
Veranstaltungsort.java 文件源码 项目:hsw 阅读 30 收藏 0 点赞 0 评论 0
@Embedded
@AttributeOverrides( {
        @AttributeOverride(name = "breite", column = @Column(name = "GEO_BREITE")),
        @AttributeOverride(name = "laenge", column = @Column(name = "GEO_LAENGE")) })
public GeoKoordinaten getKoordinaten() {
    return koordinaten;
}
Place.java 文件源码 项目:zekke-webapp 阅读 37 收藏 0 点赞 0 评论 0
@Embedded
@AttributeOverrides({
    @AttributeOverride(name = "latitude", column = @Column(name = "latitude", nullable = false, precision = 22, scale = 0)),
    @AttributeOverride(name = "longitude", column = @Column(name = "longitude", nullable = false, precision = 22, scale = 0))
})
public GeoPoint getPosition() {
    return position;
}
FileEntry.java 文件源码 项目:carcv 阅读 27 收藏 0 点赞 0 评论 0
/**
 * @return CarData of this FileEntry
 */
@Override
@NotNull
@Embedded
public CarData getCarData() {
    return carData;
}
Enhancer.java 文件源码 项目:lams 阅读 33 收藏 0 点赞 0 评论 0
private CtMethod generateFieldWriter(
        CtClass managedCtClass,
        CtField persistentField,
        AttributeTypeDescriptor typeDescriptor) {

    final FieldInfo fieldInfo = persistentField.getFieldInfo();
    final String fieldName = fieldInfo.getName();
    final String writerName = EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + fieldName;

    final CtMethod writer;

    try {
        if ( !enhancementContext.isLazyLoadable( persistentField ) ) {
            // not lazy-loadable...
            writer = CtNewMethod.setter( writerName, persistentField );
        }
        else {
            final String methodBody = typeDescriptor.buildWriteInterceptionBodyFragment( fieldName );
            writer = CtNewMethod.make(
                    Modifier.PRIVATE,
                    CtClass.voidType,
                    writerName,
                    new CtClass[] {persistentField.getType()},
                    null,
                    "{" + methodBody + "}",
                    managedCtClass
            );
        }

        if ( enhancementContext.doDirtyCheckingInline( managedCtClass ) && !isComposite ) {
            writer.insertBefore( typeDescriptor.buildInLineDirtyCheckingBodyFragment( persistentField ) );
        }

        if ( isComposite ) {
            StringBuilder builder = new StringBuilder();
            builder.append( " if(  " )
                    .append( EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME )
                    .append( " != null) " )
                    .append( EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME )
                    .append( ".callOwner(\"." )
                    .append( persistentField.getName() )
                    .append( "\");" );

            writer.insertBefore( builder.toString() );
        }

        //composite types
        if ( persistentField.getAnnotation( Embedded.class ) != null ) {
            //make sure to add the CompositeOwner interface
            if ( !doClassInheritCompositeOwner( managedCtClass ) ) {
                managedCtClass.addInterface( classPool.get( "org.hibernate.engine.spi.CompositeOwner" ) );
            }
            //if a composite have a embedded field we need to implement the method as well
            if ( isComposite ) {
                createTrackChangeCompositeMethod( managedCtClass );
            }


            writer.insertBefore( cleanupPreviousOwner( persistentField ) );

            writer.insertAfter( compositeMethodBody( persistentField ) );
        }

        managedCtClass.addMethod( writer );
        return writer;
    }
    catch (Exception e) {
        throw new EnhancementException(
                String.format(
                        "Could not enhance entity class [%s] to add field writer method [%s]",
                        managedCtClass.getName(),
                        writerName
                ),
                e
        );
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号