org.springframework.data.annotation.Id Java Examples
The following examples show how to use
org.springframework.data.annotation.Id.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CosmosEntityInformation.java From spring-data-cosmosdb with MIT License | 7 votes |
private Field getIdField(Class<?> domainType) { final Field idField; final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainType, Id.class); if (fields.isEmpty()) { idField = ReflectionUtils.findField(getJavaType(), Constants.ID_PROPERTY_NAME); } else if (fields.size() == 1) { idField = fields.get(0); } else { throw new IllegalArgumentException("only one field with @Id annotation!"); } if (idField == null) { throw new IllegalArgumentException("domain should contain @Id field or field named id"); } else if (idField.getType() != String.class && idField.getType() != Integer.class && idField.getType() != int.class) { throw new IllegalArgumentException("type of id field must be String or Integer"); } return idField; }
Example #2
Source File: MetadataParser.java From spring-data-simpledb with MIT License | 6 votes |
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; }
Example #3
Source File: SpringDataJdbcAnnotationProcessor.java From infobip-spring-data-querydsl with Apache License 2.0 | 6 votes |
@Override protected Configuration createConfiguration(RoundEnvironment roundEnv) { Class<? extends Annotation> entity = Id.class; this.roundEnv = roundEnv; CodegenModule codegenModule = new CodegenModule(); JavaTypeMappings typeMappings = new JavaTypeMappings(); codegenModule.bind(TypeMappings.class, typeMappings); codegenModule.bind(QueryTypeFactory.class, new QueryTypeFactoryImpl("", "", "")); SpringDataJdbcConfiguration springDataJdbcConfiguration = new SpringDataJdbcConfiguration(roundEnv, processingEnv, entity, null, null, null, Ignored.class, typeMappings, codegenModule); this.conf = springDataJdbcConfiguration; return springDataJdbcConfiguration; }
Example #4
Source File: MongoMetadata.java From jstarcraft-core with Apache License 2.0 | 5 votes |
/** * 构造方法 * * @param metadata */ MongoMetadata(Class<?> clazz) { Document document = clazz.getAnnotation(Document.class); if (document == null) { throw new IllegalArgumentException(); } ormName = document.collection(); if (StringUtility.isBlank(ormName)) { ormName = clazz.getSimpleName(); ormName = ormName.substring(0, 1).toLowerCase() + ormName.substring(1, ormName.length()); } ormClass = clazz; ReflectionUtility.doWithFields(ormClass, (field) -> { if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) { return; } if (field.isAnnotationPresent(Version.class)) { versionName = field.getName(); return; } Class<?> type = field.getType(); fields.put(field.getName(), type); if (field.isAnnotationPresent(Id.class)) { primaryName = field.getName(); primaryClass = type; } if (field.isAnnotationPresent(Indexed.class)) { indexNames.add(field.getName()); } }); }
Example #5
Source File: ObjectPdxInstanceAdapter.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
private boolean isAtIdAnnotatedProperty(@Nullable PropertyDescriptor propertyDescriptor) { return Optional.ofNullable(propertyDescriptor) .map(PropertyDescriptor::getReadMethod) .map(method -> AnnotationUtils.findAnnotation(method, Id.class)) .isPresent(); }
Example #6
Source File: ObjectPdxInstanceAdapter.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
private @Nullable PropertyDescriptor getPropertyForAtIdAnnotatedField(@NonNull BeanWrapper beanWrapper, @Nullable Field field) { return Optional.ofNullable(field) .filter(it -> beanWrapper.isReadableProperty(it.getName())) .filter(it -> Objects.nonNull(AnnotationUtils.findAnnotation(it, Id.class))) .map(it -> beanWrapper.getPropertyDescriptor(it.getName())) .orElse(null); }
Example #7
Source File: FieldCallback.java From tutorials with MIT License | 5 votes |
@Override public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException { ReflectionUtils.makeAccessible(field); if (field.isAnnotationPresent(Id.class)) { idFound = true; } }
Example #8
Source File: MongoPersister.java From statefulj with Apache License 2.0 | 5 votes |
@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; }
Example #9
Source File: HazelcastEntityInformation.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
/** * @param entity must not be {@literal null}. */ HazelcastEntityInformation(PersistentEntity<T, ?> entity) { super(entity); if (!entity.hasIdProperty()) { throw new MappingException( String.format("Entity %s requires a field annotated with %s", entity.getName(), Id.class.getName())); } }
Example #10
Source File: Invoice.java From spring-cloud-event-sourcing-example with GNU General Public License v3.0 | 4 votes |
@Id public String getInvoiceId() { return invoiceId; }
Example #11
Source File: DynamoDBIdIsHashAndRangeKeyEntityInformationImpl.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
public DynamoDBIdIsHashAndRangeKeyEntityInformationImpl(Class<T> domainClass, DynamoDBHashAndRangeKeyExtractingEntityMetadata<T, ID> metadata) { super(domainClass, Id.class); this.metadata = metadata; this.hashAndRangeKeyExtractor = metadata.getHashAndRangeKeyExtractor(getIdType()); }
Example #12
Source File: DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
@Override public boolean isCompositeHashAndRangeKeyProperty(String propertyName) { return isFieldAnnotatedWith(propertyName, Id.class); }
Example #13
Source File: DynamoDBPersistentPropertyImpl.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
public boolean isCompositeIdProperty() { return isAnnotationPresent(Id.class); }
Example #14
Source File: StateDocument.java From statefulj with Apache License 2.0 | 4 votes |
@Id String getId();
Example #15
Source File: MongoPersistenceSupportBeanFactory.java From statefulj with Apache License 2.0 | 4 votes |
@Override public Class<? extends Annotation> getIdAnnotationType() { return Id.class; }
Example #16
Source File: ReloadTest.java From statefulj with Apache License 2.0 | 4 votes |
@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); }
Example #17
Source File: EndUser.java From omh-dsu-ri with Apache License 2.0 | 4 votes |
@Id public String getUsername() { return username; }
Example #18
Source File: Person.java From spring-reactive-playground with Apache License 2.0 | 4 votes |
@Id public String getId() { return id; }
Example #19
Source File: Stock.java From Mastering-Spring-5.1 with MIT License | 4 votes |
@Id public String getCode() { return code; }
Example #20
Source File: ObjectPdxInstanceAdapterUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Id public void setIdentifier(Object id) { }
Example #21
Source File: ObjectPdxInstanceAdapterUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Id protected Object getAccountNumber() { return "123"; }
Example #22
Source File: ObjectPdxInstanceAdapterUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Id protected String getIdentifier() { return UUID.randomUUID().toString(); }
Example #23
Source File: ObjectPdxInstanceAdapterUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Id public String getAccountNumber() { return "0x-123456789"; }
Example #24
Source File: Stock.java From Mastering-Spring-5.0 with MIT License | 4 votes |
@Id public String getCode() { return code; }
Example #25
Source File: MahutaCustomRepositoryImpl.java From Mahuta with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public MahutaCustomRepositoryImpl(Mahuta mahuta) { this.mahuta = mahuta; // Get Entity class this.entityClazz = (Class<E>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]; // Check if annotation @IPFSDocument String indexConfigurationPath = null; InputStream indexConfiguration = null; if (!entityClazz.isAnnotationPresent(IPFSDocument.class)) { this.indexName = entityClazz.getSimpleName(); this.indexContent = DEFAULT_INDEX_CONTENT; } else { IPFSDocument ipfsDocumentAnnotation = entityClazz.getAnnotation(IPFSDocument.class); // Extract indexName, if null, take class name this.indexName = !StringUtils.isEmpty(ipfsDocumentAnnotation.index()) ? ipfsDocumentAnnotation.index() : entityClazz.getSimpleName(); // Extract indexContent flag this.indexContent = ipfsDocumentAnnotation.indexContent(); // Extract indexConfiguration path and read file if present indexConfigurationPath = ipfsDocumentAnnotation.indexConfiguration(); if(!StringUtils.isEmpty(indexConfigurationPath) ) { try { indexConfiguration = new ClassPathResource(indexConfigurationPath).getInputStream(); } catch (IOException e) { throw new TechnicalException("Cannot read indexConfigutation file " + indexConfigurationPath, e); } } } // Find @Id annotation attributeId = EntityFieldUtils.extractOptionalSingleAnnotatedField(entityClazz, Id.class, ID_CLASS); // Find @Hash annotation attributeHash = EntityFieldUtils.extractOptionalSingleAnnotatedField(entityClazz, Hash.class, HASH_CLASS); // Find @Fulltext annotation this.fullTextFields = Sets.newHashSet(EntityFieldUtils.extractMultipleAnnotatedFields(entityClazz, Fulltext.class)); // Find @Indexfield annotation this.indexFields = Sets.newHashSet(EntityFieldUtils.extractMultipleAnnotatedFields(entityClazz, Indexfield.class)); this.indexFields.addAll(fullTextFields); // Create index mahuta.prepareCreateIndex(indexName).configuration(indexConfiguration).execute(); // Configure Jackson this.mapper = new ObjectMapper(); if(attributeHash.isPresent()) { mapper.addMixIn(entityClazz, JsonIgnoreHashMixIn.class); } log.info("MahutaRepository configured for class {}", entityClazz.getSimpleName()); log.trace("indexName: {}", indexName); log.trace("indexContent: {}", indexContent); log.trace("indexConfiguration: {}", indexConfigurationPath); log.trace("attributeId: {}", attributeId); log.trace("attributeHash: {}", attributeHash); log.trace("indexfieldAnnotation: {}", indexFields); log.trace("fullTextFields: {}", fullTextFields); }