Package org.nutz.dao.entity

Examples of org.nutz.dao.entity.MappingField


   */
  public Chain updateBy(Entity<?> entity) {
    if (null != entity) {
      Chain c = head;
      while (c != null) {
        MappingField ef = entity.getField(c.name);
        if (null != ef) {
          c.name(ef.getColumnName());
        }
        c = c.next;
      }
    }
    return head;
View Full Code Here


  }

  public int joinAdaptor(Entity<?> en, ValueAdaptor[] adaptors, int off) {
    Chain c = chain.head();
    while (c != null) {
      MappingField mf = en.getField(c.name());
      adaptors[off++] = (null == mf ? Jdbcs.getAdaptorBy(c.value()) : mf.getAdaptor());
      c = c.next();
    }
    return off;
  }
View Full Code Here

  protected String _fmtcolnm(Entity<?> en, String name) {
    if (null == en && null != pojo)
      en = pojo.getEntity();

    if (null != en) {
      MappingField mf = en.getField(name);
      if (null != mf)
        return mf.getColumnName();
    }
    return name;
  }
View Full Code Here

                                      info.annNext.value())))) {
        continue;
      }
      // '@Id' : 的自动后续获取
      else if (null != info.annId && info.annId.auto()) {
        MappingField idField = en.getField(info.name);
        String autoSql = "SELECT MAX($field) AS $field FROM $view";
        Pojo autoInfo = new SqlFieldMacro(idField, autoSql);
        autoInfo.setEntity(en);
        en.addAfterInsertMacro(autoInfo);
      }
View Full Code Here

  }

  @Test
  public void test_override_field() {
    Entity<?> en = en(Pet2.class);
    MappingField ef = en.getField("nickName");
    assertEquals("alias", ef.getColumnName());
    assertEquals(1, en.cloneBeforeInsertMacroes().size());
  }
View Full Code Here

      sb.append(" NOT ");
    sb.append(_fmtcol(en)).append(op).append('?');
  }

  public int joinAdaptor(Entity<?> en, ValueAdaptor[] adaptors, int off) {
    MappingField mf = _field(en);
    if (null != mf) {
      adaptors[off++] = mf.getAdaptor();
    } else {
      adaptors[off++] = Jdbcs.getAdaptorBy(value);
    }
    return off;
  }
View Full Code Here

                sb.append("Create Index ");
            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());
View Full Code Here

        final StringBuilder sql = new StringBuilder("UPDATE ").append(tableName).append(" SET ");
        Chain head = chain.head();
        final List<Object> values = new ArrayList<Object>();
        final List<ValueAdaptor> adaptors = new ArrayList<ValueAdaptor>();
        while (head != null) {
            MappingField mf = null;
            if (en != null)
                mf = en.getField(head.name());
            String colName = head.name();
            if (mf != null)
                colName = mf.getColumnName();
            sql.append(colName).append("=");
            if (head.special()) {
                if ("+1".equals(head.value()) || "-1".equals(head.value())) {
                    sql.append(colName);
                }
                sql.append(head.value());
            } else {
                sql.append("?");
                values.add(head.value());
                ValueAdaptor adaptor = Jdbcs.getAdaptorBy(head.value());
                if (mf != null && mf.getAdaptor() != null)
                    adaptor = mf.getAdaptor();
                adaptors.add(adaptor);
            }
            sql.append(" ");
            head = head.next();
            if (head != null)
View Full Code Here

    protected String _fmtcolnm(Entity<?> en, String name) {
        if (null == en && null != pojo)
            en = pojo.getEntity();

        if (null != en) {
            MappingField mf = en.getField(name);
            if (null != mf)
                return mf.getColumnName();
        }
        return name;
    }
View Full Code Here

    public static PItem queryEntityFields() {
      return new QueryEntityFieldsPItem();
    }

    public static PItem cndId(Entity<?> en, Number id) {
        MappingField mappingField = en.getIdField();
        if (mappingField == null)
            throw new DaoException("expect @Id but NOT found. " + en.getType().getName());
      return cndColumn(mappingField, id);
    }
View Full Code Here

TOP

Related Classes of org.nutz.dao.entity.MappingField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.