Java 类org.springframework.data.annotation.Id 实例源码

项目:spring-data-documentdb    文件:DocumentDbEntityInformation.java   
private Field getIdField(Class<?> domainClass) {
    Field idField = null;

    final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, Id.class);

    if (fields.isEmpty()) {
        idField = ReflectionUtils.findField(getJavaType(), "id");
    } else if (fields.size() == 1) {
        idField = fields.get(0);
    } else {
        throw new IllegalArgumentException("only one field with @Id annotation!");
    }

    if (idField != null && idField.getType() != String.class) {
        throw new IllegalArgumentException("type of id field must be String");
    }
    return idField;
}
项目:spring-data-gclouddatastore    文件:GcloudDatastoreEntityInformation.java   
@SuppressWarnings("unchecked")
@Override
public ID getId(T entity) {
    Class<?> domainClass = getJavaType();
    while (domainClass != Object.class) {
        for (Field field : domainClass.getDeclaredFields()) {
            if (field.getAnnotation(Id.class) != null) {
                try {
                    return (ID) field.get(entity);
                }
                catch (IllegalArgumentException | IllegalAccessException e) {
                    BeanWrapper beanWrapper = PropertyAccessorFactory
                            .forBeanPropertyAccess(entity);
                    return (ID) beanWrapper.getPropertyValue(field.getName());
                }
            }
        }
        domainClass = domainClass.getSuperclass();
    }
    throw new IllegalStateException("id not found");
}
项目:Qihua    文件:JdbcRepository.java   
private String getPkColumns() {
  Class<T> entityType = entityInfo.getJavaType();

  Field[] fields = entityType.getDeclaredFields();
  for (Field field : fields) {
    Id idAnnotation = field.getAnnotation(Id.class);
    if (idAnnotation != null) {
      String id = idAnnotation.name();
      if (StringUtils.isEmpty(id)) {
        return underscoreName(field.getName());
      } else {
        return id;
      }
    }
  }

  return "";
}
项目:welshare    文件:BaseNeo4jDao.java   
protected <T> T getBean(Class<T> clazz, Node node) {
    try {
        T instance = clazz.newInstance();
        Iterable<String> propertyKeys = node.getPropertyKeys();
        for (String key : propertyKeys) {
            if (!key.equals(clazz.getName() + ID_SUFFIX)) {
                BeanUtils.setProperty(instance, key, node.getProperty(key));
            } else {
                BeanProperty prop = ReflectionUtils.getAnnotatedProperty(instance, Id.class);
                BeanUtils.setProperty(instance, prop.getName(), node.getProperty(key));
            }
        }
        return instance;
    } catch (Exception e) {
        throw new DataAccessResourceFailureException("Problem obtainig bean from node", e);
    }
}
项目:welshare    文件:BaseNeo4jDao.java   
@Override
public <T> T persist(T e) {
    BeanProperty id = ReflectionUtils.getAnnotatedProperty(e, Id.class);
    if (id == null) {
        throw new IllegalArgumentException("The bean must have an @Id field");
    }

    List<BeanProperty> persistentProperties = ReflectionUtils
            .getAnnotatedProperties(e, Persistent.class);
    Property[] properties = new Property[persistentProperties.size() + 1];
    properties[0] = new Property(e.getClass().getName() + ID_SUFFIX, id.getValue());
    int i = 1;
    for (BeanProperty property : persistentProperties) {
        properties[i] = new Property(property.getName(), property.getValue());
        i++;
    }

    Node node = template.createNode(properties);
    index.index(node, e.getClass().getName() + ID_SUFFIX, id.getValue());
    return e;
}
项目:spring-data-simpledb    文件:MetadataParser.java   
public static Field getIdField(Class<?> clazz) {
    Field idField = null;

    for(Field f : ReflectionUtils.getDeclaredFieldsInHierarchy(clazz)) {
        // named id or annotated with Id
        if(f.getName().equals(FIELD_NAME_DEFAULT_ID) || f.getAnnotation(Id.class) != null) {
            if(idField != null) {
                throw new MappingException("Multiple id fields detected for class " + clazz.getName());
            }
            idField = f;
        }

    }

    return idField;
}
项目:spring-data-gclouddatastore    文件:GcloudDatastoreEntityInformation.java   
@SuppressWarnings("unchecked")
@Override
public Class<ID> getIdType() {
    Class<?> domainClass = getJavaType();
    while (domainClass != Object.class) {
        for (Field field : domainClass.getDeclaredFields()) {
            if (field.getAnnotation(Id.class) != null) {
                return (Class<ID>) field.getType();
            }
        }
        domainClass = domainClass.getSuperclass();
    }
    throw new IllegalStateException("id not found");
}
项目:beyondj    文件:CascadingMongoEventListener.java   
public void doWith(Field field) throws IllegalArgumentException,
        IllegalAccessException {
    ReflectionUtils.makeAccessible(field);

    if (field.isAnnotationPresent(Id.class)) {
        idFound = true;
    }
}
项目:navi    文件:NaviUtil.java   
/**
 * 除@Id字段外,其他字段则更新
 *
 * @param <T>
 * @param dto
 * @return
 * @throws SecurityException
 * @throws IllegalArgumentException
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws ClassNotFoundException
 * @throws InstantiationException
 */
