Returns SQL string to add a column to an existing table.

@param entityType entity meta data
@param attr attribute
@param columnMode column mode
@return SQL string
7534
static String getSqlAddColumn(EntityType entityType, Attribute attr, ColumnMode columnMode) {
    StringBuilder sql = new StringBuilder("ALTER TABLE ");

    String columnSql = getSqlColumn(entityType, attr, columnMode);
    sql.append(getTableName(entityType)).append(" ADD ").append(columnSql);

    List<String> sqlTableConstraints = getSqlTableConstraints(entityType, attr);
    if (!sqlTableConstraints.isEmpty()) {
      sqlTableConstraints.forEach(
          sqlTableConstraint -> sql.append(",ADD ").append(sqlTableConstraint));
    }
    return sql.toString();
  }
782183
@SuppressWarnings("unchecked")
	@Override
	public int update(final Object entity) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isInstance(entity)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			Class<?> type = entity.getClass();
			TableMetadata metadata = handler.getMetadata(this.transactionManager, type);
			SqlContext context = handler.createUpdateContext(this, metadata, type, true);
			context.setSqlKind(SqlKind.UPDATE);
			handler.setUpdateParams(context, entity);
			int count = handler.doUpdate(this, context, entity);

			if (count == 0 && MappingUtils.getVersionMappingColumn(type).isPresent()) {
				throw new OptimisticLockException(context);
			}
			return count;
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.UPDATE, e);
		}
	}
355026
static QueryMeta buildInsertSql(ActiveRecord activeRecord) {
        QueryMeta     queryMeta = new QueryMeta();
        String        tableName = activeRecord.getTableName();
        StringBuilder sb        = new StringBuilder(Const.SQL_INSERT + " ");
        sb.append(tableName);
        sb.append(" (");

        StringBuffer values = new StringBuffer(" VALUES (");
        Stream.of(activeRecord.getClass().getDeclaredFields())
                .filter(field -> null == field.getAnnotation(Transient.class))
                .forEach(field -> {
                    try {
                        field.setAccessible(true);
                        if (field.get(activeRecord) != null) {
                            Pair<String, String> pair = getColumnName(field);
                            sb.append(pair.getLeft()).append(", ");
                            values.append(':').append(pair.getRight()).append(", ");
                        }
                    } catch (Exception e) {
                    }
                });

        sb.append(')');
        values.append(')');

        String sql = sb.append(values).toString().replace(", )", ")");
        queryMeta.setSql(sql);
        return queryMeta;
    }
315446
@Override
	public SqlEntityQuery<E> asc(final String... cols) {
		for (String col : cols) {
			this.sortOrders.add(new SortOrder(col, Order.ASCENDING));
		}
		return this;
	}
127765
private void updateColumn(EntityType entityType, Attribute attr, Attribute updatedAttr) {
    // nullable changes
    if (!Objects.equals(attr.isNillable(), updatedAttr.isNillable())) {
      updateNillable(entityType, attr, updatedAttr);
    }

    // unique changes
    if (!Objects.equals(attr.isUnique(), updatedAttr.isUnique())) {
      updateUnique(entityType, attr, updatedAttr);
    }

    // readonly changes
    if (!Objects.equals(attr.isReadOnly(), updatedAttr.isReadOnly())) {
      updateReadonly(entityType, attr, updatedAttr);
    }

    // data type changes
    if (!Objects.equals(attr.getDataType(), updatedAttr.getDataType())) {
      if (updatedAttr.isReadOnly()) {
        dropTableTriggers(entityType);
      }
      updateDataType(entityType, attr, updatedAttr);
      if (updatedAttr.isReadOnly()) {
        createTableTriggers(entityType);
      }
    }

    // ref entity changes
    if (attr.hasRefEntity()
        && updatedAttr.hasRefEntity()
        && !attr.getRefEntity().getId().equals(updatedAttr.getRefEntity().getId())) {
      updateRefEntity(entityType, attr, updatedAttr);
    }

    // enum option changes
    if (!Objects.equals(attr.getEnumOptions(), updatedAttr.getEnumOptions())) {
      updateEnumOptions(entityType, attr, updatedAttr);
    }
  }
1322392
public String getColumnHolder(String entityName, String suffix, String separator) {
        StringBuffer sb = new StringBuffer("#{");
        if (StringUtil.isNotEmpty(entityName)) {
            sb.append(entityName);
            sb.append(".");
        }
        sb.append(this.property);
        if (StringUtil.isNotEmpty(suffix)) {
            sb.append(suffix);
        }
        //如果 null 被当作值来传递，对于所有可能为空的列，JDBC Type 是需要的
        if (this.jdbcType != null) {
            sb.append(", jdbcType=");
            sb.append(this.jdbcType.toString());
        }
        //为了以后定制类型处理方式，你也可以指定一个特殊的类型处理器类，例如枚举
        if (this.typeHandler != null) {
            sb.append(", typeHandler=");
            sb.append(this.typeHandler.getCanonicalName());
        }
        //3.4.0 以前的 mybatis 无法获取父类中泛型的 javaType，所以如果使用低版本，就需要设置 useJavaType = true
        //useJavaType 默认 false,没有 javaType 限制时，对 ByPrimaryKey 方法的参数校验就放宽了，会自动转型
        if (useJavaType && !this.javaType.isArray()) {//当类型为数组时，不设置javaType#103
            sb.append(", javaType=");
            sb.append(javaType.getCanonicalName());
        }
        sb.append("}");
        if (StringUtil.isNotEmpty(separator)) {
            sb.append(separator);
        }
        return sb.toString();
    }
