本文整理汇总了Java中com.jfinal.plugin.activerecord.DbKit类的典型用法代码示例。如果您正苦于以下问题:Java DbKit类的具体用法?Java DbKit怎么用?Java DbKit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbKit类属于com.jfinal.plugin.activerecord包,在下文中一共展示了DbKit类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: batchSave
import com.jfinal.plugin.activerecord.DbKit; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public static int[] batchSave(List<? extends Model> data, int batchSize) {
Model model = data.get(0);
Map<String, Object> attrs = (Map<String, Object>) ReflectionUtils.getFieldValue(model, "attrs");
Class<? extends Model> modelClass = model.getClass();
Table table = TableMapping.me().getTable(modelClass);
StringBuilder sql = new StringBuilder();
List<Object> paras = new ArrayList<Object>();
DbKit.getConfig().getDialect().forModelSave(table, attrs, sql, paras);
Object[][] batchPara = new Object[data.size()][attrs.size()];
for (int i = 0; i < data.size(); i++) {
int j = 0;
for (String key : attrs.keySet()) {
batchPara[i][j++] = data.get(i).get(key);
}
}
return Db.batch(sql.toString(), batchPara, batchSize);
}
示例2: batchSave
import com.jfinal.plugin.activerecord.DbKit; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static int[] batchSave(List<? extends Model> data, int batchSize) {
Model model = data.get(0);
Map<String, Object> attrs = Reflect.on(model).field("attrs").get();
Class<? extends Model> modelClass = model.getClass();
Table tableInfo = TableMapping.me().getTable(modelClass);
StringBuilder sql = new StringBuilder();
List<Object> paras = Lists.newArrayList();
DbKit.getConfig().getDialect().forModelSave(tableInfo, attrs, sql, paras);
Object[][] batchPara = new Object[data.size()][attrs.size()];
for (int i = 0; i < data.size(); i++) {
int j = 0;
for (String key : attrs.keySet()) {
batchPara[i][j++] = data.get(i).get(key);
}
}
return Db.batch(sql.toString(), batchPara, batchSize);
}
示例3: searchByCache
import com.jfinal.plugin.activerecord.DbKit; //导入依赖的package包/类
public List<M> searchByCache(String cacheName, Object key,
Map<String, Object> maps, String orderBy) {
// checkTableName();
ICache cache = DbKit.getCache();
List<M> result = cache.get(cacheName, key);
if (result == null) {
result = search(maps);
cache.put(cacheName, key, result);
}
return result;
}
示例4: searchPaginateByCache
import com.jfinal.plugin.activerecord.DbKit; //导入依赖的package包/类
public Page<M> searchPaginateByCache(String cacheName, Object key,
int pageNumber, int pageSize, Map<String, Object> maps,
String orderBy) {
// checkTableName();
ICache cache = DbKit.getCache();
Page<M> result = cache.get(cacheName, key);
if (result == null) {
result = searchPaginate(pageNumber, pageSize, maps, orderBy);
cache.put(cacheName, key, result);
}
return result;
}
示例5: getConfig
import com.jfinal.plugin.activerecord.DbKit; //导入依赖的package包/类
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;
}
示例6: AutoTableBindPlugin
import com.jfinal.plugin.activerecord.DbKit; //导入依赖的package包/类
public AutoTableBindPlugin(IDataSourceProvider dataSourceProvider) {
this(DbKit.MAIN_CONFIG_NAME, dataSourceProvider, SimpleNameStyles.DEFAULT);
}
示例7: start
import com.jfinal.plugin.activerecord.DbKit; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public boolean start() {
final Set<Class<? extends Model>> modelClasses = ClassPathScanning.scan(Model.class);
if (CollectionUtils.isNotEmpty(modelClasses)) {
TableBind tb;
String tableName;
for (Class modelClass : modelClasses) {
if (Modifier.isAbstract(modelClass.getModifiers())) {
Logger.debug("Goja:: Model {} is Abstract! ignore...", modelClass);
continue;
}
tb = (TableBind) modelClass.getAnnotation(TableBind.class);
final boolean mainMark = StringUtils.equals(DbKit.MAIN_CONFIG_NAME, confiName);
if (mainMark && tb == null) {
tableName = name(modelClass.getSimpleName());
this.addMapping(tableName, modelClass);
} else {
if (tb.ignore()) {
continue;
}
final String[] configNames = tb.configName();
if (ArrayUtils.contains(configNames, this.confiName)) {
tableName = tb.tableName();
final String[] pks = tb.pks();
if (pks.length == 1) {
String pk_name = pks[0];
this.addMapping(tableName, pk_name, modelClass);
} else if (pks.length > 1) {
this.addMapping(tableName, Func.COMMA_JOINER.join(pks), modelClass);
} else {
this.addMapping(tableName, modelClass);
}
}
}
}
return super.start();
}
return false;
}