com.jfinal.plugin.activerecord.DbKit Java Examples

The following examples show how to use com.jfinal.plugin.activerecord.DbKit. 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: BatchSaveKit.java    From jfinal-ext3 with Apache License 2.0 6 votes vote down vote up
private static int[] batchSave(List<? extends ModelExt<?>> models, int batchSize) {
	ModelExt<?> m = models.get(0);
	Map<String, Object> attrs = m.attrs();
	Table table = m.table();

	StringBuilder sql = new StringBuilder();
	List<Object> paras = Lists.newArrayList();

	DbKit.getConfig().getDialect().forModelSave(table, attrs, sql, paras);

	Object[][] batchPara = new Object[models.size()][attrs.size()];

	for (int i = 0; i < models.size(); i++) {
		int j = 0;
		for (String key : attrs.keySet()) {
			batchPara[i][j++] = models.get(i).get(key);
		}
	}
	return Db.batch(sql.toString(), batchPara, batchSize);
}
 
Example #2
Source File: JFinalTxAop.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
/**
 * 获取配置的TxConfig,可注解到class或者方法上
 * @param pjp
 * @return Config
 */
public static Config getConfigWithTxConfig(ProceedingJoinPoint pjp) {
    MethodSignature ms = (MethodSignature) pjp.getSignature();
    Method method = ms.getMethod();
    TxConfig txConfig = method.getAnnotation(TxConfig.class);
    if (txConfig == null)
        txConfig = pjp.getTarget().getClass().getAnnotation(TxConfig.class);

    if (txConfig != null) {
        Config config = DbKit.getConfig(txConfig.value());
        if (config == null)
            throw new RuntimeException("Config not found with TxConfig: " + txConfig.value());
        return config;
    }
    return null;
}
 
Example #3
Source File: ActivitiPlugin.java    From my_curd with Apache License 2.0 6 votes vote down vote up
/**
 * 创建工作流引擎
 * @return
 */
private Boolean createProcessEngine(){
    if (processEngine != null) {
        return true;
    }
    StandaloneProcessEngineConfiguration conf =
            (StandaloneProcessEngineConfiguration) ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
    conf.setDataSource(DbKit.getConfig().getDataSource())
        .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE) // 自动更新数据库表
        .setDbHistoryUsed(true);                                                   // 历史表生效功能
    // conf.setTransactionsExternallyManaged(true); // 使用托管事务工厂(不配置,事务也可生效)


    conf.setTransactionFactory(new ActivitiTransactionFactory());

    ActivitiPlugin.processEngine = conf.buildProcessEngine();
    return true;
}
 
Example #4
Source File: InstallController.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initActiveRecordPlugin() {


        DataSourceConfig config = InstallManager.me().getDataSourceConfig();

        // 在只有 jboot.properties 但是没有 install.lock 的情况下
        // jboot 启动的时候会出初始化 jboot.properties 里配置的插件
        // 此时,会出现 config already exist 的异常
        if (DbKit.getConfig(DataSourceConfig.NAME_DEFAULT) == null) {
            config.setName(DataSourceConfig.NAME_DEFAULT);
        } else {
            config.setName(StrUtil.uuid());
        }

        DataSourceConfigManager.me().addConfig(config);

        ActiveRecordPlugin arPlugin = ArpManager.me().createRecordPlugin(config);
        arPlugin.start();
    }
 
Example #5
Source File: ActivitiTransaction.java    From my_curd with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws SQLException {
    if (connection != null) {
        log.debug("activiti close connection");
        DbKit.getConfig(ActivitiConfig.DATASOURCE_NAME).close(connection);
    }
}
 
Example #6
Source File: JfinalHelper.java    From snakerflow with Apache License 2.0 5 votes vote down vote up
public static Config getConfig() {
    if(config == null) {
        synchronized (JfinalHelper.class) {
            if(config == null) {
                if(StringHelper.isNotEmpty(configName)) {
                    config = DbKit.getConfig(configName);
                }
                if(config == null) {
                    config = DbKit.getConfig();
                }
            }
        }
    }
    return config;
}
 
Example #7
Source File: ActivitiTransaction.java    From my_curd with Apache License 2.0 4 votes vote down vote up
void openConnection() throws SQLException {
    connection = DbKit.getConfig(ActivitiConfig.DATASOURCE_NAME).getConnection();
    if (level != null) {
        connection.setTransactionIsolation(level.getLevel());
    }
}
 
Example #8
Source File: GenOnlineController.java    From my_curd with Apache License 2.0 4 votes vote down vote up
/**
 * datagrid 数据
 *
 * @throws SQLException
 */
public void query() throws SQLException {
    DataSource dataSource = null;
    try {
        if (StringUtils.isEmpty(GeneratorConfig.dsName)) {
            dataSource = DbKit.getConfig().getDataSource();
        } else {
            dataSource = DbKit.getConfig(GeneratorConfig.dsName).getDataSource();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }

    if (dataSource == null) {
        renderDatagrid(new ArrayList<>());
        return;
    }
    if (metaUtils == null) {
        metaUtils = new MysqlMetaUtils(dataSource);
    }

    List<TableMeta> tableMetaList = metaUtils.allTableMeta(GeneratorConfig.schemaPattern);

    Collection<TableMeta> result = null;
    String tableName = getPara("extra_name");
    if (StringUtils.notEmpty(tableName)) {
        result = Collections2.filter(tableMetaList, x -> x.getName().contains(tableName));
        renderDatagrid(result, result.size());
    }

    String tableRemark = getPara("extra_remark");
    if (StringUtils.notEmpty(tableRemark)) {
        result = Collections2.filter(tableMetaList, x -> x.getRemark().contains(tableRemark));
        renderDatagrid(result, result.size());
    }

    if (result == null) {
        renderDatagrid(tableMetaList, tableMetaList.size());
    } else {
        renderDatagrid(result, result.size());
    }
}