485125
public static String selectAllColumns(Class<?> entityClass) {
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT ");
        sql.append(getAllColumns(entityClass));
        sql.append(" ");
        return sql.toString();
    }
1254726
private void generateColumnsArray(Finder<SQLProperty> entity) {
		// generate columns array
		Builder sp = FieldSpec.builder(ArrayTypeName.of(String.class), "COLUMNS", Modifier.STATIC, Modifier.PRIVATE,
				Modifier.FINAL);
		String s = "";
		StringBuilder buffer = new StringBuilder();
		for (SQLProperty property : entity.getCollection()) {
			buffer.append(s + "COLUMN_" + columnNameToUpperCaseConverter.convert(property.getName()));
			s = ", ";
		}
		classBuilder.addField(sp.addJavadoc("Columns array\n").initializer("{" + buffer.toString() + "}").build());
		classBuilder.addMethod(MethodSpec.methodBuilder("columns").addModifiers(Modifier.PUBLIC)
				.addJavadoc("Columns array\n").addAnnotation(Override.class).returns(ArrayTypeName.of(String.class))
				.addStatement("return COLUMNS").build());

		classBuilder.addMethod(MethodSpec.methodBuilder("name").addModifiers(Modifier.PUBLIC).addJavadoc("table name\n")
				.addAnnotation(Override.class).returns(TypeName.get(String.class)).addStatement("return TABLE_NAME")
				.build());
	}
1181635
def add_column(self, tablename: str, fieldspec: FIELDSPEC_TYPE) -> int:
        """"""
        sql = "ALTER TABLE {} ADD COLUMN {}".format(
            tablename, self.fielddefsql_from_fieldspec(fieldspec))
        log.info(sql)
        return self.db_exec_literal(sql)
922437
public JdbcMapperBuilder<T> addMapping(final String column, final int index, final int sqlType) {
        addMapping(column, index, sqlType, FieldMapperColumnDefinition.<JdbcColumnKey>identity());
        return this;
    }
22654
public static Entity handleRow(ResultSet rs) throws SQLException {
		final ResultSetMetaData meta = rs.getMetaData();
		final int columnCount = meta.getColumnCount();
		return handleRow(columnCount, meta, rs);
	}
