本文整理汇总了Java中org.nutz.dao.util.Daos类的典型用法代码示例。如果您正苦于以下问题:Java Daos类的具体用法?Java Daos怎么用?Java Daos使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Daos类属于org.nutz.dao.util包,在下文中一共展示了Daos类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: exists
import org.nutz.dao.util.Daos; //导入依赖的package包/类
public boolean exists(final String tableName) {
final boolean[] ee = {false};
this.run(new ConnCallback() {
public void invoke(Connection conn) {
Statement stat = null;
ResultSet rs = null;
try {
stat = conn.createStatement();
// 增加不等式,减少sql执行时间
String sql = "SELECT COUNT(1) FROM " + tableName + " where 1!=1";
rs = stat.executeQuery(sql);
if (rs.next())
ee[0] = true;
}
catch (SQLException e) {}
finally {
Daos.safeClose(stat, rs);
}
}
});
return ee[0];
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:23,代码来源:NutDao.java
示例2: _runStatement
import org.nutz.dao.util.Daos; //导入依赖的package包/类
private void _runStatement(Connection conn, DaoStatement st) throws SQLException {
boolean statIsClosed = false;
Statement stat = null;
String sql = st.toPreparedStatement();
// 打印调试信息
if (log.isDebugEnabled())
log.debug(sql);
try {
stat = conn.createStatement();
stat.execute(sql);
st.getContext().setUpdateCount(stat.getUpdateCount());
stat.close();
statIsClosed = true;
}
finally {
if (!statIsClosed)
Daos.safeClose(stat);
}
// 打印更详细的调试信息
if (log.isTraceEnabled())
log.trace("...DONE");
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:25,代码来源:NutDaoExecutor.java
示例3: from
import org.nutz.dao.util.Daos; //导入依赖的package包/类
public static Chain from(Object obj, FieldMatcher fm, Dao dao) {
final Chain[] chains = new Chain[1];
boolean re = Daos.filterFields(obj, fm, dao, new Callback2<MappingField, Object>() {
public void invoke(MappingField mf, Object val) {
if (mf.isReadonly() || !mf.isUpdate())
return;
if (chains[0] == null)
chains[0] = Chain.make(mf.getName(), val);
else
chains[0].add(mf.getName(), val);
}
});
if (re)
return chains[0];
return null;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:17,代码来源:Chain.java
示例4: init
import org.nutz.dao.util.Daos; //导入依赖的package包/类
public void init(NutConfig nc) {
Daos.createTablesInPackage(dao, User.class.getPackage().getName(), false);
if (dao.count(User.class) == 0) {
log.info("create root user");
User root = new User();
root.setName("root");
root.setAlias("root");
root.setCreateTime(new Date());
root.setEmail("[email protected]");
root.setSlat(R.UU64());
root.setPasswd(Lang.sha1(root.getSlat() + "123456" + root.getSlat()));
dao.insert(root);
}
List<Class<?>> list = Scans.me().scanPackage(getClass(), "^.+Setup.class$");
for (Class<?> klass : list) {
if (klass == getClass())
continue;
((Setup) ioc.get(klass)).init(nc);
}
for(String beanName: ioc.getNames()) {
ioc.get(null, beanName);
}
}
开发者ID:amdiaosi,项目名称:nutzWx,代码行数:24,代码来源:MainSetup.java
示例5: test04
import org.nutz.dao.util.Daos; //导入依赖的package包/类
@Test
public void test04() throws Exception {
SimpleDataSource dataSource = new SimpleDataSource();
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/take");
dataSource.setUsername("root");
dataSource.setPassword("root");
Dao dao = new NutDao(dataSource);
Daos.createTablesInPackage(dao, "com.jt.stock.model", false);
}
开发者ID:jt120,项目名称:take,代码行数:11,代码来源:LoginTest.java
示例6: init
import org.nutz.dao.util.Daos; //导入依赖的package包/类
@Override
public void init(NutConfig nc) {
Ioc ioc = nc.getIoc();
ioc.get(NutQuartzCronJobFactory.class);
Dao dao = ioc.get(Dao.class);
Daos.createTablesInPackage(dao, "com.yjh", false);
}
开发者ID:yangjinhe,项目名称:maintain-robot,代码行数:8,代码来源:MainSetup.java
示例7: init
import org.nutz.dao.util.Daos; //导入依赖的package包/类
public void init(NutConfig conf) {
Ioc ioc = conf.getIoc();
Dao dao = ioc.get(Dao.class);
Daos.createTablesInPackage(dao, "com.window", false);
// 初始化默认根用户
if (dao.count(User.class) == 0) {
User user = new User();
user.setName("admin");
user.setPassword("123456");
user.setCreateTime(new Date(System.currentTimeMillis()));
user.setUpdateTime(new Date(System.currentTimeMillis()));
dao.insert(user);
}
}
开发者ID:strictnerd,项目名称:windows-file-change,代码行数:15,代码来源:MainSetup.java
示例8: from
import org.nutz.dao.util.Daos; //导入依赖的package包/类
/**
* 根据一个对象生成Cnd条件, FieldMatcher详细控制.<p/>
* <code>assertEquals(" WHERE name='wendal' AND age=0", Cnd.from(dao, pet, FieldMatcher.make("age|name", null, true).setIgnoreDate(true)).toString());</code>
* @param dao Dao实例
* @param obj 基对象,不可以是Class,字符串,数值和Boolean
* @param matcher 过滤字段属性, 可配置哪些字段可用/不可用/是否忽略空值/是否忽略0值/是否忽略java.util.Date类及其子类的对象/是否忽略@Id所标注的主键属性/是否忽略 \@Name 所标注的主键属性/是否忽略 \@Pk 所引用的复合主键
* @return Cnd条件
*/
public static Cnd from(Dao dao, Object obj, FieldMatcher matcher) {
final SqlExpressionGroup exps = new SqlExpressionGroup();
boolean re = Daos.filterFields(obj, matcher, dao, new Callback2<MappingField, Object>() {
public void invoke(MappingField mf, Object val) {
exps.and(mf.getName(), "=", val);
}
});
if (re)
return Cnd.where(exps);
return null;
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:20,代码来源:Cnd.java
示例9: insert
import org.nutz.dao.util.Daos; //导入依赖的package包/类
public void insert(String tableName, Chain chain) {
if (chain.isSpecial()) {
Daos.insertBySpecialChain(this, null, tableName, chain);
return;
}
EntityOperator opt = _optBy(chain.toEntityMap(tableName));
if (null == opt)
return;
opt.addInsert();
opt.exec();
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:12,代码来源:NutDao.java
示例10: update
import org.nutz.dao.util.Daos; //导入依赖的package包/类
public int update(String tableName, Chain chain, Condition cnd) {
if (chain.isSpecial())
return Daos.updateBySpecialChain(this, null, tableName, chain, cnd);
EntityOperator opt = _optBy(chain.toEntityMap(tableName));
if (null == opt)
return 0;
opt.addUpdate(cnd);
opt.exec();
return opt.getUpdateCount();
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:11,代码来源:NutDao.java
示例11: init
import org.nutz.dao.util.Daos; //导入依赖的package包/类
@Override
public void init(NutConfig nc) {
String pkg = Iots.class.getPackage().getName();
for (int i = 0; i < Iots.PART; i++) {
Dao dao = Daos.ext(nc.getIoc().get(Dao.class), ""+i);
Daos.createTablesInPackage(dao, pkg, false);
}
iotService.rootUser();
nc.getIoc().get(IotNettyService.class);
log.info("iot setup complete");
}
开发者ID:wendal,项目名称:whale,代码行数:12,代码来源:IotSetup.java
示例12: init
import org.nutz.dao.util.Daos; //导入依赖的package包/类
@Override
public void init(NutConfig nc) {
Ioc ioc = nc.getIoc();
Dao dao = ioc.get(Dao.class);
Daos.createTablesInPackage(dao, WxUser.class.getPackage().toString(), false);
// PropertiesProxy pp = ioc.get(PropertiesProxy.class, "config");
// 按需选择
ResourceService resourceService = null;
// try {
// SSDB ssdb = SSDBs.pool("127.0.0.1", 8888, 5000, null);
// resourceService = new SsdbResourceService(ssdb);
// ((Ioc2)ioc).getIocContext().save("app", "resourceService", new ObjectProxy(resourceService));
// } catch (Exception e) {
// log.info("fail to connect ssdb? using DaoResourceService now", e);
resourceService = new DaoResourceService(dao);
((Ioc2)ioc).getIocContext().save("app", "resourceService", new ObjectProxy(resourceService));
// }
// try {
// scheduler = StdSchedulerFactory.getDefaultScheduler();
// scheduler.startDelayed(5000);;
// } catch (SchedulerException e) {
// log.warn("Scheduler start fail", e);
// }
}
开发者ID:amdiaosi,项目名称:nutzWx,代码行数:29,代码来源:WxSetup.java
示例13: init
import org.nutz.dao.util.Daos; //导入依赖的package包/类
@Override
public void init(NutConfig nc) {
String pkg = IotSensor.class.getPackage().toString();
for (int i = 0; i < Iots.PART; i++) {
Dao dao = Daos.ext(nc.getIoc().get(Dao.class), ""+i);
Daos.createTablesInPackage(dao, pkg, false);
}
iotService.rootUser();
log.info("iot setup complete");
}
开发者ID:amdiaosi,项目名称:nutzWx,代码行数:11,代码来源:IotSetup.java
示例14: _runSelect
import org.nutz.dao.util.Daos; //导入依赖的package包/类
private void _runSelect(Connection conn, DaoStatement st)
throws SQLException {
Object[][] paramMatrix = st.getParamMatrix();
// -------------------------------------------------
// 以下代码,就为了该死的游标分页!!
// -------------------------------------------------
int startRow = -1;
int lastRow = -1;
if (st.getContext().getResultSetType() == ResultSet.TYPE_SCROLL_INSENSITIVE) {
Pager pager = st.getContext().getPager();
if (pager != null) {
startRow = pager.getOffset();
lastRow = pager.getOffset() + pager.getPageSize();
}
}
// -------------------------------------------------
// 生成 Sql 语句
String sql = st.toPreparedStatement();
// 打印调试信息
ResultSet rs = null;
Statement stat = null;
try {
// 木有参数,直接运行
if (null == paramMatrix || paramMatrix.length == 0
|| paramMatrix[0].length == 0) {
if (log.isDebugEnabled())
log.debug(st.forPrint());
stat = conn.createStatement(st.getContext()
.getResultSetType(), ResultSet.CONCUR_READ_ONLY);
if (lastRow > 0)
stat.setMaxRows(lastRow); // 游标分页,现在总行数
if (st.getContext().getFetchSize() != 0)
stat.setFetchSize(st.getContext().getFetchSize());
rs = stat.executeQuery(sql);
}
// 有参数,用缓冲语句
else {
// 打印调试信息
if (paramMatrix.length > 1) {
if (log.isWarnEnabled())
log.warnf("Drop last %d rows parameters for:\n%s",
paramMatrix.length - 1, st);
}
if (log.isDebugEnabled()) {
log.debug(st);
}
// 准备运行语句
ValueAdaptor[] adaptors = st.getAdaptors();
// 创建语句并设置参数
stat = conn.prepareStatement(sql, st
.getContext().getResultSetType(),
ResultSet.CONCUR_READ_ONLY);
if (lastRow > 0)
stat.setMaxRows(lastRow);
if (st.getContext().getFetchSize() != 0)
stat.setFetchSize(st.getContext().getFetchSize());
for (int i = 0; i < paramMatrix[0].length; i++) {
adaptors[i].set((PreparedStatement) stat,
paramMatrix[0][i], i + 1);
}
rs = ((PreparedStatement) stat).executeQuery();
}
if (startRow > 0)
rs.absolute(startRow);
// 执行回调
st.onAfter(conn, rs);
} finally {
Daos.safeClose(stat, rs);
}
// 打印更详细的调试信息
if (log.isTraceEnabled())
log.trace("...DONE");
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:79,代码来源:NutDaoExecutor.java
示例15: partDao
import org.nutz.dao.util.Daos; //导入依赖的package包/类
public Dao partDao(IotSensor sensor) {
long part = sensor.getId() / Iots.PART;
return Daos.ext(dao, "" + part);
}
开发者ID:wendal,项目名称:whale,代码行数:5,代码来源:IotSensorService.java
注:本文中的org.nutz.dao.util.Daos类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论