me.ahoo.cosid.spring.data.jdbc.IdAnnotationDefinitionParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cosid-spring-data-jdbc Show documentation
Show all versions of cosid-spring-data-jdbc Show documentation
Universal, flexible, high-performance distributed ID generator.
The newest version!
/*
* Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)].
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.ahoo.cosid.spring.data.jdbc;
import me.ahoo.cosid.accessor.IdDefinition;
import me.ahoo.cosid.accessor.parser.FieldDefinitionParser;
import me.ahoo.cosid.provider.IdGeneratorProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.annotation.Id;
import java.lang.reflect.Field;
import java.util.List;
/**
* Id Annotation FieldDefinitionParser.
*
* @author ahoo wang
* @see org.springframework.data.annotation.Id
*/
@Slf4j
public class IdAnnotationDefinitionParser implements FieldDefinitionParser {
public static final IdAnnotationDefinitionParser INSTANCE = new IdAnnotationDefinitionParser();
@Override
public IdDefinition parse(List> lookupClassList, Field field) {
Id fieldId = field.getAnnotation(Id.class);
if (null == fieldId) {
return IdDefinition.NOT_FOUND;
}
return new IdDefinition(IdGeneratorProvider.SHARE, field);
}
}