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


Java Field.pos方法代碼示例

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


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

示例1: generateAppropriateWrapper

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
public static String generateAppropriateWrapper(Schema schema, Field field) {
  if (DIRTY_BYTES_FIELD_NAME.equals(field.name())) {
    return "java.nio.ByteBuffer.wrap(new byte["
      + getNumberOfBytesNeededForDirtyBits(schema) + "])";
  } else {
    switch (field.schema().getType()) {
    case RECORD:
      return field.schema().getName()+".newBuilder().build()";
    case MAP:
      return "new org.apache.gora.persistency.impl.DirtyMapWrapper((java.util.Map)defaultValue(fields()["+field.pos()+"]))";
    case ARRAY:
      return "new org.apache.gora.persistency.impl.DirtyListWrapper((java.util.List)defaultValue(fields()["+field.pos()+"]))";
    default:
      return "defaultValue(fields()["+field.pos()+"])";
    }
  }
  
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:19,代碼來源:GoraCompiler.java

示例2: getPersistent

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Returns a clone with exactly the requested fields shallowly copied
 */
private static<T extends Persistent> T getPersistent(T obj, String[] fields) {
  List<Field> otherFields = obj.getSchema().getFields();
  String[] otherFieldStrings = new String[otherFields.size()];
  for(int i = 0; i<otherFields.size(); i++ ){
    otherFieldStrings[i] = otherFields.get(i).name();
  }
  if(Arrays.equals(fields, otherFieldStrings)) { 
    return obj;
  }
  T newObj = AvroUtils.deepClonePersistent(obj);
  for (Field otherField : otherFields) {
    int index = otherField.pos();
    newObj.put(index, obj.get(index));
  }
  return newObj;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:20,代碼來源:MemStore.java

示例3: checkIfMutableFieldAndDirty

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
private boolean checkIfMutableFieldAndDirty(Field field) {
  if (field.pos() == 0)
    return false;
  switch (field.schema().getType()) {
  case RECORD:
  case MAP:
  case ARRAY:
    Object value = get(field.pos());
    return !(value instanceof Dirtyable) || value==null ? false : ((Dirtyable) value).isDirty();
  case UNION:
    value = get(field.pos());
    return !(value instanceof Dirtyable) || value==null ? false : ((Dirtyable) value).isDirty();
  default:
    break;
  }
  return false;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:18,代碼來源:PersistentBase.java

示例4: convertToAvro

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public IndexedRecord convertToAvro(GettableT gettable) {
    if (containerDataSpec == null) {
        setContainerDataSpecFromInstance(gettable);
    }

    IndexedRecordAdapterWithCache record = new IndexedRecordAdapterWithCache(gettable);

    // Create all of the readers for the record immediately.
    if (fieldReader == null) {
        fieldReader = new ContainerReaderByIndex[fieldType.length];
        for (Field f : AvroUtils.unwrapIfNullable(getSchema()).getFields()) {
            int i = f.pos();
            fieldType[i] = getFieldDataSpec(i);
            fieldReader[i] = getFieldReader(fieldType[i]);
        }
    }

    return record;
}
 
開發者ID:Talend,項目名稱:daikon,代碼行數:22,代碼來源:CachedIndexedRecordConverterBase.java

示例5: write

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Removes input data resources from Jira server <br>
 * Method should be called only after {@link JiraDeleteWriter#open(String)}
 * 
 * @param datum input data
 */
@Override
public void write(Object datum) throws IOException {
    if (!opened) {
        throw new IOException(MESSAGES.getMessage("error.writerNotOpened"));
    }
    result.totalCount++;
    if (datum == null) {
        return;
    }
    IndexedRecord record = getFactory(datum).convertToAvro(datum);
    if (dataSchema == null) {
        dataSchema = record.getSchema();
        Field idField = dataSchema.getField("id");
        if (idField == null) {
            throw new IOException(MESSAGES.getMessage("error.schemaNotContainId"));
        }
        idPos = idField.pos();
    }

    String id = (String) record.get(idPos);
    String resourceToDelete = resource + "/" + id;
    JiraResponse response = getConnection().delete(resourceToDelete, sharedParameters);
    handleResponse(response, id, record);
}
 
開發者ID:Talend,項目名稱:components,代碼行數:31,代碼來源:JiraDeleteWriter.java

示例6: write

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Inserts resources into Jira server formed from incoming data input <br>
 * Method should be called only after {@link JiraInsertWriter#open(String)}
 * 
 * @param datum input data
 */
@Override
public void write(Object datum) throws IOException {
    if (!opened) {
        throw new IOException(MESSAGES.getMessage("error.writerNotOpened"));
    }
    result.totalCount++;
    if (datum == null) {
        return;
    }
    IndexedRecord record = getFactory(datum).convertToAvro(datum);

    if (dataSchema == null) {
        dataSchema = record.getSchema();
        Field jsonField = dataSchema.getField("json");
        if (jsonField == null) {
            throw new IOException(MESSAGES.getMessage("error.schemaNotContainJson"));
        }
        jsonPos = jsonField.pos();
    }

    String json = (String) record.get(jsonPos);
    validateRequestBody(json);

    JiraResponse response = getConnection().post(resource, json);
    handleResponse(response, json, record);
}
 
開發者ID:Talend,項目名稱:components,代碼行數:33,代碼來源:JiraInsertWriter.java

示例7: write

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * Updates Jira resources according incoming data <br>
 * Method should be called only after {@link JiraUpdateWriter#open(String)}
 * 
 * @param datum input data
 */
@Override
public void write(Object datum) throws IOException {
    if (!opened) {
        throw new IOException(MESSAGES.getMessage("error.writerNotOpened"));
    }
    result.totalCount++;
    if (datum == null) {
        return;
    }
    IndexedRecord record = getFactory(datum).convertToAvro(datum);

    if (dataSchema == null) {
        dataSchema = record.getSchema();
        Field idField = dataSchema.getField("id");
        if (idField == null) {
            throw new IOException(MESSAGES.getMessage("error.schemaNotContainId"));
        }
        idPos = idField.pos();
        Field jsonField = dataSchema.getField("json");
        if (jsonField == null) {
            throw new IOException(MESSAGES.getMessage("error.schemaNotContainJson"));
        }
        jsonPos = jsonField.pos();
    }

    String id = (String) record.get(idPos);
    String resourceToUpdate = resource + "/" + id;

    String json = (String) record.get(jsonPos);
    validateRequestBody(json);

    JiraResponse response = getConnection().put(resourceToUpdate, json);
    handleResponse(response, json, record);
}
 
開發者ID:Talend,項目名稱:components,代碼行數:41,代碼來源:JiraUpdateWriter.java

示例8: getConverter

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
@Override
public JDBCConverter getConverter(final Field f) {
    final Schema basicSchema = AvroUtils.unwrapIfNullable(f.schema());

    return null == basicSchema.getLogicalType() ? super.getConverter(f) : new JDBCConverter() {

        @Override
        public Object convertToAvro(ResultSet value) {
            int index = f.pos() + 1;
            try {
                if (basicSchema.getLogicalType() == LogicalTypes.date()) {
                    // Snowflake stores the value as the number of days. So it is possible to retrieve that as an
                    // int value instead of converting it to Date first and then to days from milliseconds. If we
                    // convert it to date, Snowflake jdbc shifts the time to 00:00 in current timezone.
                    return value.getInt(index);
                } else if (basicSchema.getLogicalType() == LogicalTypes.timeMillis()) {
                    java.sql.Time time = value.getTime(index);
                    return (time != null) ? (int) time.getTime() : null;
                } else {
                    java.sql.Timestamp timestamp = value.getTimestamp(index);
                    return (timestamp != null) ? timestamp.getTime() : null;
                }
            } catch (SQLException e) {
                throw new ComponentException(e);
            }
        }
    };
}
 
開發者ID:Talend,項目名稱:components,代碼行數:29,代碼來源:SnowflakeAvroRegistry.java

示例9: getFieldValue

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
/**
 * For every field within an object, we pass in a field schema, Type and value.
 * This enables us to process fields (based on their characteristics) 
 * preparing them for persistence.
 * @param fieldSchema the associated field schema
 * @param type the field type
 * @param fieldValue the field value.
 * @return
 */
private Object getFieldValue(Schema fieldSchema, Type type, Object fieldValue ){
  switch(type) {
  case RECORD:
    Persistent persistent = (Persistent) fieldValue;
    Persistent newRecord = (Persistent) SpecificData.get().newRecord(persistent, persistent.getSchema());
    for (Field member: fieldSchema.getFields()) {
      if (member.pos() == 0 || !persistent.isDirty()) {
        continue;
      }
      Schema memberSchema = member.schema();
      Type memberType = memberSchema.getType();
      Object memberValue = persistent.get(member.pos());
      newRecord.put(member.pos(), getFieldValue(memberSchema, memberType, memberValue));
    }
    fieldValue = newRecord;
    break;
  case MAP:
    Map<?, ?> map = (Map<?, ?>) fieldValue;
    fieldValue = map;
    break;
  case ARRAY:
    fieldValue = (List<?>) fieldValue;
    break;
  case UNION:
    // storing the union selected schema, the actual value will 
    // be stored as soon as we get break out.
    if (fieldValue != null){
      int schemaPos = getUnionSchema(fieldValue,fieldSchema);
      Schema unionSchema = fieldSchema.getTypes().get(schemaPos);
      Type unionType = unionSchema.getType();
      fieldValue = getFieldValue(unionSchema, unionType, fieldValue);
    }
    //p.put( schemaPos, p.getSchema().getField(field.name() + CassandraStore.UNION_COL_SUFIX));
    //p.put(fieldPos, fieldValue);
    break;
  default:
    break;
  }    
  return fieldValue;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:50,代碼來源:CassandraStore.java


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