io.requery.Entity Java Examples

The following examples show how to use io.requery.Entity. 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: EntityType.java    From requery with Apache License 2.0 6 votes vote down vote up
@Override
public String modelName() {
    // it's important that the AnnotationMirror is used here since the model name needs to be
    // known before process() is called
    if (Mirrors.findAnnotationMirror(element(), Entity.class).isPresent()) {
        return Mirrors.findAnnotationMirror(element(), Entity.class)
                .flatMap(mirror -> Mirrors.findAnnotationValue(mirror, "model"))
                .map(value -> value.getValue().toString())
                .filter(name -> !Names.isEmpty(name))
                .orElse("default");
    } else if (Mirrors.findAnnotationMirror(element(),
            javax.persistence.Entity.class).isPresent()) {
        Elements elements = processingEnvironment.getElementUtils();
        Name packageName = elements.getPackageOf(element()).getQualifiedName();
        String[] parts = packageName.toString().split("\\.");
        return parts[parts.length - 1];
    }
    return "";
}
 
Example #2
Source File: EntityType.java    From requery with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<TypeMirror> builderType() {
    Optional<Entity> entityAnnotation = annotationOf(Entity.class);
    if (entityAnnotation.isPresent()) {
        Entity entity = entityAnnotation.get();
        Elements elements = processingEnvironment.getElementUtils();
        TypeMirror mirror = null;
        try {
            Class<?> builderClass = entity.builder(); // easiest way to get the class TypeMirror
            if (builderClass != void.class) {
                mirror = elements.getTypeElement(builderClass.getName()).asType();
            }
        } catch (MirroredTypeException typeException) {
            mirror = typeException.getTypeMirror();
        }
        if (mirror != null && mirror.getKind() != TypeKind.VOID) {
            return Optional.of(mirror);
        }
    }
    if (builderFactoryMethod().isPresent()) {
        return Optional.of(builderFactoryMethod().get().getReturnType());
    }
    return ElementFilter.typesIn(element().getEnclosedElements()).stream()
            .filter(element -> element.getSimpleName().toString().contains("Builder"))
            .map(Element::asType)
            .filter(Objects::nonNull)
            .filter(type -> type.getKind() != TypeKind.VOID)
            .findFirst();
}
 
Example #3
Source File: EntityProcessor.java    From requery with Apache License 2.0 4 votes vote down vote up
private boolean isEntity(TypeElement element) {
    return Mirrors.findAnnotationMirror(element, Entity.class).isPresent() ||
        (getOption(GENERATE_JPA, true) &&
         Mirrors.findAnnotationMirror(element, javax.persistence.Entity.class).isPresent());
}
 
Example #4
Source File: EntityType.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyNameStyle propertyNameStyle() {
    return annotationOf(Entity.class)
            .map(Entity::propertyNameStyle)
            .orElse(PropertyNameStyle.BEAN);
}
 
Example #5
Source File: EntityType.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public PropertyVisibility propertyVisibility() {
    return annotationOf(Entity.class)
            .map(Entity::propertyVisibility)
            .orElse(PropertyVisibility.PRIVATE);
}
 
Example #6
Source File: EntityType.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCacheable() {
    return annotationOf(Entity.class).map(Entity::cacheable)
        .orElse( annotationOf(Cacheable.class).map(Cacheable::value).orElse(true));
}
 
Example #7
Source File: EntityType.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isCopyable() {
    return annotationOf(Entity.class).map(Entity::copyable).orElse(false);
}
 
Example #8
Source File: EntityType.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isImmutable() {
    // check known immutable type annotations then check the annotation value
    return ImmutableAnnotationKind.of(element()).isPresent() || isUnimplementable() ||
            annotationOf(Entity.class).map(Entity::immutable).orElse(false);
}
 
Example #9
Source File: EntityType.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isStateless() {
    return isImmutable() || isUnimplementable() ||
        annotationOf(Entity.class).map(Entity::stateless).orElse(false);
}
 
Example #10
Source File: EntityType.java    From requery with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isUnimplementable() {
    boolean extendable = annotationOf(Entity.class).map(Entity::extendable).orElse(true);
    return !extendable || (element().getKind().isClass() &&
        element().getModifiers().contains(Modifier.FINAL));
}