예제 #1
0
 public void formatQuery(DaoStatement daoStatement) {
   if (daoStatement == null) return;
   SqlContext ctx = daoStatement.getContext();
   if (ctx == null || ctx.getPager() == null) return;
   if (daoStatement instanceof Pojo) formatQuery((Pojo) daoStatement);
   else if (daoStatement instanceof Sql) formatQuery((Sql) daoStatement);
   else throw Lang.noImplement();
 }
예제 #2
0
  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;
  }
예제 #3
0
파일: NutDao.java 프로젝트: JRed1989/nutz
  public int updateRelation(Class<?> classOfT, String regex, Chain chain, Condition cnd) {
    if (chain.isSpecial()) throw Lang.noImplement();

    EntityOperator opt = this._opt(classOfT);

    opt.entity.visitManyMany(null, regex, doUpdateRelation(opt, chain, cnd));
    opt.exec();

    return opt.getUpdateCount();
  }
예제 #4
0
 public void formatQuery(Sql sql) {
   throw Lang.noImplement();
 }
예제 #5
0
 public Pojo duplicate() {
   throw Lang.noImplement();
 }
예제 #6
0
 public Reader getCharacterStream(long pos, long length) throws SQLException {
   throw Lang.noImplement();
 }
예제 #7
0
 public Writer setCharacterStream(long pos) throws SQLException {
   throw Lang.noImplement();
 }
예제 #8
0
 public OutputStream setAsciiStream(long pos) throws SQLException {
   throw Lang.noImplement();
 }
예제 #9
0
 public int setString(long pos, String str, int offset, int len) throws SQLException {
   throw Lang.noImplement();
 }
예제 #10
0
 public long position(Clob searchstr, long start) throws SQLException {
   throw Lang.noImplement();
 }
예제 #11
0
 public String getSubString(long pos, int length) throws SQLException {
   throw Lang.noImplement();
 }