微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javax.persistence.Embedded的实例源码

项目:invesdwin-context-persistence    文件ACustomIdDao.java   
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();
}
项目:Metaworks_framework    文件AdminAuditableListener.java   
@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);
        }
    }
}
项目:Metaworks_framework    文件AdminAuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField,auditable);
        }
    }
}
项目:Metaworks_framework    文件AuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateCreated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalField,auditable);
        }
    }
}
项目:Metaworks_framework    文件AuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField,auditable);
        }
    }
}
项目:SparkCommerce    文件AdminAuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),auditable);
        }
    }
}
项目:SparkCommerce    文件AdminAuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),auditable);
        }
    }
}
项目:SparkCommerce    文件AuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),auditable);
        }
    }
}
项目:SparkCommerce    文件AuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),auditable);
        }
    }
}
项目:blcdemo    文件AdminAuditableListener.java   
@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,auditable);
        }
    }
}
项目:blcdemo    文件AdminAuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),auditable);
        }
    }
}
项目:blcdemo    文件AuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),auditable);
        }
    }
}
项目:blcdemo    文件AuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(),auditable);
        }
    }
}
项目:org.fastnate    文件EntityClass.java   
/**
 * 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,override);
        } else if (EntityProperty.isEntityProperty(attribute)) {
            return new EntityProperty<>(this.context,getTable(),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,columnMetadata);
        } else {
            return new PrimitiveProperty<>(this.context,columnMetadata);
        }
    }
    return null;
}
项目:easyjweb    文件AllProcessor.java   
@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);
    }
}
项目:cosmic    文件DbUtil.java   
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;
}
项目:Metaworks_framework    文件TemporalTimestampListener.java   
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);
            }
        }
    }
}
项目:alex    文件Statistics.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner",column = @Column(name = "duration_learner")),@AttributeOverride(name = "eqOracle",column = @Column(name = "duration_eqOracle"))
})
public DetailedStatistics getDuration() {
    return duration;
}
项目:alex    文件Statistics.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner",column = @Column(name = "mqs_learner")),column = @Column(name = "mqs_eqOracle"))
})
public DetailedStatistics getMqsUsed() {
    return mqsUsed;
}
项目:alex    文件Statistics.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner",column = @Column(name = "symbolsUsed_learner")),column = @Column(name = "symbolsUsed_eqOracle"))
})
public DetailedStatistics getSymbolsUsed() {
    return symbolsUsed;
}
项目:SparkCommerce    文件TemporalTimestampListener.java   
private void setTimestamps(Field[] fields,field.get(entity));
            } finally {
                field.setAccessible(false);
            }
        }
    }
}
项目:amos-ss15-proj2    文件SuperTripSubQuery.java   
@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;
}
项目:amos-ss15-proj2    文件SuperTripSubQuery.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name= RouteLocation.COLUMN_LAT,column = @Column(name = "eLat")),column = @Column(name = "eLng"))
})
public RouteLocation getDestinationLocation() {
    return destinationLocation;
}
项目:blcdemo    文件TemporalTimestampListener.java   
private void setTimestamps(Field[] fields,field.get(entity));
            } finally {
                field.setAccessible(false);
            }
        }
    }
}
项目:petit    文件BeanMappingUtils.java   
/**
 * 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;
}
项目:cloudstack    文件DbUtil.java   
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;
}
项目:hsw    文件Veranstaltungsort.java   
@Embedded
@AttributeOverrides( {
        @AttributeOverride(name = "breite",column = @Column(name = "GEO_BREITE")),@AttributeOverride(name = "laenge",column = @Column(name = "GEO_LAENGE")) })
public GeoKoordinaten getKoordinaten() {
    return koordinaten;
}
项目:zekke-webapp    文件Place.java   
@Embedded
@AttributeOverrides({
    @AttributeOverride(name = "latitude",column = @Column(name = "latitude",nullable = false,precision = 22,scale = 0)),@AttributeOverride(name = "longitude",column = @Column(name = "longitude",scale = 0))
})
public GeoPoint getPosition() {
    return position;
}
项目:carcv    文件FileEntry.java   
/**
 * @return CarData of this FileEntry
 */
@Override
@NotNull
@Embedded
public CarData getCarData() {
    return carData;
}
项目:lams    文件Enhancer.java   
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
        );
    }
}
项目:Hibernate_Component_Mapping_Using_DAO_Using_Maven    文件person.java   
@Embedded
public Jobs getJob() {
    return job;
}
项目:webpedidos    文件Pedido.java   
@Embedded
public EnderecoEntrega getEnderecoEntrega() {
    return this.enderecoEntrega;
}
项目:oma-riista-web    文件JpaModelTest.java   
@Test
public void nullableConstraintsMustBeMutuallyConsistent() {
    final Stream<Field> FailedFields = filterFieldsOfManagedJpaTypes(field -> {
        if (field.isAnnotationPresent(Version.class) || field.isAnnotationPresent(ElementCollection.class)) {
            return false;
        }

        final boolean isPrimitive = field.getType().isPrimitive();

        final boolean notNull = field.isAnnotationPresent(NotNull.class);
        final boolean notEmpty = field.isAnnotationPresent(NotEmpty.class);
        final boolean notBlank = field.isAnnotationPresent(NotBlank.class);

        final boolean notNullOrEmpty = notNull || notEmpty || notBlank;

        final boolean embedded = field.isAnnotationPresent(Embedded.class);

        final Column column = field.getAnnotation(Column.class);
        final ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);
        final OnetoOne onetoOne = field.getAnnotation(OnetoOne.class);
        final JoinColumn joinColumn = field.getAnnotation(JoinColumn.class);

        if (column != null) {
            if (manyToOne != null && column.nullable() != manyToOne.optional() ||
                    onetoOne != null && column.nullable() != onetoOne.optional() ||
                    joinColumn != null && column.nullable() != joinColumn.nullable() ||
                    column.nullable() && (notNullOrEmpty || isPrimitive) ||
                    !isPrimitive && column.insertable() && !column.nullable() && !notNullOrEmpty) {

                return true;
            }
        }
        if (joinColumn != null) {
            if (manyToOne != null && joinColumn.nullable() != manyToOne.optional() ||
                    onetoOne != null && joinColumn.nullable() != onetoOne.optional() ||
                    joinColumn.nullable() && notNull ||
                    joinColumn.insertable() && !joinColumn.nullable() && !notNull) {

                return true;
            }
        }
        if (manyToOne != null) {
            if (!isIdField(field) && manyToOne.optional() == notNull) {
                return true;
            }
        }
        if (onetoOne != null) {
            if (!isIdField(field) && onetoOne.optional() == notNull) {
                return true;
            }
        }
        if (notNullOrEmpty && !embedded) {
            if (column == null && joinColumn == null && manyToOne == null && onetoOne == null) {
                return true;
            }
        }

        return false;
    });

    assertNoFields(FailedFields,"Entity fields should have consistency with regard to:\n" +
                    "    (1) Presence of @NotNull,@NotBlank or @NotEmpty\n" +
                    "    (2) Values of @Column.nullable,@ManyToOne.optional,@OnetoOne.optional and " +
                    "@JoinColumn.nullable\n" +
                    "    (3) Whether the type of field is primitive or not\n" +
                    "  These fields fail: ");
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。