當前位置: 首頁>>代碼示例>>Java>>正文


Java Id類代碼示例

本文整理匯總了Java中org.springframework.data.annotation.Id的典型用法代碼示例。如果您正苦於以下問題:Java Id類的具體用法?Java Id怎麽用?Java Id使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Id類屬於org.springframework.data.annotation包,在下文中一共展示了Id類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getIdField

import org.springframework.data.annotation.Id; //導入依賴的package包/類
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;
}
 
開發者ID:Microsoft,項目名稱:spring-data-documentdb,代碼行數:19,代碼來源:DocumentDbEntityInformation.java

示例2: getId

import org.springframework.data.annotation.Id; //導入依賴的package包/類
@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");
}
 
開發者ID:tkob,項目名稱:spring-data-gclouddatastore,代碼行數:22,代碼來源:GcloudDatastoreEntityInformation.java

示例3: getPkColumns

import org.springframework.data.annotation.Id; //導入依賴的package包/類
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 "";
}
 
開發者ID:nickevin,項目名稱:Qihua,代碼行數:19,代碼來源:JdbcRepository.java

示例4: getBean

import org.springframework.data.annotation.Id; //導入依賴的package包/類
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);
    }
}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:18,代碼來源:BaseNeo4jDao.java

示例5: persist

import org.springframework.data.annotation.Id; //導入依賴的package包/類
@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;
}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:22,代碼來源:BaseNeo4jDao.java

示例6: getIdField

import org.springframework.data.annotation.Id; //導入依賴的package包/類
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;
}
 
開發者ID:3pillarlabs,項目名稱:spring-data-simpledb,代碼行數:17,代碼來源:MetadataParser.java

示例7: getIdType

import org.springframework.data.annotation.Id; //導入依賴的package包/類
@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");
}
 
開發者ID:tkob,項目名稱:spring-data-gclouddatastore,代碼行數:15,代碼來源:GcloudDatastoreEntityInformation.java

示例8: doWith

import org.springframework.data.annotation.Id; //導入依賴的package包/類
public void doWith(Field field) throws IllegalArgumentException,
		IllegalAccessException {
	ReflectionUtils.makeAccessible(field);

	if (field.isAnnotationPresent(Id.class)) {
		idFound = true;
	}
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:9,代碼來源:CascadingMongoEventListener.java

示例9: buildUpdate

import org.springframework.data.annotation.Id; //導入依賴的package包/類
/**
 * 除@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;
}
 
開發者ID:sunguangran,項目名稱:navi,代碼行數:41,代碼來源:NaviUtil.java

示例10: getIdField

import org.springframework.data.annotation.Id; //導入依賴的package包/類
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;
}
 
開發者ID:create1st,項目名稱:spring-boot-starter-mybatis,代碼行數:14,代碼來源:MappingMyBatisEntityInformation.java

示例11: doWith

import org.springframework.data.annotation.Id; //導入依賴的package包/類
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
    ReflectionUtils.makeAccessible(field);

    if (field.isAnnotationPresent(Id.class)) {
        idFound = true;
    }
}
 
開發者ID:ssouporg,項目名稱:denv,代碼行數:8,代碼來源:CascadingMongoEventListener.java

示例12: findIdField

import org.springframework.data.annotation.Id; //導入依賴的package包/類
@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;
}
 
開發者ID:statefulj,項目名稱:statefulj,代碼行數:12,代碼來源:MongoPersister.java

示例13: matches

import org.springframework.data.annotation.Id; //導入依賴的package包/類
@Override
public boolean matches(Field field) {
    return field.getAnnotation(Id.class) == null;
}
 
開發者ID:snowdrop,項目名稱:spring-data-snowdrop,代碼行數:5,代碼來源:GenericEntityToModelMapper.java

示例14: getCode

import org.springframework.data.annotation.Id; //導入依賴的package包/類
@Id
public String getCode() {
	return code;
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Spring-5.0,代碼行數:5,代碼來源:Stock.java

示例15: isIdProperty

import org.springframework.data.annotation.Id; //導入依賴的package包/類
public boolean isIdProperty() {
    return isAnnotationPresent(Id.class) 
           || isAnnotationPresent(com.googlecode.objectify.annotation.Id.class);
}
 
開發者ID:nhuttrung,項目名稱:spring-data-objectify,代碼行數:5,代碼來源:ObjectifyPersistentProperty.java


注:本文中的org.springframework.data.annotation.Id類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。