41611
List<String> getColumnList(EntityMetadata m, MetamodelImpl metamodel, String[] results,
        EmbeddableType compoundKey) {
        List<String> columns = new ArrayList<String>();
        if (results != null && results.length > 0) {
            MetamodelImpl metaModel =
                (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
            EntityType entity = metaModel.entity(m.getEntityClazz());

            String keyFieldName = CassandraUtilities.getIdColumnName(kunderaMetadata, m, externalProperties,
                ((CassandraClientBase) persistenceDelegeator.getClient(m)).isCql3Enabled(m));
            for (int i = 1; i < results.length; i++) {
                if (results[i] != null) {
                    if (results[i].indexOf(".") > 0) {
                        String fieldName = results[i].substring(0, results[i].indexOf("."));
                        String embeddedFieldName =
                            results[i].substring(results[i].indexOf(".") + 1, results[i].length());
                        AbstractAttribute attribute = (AbstractAttribute) entity.getAttribute(fieldName);
                        EmbeddableType embeddable = metamodel.embeddable(attribute.getBindableJavaType());
                        Attribute embeddableAttribute = embeddable.getAttribute(embeddedFieldName);
                        columns.add(((AbstractAttribute) embeddableAttribute).getJPAColumnName());
                    } else {
                        Attribute attribute = entity.getAttribute(results[i]);
                        if (attribute == null) {
                            throw new QueryHandlerException("Column type is null for : " + results);
                        } else if (m.getIdAttribute().equals(attribute) && compoundKey != null) {
                            Field[] fields = m.getIdAttribute().getBindableJavaType().getDeclaredFields();
                            for (Field field : fields) {
                                addCompositeIdToColumns(metamodel, compoundKey, columns, field);
                            }
                        } else if (m.getIdAttribute().equals(attribute) && compoundKey == null) {
                            columns.add(keyFieldName);
                        } else {
                            columns.add(((AbstractAttribute) attribute).getJPAColumnName());
                        }
                    }
                }
            }
            return columns;
        }

        if (log.isInfoEnabled()) {
            log.info("No record found, returning null.");
        }
        return null;
    }
1182093
public static Object getTypedValue(String valueStr, Attribute attr, EntityManager entityManager) {
    if (valueStr == null) return null;
    switch (attr.getDataType()) {
      case BOOL:
        return Boolean.valueOf(valueStr);
      case CATEGORICAL:
      case FILE:
      case XREF:
        EntityType xrefEntity = attr.getRefEntity();
        Object xrefIdValue = getTypedValue(valueStr, xrefEntity.getIdAttribute(), entityManager);
        return entityManager.getReference(xrefEntity, xrefIdValue);
      case CATEGORICAL_MREF:
      case MREF:
      case ONE_TO_MANY:
        EntityType mrefEntity = attr.getRefEntity();
        List<String> mrefIdStrValues = ListEscapeUtils.toList(valueStr);
        return mrefIdStrValues
            .stream()
            .map(
                mrefIdStrValue ->
                    getTypedValue(mrefIdStrValue, mrefEntity.getIdAttribute(), entityManager))
            .map(mrefIdValue -> entityManager.getReference(mrefEntity, mrefIdValue))
            .collect(toList());
      case COMPOUND:
        throw new IllegalArgumentException("Compound attribute has no value");
      case DATE:
        try {
          return parseLocalDate(valueStr);
        } catch (DateTimeParseException e) {
          throw new MolgenisDataException(
              format(FAILED_TO_PARSE_ATTRIBUTE_AS_DATE_MESSAGE, attr.getName(), valueStr), e);
        }
      case DATE_TIME:
        try {
          return parseInstant(valueStr);
        } catch (DateTimeParseException e) {
          throw new MolgenisDataException(
              format(FAILED_TO_PARSE_ATTRIBUTE_AS_DATETIME_MESSAGE, attr.getName(), valueStr), e);
        }
      case DECIMAL:
        return Double.valueOf(valueStr);
      case EMAIL:
      case ENUM:
      case HTML:
      case HYPERLINK:
      case SCRIPT:
      case STRING:
      case TEXT:
        return valueStr;
      case INT:
        return Integer.valueOf(valueStr);
      case LONG:
        return Long.valueOf(valueStr);
      default:
        throw new UnexpectedEnumException(attr.getDataType());
    }
  }
160635
private Object getColumnValue(EntityMetadata m, Object e, Attribute attribute)
    {
        Field field = (Field) ((Attribute) attribute).getJavaMember();
        Object value;
        if (!m.isCounterColumnType())
        {
            value = getThriftColumnValue(e, attribute);
        }
        else
        {
            value = PropertyAccessorHelper.getString(e, field);
        }
        return value;
    }
1037524
function _addColumn(){
    self._visitingAlter = true;
    var table = self._queryNode.table;
    self._visitingAddColumn = true;
    var result='ALTER TABLE '+self.visit(table.toNode())+' ADD ('+self.visit(alter.nodes[0].nodes[0]);
    for (var i= 1,len=alter.nodes.length; i<len; i++){
      var node=alter.nodes[i];
      assert(node.type=='ADD COLUMN',errMsg);
      result+=', '+self.visit(node.nodes[0]);
    }
    result+=')';
    self._visitingAddColumn = false;
    self._visitingAlter = false;
    return [result];
  }
552773
public String onQueryOverCQL3(EntityMetadata m, Client client, MetamodelImpl metaModel, List<String> relations) {
        // select column will always be of entity field only!
        // where clause ordering

        Class compoundKeyClass = m.getIdAttribute().getBindableJavaType();
        EmbeddableType compoundKey = null;
        String idColumn;
        if (metaModel.isEmbeddable(compoundKeyClass)) {
            compoundKey = metaModel.embeddable(compoundKeyClass);
            idColumn = ((AbstractAttribute) m.getIdAttribute()).getJPAColumnName();
        } else {
            idColumn = ((AbstractAttribute) m.getIdAttribute()).getJPAColumnName();
        }
        StringBuilder builder = new StringBuilder();

        boolean isPresent = false;
        List<String> columns = getColumnList(m, metaModel, getKunderaQuery().getResult(), compoundKey);
        String selectQuery = setSelectQuery(columns);

        CQLTranslator translator = new CQLTranslator();

        selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMN_FAMILY,
            translator.ensureCase(new StringBuilder(), m.getTableName(), false).toString());

        builder = CassandraUtilities.appendColumns(builder, columns, selectQuery, translator);

        addWhereClause(builder);

        onCondition(m, metaModel, compoundKey, idColumn, builder, isPresent, translator, true);

        return builder.toString();
    }
261867
@PostMapping(
      value = "/{entityTypeId}/meta/{attributeName}",
      params = "_method=GET",
      produces = APPLICATION_JSON_VALUE)
  public AttributeResponse retrieveEntityAttributeMetaPost(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("attributeName") String attributeName,
      @Valid @RequestBody EntityTypeRequest request) {
    Set<String> attributeSet = toAttributeSet(request != null ? request.getAttributes() : null);
    Map<String, Set<String>> attributeExpandSet =
        toExpandMap(request != null ? request.getExpand() : null);

    return getAttributePostInternal(entityTypeId, attributeName, attributeSet, attributeExpandSet);
  }