public static <T extends AbstractNaviBaseDto> Update buildUpdate(T dto) throws SecurityException, IllegalArgumentException,
    NoSuchMethodException, IllegalAccessException,
    InvocationTargetException, InstantiationException,
    ClassNotFoundException {
    Field[] fields = dto.getClass().getDeclaredFields();
    AbstractNaviBaseDto initDto = (AbstractNaviBaseDto) Class.forName(
        dto.getClass().getName(), true, dto.getClass().getClassLoader()
    ).newInstance();
    Update up = new Update();
    for (Field field : fields) {
        String fnm = field.getName();
        int finalNo = field.getModifiers() & Modifier.FINAL;
        int staticNo = field.getModifiers() & Modifier.STATIC;
        int transitNo = field.getModifiers() & Modifier.TRANSIENT;
        if (finalNo != 0 || staticNo != 0 || transitNo != 0
            || field.isAnnotationPresent(Id.class)) {
            continue;
        }
        Object newValue = dto.getValue(fnm);
        if (newValue == null || newValue.equals(initDto.getValue(fnm))) {
            continue;
        }
        up.set(fnm, newValue);
    }
    return up;
}
项目:spring-boot-starter-mybatis    文件:MappingMyBatisEntityInformation.java   
private Field getIdField(final Class<T> domainClass) {
    Field idField = null;
    for (final Field field : domainClass.getDeclaredFields()) {
        final Class type = field.getType();
        final String name = field.getName();
        if (field.isAnnotationPresent(Id.class)) {
            idField = field;
            idField.setAccessible(true);
            break;
        }
    }
    return idField;
}
项目:spring-boot-starter-mybatis    文件:MappingMyBatisEntityInformation.java   
private Field getIdField(final Class<T> domainClass) {
    Field idField = null;
    for (final Field field : domainClass.getDeclaredFields()) {
        final Class type = field.getType();
        final String name = field.getName();
        if (field.isAnnotationPresent(Id.class)) {
            idField = field;
            idField.setAccessible(true);
            break;
        }
    }
    return idField;
}
项目:denv    文件:CascadingMongoEventListener.java   
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
    ReflectionUtils.makeAccessible(field);

    if (field.isAnnotationPresent(Id.class)) {
        idFound = true;
    }
}
项目:statefulj    文件:MongoPersister.java   
@Override
protected Field findIdField(Class<?> clazz) {
    Field idField = getReferencedField(this.getClazz(), Id.class);
    if (idField == null) {
        idField = getReferencedField(this.getClazz(), javax.persistence.Id.class);
        if (idField == null) {
            idField = getReferencedField(this.getClazz(), EmbeddedId.class);
        }
    }
    return idField;
}
项目:spring-data-snowdrop    文件:GenericEntityToModelMapper.java   
@Override
public boolean matches(Field field) {
    return field.getAnnotation(Id.class) == null;
}
项目:Mastering-Spring-5.0    文件:Stock.java   
@Id
public String getCode() {
    return code;
}
项目:spring-data-objectify    文件:ObjectifyPersistentProperty.java   
public boolean isIdProperty() {
    return isAnnotationPresent(Id.class) 
           || isAnnotationPresent(com.googlecode.objectify.annotation.Id.class);
}
项目:spring-security-rest    文件:User.java   
@Id
public String getId() {
    return id;
}
项目:spring-cloud-event-sourcing-example    文件:Invoice.java   
@Id
public String getInvoiceId() {
    return invoiceId;
}
项目:switchman    文件:AbTestConfiguration.java   
@Id
@Override
public String getName() {
  return super.getName();
}
项目:spring-data-cloudant    文件:BasicCloudantPersistentProperty.java   
@Override
public boolean isExplicitIdProperty() {
    return isAnnotationPresent(Id.class);
}
项目:spring-reactive-playground    文件:Person.java   
@Id
public String getId() {
    return id;
}
项目:denv    文件:Image.java   
@Id
String getId();
项目:denv    文件:ImageConfiguration.java   
@Id
String getId();
项目:denv    文件:Environment.java   
@Id
String getId();
项目:denv    文件:EnvironmentConfiguration.java   
@Id
String getId();
项目:denv    文件:EnvironmentConfigurationVersion.java   
@Id
String getId();
项目:omh-dsu-ri    文件:EndUser.java   
@Id
public String getUsername() {
    return username;
}
项目:statefulj    文件:ReloadTest.java   
@SuppressWarnings("unchecked")
@Test
public void testReload() throws RetryException {

    Identifiable value = new Identifiable(1L);

    Class<Identifiable> clazz = Identifiable.class;
    String event = "pow";
    Finder<Identifiable, Object> finder = mock(Finder.class);
    Object context = new Object();
    ContextWrapper<Object> cw = new ContextWrapper<Object>(context);

    when(finder.find(clazz, 1L, event, context)).thenReturn(value);

    State<Identifiable> from = mock(State.class);
    State<Identifiable> to = mock(State.class);
    Persister<Identifiable> persister = mock(Persister.class);
    ApplicationContext appContext = mock(ApplicationContext.class);
    when(appContext.getAutowireCapableBeanFactory()).thenReturn(mock(AutowireCapableBeanFactory.class));

    TransitionImpl<Identifiable> transition = new TransitionImpl<Identifiable>(
            from,
            to, 
            event,
            null,
            false,
            true);

    FSM<Identifiable, Object> fsm = new FSM<Identifiable, Object>(
            "fsm", 
            persister, 
            1, 
            1, 
            Identifiable.class, 
            Id.class, 
            appContext,
            finder);

    fsm.transition(value, from, event, transition, cw);
    verify(finder).find(clazz, 1L, event, context);
}
项目:statefulj    文件:MongoPersistenceSupportBeanFactory.java   
@Override
public Class<? extends Annotation> getIdAnnotationType() {
    return Id.class;
}
项目:statefulj    文件:StateDocument.java   
@Id
String getId();
项目:spring-data-dynamodb    文件:DynamoDBPersistentPropertyImpl.java   
public boolean isCompositeIdProperty() {
    return isAnnotationPresent(Id.class);
}
项目:spring-data-dynamodb    文件:DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java   
@Override
public boolean isCompositeHashAndRangeKeyProperty(String propertyName) {
    return isFieldAnnotatedWith(propertyName, Id.class);
}
项目:spring-data-dynamodb    文件:DynamoDBIdIsHashAndRangeKeyEntityInformationImpl.java   
public DynamoDBIdIsHashAndRangeKeyEntityInformationImpl(Class<T> domainClass,
        DynamoDBHashAndRangeKeyExtractingEntityMetadata<T, ID> metadata) {
    super(domainClass, Id.class);
    this.metadata = metadata;
    this.hashAndRangeKeyExtractor = metadata.getHashAndRangeKeyExtractor(getIdType());
}