コード例 #1
0
  public void introduceType(SpaceTypeDescriptor typeDescriptor) {

    DBCollection m = getConnection().getCollection(METADATA_COLLECTION_NAME);

    BasicDBObjectBuilder builder =
        BasicDBObjectBuilder.start().add(Constants.ID_PROPERTY, typeDescriptor.getTypeName());
    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(bos);
      IOUtils.writeObject(
          out, SpaceTypeDescriptorVersionedSerializationUtils.toSerializableForm(typeDescriptor));

      builder.add(TYPE_DESCRIPTOR_FIELD_NAME, bos.toByteArray());

      WriteResult wr = m.save(builder.get());

      if (logger.isTraceEnabled()) logger.trace(wr);

      indexBuilder.ensureIndexes(typeDescriptor);

    } catch (IOException e) {
      logger.error(e);

      throw new SpaceMongoException(
          "error occurs while serialize and save type descriptor: " + typeDescriptor, e);
    }
  }
コード例 #2
0
  private static DBObject normalize(DBObject obj) {
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();

    Iterator<String> iterator = obj.keySet().iterator();
    builder.push("$set");
    while (iterator.hasNext()) {

      String key = iterator.next();

      if (Constants.ID_PROPERTY.equals(key)) continue;

      Object value = obj.get(key);

      if (value == null) continue;

      builder.add(key, value);
    }

    return builder.get();
  }