com.wesleyhome.dao.processor.model.EntityInfo.java Source code

Java tutorial

Introduction

Here is the source code for com.wesleyhome.dao.processor.model.EntityInfo.java

Source

/*
 * Copyright 2014 Justin Wesley
 *
 * 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 com.wesleyhome.dao.processor.model;

import java.util.ArrayList;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.persistence.Entity;
import org.apache.commons.lang3.StringUtils;
import com.wesleyhome.dao.annotations.ScopeType;
import com.wesleyhome.dao.processor.AnnotationHelperImpl;

/**
 * The <code>GeneratedQuery</code> class is a
 *
 * @author
 * @since
 */
public class EntityInfo implements Comparable<EntityInfo> {
    private final TypeElement typeElement;
    private final String subPackageName;
    private final String fullEntityClassName;
    private final String entityName;
    private final ScopeType scopeType;
    private final List<CustomQueryInfo> customQueryInfoList;
    private final List<QueryParameterInfo> queryParameterInfoList;
    private final List<Element> idElements;
    private EntityInfo superClassInfo;
    private final List<EntityInfo> subClassList;
    private final boolean cacheable;
    private final boolean findAll;
    private final boolean paginateFindAll;
    private final boolean filterable;

    /**
     * @param typeElement
     * @param subPackageName
     * @param fullEntityClassName
     * @param entityName
     * @param scopeType
     * @param customQueryInfoList
     * @param queryParameterInfoList
     * @param filterable
     */
    public EntityInfo(final TypeElement typeElement, final String subPackageName, final String fullEntityClassName,
            final String entityName, final ScopeType scopeType, final List<CustomQueryInfo> customQueryInfoList,
            final List<QueryParameterInfo> queryParameterInfoList, final List<Element> idElements,
            final boolean cacheable, final boolean findAll, final boolean paginateFindAll,
            final boolean filterable) {
        super();
        this.typeElement = typeElement;
        this.subPackageName = subPackageName;
        this.fullEntityClassName = fullEntityClassName;
        this.entityName = entityName;
        this.scopeType = scopeType;
        this.customQueryInfoList = customQueryInfoList;
        this.queryParameterInfoList = queryParameterInfoList;
        this.idElements = idElements;
        this.cacheable = cacheable;
        this.findAll = findAll;
        this.paginateFindAll = paginateFindAll;
        this.filterable = filterable;
        subClassList = new ArrayList<>();
    }

    public void applySuperclass(final EntityInfo info) {
        superClassInfo = info;
        info.subClassList.add(this);
        customQueryInfoList.addAll(info.customQueryInfoList);
        queryParameterInfoList.addAll(info.queryParameterInfoList);
        idElements.addAll(info.idElements);
    }

    public boolean hasSuperClass() {
        return superClassInfo != null;
    }

    public boolean isBaseClass() {
        return superClassInfo == null;
    }

    public boolean isEntityClass() {
        return new AnnotationHelperImpl().getAnnotationMirror(typeElement, Entity.class) != null;
    }

    public boolean isAbstract() {
        if (!subClassList.isEmpty()) {
            return true;
        }
        if (!customQueryInfoList.isEmpty()) {
            return true;
        }
        for (QueryParameterInfo info : queryParameterInfoList) {
            if (!info.isGenerate()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int compareTo(final EntityInfo o) {
        if (o.isSuperClass(this)) {
            return -1;
        }
        if (isSuperClass(o)) {
            return 1;
        }
        return fullEntityClassName.compareTo(o.fullEntityClassName);
    }

    public boolean isSuperClass(final EntityInfo info) {
        if (superClassInfo == null) {
            return false;
        }
        if (superClassInfo == info) {
            return true;
        }
        return superClassInfo.isSuperClass(info);
    }

    public String packageName() {
        return StringUtils.removeEnd(fullEntityClassName, "." + entityName);
    }

    public TypeElement getTypeElement() {
        return typeElement;
    }

    public String getSubPackageName() {
        return subPackageName;
    }

    public String getFullEntityClassName() {
        return fullEntityClassName;
    }

    public String getEntityName() {
        return entityName;
    }

    public ScopeType getScopeType() {
        return scopeType;
    }

    public List<CustomQueryInfo> getCustomQueryInfoList() {
        return customQueryInfoList;
    }

    public List<QueryParameterInfo> getQueryParameterInfoList() {
        return queryParameterInfoList;
    }

    public List<Element> getIdElements() {
        return idElements;
    }

    public EntityInfo getSuperClassInfo() {
        return superClassInfo;
    }

    public List<EntityInfo> getSubClassList() {
        return subClassList;
    }

    public boolean isCacheable() {
        return cacheable;
    }

    public boolean isFindAll() {
        return findAll;
    }

    public boolean isPaginateFindAll() {
        return paginateFindAll;
    }

    public boolean isFilterable() {
        return filterable;
    }
}