當前位置: 首頁>>代碼示例>>Java>>正文


Java FieldDescriptor.getName方法代碼示例

本文整理匯總了Java中com.google.protobuf.Descriptors.FieldDescriptor.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java FieldDescriptor.getName方法的具體用法?Java FieldDescriptor.getName怎麽用?Java FieldDescriptor.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.protobuf.Descriptors.FieldDescriptor的用法示例。


在下文中一共展示了FieldDescriptor.getName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createProtoBuf

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
Message createProtoBuf(
    Descriptor descriptor, Message.Builder builder, Map<String, Object> input) {

  if (input == null) {
    return builder.build();
  }
  for (FieldDescriptor field : descriptor.getFields()) {
    String fieldName = field.getName();

    if (!input.containsKey(fieldName)) {
      // TODO: validate required fields
      continue;
    }

    if (field.isRepeated()) {
      List<Object> values = (List<Object>) input.get(fieldName);
      for (Object value : values) {
        builder.addRepeatedField(field, getValueForField(field, value, builder));
      }
    } else {
      builder.setField(field, getValueForField(field, input.get(fieldName), builder));
    }
  }

  return builder.build();
}
 
開發者ID:google,項目名稱:rejoiner,代碼行數:27,代碼來源:GqlInputConverter.java

示例2: insert

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
/**
 * 插入對象到給定的表中。注意,這裏並不自動生成ID。
 * 
 * @param message
 * @param tableName
 * @return
 */
public long insert(M message, String tableName) {
	StringBuilder insertSql = new StringBuilder("insert into ");
	insertSql.append(tableName).append("(");
	StringBuilder fields = new StringBuilder("");
	StringBuilder values = new StringBuilder("");
	List<Object> args = new ArrayList<Object>();
	Map<FieldDescriptor, Object> fieldMap = message.getAllFields();

	for (Entry<FieldDescriptor, Object> entry : fieldMap.entrySet()) {
		FieldDescriptor fieldDescriptor = entry.getKey();
		FieldOptions fieldOptions = fieldDescriptor.getOptions();
		ColumnFieldOption columnFieldOption = fieldOptions
				.getExtension(Taglib.columnOption);
		String fieldName = fieldDescriptor.getName();
		Object value = entry.getValue();

		if (columnFieldOption.getColumnType() == ColumnType.DATETIME
				|| columnFieldOption.getColumnType() == ColumnType.TIMESTAMP) {// datetime類型
			if (value != null && (long) value > 0) {
				fields.append('`').append(fieldName).append("`,");
				values.append("?, ");
				args.add(new Timestamp((long) value));
			}
		} else {
			fields.append('`').append(fieldName).append("`,");
			values.append("?, ");
			args.add(value);
		}
	}
	int tmpIndex = fields.lastIndexOf(",");
	insertSql.append(fields.substring(0, tmpIndex)).append(") values(");
	tmpIndex = values.lastIndexOf(",");
	insertSql.append(values.substring(0, tmpIndex)).append(")");
	String sql = insertSql.toString();
	return update(sql, args);
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:44,代碼來源:JdbcProtobufTemplate.java

示例3: updateMessageByCondition

import com.google.protobuf.Descriptors.FieldDescriptor; //導入方法依賴的package包/類
/**
 * 
 * @param message
 * @param conditionFields
 * @param conditionParams
 * @param tableName
 * @return
 */
protected int updateMessageByCondition(M message, String[] conditionFields,
		Object[] conditionParams, String tableName) {
	StringBuilder updateSql = new StringBuilder("update ");
	updateSql.append(tableName).append(" set ");
	StringBuilder options = new StringBuilder("");
	List<Object> args = new ArrayList<Object>();
	Map<FieldDescriptor, Object> fieldMap = message.getAllFields();

	for (Entry<FieldDescriptor, Object> entry : fieldMap.entrySet()) {
		FieldDescriptor fieldDescriptor = entry.getKey();
		if (!Arrays.asList(conditionFields).contains(
				fieldDescriptor.getName())) {
			FieldOptions fieldOptions = fieldDescriptor.getOptions();
			ColumnFieldOption columnFieldOption = fieldOptions
					.getExtension(Taglib.columnOption);
			String fieldName = fieldDescriptor.getName();
			Object value = entry.getValue();
			if (columnFieldOption.getColumnType() == ColumnType.DATETIME
					|| columnFieldOption.getColumnType() == ColumnType.TIMESTAMP) {// datetime類型
				if (value != null && (long) value > 0) {
					options.append(fieldName).append("=?, ");
					args.add(new Timestamp((long) value));
				}
			} else {
				options.append(fieldName).append("=?, ");
				args.add(value);
			}
		}
	}
	int tmpIndex = options.lastIndexOf(",");
	updateSql.append(options.substring(0, tmpIndex)).append(" where 1=1 ");
	StringBuilder condition = new StringBuilder();
	if (conditionFields.length != conditionParams.length) {
		throw new IllegalArgumentException("condition error");
	} else {
		for (int i = 0; i < conditionFields.length; i++) {
			condition.append("AND ").append(conditionFields[i])
					.append("=? ");
			args.add(conditionParams[i]);
		}
		updateSql.append(condition);
		String sql = updateSql.toString();
		logger.debug(sql);
		return update(sql, args);
	}
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:55,代碼來源:JdbcProtobufTemplate.java


注:本文中的com.google.protobuf.Descriptors.FieldDescriptor.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。