• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PersistentBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.gora.persistency.impl.PersistentBase的典型用法代码示例。如果您正苦于以下问题:Java PersistentBase类的具体用法?Java PersistentBase怎么用?Java PersistentBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PersistentBase类属于org.apache.gora.persistency.impl包,在下文中一共展示了PersistentBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: recordToMongo

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
private BasicDBObject recordToMongo(final String docf,
    final Schema fieldSchema, final Object value) {
  BasicDBObject record = new BasicDBObject();
  for (Field member : fieldSchema.getFields()) {
    Object innerValue = ((PersistentBase) value).get(member.pos());
    String innerDoc = mapping.getDocumentField(member.name());
    Type innerType = member.schema().getType();
    DocumentFieldType innerStoreType = mapping.getDocumentFieldType(innerDoc);
    LOG.debug(
        "Transform value to DBObject (RECORD), docField:{}, schemaType:{}, storeType:{}",
        new Object[] { member.name(), member.schema().getType(),
            innerStoreType });
    record.put(
        member.name(),
        toDBObject(docf, member.schema(), innerType, innerStoreType,
            innerValue));
  }
  return record;
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:20,代码来源:MongoStore.java


示例2: buildDynamoDBStore

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <K, T extends Persistent> IDynamoDB<K, T> buildDynamoDBStore(
    DynamoDBUtils.DynamoDBType serType) {
  final IDynamoDB<K, T> ds;
  switch (serType) {
    case DYNAMO:
      ds = new DynamoDBNativeStore<K, T>();
      LOG.debug("Using DynamoDB based serialization mode.");
      break;
    case AVRO:
      ds = (IDynamoDB<K, T>) new DynamoDBAvroStore<K, PersistentBase>();
      LOG.debug("Using Avro based serialization mode.");
      break;
    default:
      throw new IllegalStateException("Serialization mode not supported.");
  }
  return ds;
}
 
开发者ID:apache,项目名称:gora,代码行数:19,代码来源:DynamoDBFactory.java


示例3: getPersistent

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
/**
 * Returns a clone with exactly the requested fields shallowly copied
 */
private static<T extends PersistentBase> 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);
  newObj.clear();
  for (String field : fields) {
    Field otherField = obj.getSchema().getField(field);
    int index = otherField.pos();
    newObj.put(index, obj.get(index));
  }
  return newObj;
}
 
开发者ID:apache,项目名称:gora,代码行数:22,代码来源:MemStore.java


示例4: processKeys

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
static void processKeys(CassandraMapping cassandraMapping, Object key, List<String> keys, List<Object> values) {
  CassandraKey cassandraKey = cassandraMapping.getCassandraKey();
  if (cassandraKey != null) {
    if (key instanceof PersistentBase) {
      PersistentBase keyBase = (PersistentBase) key;
      for (Schema.Field field : keyBase.getSchema().getFields()) {
        Field mappedField = cassandraKey.getFieldFromFieldName(field.name());
        if (mappedField != null) {
          keys.add(field.name());
          Object value = keyBase.get(field.pos());
          value = getFieldValueFromAvroBean(field.schema(), field.schema().getType(), value, mappedField);
          values.add(value);
        } else {
          LOG.debug("Ignoring field {}, Since field couldn't find in the {} mapping", new Object[]{field.name(), cassandraMapping.getPersistentClass()});
        }
      }
    } else {
      LOG.error("Key bean isn't extended by {} .", new Object[]{cassandraMapping.getKeyClass(), PersistentBase.class});
    }
  } else {
    keys.add(cassandraMapping.getInlinedDefinedPartitionKey().getFieldName());
    values.add(key);
  }
}
 
开发者ID:apache,项目名称:gora,代码行数:25,代码来源:AvroCassandraUtils.java


示例5: analyzePersistent

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @throws Exception
 */
