com.baomidou.mybatisplus.annotations.TableName Java Examples

The following examples show how to use com.baomidou.mybatisplus.annotations.TableName. 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: DataRuleInitializer.java    From bird-java with MIT License 5 votes vote down vote up
public void init() {
    Set<Class<?>> classes = ClassHelper.getClasses(this.basePackages);
    Set<DataRuleInfo> ruleInfos = classes.stream()
            .filter(IModel.class::isAssignableFrom)
            .filter(p -> p.isAnnotationPresent(TableName.class))
            .map(this::collectRuleInfos).flatMap(Collection::stream)
            .collect(Collectors.toSet());

    dataRuleStore.store(ruleInfos);
}
 
Example #2
Source File: DataRuleInitializer.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * 扫描项目类所有class
 *
 * @param clazz class
 */
private Set<DataRuleInfo> collectRuleInfos(Class<?> clazz) {
    Set<DataRuleInfo> ruleInfos = new HashSet<>();

    TableName tableName = clazz.getAnnotation(TableName.class);
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        TableField tableField = field.getAnnotation(TableField.class);
        if (tableField != null && !tableField.exist()) continue;

        DataRule dataRule = field.getAnnotation(DataRule.class);

        if (dataRule != null) {
            DataRuleInfo ruleInfo = new DataRuleInfo();
            ruleInfo.setAppName(applicationName);
            ruleInfo.setClassName(clazz.getName());
            ruleInfo.setFieldName(field.getName());
            ruleInfo.setDbFieldName(QueryDescriptor.getDbFieldName(field));
            ruleInfo.setName(dataRule.name());
            ruleInfo.setSourceStrategy(String.valueOf(dataRule.strategy().getKey()));
            ruleInfo.setTableName(StringUtils.wrapIfMissing(tableName.value(), "`"));
            if (RuleSourceStrategy.CHOICE.equals(dataRule.strategy())) {
                ruleInfo.setSourceUrl(dataRule.url());
            }
            if (RuleSourceStrategy.SYSTEM.equals(dataRule.strategy())) {
                ruleInfo.setSourceProvider(dataRule.provider().getName());
            }

            ruleInfos.add(ruleInfo);
        }
    }
    return ruleInfos;
}
 
Example #3
Source File: QueryDescriptor.java    From bird-java with MIT License 5 votes vote down vote up
public static QueryDescriptor parseClass(Class<?> tClass) {
    Map<String, String> fieldMap = new HashMap<>(16);

    if (tClass == null) return null;
    Class tempClass = tClass;
    StringBuilder sb = new StringBuilder();

    while (tempClass != null && !StringUtils.equals(tempClass.getName(), OBJECT_CLASS_NAME)) {
        Field[] tempFields = tempClass.getDeclaredFields();
        for (Field field : tempFields) {
            if(EXCLUDE_FIELD_NAMES.contains(field.getName()))continue;

            TableField tableField = field.getAnnotation(TableField.class);
            if (tableField != null && !tableField.exist()) continue;

            String fieldName = StringUtils.wrapIfMissing(field.getName(), '`');
            String dbFieldName = getDbFieldName(field);
            fieldMap.putIfAbsent(fieldName, dbFieldName);
        }

        tempClass = tempClass.getSuperclass();
    }

    for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
        sb.append(entry.getValue());
        sb.append(" AS ");
        sb.append(entry.getKey());
        sb.append(",");
    }

    String select = StringUtils.stripEnd(sb.toString(), ",");

    String from = "";
    TableName tableName = tClass.getAnnotation(TableName.class);
    if (tableName != null) {
        from = tableName.value();
    }
    return new QueryDescriptor(select, from, fieldMap);
}
 
Example #4
Source File: CommonSaveParam.java    From bird-java with MIT License 5 votes vote down vote up
public String getTableName() {
    TableName tableName = this.tClass.getAnnotation(TableName.class);
    if (tableName == null) {
        throw new UserFriendlyException(this.tClass.getName() + "未定义表名com.baomidou.mybatisplus.annotations.TableName");
    }
    return tableName.value();
}