io.jboot.db.annotation.Table Java Examples

The following examples show how to use io.jboot.db.annotation.Table. 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: AddonManager.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void clearStopedTableMapping(ActiveRecordPlugin arp) throws Exception {

        List<com.jfinal.plugin.activerecord.Table> tables = getTableList(arp);

        if (tables == null || tables.isEmpty()) {
            return;
        }


        Field modelToTableMapField = TableMapping.class.getDeclaredField("modelToTableMap");
        modelToTableMapField.setAccessible(true);
        Map<Class<? extends Model<?>>, com.jfinal.plugin.activerecord.Table> modelToTableMap =
                (Map<Class<? extends Model<?>>, com.jfinal.plugin.activerecord.Table>) modelToTableMapField.get(TableMapping.me());

        if (modelToTableMap == null || modelToTableMap.isEmpty()) {
            return;
        }

        for (com.jfinal.plugin.activerecord.Table table : tables) {
            modelToTableMap.remove(table.getModelClass());
        }
    }
 
Example #2
Source File: TableInfoManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
private void initTableInfos(List<TableInfo> tableInfoList) {
    List<Class<Model>> modelClassList = ClassScanner.scanSubClass(Model.class);
    if (ArrayUtil.isNullOrEmpty(modelClassList)) {
        return;
    }

    String scanPackage = JbootModelConfig.getConfig().getScanPackage();
    String unscanPackage = JbootModelConfig.getConfig().getUnscanPackage();

    for (Class<Model> clazz : modelClassList) {
        Table tb = clazz.getAnnotation(Table.class);
        if (tb == null) {
            continue;
        }

        if (StrUtil.isNotBlank(scanPackage)
                && clazz.getName().startsWith(scanPackage.trim())) {
            addTable(tableInfoList, clazz, tb);
            continue;
        }


        if (StrUtil.isNotBlank(unscanPackage)
                && ("*".equals(unscanPackage.trim()) || clazz.getName().startsWith(unscanPackage.trim()))) {
            continue;
        }

        addTable(tableInfoList, clazz, tb);
    }

}
 
Example #3
Source File: TableInfoManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
private void addTable(List<TableInfo> tableInfoList, Class<Model> clazz, Table tb) {
    TableInfo tableInfo = new TableInfo();
    tableInfo.setModelClass(clazz);
    tableInfo.setPrimaryKey(AnnotationUtil.get(tb.primaryKey()));
    tableInfo.setTableName(AnnotationUtil.get(tb.tableName()));

    tableInfoList.add(tableInfo);
}
 
Example #4
Source File: AddonManager.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void startActiveRecordPlugin(AddonInfo addonInfo) {
    List<Class<? extends JbootModel>> modelClasses = addonInfo.getModels();
    if (modelClasses != null && !modelClasses.isEmpty()) {

        ActiveRecordPlugin arp = addonInfo.getOrCreateArp();

        List<com.jfinal.plugin.activerecord.Table> tableList = getTableList(arp);

        for (Class<? extends JbootModel> c : modelClasses) {

            Table tableAnnotation = c.getAnnotation(Table.class);
            boolean needAddMapping = true;

            if (tableList != null && !tableList.isEmpty()) {
                for (com.jfinal.plugin.activerecord.Table t : tableList) {
                    if (t.getName().equals(AnnotationUtil.get(tableAnnotation.tableName()))) {
                        needAddMapping = false;
                        break;
                    }
                }
            }

            if (needAddMapping) {
                if (StrUtil.isNotBlank(tableAnnotation.primaryKey())) {
                    arp.addMapping(AnnotationUtil.get(tableAnnotation.tableName()), AnnotationUtil.get(tableAnnotation.primaryKey()), (Class<? extends Model<?>>) c);
                } else {
                    arp.addMapping(AnnotationUtil.get(tableAnnotation.tableName()), (Class<? extends Model<?>>) c);
                }
            }
        }
        addonInfo.setArp(arp);
        arp.start();
    }
}
 
Example #5
Source File: AddonManager.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
private List<com.jfinal.plugin.activerecord.Table> getTableList(ActiveRecordPlugin arp) {
    try {
        Field tableListField = ActiveRecordPlugin.class.getDeclaredField("tableList");
        tableListField.setAccessible(true);
        return (List<com.jfinal.plugin.activerecord.Table>) tableListField.get(arp);
    } catch (Exception ex) {
        LogKit.error(ex.toString(), ex);
    }
    return null;
}
 
Example #6
Source File: AddonManager.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 必须要移除所有的缓存,否则当插件卸载重新安装的时候,
 * 缓存里的可能还存在数据,由于可能是内存缓存,所有可能导致Class转化异常的问题
 * PS:每次新安装的插件,都是一个新的 Classloader
 *
 * @param addonInfo
 */
private void removeModelsCache(AddonInfo addonInfo) {
    List<Class<? extends JbootModel>> modelClasses = addonInfo.getModels();
    if (modelClasses != null) {
        modelClasses.forEach(aClass -> {
            Table table = aClass.getAnnotation(Table.class);
            String tableName = AnnotationUtil.get(table.tableName());
            JbootModelConfig.getConfig().getIdCache().removeAll(tableName);
            Jboot.getCache().removeAll(tableName);
        });
    }
}
 
Example #7
Source File: AddonInfo.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void addModel(Class<? extends JbootModel> clazz) {
    Table table = clazz.getAnnotation(Table.class);
    if (table == null) {
        return;
    }
    if (models == null) {
        models = new ArrayList<>();
    }
    models.add(clazz);
}