protected void analyzePersistent() throws Exception {
  userDefineTypeMaps = new HashMap<>();
  for (Field field : mapping.getFieldList()) {
    String fieldType = field.getType();
    if (fieldType.contains("frozen")) {
      String udtType = fieldType.substring(fieldType.indexOf("<") + 1, fieldType.indexOf(">"));
      if (PersistentBase.class.isAssignableFrom(persistentClass)) {
        Schema fieldSchema = persistentSchema.getField(field.getFieldName()).schema();
        if (fieldSchema.getType().equals(Schema.Type.UNION)) {
          for (Schema currentSchema : fieldSchema.getTypes()) {
            if (currentSchema.getType().equals(Schema.Type.RECORD)) {
              fieldSchema = currentSchema;
              break;
            }
          }
        }
        String createQuery = CassandraQueryFactory.getCreateUDTTypeForAvro(mapping, udtType, fieldSchema);
        userDefineTypeMaps.put(udtType, createQuery);
      } else {
        throw new RuntimeException("Unsupported Class for User Define Types, Please use PersistentBase class. field : " + udtType);
      }
    }
  }
}
 
开发者ID:apache,项目名称:gora,代码行数:30,代码来源:AvroSerializer.java


示例6: populateValuesToPersistent

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
/**
 * This method wraps result set data in to DataEntry and creates a list of DataEntry.
 **/
private void populateValuesToPersistent(AbstractGettableData row, ColumnDefinitions columnDefinitions, PersistentBase base, String[] fields) {
  Object paramValue;
  for (String fieldName : fields) {
    Schema.Field avroField = base.getSchema().getField(fieldName);
    Field field = mapping.getFieldFromFieldName(fieldName);
    //to ignore unspecified fields in the mapping
    if (field == null || avroField == null) {
      continue;
    }
    Schema fieldSchema = avroField.schema();
    String columnName = field.getColumnName();
    paramValue = getValue(row, columnDefinitions.getType(columnName), columnName, fieldSchema);
    Object value = AvroCassandraUtils.getAvroFieldValue(paramValue, fieldSchema);
    base.put(avroField.pos(), value);
  }
}
 
开发者ID:apache,项目名称:gora,代码行数:20,代码来源:AvroSerializer.java


示例7: fromCouchDBRecord

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
private Object fromCouchDBRecord(final Schema fieldSchema, final String docf, final Object value) {

    final Object innerValue = ((Map) value).get(docf);
    if (innerValue == null) {
      return null;
    }

    Class<?> clazz = null;
    try {
      clazz = ClassLoadingUtils.loadClass(fieldSchema.getFullName());
    } catch (ClassNotFoundException e) {
      LOG.debug(e.getMessage());
    }

    final PersistentBase record = (PersistentBase) new BeanFactoryImpl(keyClass, clazz).newPersistent();

    for (Field recField : fieldSchema.getFields()) {
      Schema innerSchema = recField.schema();

      record.put(recField.pos(), fromDBObject(innerSchema, recField, recField.name(), innerValue));
    }
    return record;
  }
 
开发者ID:apache,项目名称:gora,代码行数:24,代码来源:CouchDBStore.java


示例8: convertAvroBeanToOrientDoc

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
private Object convertAvroBeanToOrientDoc(final Schema fieldSchema,
                                          final ODocument doc) {
  Object result;
  Class<?> clazz = null;
  try {
    clazz = ClassLoadingUtils.loadClass(fieldSchema.getFullName());
  } catch (ClassNotFoundException e) {
    //Ignore
  }
  PersistentBase record = (PersistentBase) new BeanFactoryImpl(keyClass, clazz).newPersistent();
  for (Schema.Field recField : fieldSchema.getFields()) {
    Schema innerSchema = recField.schema();
    OrientDBMapping.DocumentFieldType innerStoreType = orientDBMapping
            .getDocumentFieldType(recField.name());
    String innerDocField = orientDBMapping.getDocumentField(recField.name()) != null ? orientDBMapping
            .getDocumentField(recField.name()) : recField.name();
    LOG.debug("Load from ODocument (RECORD), field:{}, schemaType:{}, docField:{}, storeType:{}",
            new Object[]{recField.name(), innerSchema.getType(), innerDocField,
                    innerStoreType});
    record.put(recField.pos(),
            convertDocFieldToAvroField(innerSchema, innerStoreType, recField, innerDocField,
                    doc));
  }
  result = record;
  return result;
}
 
开发者ID:apache,项目名称:gora,代码行数:27,代码来源:OrientDBStore.java


