• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Sqls类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.nutz.dao.Sqls的典型用法代码示例。如果您正苦于以下问题:Java Sqls类的具体用法?Java Sqls怎么用?Java Sqls使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

Sqls类属于org.nutz.dao包,在下文中一共展示了Sqls类的38个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: toSql

点赞 3

import org.nutz.dao.Sqls; //导入依赖的package包/类
public String toSql(Entity<?> en) {
    Object[] params = new Object[this.paramCount(en)];
    int i = where.joinParams(en, null, params, 0);
    orderBy.joinParams(en, null, params, i);

    StringBuilder sb = new StringBuilder();
    this.joinSql(en, sb);
    String[] ss = sb.toString().split("[?]");

    sb = new StringBuilder();
    for (i = 0; i < params.length; i++) {
        sb.append(ss[i]);
        sb.append(Sqls.formatFieldValue(params[i]));
    }
    if (i < ss.length)
        sb.append(ss[i]);

    return sb.toString();
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:20,
代码来源:SimpleCriteria.java

示例2: dropEntity

点赞 3

import org.nutz.dao.Sqls; //导入依赖的package包/类
public boolean dropEntity(Dao dao, Entity<?> en) {
    String tableName = en.getTableName();
    String viewName = en.getViewName();

    try {
        dropRelation(dao, en);
        if (!tableName.equals(viewName) && dao.exists(viewName)) {
            dao.execute(Sqls.create("DROP VIEW " + viewName));
        }
        dao.execute(Sqls.create("DROP TABLE " + tableName));
    }
    catch (Exception e) {
        return false;
    }
    return true;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:17,
代码来源:AbstractJdbcExpert.java

示例3: dropEntity

点赞 3

import org.nutz.dao.Sqls; //导入依赖的package包/类
@Override
public boolean dropEntity(Dao dao, Entity<?> en) {
    if (super.dropEntity(dao, en)) {
        if (en.getPks().isEmpty())
            return true;
        List<Sql> sqls = new ArrayList<Sql>();
        for (MappingField pk : en.getPks()) {
            if (pk.isAutoIncreasement()) {
                String sql = gSQL(DSEQ, en.getTableName(), pk.getColumnName());
                sqls.add(Sqls.create(sql));
            }
        }
        try {
            dao.execute(sqls.toArray(new Sql[sqls.size()]));
            return true;
        }
        catch (Exception e) {}
    }
    return false;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:21,
代码来源:OracleJdbcExpert.java

示例4: addComment

点赞 3

import org.nutz.dao.Sqls; //导入依赖的package包/类
private void addComment(Dao dao, Entity<?> en, String commentColumn) {
    // TODO 表注释 SQLServer2005中貌似不行
    // 字段注释
    if (en.hasColumnComment()) {
        List<Sql> sqls = new ArrayList<Sql>();
        for (MappingField mf : en.getMappingFields()) {
            if (mf.hasColumnComment()) {
                Sql columnCommentSQL = Sqls.create(commentColumn);
                columnCommentSQL.vars()
                                .set("table", en.getTableName())
                                .set("column", mf.getColumnName())
                                .set("columnComment", mf.getColumnComment());
                sqls.add(columnCommentSQL);
            }
        }
        // 执行创建语句
        dao.execute(sqls.toArray(new Sql[sqls.size()]));
    }
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:20,
代码来源:Sqlserver2005JdbcExpert.java

示例5: executeQueryWithKeyValue

点赞 3

import org.nutz.dao.Sqls; //导入依赖的package包/类
public List<Map> executeQueryWithKeyValue(String sql, Map<String, Object> params, final String key, final String value){
    Sql sqlObject = Sqls.create(sql);
    if(params!=null){
        for (Entry<String,Object> entry : params.entrySet()) {
            sqlObject.params().set(entry.getKey(), entry.getValue());
        }
    }
    sqlObject.setCallback(new SqlCallback() {

        @Override
        public Object invoke(Connection conn, ResultSet rs, Sql s) throws SQLException {
            List<Map<String,Object>> list = new LinkedList<Map<String,Object>>();
            Map<String,Object> map = new HashMap<String,Object>();
            while (rs.next()){
                map.put((String) rs.getObject(key), rs.getObject(value));
            }
            list.add(map);
            return list;
        }

    });
    getDao().execute(sqlObject);
    return sqlObject.getList(Map.class);
}
 

开发者ID:yancykim,
项目名称:support,
代码行数:25,
代码来源:RedShiftBasicDao.java

示例6: empty

点赞 3

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 清空验证码
 * 
 * @param mobi
 * @return
 */
public boolean empty(String mobi) {

	if (ToolUtility.verifyMobile(mobi)) {
		try {
			Sql sql = Sqls
					.create("DELETE FROM tb_nutz_rand_code where MOBI = @MOBI");
			sql.params().set("MOBI", mobi);
			dao.execute(sql);
			return true;
		} catch (Exception e) {
			if (log.isDebugEnabled())
				log.debug("emptyRandCode!!", e);
			return false;
		}
	} else
		return false;
}
 

开发者ID:howe,
项目名称:nutz,
代码行数:24,
代码来源:RandCodeInterFace.java

示例7: insert

点赞 3

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 插入验证码
 * 
 * @param randCode
 * @param identifier
 * @return
 */
public boolean insert(String randCode, String identifier) {

	if (randCode.length() == 6 && !identifier.equals("")) {

		try {
			Sql sql = Sqls
					.create("CALL pro_insert_ccode_2(@RANDCODE, @IDENTIFIER)");
			sql.params().set("RANDCODE", randCode)
					.set("IDENTIFIER", identifier);
			dao.execute(sql);
			return true;
		} catch (Exception e) {

			if (log.isErrorEnabled())
				log.error("insertRandCode!!", e);
			return false;
		}
	} else
		return false;
}
 

开发者ID:howe,
项目名称:nutz,
代码行数:28,
代码来源:RandCodeInterFace.java

示例8: query

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 查询sql并把结果放入传入的class组成的List中
 */
public static <T> List<T> query(Dao dao, Class<T> classOfT, String sql, Condition cnd, Pager pager) {
	Sql sql2 = Sqls.queryEntity(sql);
	sql2.setEntity(dao.getEntity(classOfT));
	sql2.setCondition(cnd);
	sql2.setPager(pager);
	dao.execute(sql2);
	return sql2.getList(classOfT);
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:12,
代码来源:Daos.java

示例9: SqlFieldMacro

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public SqlFieldMacro(MappingField field, String str) {
    super();
    this.entityField = field;
    this.sql = Sqls.create(str);
    this.setSqlType(this.sql.getSqlType());
    this.setEntity(field.getEntity());
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:8,
代码来源:SqlFieldMacro.java

示例10: createCondition

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public Condition createCondition(Object host) {
    SimpleCriteria cri = Cnd.cri();
    cri.where().andInBySql(    linkedField.getColumnName(),
                            "SELECT %s FROM %s WHERE %s=%s",
                            toColumnName,
                            this.getRelationName(),
                            fromColumnName,
                            Sqls.formatFieldValue(hostField.getValue(host)));
    return cri;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:11,
代码来源:ManyManyLinkField.java

示例11: drop

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public boolean drop(String tableName) {
    if (!exists(tableName))
        return false;
    Sql sql = Sqls.createf("DROP TABLE %s", tableName);
    _exec(sql);
    return true;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:8,
代码来源:NutDao.java

示例12: createRelation

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
protected void createRelation(Dao dao, Entity<?> en) {
    final List<Sql> sqls = new ArrayList<Sql>(5);
    for (LinkField lf : en.visitManyMany(null, null, null)) {
        ManyManyLinkField mm = (ManyManyLinkField) lf;
        if (dao.exists(mm.getRelationName()))
            continue;
        String sql = "CREATE TABLE " + mm.getRelationName() + "(";
        sql += mm.getFromColumnName() + " " + evalFieldType(mm.getHostField()) + ",";
        sql += mm.getToColumnName() + " " + evalFieldType(mm.getLinkedField());
        sql += ")";
        sqls.add(Sqls.create(sql));
    }
    dao.execute(sqls.toArray(new Sql[sqls.size()]));
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:15,
代码来源:AbstractJdbcExpert.java

示例13: dropRelation

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
protected void dropRelation(Dao dao, Entity<?> en) {
    final List<Sql> sqls = new ArrayList<Sql>(5);
    for (LinkField lf : en.visitManyMany(null, null, null)) {
        ManyManyLinkField mm = (ManyManyLinkField) lf;
        if (!dao.exists(mm.getRelationName()))
            continue;
        sqls.add(Sqls.create("DROP TABLE " + mm.getRelationName()));
    }
    dao.execute(sqls.toArray(new Sql[sqls.size()]));
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:11,
代码来源:AbstractJdbcExpert.java

示例14: wrap

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
protected static List<DaoStatement> wrap(String... sqls) {
    List<DaoStatement> sts = new ArrayList<DaoStatement>(sqls.length);
    for (String sql : sqls)
        if (!Strings.isBlank(sql))
            sts.add(Sqls.create(sql));
    return sts;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:8,
代码来源:AbstractJdbcExpert.java

示例15: createIndexs

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
protected List<Sql> createIndexs(Entity<?> en) {
    List<Sql> sqls = new ArrayList<Sql>();
    StringBuilder sb = new StringBuilder();
    List<EntityIndex> indexs = en.getIndexes();
    for (EntityIndex index : indexs) {
        sb.setLength(0);
        if (index.isUnique())
            sb.append("Create UNIQUE Index ");
        else
            sb.append("Create Index ");
        if (index.getName().contains("$"))
        	sb.append(TableName.render(new CharSegment(index.getName())));
        else
        	sb.append(index.getName());
        sb.append(" ON ").append(en.getTableName()).append("(");
        for (EntityField field : index.getFields()) {
            if (field instanceof MappingField) {
                MappingField mf = (MappingField) field;
                sb.append(mf.getColumnName()).append(',');
            } else {
                throw Lang.makeThrow(    DaoException.class,
                                        "%s %s is NOT a mapping field, can't use as index field!!",
                                        en.getClass(),
                                        field.getName());
            }
        }
        sb.setCharAt(sb.length() - 1, ')');
        sqls.add(Sqls.create(sb.toString()));
    }
    return sqls;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:32,
代码来源:AbstractJdbcExpert.java

示例16: addComment

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public void addComment(Dao dao, Entity<?> en, String commentTable, String commentColumn) {
    if (!en.hasTableComment() && !en.hasColumnComment()) {
        return;
    }
    List<Sql> sqls = new ArrayList<Sql>();
    // 表注释
    if (en.hasTableComment()) {
        Sql tableCommentSQL = Sqls.create(Strings.isBlank(commentTable)    ? DEFAULT_COMMENT_TABLE
                                                                        : commentTable);
        tableCommentSQL.vars()
                        .set("table", en.getTableName())
                        .set("tableComment", en.getTableComment());
        sqls.add(tableCommentSQL);
    }
    // 字段注释
    if (en.hasColumnComment()) {
        for (MappingField mf : en.getMappingFields()) {
            if (mf.hasColumnComment()) {
                Sql columnCommentSQL = Sqls.create(Strings.isBlank(commentColumn)    ? DEFAULT_COMMENT_COLUMN
                                                                                    : commentColumn);
                columnCommentSQL.vars()
                                .set("table", en.getTableName())
                                .set("column", mf.getColumnName())
                                .set("columnComment", mf.getColumnComment());
                sqls.add(columnCommentSQL);
            }
        }
    }
    // 执行创建语句
    dao.execute(sqls.toArray(new Sql[sqls.size()]));
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:32,
代码来源:AbstractJdbcExpert.java

示例17: toExampleStatement

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
protected String toExampleStatement(Object[][] mtrx, String sql) {
    StringBuilder sb = new StringBuilder();
    String[] ss = sql.split("[?]");
    int i = 0;
    if (mtrx.length > 0) {
        for (; i < mtrx[0].length; i++) {
            sb.append(ss[i]);
            Object obj = mtrx[0][i];
            if (obj != null) {
                if (obj instanceof Blob) {
                    Blob blob = (Blob) obj;
                    obj = "Blob(" + blob.hashCode() + ")";
                } else if (obj instanceof Clob) {
                    Clob clob = (Clob) obj;
                    obj = "Clob(" + clob.hashCode() + ")";
                } else if (obj instanceof byte[] || obj instanceof char[]) {
                    if (Array.getLength(obj) > 10240)
                        obj = "*BigData[len=" + Array.getLength(obj) + "]";
                } else if (obj instanceof InputStream) {
                    try {
                        obj = "*InputStream[len=" + ((InputStream) obj).available() + "]";
                    }
                    catch (IOException e) {}
                } else if (obj instanceof Reader) {
                    obj = "*[email protected]" + obj.hashCode();
                }
            }
            sb.append(Sqls.formatFieldValue(obj));
        }
    }
    if (i < ss.length)
        sb.append(ss[i]);

    return sb.toString();
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:36,
代码来源:NutStatement.java

示例18: toStatement

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
protected String toStatement(Object[][] mtrx, String sql) {
      StringBuilder sb = new StringBuilder();
      String[] ss = sql.split("[?]");
      int i = 0;
      if (mtrx.length > 0) {
          for (; i < mtrx[0].length; i++) {
              sb.append(ss[i]);
              sb.append(Sqls.formatFieldValue(mtrx[0][i]));
          }
      }
      for (; i < ss.length; i++) {
      	sb.append(ss[i]);
}
      return sb.toString();
  }
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:16,
代码来源:NutStatement.java

示例19: get

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
@Override
public WxAccessToken get() {
    Sql sql = Sqls.fetchRecord(fetch);
    if (params != null)
        sql.params().putAll(params);
    dao.execute(sql);
    Record record = sql.getObject(Record.class);
    WxAccessToken at = new WxAccessToken();
    at.setToken(record.getString(tableAccessToken));
    at.setExpires(record.getInt(tableAccessTokenExpires));
    at.setLastCacheTimeMillis(record.getLong(tableAccessTokenLastat));
    return at;
}
 

开发者ID:nutzam,
项目名称:nutzwx,
代码行数:14,
代码来源:DaoAccessTokenStore.java

示例20: save

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
@Override
public void save(String token, int time, long lastCacheTimeMillis) {
    Sql sql = Sqls.create(update);
    if (params != null)
        sql.params().putAll(params);
    sql.params().set(tableAccessToken, token);
    sql.params().set(tableAccessTokenExpires, time);
    sql.params().set(tableAccessTokenLastat, lastCacheTimeMillis);
    dao.execute(sql);
}
 

开发者ID:nutzam,
项目名称:nutzwx,
代码行数:11,
代码来源:DaoAccessTokenStore.java

示例21: executeQuery

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public List<Map> executeQuery(String sql,Map<String,Object> params){
 	Sql sqlObject = Sqls.create(sql);
 	if(params!=null){
 		for (Entry<String,Object> entry : params.entrySet()) {
 			sqlObject.params().set(entry.getKey(), entry.getValue());
}
 	}

 	final String[] selects = buildSelect(sql);
 	sqlObject.setCallback(new SqlCallback() {

 		@Override
         public Object invoke(Connection conn, ResultSet rs, Sql s) throws SQLException {
             List<Map<String,Object>> list = new LinkedList<Map<String,Object>>();
             while (rs.next()){
             	Map<String,Object> map = new HashMap<String,Object>();
             	for (String select : selects) {
             		map.put(select, rs.getObject(select));
		}
             	list.add(map);
             }
             return list;
         }

 	});
 	getDao().execute(sqlObject);
 	return sqlObject.getList(Map.class);
 }
 

开发者ID:yancykim,
项目名称:support,
代码行数:29,
代码来源:RedShiftBasicDao.java

示例22: updateRoles

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public EUser updateRoles(EUser vo) {
	dao().execute(Sqls.create("delete from sys_user_role where userid=" + vo.getId()));
	return _insertRelation(vo, "roles");
}
 

开发者ID:DataAgg,
项目名称:DAFramework,
代码行数:5,
代码来源:UserDao.java

示例23: updateAuthorities

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public ERole updateAuthorities(ERole vo) {
	dao().execute(Sqls.create("delete from sys_role_authority where role_id=" + vo.getId()));
	return _insertRelation(vo, "authorities");
}
 

开发者ID:DataAgg,
项目名称:DAFramework,
代码行数:5,
代码来源:RoleDao.java

示例24: queryCount

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 查询某sql的结果条数
 */
public static long queryCount(Dao dao, String sql) {
	Sql sql2 = Sqls.fetchInt("select count(1) from (" + sql + ") as _nutz_tmp_" + System.currentTimeMillis());
	dao.execute(sql2);
	return sql2.getInt();
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:9,
代码来源:Daos.java

示例25: create

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public Sql create(String key) throws SqlNotFoundException {
    return Sqls.create(get(key));
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:4,
代码来源:AbstractSqlManager.java

示例26: createEntity

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public boolean createEntity(Dao dao, Entity<?> en) {
    StringBuilder sb = new StringBuilder("CREATE TABLE " + en.getTableName() + "(");
    // 创建字段
    for (MappingField mf : en.getMappingFields()) {
        if (mf.isReadonly())
            continue;
        sb.append('\n').append(mf.getColumnName());
        sb.append(' ').append(evalFieldType(mf));
        // 非主键的 @Name,应该加入唯一性约束
        if (mf.isName() && en.getPkType() != PkType.NAME) {
            sb.append(" UNIQUE NOT NULL");
        }
        // 普通字段
        else {
            // 下面的关于Timestamp处理,是因为MySql中第一出现Timestamp的话,如果没有设定default,数据库默认会设置为CURRENT_TIMESTAMP
            if (mf.isUnsigned())
                sb.append(" UNSIGNED");

            if (mf.isNotNull()) {
                sb.append(" NOT NULL");
            }

            if (mf.isAutoIncreasement())
                sb.append(" generated by default as identity");

            if (mf.getColumnType() == ColType.TIMESTAMP) {
                if (mf.hasDefaultValue()) {
                    sb.append(" ").append(getDefaultValue(mf));
                } else {
                    if (mf.isNotNull()) {
                        sb.append(" DEFAULT 0");
                    } else {
                        sb.append(" DEFAULT NULL");
                    }
                }
            } else {
                if (mf.hasDefaultValue())
                    sb.append(" DEFAULT '").append(getDefaultValue(mf)).append("'");
            }
        }

        if (mf.hasColumnComment()) {
            sb.append(" COMMENT '").append(mf.getColumnComment()).append("'");
        }

        sb.append(',');
    }
    // 创建主键
    List<MappingField> pks = en.getPks();
    if (!pks.isEmpty()) {
        sb.append('\n');
        sb.append("PRIMARY KEY (");
        for (MappingField pk : pks) {
            sb.append(pk.getColumnName()).append(',');
        }
        sb.setCharAt(sb.length() - 1, ')');
        sb.append("\n ");
    }

    // 结束表字段设置
    sb.setCharAt(sb.length() - 1, ')');
    // 表名注释
    if (en.hasTableComment()) {
        sb.append(" COMMENT='").append(en.getTableComment()).append("'");
    }

    // 执行创建语句
    dao.execute(Sqls.create(sb.toString()));

    // 创建索引
    dao.execute(createIndexs(en).toArray(new Sql[0]));

    // 创建关联表
    createRelation(dao, en);

    return true;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:78,
代码来源:DerbyJdbcExpert.java

示例27: createEntity

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public boolean createEntity(Dao dao, Entity<?> en) {
    StringBuilder sb = new StringBuilder("CREATE TABLE " + en.getTableName() + "(");
    // 创建字段
    for (MappingField mf : en.getMappingFields()) {
        if (mf.isReadonly())
            continue;
        sb.append('\n').append(mf.getColumnName());
        // 自增主键特殊形式关键字
        if (mf.isId() && mf.isAutoIncreasement()) {
            sb.append(" SERIAL");
        } else {
            sb.append(' ').append(evalFieldType(mf));
            // 非主键的 @Name,应该加入唯一性约束
            if (mf.isName() && en.getPkType() != PkType.NAME) {
                sb.append(" UNIQUE NOT NULL");
            }
            // 普通字段
            else {
                if (mf.isUnsigned())
                    sb.append(" UNSIGNED");
                if (mf.isNotNull())
                    sb.append(" NOT NULL");
                if (mf.isAutoIncreasement())
                    throw Lang.noImplement();
                if (mf.hasDefaultValue())
                    sb.append(" DEFAULT '").append(getDefaultValue(mf)).append('\'');
            }
        }
        sb.append(',');
    }
    // 创建主键
    List<MappingField> pks = en.getPks();
    if (!pks.isEmpty()) {
        sb.append('\n');
        sb.append(String.format("CONSTRAINT %s_pkey PRIMARY KEY (",
                                en.getTableName().replace('.', '_').replace('"', '_')));
        for (MappingField pk : pks) {
            sb.append(pk.getColumnName()).append(',');
        }
        sb.setCharAt(sb.length() - 1, ')');
        sb.append("\n ");
    }

    // 结束表字段设置
    sb.setCharAt(sb.length() - 1, ')');

    // 执行创建语句
    dao.execute(Sqls.create(sb.toString()));

    // 创建索引
    dao.execute(createIndexs(en).toArray(new Sql[0]));

    // 创建关联表
    createRelation(dao, en);

    // 添加注释(表注释与字段注释)
    addComment(dao, en);

    return true;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:61,
代码来源:PsqlJdbcExpert.java

示例28: createEntity

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public boolean createEntity(Dao dao, Entity<?> en) {
    StringBuilder sb = new StringBuilder("CREATE TABLE " + en.getTableName() + "(");
    // 创建字段
    for (MappingField mf : en.getMappingFields()) {
        if (mf.isReadonly())
            continue;
        sb.append('\n').append(mf.getColumnName());
        sb.append(' ').append(evalFieldType(mf));
        // 非主键的 @Name,应该加入唯一性约束
        if (mf.isName() && en.getPkType() != PkType.NAME) {
            sb.append(" UNIQUE NOT NULL");
        }
        // 普通字段
        else {
            if (mf.isUnsigned())
                sb.append(" UNSIGNED");
            if (mf.isNotNull())
                sb.append(" NOT NULL");
            if (mf.isAutoIncreasement())
                sb.append(" IDENTITY");
            if (mf.hasDefaultValue())
                sb.append(" DEFAULT '").append(getDefaultValue(mf)).append('\'');
        }
        sb.append(',');
    }
    // 创建主键
    List<MappingField> pks = en.getPks();
    if (!pks.isEmpty()) {
        sb.append('\n');
        sb.append("PRIMARY KEY (");
        for (MappingField pk : pks) {
            sb.append(pk.getColumnName()).append(',');
        }
        sb.setCharAt(sb.length() - 1, ')');
        sb.append("\n ");
    }

    // 结束表字段设置
    sb.setCharAt(sb.length() - 1, ')');

    // 执行创建语句
    dao.execute(Sqls.create(sb.toString()));
    // 创建索引
    dao.execute(createIndexs(en).toArray(new Sql[0]));
    // 创建关联表
    createRelation(dao, en);
    // 添加注释(表注释与字段注释)
    addComment(dao, en, COMMENT_COLUMN);

    return true;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:52,
代码来源:Sqlserver2005JdbcExpert.java

示例29: createEntity

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
@Override
public boolean createEntity(Dao dao, Entity<?> en) {
    StringBuilder sb = new StringBuilder("CREATE TABLE " + en.getTableName() + "(");
    if (en.getPks().size() > 1 && en.getPkType() == PkType.ID) {
        return false;
    }
    // 创建字段
    boolean mPks = en.getPks().size() > 1;
    for (MappingField mf : en.getMappingFields()) {
        if (mf.isReadonly())
            continue;
        sb.append('\n').append(mf.getColumnName());
        // Sqlite的整数型主键,一般都是自增的,必须定义为(PRIMARY KEY
        // AUTOINCREMENT),但这样就无法定义多主键!!
        if (mf.isId() && en.getPkType() == PkType.ID) {
            sb.append(" INTEGER PRIMARY KEY AUTOINCREMENT,");
            continue;
        } else
            sb.append(' ').append(evalFieldType(mf));
        // 非主键的 @Name,应该加入唯一性约束
        if (mf.isName() && en.getPkType() != PkType.NAME) {
            sb.append(" UNIQUE NOT NULL");
        }
        // 普通字段
        else {
            if (mf.isUnsigned())
                sb.append(" UNSIGNED");
            if (mf.isNotNull())
                sb.append(" NOT NULL");
            if (mf.isPk() && !mPks) {// 复合主键需要另外定义
                sb.append(" PRIMARY KEY");
            }
            if (mf.hasDefaultValue())
                sb.append(" DEFAULT '").append(getDefaultValue(mf)).append('\'');
        }
        sb.append(',');
    }
    // 创建主键
    List<MappingField> pks = en.getPks();
    if (mPks) {
        sb.append('\n');
        sb.append("constraint pk_").append(en.getTableName()).append(" PRIMARY KEY (");
        for (MappingField pk : pks) {
            sb.append(pk.getColumnName()).append(',');
        }
        sb.setCharAt(sb.length() - 1, ')');
        sb.append("\n ");
    }
    // 创建索引
    dao.execute(createIndexs(en).toArray(new Sql[0]));

    // 结束表字段设置
    sb.setCharAt(sb.length() - 1, ')');

    // 执行创建语句
    dao.execute(Sqls.create(sb.toString()));
    // 创建关联表
    createRelation(dao, en);

    return true;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:62,
代码来源:SQLiteJdbcExpert.java

示例30: createEntity

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public boolean createEntity(Dao dao, Entity<?> en) {
    StringBuilder sb = new StringBuilder("CREATE TABLE " + en.getTableName() + "(");
    // 创建字段
    for (MappingField mf : en.getMappingFields()) {
        if (mf.isReadonly())
            continue;
        sb.append('\n').append(mf.getColumnName());
        sb.append(' ').append(evalFieldType(mf));
        // 非主键的 @Name,应该加入唯一性约束
        if (mf.isName() && en.getPkType() != PkType.NAME) {
            sb.append(" UNIQUE NOT NULL");
        }
        // 普通字段
        else {
            if (mf.isUnsigned())
                sb.append(" UNSIGNED");
            if (mf.isAutoIncreasement()) // 自增与非空,不允许同时使用!
                sb.append(" GENERATED BY DEFAULT AS IDENTITY(START WITH 1)");
            else if (mf.isNotNull())
                sb.append(" NOT NULL");
            if (mf.hasDefaultValue())
                sb.append(" DEFAULT '").append(getDefaultValue(mf)).append('\'');
        }
        sb.append(',');
    }
    // 创建主键
    List<MappingField> pks = en.getPks();
    if (!pks.isEmpty()) {
        sb.append('\n');
        sb.append("PRIMARY KEY (");
        for (MappingField pk : pks) {
            sb.append(pk.getColumnName()).append(',');
        }
        sb.setCharAt(sb.length() - 1, ')');
        sb.append("\n ");
    }

    // 结束表字段设置
    sb.setCharAt(sb.length() - 1, ')');

    // 执行创建语句
    dao.execute(Sqls.create(sb.toString()));

    // 创建索引
    dao.execute(createIndexs(en).toArray(new Sql[0]));

    // 创建关联表
    createRelation(dao, en);
    // 添加注释(表注释与字段注释)
    addComment(dao, en);

    return true;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:54,
代码来源:HsqldbJdbcExpert.java

示例31: execute

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
public void execute(String sql){
	getDao().execute(Sqls.create(sql));
}
 

开发者ID:yancykim,
项目名称:support,
代码行数:4,
代码来源:RedShiftBasicDao.java

示例32: send

点赞 2

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 发送验证码
 * 
 * @param mobi
 * @return
 */
public boolean send(String mobi) {

	if (ToolUtility.verifyMobile(mobi)) {
		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String timestamp = dateFormat.format(date);
		String sign = encryptBASE64(HmacSHA1Encrypt("access_token="
				+ ACCESS_TOKEN + "&app_id=" + APP_ID + "&timestamp="
				+ timestamp, APP_SECRET));
		Map<String, Object> parms = new HashMap<String, Object>();
		parms.put("app_id", APP_ID);
		parms.put("access_token", ACCESS_TOKEN);
		parms.put("timestamp", timestamp);
		parms.put("sign", sign);
		String tmp = HttpClientTool.post(
				"http://api.189.cn/v2/dm/randcode/token", parms);

		System.out.println("获取token: " + tmp);
		if (tmp.indexOf("token") >= 0) {

			String token = tmp.substring(tmp.indexOf("token") + 8,
					tmp.indexOf("res_code") - 3);

			sign = encryptBASE64(HmacSHA1Encrypt("access_token="
					+ ACCESS_TOKEN + "&app_id=" + APP_ID + "&exp_time="
					+ EXP_TIME + "&phone=" + mobi + "&timestamp="
					+ timestamp + "&token=" + token + "&url=" + URL,
					APP_SECRET));

			parms = new HashMap<String, Object>();
			parms.put("app_id", APP_ID);
			parms.put("access_token", ACCESS_TOKEN);
			parms.put("token", token);
			parms.put("phone", mobi);
			parms.put("url", URL);
			parms.put("timestamp", timestamp);
			parms.put("exp_time", EXP_TIME);
			parms.put("sign", sign);
			tmp = HttpClientTool.post(
					"http://api.189.cn/v2/dm/randcode/send", parms);
			System.out.println("获取identifier: " + tmp);
			if (tmp.indexOf("identifier") >= 0) {

				try {
					Sql sql = Sqls
							.create("CALL pro_insert_ccode_1(@MOBI, @IDENTIFIER)");
					sql.params()
							.set("MOBI", mobi)
							.set("IDENTIFIER",
									tmp.substring(
											tmp.indexOf("identifier") + 13,
											tmp.indexOf("create_at") - 3));
					dao.execute(sql);
					return true;
				} catch (Exception e) {

					if (log.isErrorEnabled())
						log.error("send!!", e);
					return false;
				}
			} else
				return false;
		} else
			return false;
	} else
		return false;
}
 

开发者ID:howe,
项目名称:nutz,
代码行数:75,
代码来源:RandCodeInterFace.java

示例33: queryForInt

点赞 1

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 执行一个SQL查询操作,结果为一个int形数值。
 * 
 * @param sql
 *            包含变量占位符的SQL
 * @param vars
 *            变量map,无参数时,可为null
 * @param params
 *            参数map,无参数时,可为null
 * 
 * @return int数值,当查询为null时返回0
 */
public int queryForInt(String sql, Map<String, Object> vars, Map<String, Object> params) {
    Sql sqlObj = createSqlObj(sql, params);
    sqlObj.setCallback(Sqls.callback.integer());
    execute(sqlObj, vars, params);
    return sqlObj.getInt();
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:19,
代码来源:SqlTemplate.java

示例34: queryForLong

点赞 1

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 执行一个SQL查询操作,结果为一个long形数值。
 * 
 * @param sql
 *            包含变量占位符的SQL
 * @param vars
 *            变量map,无参数时,可为null
 * @param params
 *            参数map,无参数时,可为null
 * 
 * @return long数值,当查询为null时返回0
 */
public long queryForLong(String sql, Map<String, Object> vars, Map<String, Object> params) {
    Sql sqlObj = createSqlObj(sql, params);
    sqlObj.setCallback(Sqls.callback.longValue());
    execute(sqlObj, vars, params);
    Long result = sqlObj.getObject(Long.class);
    return result == null ? 0 : result;
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:20,
代码来源:SqlTemplate.java

示例35: queryForObject

点赞 1

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 执行一个SQL查询操作,结果为给定实体的对象。
 * 
 * @param sql
 *            包含变量占位符的SQL
 * @param vars
 *            变量map,无参数时,可为null
 * @param params
 *            参数map,无参数时,可为null
 * @param entity
 *            实体类型
 * 
 * @return 对象,无查询结果时返回null
 */
public <T> T queryForObject(String sql,
                            Map<String, Object> vars,
                            Map<String, Object> params,
                            Entity<T> entity) {
    Sql sqlObj = createSqlObj(sql, params);
    sqlObj.setCallback(Sqls.callback.entity());
    sqlObj.setEntity(entity);

    execute(sqlObj, vars, params);

    return sqlObj.getObject(entity.getType());
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:27,
代码来源:SqlTemplate.java

示例36: queryForRecord

点赞 1

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 执行一个SQL查询操作,结果为Record的对象。
 * 
 * @param sql
 *            包含变量占位符的SQL
 * @param vars
 *            变量map,无参数时,可为null
 * @param params
 *            参数map,无参数时,可为null
 * @return Record对象,无查询结果时返回null
 */
public Record queryForRecord(String sql, Map<String, Object> vars, Map<String, Object> params) {
    Sql sqlObj = createSqlObj(sql, params);
    sqlObj.setCallback(Sqls.callback.record());

    execute(sqlObj, vars, params);

    return sqlObj.getObject(Record.class);
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:20,
代码来源:SqlTemplate.java

示例37: query

点赞 1

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 执行一个SQL查询操作,结果为一组对象。
 * 
 * @param sql
 *            包含变量占位符的SQL
 * @param vars
 *            变量map,无参数时,可为null
 * @param params
 *            参数map,无参数时,可为null
 * @param entity
 *            对象类型
 * 
 * @return 对象列表,无查询结果时返回长度为0的List对象
 */
public <T> List<T> query(String sql,
                         Map<String, Object> vars,
                         Map<String, Object> params,
                         Entity<T> entity) {
    Sql sqlObj = createSqlObj(sql, params);
    sqlObj.setCallback(Sqls.callback.entities());
    sqlObj.setEntity(entity);

    execute(sqlObj, vars, params);

    return sqlObj.getList(entity.getType());
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:27,
代码来源:SqlTemplate.java

示例38: queryRecords

点赞 1

import org.nutz.dao.Sqls; //导入依赖的package包/类
/**
 * 执行一个SQL查询操作,结果为Record对象列表。
 * 
 * @param sql
 *            包含变量占位符的SQL
 * @param vars
 *            变量map,无参数时,可为null
 * @param params
 *            参数map,无参数时,可为null
 * 
 * @return Record列表,无查询结果时返回长度为0的List对象
 */
public List<Record> queryRecords(String sql,
                                 Map<String, Object> vars,
                                 Map<String, Object> params) {
    Sql sqlObj = createSqlObj(sql, params);
    sqlObj.setCallback(Sqls.callback.records());

    execute(sqlObj, vars, params);

    return sqlObj.getList(Record.class);
}
 

开发者ID:cowthan,
项目名称:JavaAyo,
代码行数:23,
代码来源:SqlTemplate.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)