Java 类javax.persistence.EmbeddedId 实例源码
项目:crnk-framework
文件:JpaResourceFieldInformationProvider.java
@Override
public Optional<ResourceFieldType> getFieldType(BeanAttributeInformation attributeDesc) {
Optional<OneToOne> oneToOne = attributeDesc.getAnnotation(OneToOne.class);
Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class);
Optional<ManyToOne> manyToOne = attributeDesc.getAnnotation(ManyToOne.class);
Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class);
if (oneToOne.isPresent() || oneToMany.isPresent() || manyToOne.isPresent() || manyToMany.isPresent()) {
return Optional.of(ResourceFieldType.RELATIONSHIP);
}
Optional<Id> id = attributeDesc.getAnnotation(Id.class);
Optional<EmbeddedId> embeddedId = attributeDesc.getAnnotation(EmbeddedId.class);
if (id.isPresent() || embeddedId.isPresent()) {
return Optional.of(ResourceFieldType.ID);
}
return Optional.empty();
}
项目:lams
文件:InheritanceState.java
public Boolean hasIdClassOrEmbeddedId() {
if ( hasIdClassOrEmbeddedId == null ) {
hasIdClassOrEmbeddedId = false;
if ( getClassWithIdClass( true ) != null ) {
hasIdClassOrEmbeddedId = true;
}
else {
final ElementsToProcess process = getElementsToProcess();
for ( PropertyData property : process.getElements() ) {
if ( property.getProperty().isAnnotationPresent( EmbeddedId.class ) ) {
hasIdClassOrEmbeddedId = true;
break;
}
}
}
}
return hasIdClassOrEmbeddedId;
}
项目:lams
文件:ComponentPropertyHolder.java
public ComponentPropertyHolder(
Component component,
String path,
PropertyData inferredData,
PropertyHolder parent,
Mappings mappings) {
super( path, parent, inferredData.getPropertyClass(), mappings );
final XProperty embeddedXProperty = inferredData.getProperty();
setCurrentProperty( embeddedXProperty );
this.component = component;
this.isOrWithinEmbeddedId =
parent.isOrWithinEmbeddedId()
|| ( embeddedXProperty != null &&
( embeddedXProperty.isAnnotationPresent( Id.class )
|| embeddedXProperty.isAnnotationPresent( EmbeddedId.class ) ) );
this.virtual = embeddedXProperty == null;
if ( !virtual ) {
this.embeddedAttributeName = embeddedXProperty.getName();
this.attributeConversionInfoMap = processAttributeConversions( embeddedXProperty );
}
else {
embeddedAttributeName = "";
this.attributeConversionInfoMap = Collections.emptyMap();
}
}
项目:lams
文件:JPAOverriddenAnnotationReader.java
private boolean isProcessingId(XMLContext.Default defaults) {
boolean isExplicit = defaults.getAccess() != null;
boolean correctAccess =
( PropertyType.PROPERTY.equals( propertyType ) && AccessType.PROPERTY.equals( defaults.getAccess() ) )
|| ( PropertyType.FIELD.equals( propertyType ) && AccessType.FIELD
.equals( defaults.getAccess() ) );
boolean hasId = defaults.canUseJavaAnnotations()
&& ( isPhysicalAnnotationPresent( Id.class ) || isPhysicalAnnotationPresent( EmbeddedId.class ) );
//if ( properAccessOnMetadataComplete || properOverridingOnMetadataNonComplete ) {
boolean mirrorAttributeIsId = defaults.canUseJavaAnnotations() &&
( mirroredAttribute != null &&
( mirroredAttribute.isAnnotationPresent( Id.class )
|| mirroredAttribute.isAnnotationPresent( EmbeddedId.class ) ) );
boolean propertyIsDefault = PropertyType.PROPERTY.equals( propertyType )
&& !mirrorAttributeIsId;
return correctAccess || ( !isExplicit && hasId ) || ( !isExplicit && propertyIsDefault );
}
项目:cosmic
文件:GenericDaoBase.java
@DB()
protected String buildSelectByIdSql(final StringBuilder sql) {
if (_idField == null) {
return null;
}
if (_idField.getAnnotation(EmbeddedId.class) == null) {
sql.append(_table).append(".").append(DbUtil.getColumnName(_idField, null)).append(" = ? ");
} else {
final Class<?> clazz = _idField.getClass();
final AttributeOverride[] overrides = DbUtil.getAttributeOverrides(_idField);
for (final Field field : clazz.getDeclaredFields()) {
sql.append(_table).append(".").append(DbUtil.getColumnName(field, overrides)).append(" = ? AND ");
}
sql.delete(sql.length() - 4, sql.length());
}
return sql.toString();
}
项目:cosmic
文件:GenericDaoBase.java
protected T findById(final ID id, final boolean removed, final Boolean lock) {
final StringBuilder sql = new StringBuilder(_selectByIdSql);
if (!removed && _removed != null) {
sql.append(" AND ").append(_removed.first());
}
if (lock != null) {
sql.append(lock ? FOR_UPDATE_CLAUSE : SHARE_MODE_CLAUSE);
}
final TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
if (_idField.getAnnotation(EmbeddedId.class) == null) {
prepareAttribute(1, pstmt, _idAttributes.get(_table)[0], id);
}
final ResultSet rs = pstmt.executeQuery();
return rs.next() ? toEntityBean(rs, true) : null;
} catch (final SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + pstmt, e);
}
}
项目:xap-openspaces
文件:StoreManager.java
/**
* Validates the provided class' annotations.
* Currently the only validation performed is for @Id & @SpaceId annotations
* that must be declared on the same getter.
*/
private void validateClassAnnotations(Class<?> type) {
// Validation is only relevant for Entities
if (type.getAnnotation(Entity.class) == null)
return;
for (Method getter : type.getMethods()) {
if (!getter.getName().startsWith("get"))
continue;
SpaceId spaceId = getter.getAnnotation(SpaceId.class);
boolean hasJpaId = getter.getAnnotation(Id.class) != null || getter.getAnnotation(EmbeddedId.class) != null;
if (spaceId != null || hasJpaId) {
if (!hasJpaId || spaceId == null)
throw new IllegalArgumentException("SpaceId and Id annotations must both be declared on the same property in JPA entities in type: " + type.getName());
if (spaceId.autoGenerate()) {
GeneratedValue generatedValue = getter.getAnnotation(GeneratedValue.class);
if (generatedValue == null || generatedValue.strategy() != GenerationType.IDENTITY)
throw new IllegalArgumentException(
"SpaceId with autoGenerate=true annotated property should also have a JPA GeneratedValue annotation with strategy = GenerationType.IDENTITY.");
}
break;
}
}
}
项目:IGSN
文件:RasterColumns.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "RTableCatalog", column = @Column(name = "r_table_catalog")),
@AttributeOverride(name = "RTableSchema", column = @Column(name = "r_table_schema")),
@AttributeOverride(name = "RTableName", column = @Column(name = "r_table_name")),
@AttributeOverride(name = "RRasterColumn", column = @Column(name = "r_raster_column")),
@AttributeOverride(name = "srid", column = @Column(name = "srid")),
@AttributeOverride(name = "scaleX", column = @Column(name = "scale_x", precision = 17, scale = 17)),
@AttributeOverride(name = "scaleY", column = @Column(name = "scale_y", precision = 17, scale = 17)),
@AttributeOverride(name = "blocksizeX", column = @Column(name = "blocksize_x")),
@AttributeOverride(name = "blocksizeY", column = @Column(name = "blocksize_y")),
@AttributeOverride(name = "sameAlignment", column = @Column(name = "same_alignment")),
@AttributeOverride(name = "regularBlocking", column = @Column(name = "regular_blocking")),
@AttributeOverride(name = "numBands", column = @Column(name = "num_bands")),
@AttributeOverride(name = "pixelTypes", column = @Column(name = "pixel_types")),
@AttributeOverride(name = "nodataValues", column = @Column(name = "nodata_values")),
@AttributeOverride(name = "outDb", column = @Column(name = "out_db")),
@AttributeOverride(name = "extent", column = @Column(name = "extent")) })
public RasterColumnsId getId() {
return this.id;
}
项目:comparison
文件:BeanUtils.java
public static String getIdProp(Class c){
for(Method m : c.getMethods()){
boolean isGetter = m.getName().startsWith("get");
boolean noParameters = (m.getParameterTypes().length == 0);
boolean notGetClass = !m.getName().equals("getClass");
if (isGetter && noParameters && notGetClass) {
boolean hasIdMethod = m.isAnnotationPresent(Id.class) || m.isAnnotationPresent(EmbeddedId.class);
String fieldName = acessorToProperty(m.getName());
boolean hasIdField = isIdField(c, fieldName);
if(hasIdMethod || hasIdField){
return fieldName;
}
}
}
return null;
}
项目:SyncRunner-Pub
文件:SkuShoeView.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "skuItem", column = @Column(name = "SKU_Item", length = 13)),
@AttributeOverride(name = "upc", column = @Column(name = "UPC", length = 12)),
@AttributeOverride(name = "sku", column = @Column(name = "SKU", length = 6)),
@AttributeOverride(name = "itemNumber", column = @Column(name = "Item_Number", length = 6)),
@AttributeOverride(name = "brand", column = @Column(name = "Brand", nullable = false, length = 45)),
@AttributeOverride(name = "style", column = @Column(name = "Style", nullable = false, length = 45)),
@AttributeOverride(name = "colorMap", column = @Column(name = "Color_Map", length = 45)),
@AttributeOverride(name = "color", column = @Column(name = "Color", length = 45)),
@AttributeOverride(name = "sizeMap", column = @Column(name = "Size_Map", length = 45)),
@AttributeOverride(name = "size", column = @Column(name = "Size", length = 45)),
@AttributeOverride(name = "sortSize", column = @Column(name = "Sort_Size", nullable = false)),
@AttributeOverride(name = "inStock", column = @Column(name = "In_Stock", precision = 23, scale = 0)),
@AttributeOverride(name = "material", column = @Column(name = "Material", nullable = false, length = 45)),
@AttributeOverride(name = "shoeType", column = @Column(name = "Shoe_Type", nullable = false, length = 4)),
@AttributeOverride(name = "description", column = @Column(name = "Description", nullable = false, length = 11)) })
public SkuShoeViewId getId() {
return this.id;
}
项目:org.fastnate
文件:EntityClass.java
/**
* Fills the {@link #properties}.
*
* @param c
* the currently inspected class
* @param stopClass
* the class in the hierarchy to stop inspecting
*/
private void buildProperties(final Class<? super E> c, final Class<? super E> stopClass) {
// Fill properties of super classes (at least until we find the joined parent class)
if (c.getSuperclass() != null && c.getSuperclass() != stopClass) {
buildProperties(c.getSuperclass(), stopClass);
}
// And now fill the properties of this class
if (c.isAnnotationPresent(MappedSuperclass.class) || c.isAnnotationPresent(Entity.class)) {
for (final AttributeAccessor field : this.accessStyle.getDeclaredAttributes(c, this.entityClass)) {
if (!field.isAnnotationPresent(EmbeddedId.class) && !field.isAnnotationPresent(Id.class)) {
final Property<E, ?> property = buildProperty(field, getColumnAnnotation(field),
this.associationOverrides.get(field.getName()));
if (property != null) {
this.properties.put(field.getName(), property);
this.allProperties.add(property);
if (property instanceof SingularProperty) {
buildUniqueProperty((SingularProperty<E, ?>) property);
}
}
}
}
}
}
项目:org.fastnate
文件:EntityClass.java
private boolean findIdProperty(final Iterable<AttributeAccessor> declaredAttributes) {
for (final AttributeAccessor attribute : declaredAttributes) {
if (attribute.isAnnotationPresent(EmbeddedId.class)) {
this.idProperty = new EmbeddedProperty<>(this, attribute);
return true;
} else if (attribute.isAnnotationPresent(Id.class)) {
if (attribute.isAnnotationPresent(GeneratedValue.class)) {
this.context.registerGenerators(attribute, this.table);
this.idProperty = new GeneratedIdProperty<>(this, attribute, getColumnAnnotation(attribute));
} else {
this.idProperty = buildProperty(attribute, getColumnAnnotation(attribute),
this.associationOverrides.get(attribute.getName()));
}
return true;
}
}
return false;
}
项目:cloudstack
文件:GenericDaoBase.java
@DB()
protected String buildSelectByIdSql(final StringBuilder sql) {
if (_idField == null) {
return null;
}
if (_idField.getAnnotation(EmbeddedId.class) == null) {
sql.append(_table).append(".").append(DbUtil.getColumnName(_idField, null)).append(" = ? ");
} else {
final Class<?> clazz = _idField.getClass();
final AttributeOverride[] overrides = DbUtil.getAttributeOverrides(_idField);
for (final Field field : clazz.getDeclaredFields()) {
sql.append(_table).append(".").append(DbUtil.getColumnName(field, overrides)).append(" = ? AND ");
}
sql.delete(sql.length() - 4, sql.length());
}
return sql.toString();
}
项目:cloudstack
文件:GenericDaoBase.java
protected T findById(ID id, boolean removed, Boolean lock) {
StringBuilder sql = new StringBuilder(_selectByIdSql);
if (!removed && _removed != null) {
sql.append(" AND ").append(_removed.first());
}
if (lock != null) {
sql.append(lock ? FOR_UPDATE_CLAUSE : SHARE_MODE_CLAUSE);
}
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
if (_idField.getAnnotation(EmbeddedId.class) == null) {
prepareAttribute(1, pstmt, _idAttributes.get(_table)[0], id);
}
ResultSet rs = pstmt.executeQuery();
return rs.next() ? toEntityBean(rs, true) : null;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + pstmt, e);
}
}
项目:howsun-javaee-framework
文件:HibernateGenericDao.java
private <T> Field getIdField(Class<T> entityClass){
Field idField = ID_FIELD.get(entityClass);
if(idField != null){
return idField;
}
List<Field> fields = new ArrayList<Field>();
Beans.getDeclaredFields(fields, entityClass);
for(Field f : fields){
if(f.getAnnotation(Id.class) != null || f.getAnnotation(EmbeddedId.class) != null){
idField = f;
}
}
ID_FIELD.put(entityClass, idField);
Asserts.notNull(idField, String.format("%s实体中没有ID字段", entityClass));
return idField;
}
项目:GitHub
文件:Payment.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "customerNumber", column = @Column(name = "customerNumber", nullable = false)),
@AttributeOverride(name = "checkNumber", column = @Column(name = "checkNumber", nullable = false, length = 50)) })
public PaymentId getId() {
return this.id;
}
项目:spring-data-generator
文件:RepositoryStructure.java
@SuppressWarnings("unchecked")
private Tuple<String, Boolean> getEntityId(String entityClass){
try {
Class<?> entity = null;
if (loader == null) {
entity = Class.forName(entityClass);
} else {
entity = loader.getUrlClassLoader().loadClass(entityClass);
}
while (entity != null){
for (Field field : entity.getDeclaredFields()) {
if (field.isAnnotationPresent(Id.class) || field.isAnnotationPresent(EmbeddedId.class)) {
this.implementsSerializable(field.getType());
return new Tuple<>(field.getType().getName(), this.isCustomType(field.getType()));
}
}
for (Method method : entity.getDeclaredMethods()) {
if (!method.getReturnType().equals(Void.TYPE) && (method.isAnnotationPresent(Id.class) || method.isAnnotationPresent(EmbeddedId.class))) {
this.implementsSerializable(method.getReturnType());
return new Tuple<>(method.getReturnType().getName(), this.isCustomType(method.getReturnType()));
}
}
entity = entity.getSuperclass();
}
error = SDLogger.addError("Repository Error: Primary key not found in " + GeneratorUtils.getSimpleClassName(entityClass) + ".java");
return null;
} catch (GeneratorException ex) {
error = SDLogger.addError(ex.getMessage());
return null;
} catch (Exception e) {
error = SDLogger.addError("Repository Error: Failed to access entity " + GeneratorUtils.getSimpleClassName(entityClass) + ".java");
return null;
}
}
项目:lams
文件:AnnotationBinder.java
private static void processId(
PropertyHolder propertyHolder,
PropertyData inferredData,
SimpleValue idValue,
HashMap<String, IdGenerator> classGenerators,
boolean isIdentifierMapper,
Mappings mappings) {
if ( isIdentifierMapper ) {
throw new AnnotationException(
"@IdClass class should not have @Id nor @EmbeddedId properties: "
+ BinderHelper.getPath( propertyHolder, inferredData )
);
}
XClass returnedClass = inferredData.getClassOrElement();
XProperty property = inferredData.getProperty();
//clone classGenerator and override with local values
HashMap<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
localGenerators.putAll( buildLocalGenerators( property, mappings ) );
//manage composite related metadata
//guess if its a component and find id data access (property, field etc)
final boolean isComponent = returnedClass.isAnnotationPresent( Embeddable.class )
|| property.isAnnotationPresent( EmbeddedId.class );
GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
String generatorType = generatedValue != null ?
generatorType( generatedValue.strategy(), mappings ) :
"assigned";
String generatorName = generatedValue != null ?
generatedValue.generator() :
BinderHelper.ANNOTATION_STRING_DEFAULT;
if ( isComponent ) {
generatorType = "assigned";
} //a component must not have any generator
BinderHelper.makeIdGenerator( idValue, generatorType, generatorName, mappings, localGenerators );
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Bind {0} on {1}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName() );
}
}
项目:rpb
文件:JpaUtil.java
private static boolean isManuallyAssigned(Method method) {
if (method.getAnnotation(Id.class) != null) {
return method.getAnnotation(GeneratedValue.class) == null;
} else if (method.getAnnotation(EmbeddedId.class) != null) {
return true;
} else {
return true;
}
}
项目:rpb
文件:JpaUtil.java
public static <T extends Identifiable<?>> String compositePkPropertyName(T entity) {
for (Method m : entity.getClass().getMethods()) {
if (m.getAnnotation(EmbeddedId.class) != null) {
return BeanUtils.findPropertyForMethod(m).getName();
}
}
for (Field f : entity.getClass().getFields()) {
if (f.getAnnotation(EmbeddedId.class) != null) {
return f.getName();
}
}
return null;
}
项目: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;
}
项目:katharsis-framework
文件:AbstractEntityMetaProvider.java
private void setKey(T meta) {
if (meta.getPrimaryKey() == null) {
boolean generated = false;
ArrayList<MetaAttribute> pkElements = new ArrayList<>();
for (MetaAttribute attr : meta.getAttributes()) {
if (attr.getAnnotation(Id.class) != null || attr.getAnnotation(EmbeddedId.class) != null) {
pkElements.add(attr);
boolean attrGenerated = attr.getAnnotation(GeneratedValue.class) != null;
if (pkElements.size() == 1) {
generated = attrGenerated;
} else if (generated != attrGenerated) {
throw new IllegalStateException(
"cannot mix generated and not-generated primary key elements for " + meta.getId());
}
}
}
if (!pkElements.isEmpty()) {
MetaPrimaryKey primaryKey = new MetaPrimaryKey();
primaryKey.setName(meta.getName() + "$primaryKey");
primaryKey.setElements(pkElements);
primaryKey.setUnique(true);
primaryKey.setParent(meta, true);
primaryKey.setGenerated(generated);
meta.setPrimaryKey(primaryKey);
}
}
}
项目:katharsis-framework
文件:AbstractEntityMetaProvider.java
private boolean hasJpaAnnotations(MetaAttribute attribute) {
List<Class<? extends Annotation>> annotationClasses = Arrays.asList(Id.class, EmbeddedId.class, Column.class,
ManyToMany.class, ManyToOne.class, OneToMany.class, OneToOne.class, Version.class,
ElementCollection.class);
for (Class<? extends Annotation> annotationClass : annotationClasses) {
if (attribute.getAnnotation(annotationClass) != null) {
return true;
}
}
return false;
}
项目:jpa-unit
文件:EntityUtils.java
private static void collectIdNamesFromFields(final List<String> idList, final Class<?> clazz) {
for (final Field field : clazz.getDeclaredFields()) {
if (field.getAnnotation(Id.class) != null) {
idList.add(getPropertyName(field));
} else if (field.getAnnotation(EmbeddedId.class) != null) {
final Class<?> fieldType = field.getType();
// all fields have to be used as a composite ID
for (final Field idField : fieldType.getDeclaredFields()) {
idList.add(field.getName() + "." + getPropertyName(idField));
}
}
}
}
项目:jpa-unit
文件:EntityUtilsTest.java
@Test
public void testGetNamesOfIdPropertiesFromASingleClassHavingAFieldAnnotatedWithEmbeddedId() throws Exception {
// GIVEN
final String simpleClassName = "EntityClass";
final String compositeIdPropertyName = "compositeKey";
final String id1PropertyName = "key1";
final String id2PropertyName = "key2";
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType");
jIdTypeClass.annotate(Embeddable.class);
jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName);
jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName);
final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName);
jClass.annotate(Entity.class);
jClass.field(JMod.PRIVATE, jIdTypeClass, compositeIdPropertyName).annotate(EmbeddedId.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> entityClass = loadClass(testFolder.getRoot(), jClass.name());
// WHEN
final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass);
// THEN
assertThat(namesOfIdProperties.size(), equalTo(2));
assertThat(namesOfIdProperties,
hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName));
}
项目:jpa-unit
文件:EntityUtilsTest.java
@Test
public void testGetNamesOfIdPropertiesFromASingleClassHavingAMethodAnnotatedWithEmbeddedId() throws Exception {
// GIVEN
final String simpleClassName = "EntityClass";
final String compositeIdPropertyName = "compositeKey";
final String id1PropertyName = "key1";
final String id2PropertyName = "key2";
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType");
jIdTypeClass.annotate(Embeddable.class);
jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName);
jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName);
final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName);
jClass.annotate(Entity.class);
final JMethod method = jClass.method(JMod.PUBLIC, jIdTypeClass, "getCompositeKey");
method.annotate(EmbeddedId.class);
method.body()._return(JExpr._null());
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> entityClass = loadClass(testFolder.getRoot(), jClass.name());
// WHEN
final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass);
// THEN
assertThat(namesOfIdProperties.size(), equalTo(2));
assertThat(namesOfIdProperties,
hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName));
}
项目:jpa-unit
文件:EntityUtilsTest.java
@Test
public void testGetNamesOfIdPropertiesFromAClassHierarchyHavingAFieldAnnotatedWithEmbeddedId() throws Exception {
// GIVEN
final String simpleClassNameBase = "EntityClass";
final String simpleClassNameB = "SubEntityClass";
final String compositeIdPropertyName = "compositeKey";
final String id1PropertyName = "key1";
final String id2PropertyName = "key2";
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType");
jIdTypeClass.annotate(Embeddable.class);
jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName);
jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName);
final JDefinedClass jBaseClass = jp._class(JMod.PUBLIC, simpleClassNameBase);
jBaseClass.annotate(Entity.class);
jBaseClass.annotate(Inheritance.class).param("strategy", InheritanceType.TABLE_PER_CLASS);
jBaseClass.field(JMod.PRIVATE, jIdTypeClass, compositeIdPropertyName).annotate(EmbeddedId.class);
final JDefinedClass jSubclass = jp._class(JMod.PUBLIC, simpleClassNameB)._extends(jBaseClass);
jSubclass.annotate(Entity.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> entityClass = loadClass(testFolder.getRoot(), jSubclass.name());
// WHEN
final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass);
// THEN
assertThat(namesOfIdProperties.size(), equalTo(2));
assertThat(namesOfIdProperties,
hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName));
}
项目:jpa-unit
文件:EntityUtilsTest.java
@Test
public void testGetNamesOfIdPropertiesFromAClassHierarchyHavingAMethodAnnotatedWithEmbeddedId() throws Exception {
// GIVEN
final String simpleClassNameBase = "EntityClass";
final String simpleClassNameB = "SubEntityClass";
final String compositeIdPropertyName = "compositeKey";
final String id1PropertyName = "key1";
final String id2PropertyName = "key2";
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType");
jIdTypeClass.annotate(Embeddable.class);
jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName);
jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName);
final JDefinedClass jBaseClass = jp._class(JMod.PUBLIC, simpleClassNameBase);
jBaseClass.annotate(Entity.class);
jBaseClass.annotate(Inheritance.class).param("strategy", InheritanceType.TABLE_PER_CLASS);
final JMethod method = jBaseClass.method(JMod.PUBLIC, jIdTypeClass, "getCompositeKey");
method.annotate(EmbeddedId.class);
method.body()._return(JExpr._null());
final JDefinedClass jSubclass = jp._class(JMod.PUBLIC, simpleClassNameB)._extends(jBaseClass);
jSubclass.annotate(Entity.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> entityClass = loadClass(testFolder.getRoot(), jSubclass.name());
// WHEN
final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass);
// THEN
assertThat(namesOfIdProperties.size(), equalTo(2));
assertThat(namesOfIdProperties,
hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName));
}
项目:bygle-ldp
文件:Relations.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "refIdRecord1", column = @Column(name = "ref_id_record_1", nullable = false)),
@AttributeOverride(name = "refIdRecord2", column = @Column(name = "ref_id_record_2", nullable = false)),
@AttributeOverride(name = "refIdRelationType", column = @Column(name = "ref_id_relation_type", nullable = false)) })
public RelationsId getId() {
return this.id;
}
项目:submerge
文件:UserAuthorities.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "fkIdAccount", column = @Column(name = "fk_id_account", nullable = false)),
@AttributeOverride(name = "fkIdAuthorities", column = @Column(name = "fk_id_authorities", nullable = false)) })
public UserAuthoritiesId getId() {
return this.id;
}
项目:karaf4-eclipselink-jpa
文件:JpaUtil.java
private static boolean isManuallyAssigned(final Method method) {
if (method.getAnnotation(Id.class) != null) {
return method.getAnnotation(GeneratedValue.class) == null;
} else if (method.getAnnotation(EmbeddedId.class) != null) {
return true;
} else {
return true;
}
}
项目:rpb
文件:JpaUtil.java
private static boolean isManuallyAssigned(Method method) {
if (method.getAnnotation(Id.class) != null) {
return method.getAnnotation(GeneratedValue.class) == null;
} else if (method.getAnnotation(EmbeddedId.class) != null) {
return true;
} else {
return true;
}
}
项目:rpb
文件:JpaUtil.java
public static <T extends Identifiable<?>> String compositePkPropertyName(T entity) {
for (Method m : entity.getClass().getMethods()) {
if (m.getAnnotation(EmbeddedId.class) != null) {
return BeanUtils.findPropertyForMethod(m).getName();
}
}
for (Field f : entity.getClass().getFields()) {
if (f.getAnnotation(EmbeddedId.class) != null) {
return f.getName();
}
}
return null;
}
项目:sample-java-spring-genericdao
文件:StudentClasses.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "studentId", column = @Column(name = "STUDENT_ID", nullable = false, precision = 5, scale = 0)),
@AttributeOverride(name = "classesId", column = @Column(name = "CLASSES_ID", nullable = false, precision = 4, scale = 0)),
@AttributeOverride(name = "status", column = @Column(name = "STU_CLASSES_STATUS", nullable = false, length = 1)) })
public StudentClassesId getId() {
return this.id;
}
项目:nics-common
文件:Assignment.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "unitId", column = @Column(name = "unit_id", nullable = false)),
@AttributeOverride(name = "operationalPeriodId", column = @Column(name = "operational_period_id", nullable = false)) })
public AssignmentId getId() {
return this.id;
}
项目:pedal-dialect
文件:EmbeddedIdColumnEvaluator.java
@Override
public void evaluate(Method method, EvaluatorChain chain) {
if (method.isAnnotationPresent(EmbeddedId.class)) {
Map<String, AttributeOverride> overrides = getAttributeOverrides(method);
Class<?> embeddedClz = method.getReturnType();
BeanInfo info = null;
try {
info = Introspector.getBeanInfo(embeddedClz);
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
for (String propertyName : overrides.keySet()) {
for (PropertyDescriptor propDesc : info.getPropertyDescriptors()) {
if (propDesc.getName().equals(propertyName)) {
CopyAttribute attribute = new CopyAttribute();
attribute.getMethods().add(method);
attribute.getMethods().add(propDesc.getReadMethod());
attribute.setColumnName(overrides.get(propertyName).column().name());
chain.add(attribute);
break;
}
}
}
} else {
chain.doNext();
}
}
项目:pedal-dialect
文件:Planet.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "name", column = @Column(name = "name", nullable = false)),
@AttributeOverride(name = "position", column = @Column(name = "position", nullable = false)) })
public PlanetId getId() {
return id;
}
项目:watchout
文件:PlayersHasInsurances.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "playersIdplayers", column = @Column(name = "players_idplayers", nullable = false)),
@AttributeOverride(name = "insurancesIdinsurances", column = @Column(name = "insurances_idinsurances", nullable = false)) })
public PlayersHasInsurancesId getId() {
return this.id;
}
项目:watchout
文件:TurnsHistory.java
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "playersHasQuestsPlayersIdplayers", column = @Column(name = "players_has_quests_players_idplayers", nullable = false)),
@AttributeOverride(name = "playersHasQuestsQuestsIdquests", column = @Column(name = "players_has_quests_quests_idquests", nullable = false)),
@AttributeOverride(name = "placesHasTransportsPlacesOrigin", column = @Column(name = "places_has_transports_places_origin", nullable = false)),
@AttributeOverride(name = "placesHasTransportsTransportation", column = @Column(name = "places_has_transports_transportation", nullable = false)),
@AttributeOverride(name = "placesHasTransportsPlacesDestination", column = @Column(name = "places_has_transports_places_destination", nullable = false)) })
public TurnsHistoryId getId() {
return this.id;
}