示例9: clone

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
public Persistent clone(Persistent persistent, Schema schema) {
  Persistent cloned = (PersistentBase)persistent.newInstance(new StateManagerImpl());
  List<Field> fields = schema.getFields();
  for(Field field: fields) {
    int pos = field.pos();
    switch(field.schema().getType()) {
      case MAP    :
      case ARRAY  :
      case RECORD : 
      case STRING : ((PersistentBase)cloned).put(pos, cloneObject(
          field.schema(), ((PersistentBase)persistent).get(pos), ((PersistentBase)cloned).get(pos))); break;
      case NULL   : break;
      default     : ((PersistentBase)cloned).put(pos, ((PersistentBase)persistent).get(pos)); break;
    }
  }
  
  return cloned;
}
 
开发者ID:galaxyeye,项目名称:gora-0.3-simplified,代码行数:19,代码来源:PersistentDatumReader.java


示例10: createStatement

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
public static <K, T extends PersistentBase>
InsertUpdateStatement<K, T> createStatement(SqlStore<K, T> store,
    SqlMapping mapping, DBVendor dbVendor) {
  switch(dbVendor) {
    case MYSQL:
      return new MySqlInsertUpdateStatement<K, T>(store, mapping, mapping.getTableName());
    case HSQL:
      return new HSqlInsertUpdateStatement<K, T>(store, mapping, mapping.getTableName());
    case GENERIC:
    default :
      throw new RuntimeException("Database is not supported yet.");    
  }
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:14,代码来源:InsertUpdateStatementFactory.java


示例11: serialize

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
/**
 * Do the serialization of the {@link PersistentBase} object
 *
 * @param persistent {@link PersistentBase} object to serialize
 * @throws IOException if there is an error during serialization
 */
@Override
public void serialize(PersistentBase persistent) throws IOException {
  datumWriter.setSchema(persistent.getSchema());
  datumWriter.write(persistent, encoder);
  encoder.writeFixed(persistent.getDirtyBytes().array());
}
 
开发者ID:apache,项目名称:gora,代码行数:13,代码来源:PersistentSerializer.java


示例12: PersistentDeserializer

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
public PersistentDeserializer(Class<? extends PersistentBase> c, boolean reuseObjects) {
  this.persistentClass = c;
  this.reuseObjects = reuseObjects;
  try {
    Schema schema = AvroUtils.getSchema(persistentClass);
    datumReader = new SpecificDatumReader<PersistentBase>(schema);

  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:apache,项目名称:gora,代码行数:12,代码来源:PersistentDeserializer.java


示例13: deserialize

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
@Override
public PersistentBase deserialize(PersistentBase persistent) throws IOException {
  persistent = datumReader.read(reuseObjects ? persistent : null, decoder);
  byte[] __g__dirty = new byte[persistent.getFieldsCount()];
  decoder.readFixed(__g__dirty);
  persistent.setDirtyBytes(java.nio.ByteBuffer.wrap(__g__dirty));
  return persistent;
}
 
开发者ID:apache,项目名称:gora,代码行数:9,代码来源:PersistentDeserializer.java


示例14: AvroSerializer

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
AvroSerializer(CassandraClient cassandraClient, DataStore<K, T> dataStore, CassandraMapping mapping) {
  super(cassandraClient, dataStore.getKeyClass(), dataStore.getPersistentClass(), mapping);
  if (PersistentBase.class.isAssignableFrom(dataStore.getPersistentClass())) {
    persistentSchema = ((PersistentBase) dataStore.getBeanFactory().getCachedPersistent()).getSchema();
  } else {
    throw new RuntimeException("Unsupported persistent class, couldn't able to find the Avro schema.");
  }
  this.cassandraDataStore = dataStore;
  try {
    analyzePersistent();
  } catch (Exception e) {
    throw new RuntimeException("Error occurred while analyzing the persistent class, :" + e.getMessage());
  }
}
 
开发者ID:apache,项目名称:gora,代码行数:15,代码来源:AvroSerializer.java


示例15: recordToCouchDB

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
private Map<String, Object> recordToCouchDB(final Schema fieldSchema, final Object fieldValue) {
  final PersistentBase persistent = (PersistentBase) fieldValue;
  final Map<String, Object> newMap = new LinkedHashMap<>();

  if (persistent != null) {
    for (Field member : fieldSchema.getFields()) {
      Schema memberSchema = member.schema();
      Object memberValue = persistent.get(member.pos());
      newMap.put(member.name(), toDBObject(memberSchema, memberValue));
    }
    return newMap;
  }
  return null;
}
 
开发者ID:apache,项目名称:gora,代码行数:15,代码来源:CouchDBStore.java


示例16: fromMongoRecord

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object fromMongoRecord(final Schema fieldSchema, final String docf,
    final DBObject rec) {
  Object result;
  BSONDecorator innerBson = new BSONDecorator(rec);
  Class<?> clazz = null;
  try {
    clazz = ClassLoadingUtils.loadClass(fieldSchema.getFullName());
  } catch (ClassNotFoundException e) {
  }
  PersistentBase record = (PersistentBase) new BeanFactoryImpl(keyClass, clazz).newPersistent();
  for (Field recField : fieldSchema.getFields()) {
    Schema innerSchema = recField.schema();
    DocumentFieldType innerStoreType = mapping
        .getDocumentFieldType(innerSchema.getName());
    String innerDocField = mapping.getDocumentField(recField.name()) != null ? mapping
        .getDocumentField(recField.name()) : recField.name();
        String fieldPath = docf + "." + innerDocField;
        LOG.debug(
            "Load from DBObject (RECORD), field:{}, schemaType:{}, docField:{}, storeType:{}",
            new Object[] { recField.name(), innerSchema.getType(), fieldPath,
                innerStoreType });
        record.put(
            recField.pos(),
            fromDBObject(innerSchema, innerStoreType, recField, innerDocField,
                innerBson));
  }
  result = record;
  return result;
}
 
开发者ID:apache,项目名称:gora,代码行数:31,代码来源:MongoStore.java


示例17: getPersistent

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
/**
 * Returns a clone with exactly the requested fields shallowly copied
 */
@SuppressWarnings("unchecked")
private static<T extends Persistent> T getPersistent(T obj, String[] fields) {
  if(Arrays.equals(fields, obj.getFields())) {
    return obj;
  }
  T newObj = (T) obj.newInstance(new StateManagerImpl());
  for(String field:fields) {
    int index = newObj.getFieldIndex(field);
    ((PersistentBase)newObj).put(index, ((PersistentBase)obj).get(index));
  }
  return newObj;
}
 
开发者ID:galaxyeye,项目名称:gora-0.3-simplified,代码行数:16,代码来源:MemStore.java


示例18: serialize

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
@Override
public void serialize(PersistentBase persistent) throws IOException {   
  datumWriter.setSchema(persistent.getSchema());
  datumWriter.setPersistent(persistent);
      
  datumWriter.write(persistent, encoder);
}
 
开发者ID:galaxyeye,项目名称:gora-0.3-simplified,代码行数:8,代码来源:PersistentSerializer.java


示例19: PersistentDeserializer

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
public PersistentDeserializer(Class<? extends PersistentBase> c, boolean reuseObjects) {
  this.persistentClass = c;
  this.reuseObjects = reuseObjects;
  try {
    Schema schema = AvroUtils.getSchema(persistentClass);
    datumReader = new PersistentDatumReader<PersistentBase>(schema, true);

  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:galaxyeye,项目名称:gora-0.3-simplified,代码行数:12,代码来源:PersistentDeserializer.java


示例20: serialize

import org.apache.gora.persistency.impl.PersistentBase; //导入依赖的package包/类
/**
 * Serializes the field object using the datumWriter.
 */
public static<T extends PersistentBase> void serialize(OutputStream os,
    PersistentDatumWriter<T> datumWriter, Schema schema, Object object)
    throws IOException {

  BinaryEncoder encoder = new BinaryEncoder(os);
  datumWriter.write(schema, object, encoder);
  encoder.flush();
}
 
开发者ID:galaxyeye,项目名称:gora-0.3-simplified,代码行数:12,代码来源:IOUtils.java



注:本文中的org.apache.gora.persistency.impl.PersistentBase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Converters类代码示例发布时间:2022-05-22
下一篇:
Java BranchState类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap