Package org.persvr.data

Examples of org.persvr.data.Persistable


     
      //if (newObject.getId().toString().equals("284"))
        //System.err.println(newObject.getId());
      if (!visitedObjects.contains(newObject) && newObject.getId().getSource() == newSource) {
        visitedObjects.add(newObject);
        Persistable oldObject = (Persistable) ObjectId.idForObject(oldSource,newObject.getId().subObjectId).getTarget();
        for (Map.Entry<String,Object> entry: newObject.entrySet(0)) {
          String key = entry.getKey();
          Object value = entry.getValue();
          if (!key.equals(":importMaps")
              && !key.equals("history")
              && !key.equals("version")
              //&& !key.equals(GlobalData.IN_GROUPS_FIELD)
              && !compareValues(oldObject.get(key),value)
              && !excludedObjects.contains(value)) {
            if (!identified) {
              write("\n{\"id\":\"" + newObject.getId().toString(newSource,null) + "\"");
              identified = true;
            }           
View Full Code Here


  }
  public Persistable clientSideObject(String id,Persistable newObject) {
    synchronized (clientObjectsChangeIdNeeded) {
      if(clientSideObjects == null)
        clientSideObjects = new HashMap<String,Persistable>();
      Persistable value = clientSideObjects.get(id);
      if (value != null) {
        clientObjectsChangeIdNeeded.put(id,value);
        return value;
      }
      value = newObject;
View Full Code Here

      noVersionObjectId = Long.parseLong((String) noVersionObjectId);
    }catch(NumberFormatException e){
    }
    traverser.minKey = noVersionObjectId;
    traverser.maxKey = noVersionObjectId;
    Persistable object;
    // this should trigger the loading of the object
    if((object = (Persistable) traverser.nextObject()) == null){
      throw new ObjectNotFoundException(this, objectId);
    }
    //FIXME: remove this
/*    if((Persistable) traverser.nextObject() != null){
      throw new IllegalStateException("shouldn't be duplicate ids");
    }*/
   
    // if a version was specified, we need to make sure we load it
    if(version > -1){
      while(((ObjectVersion) object.getVersion()).versionNumber > version){
        object = getDatabase().getVersionByReference(((ObjectVersion) object.getVersion()).previousVersionReference);
      }
      if(((ObjectVersion) object.getVersion()).versionNumber != version)
        throw new ObjectNotFoundException(this, objectId);
    }
  }
View Full Code Here

   * @param data
   * @return
   * @throws IOException
   */
  private static Persistable createFile(String contentType, String contentDisposition, Object data) throws IOException {
    Persistable fileTarget = Persevere.newObject("File");
    String charSet = null;

    if (contentType != null) {
      String[] contentTypeParts = contentType.split(";\\s*");
      contentType = contentTypeParts[0];
      for (String part : contentTypeParts) {
        if (part.startsWith("charset")) {
          charSet = part.split("=")[1];
        }
      }
    }
    fileTarget.set("contentType", contentType);
    if(contentDisposition != null)
      fileTarget.set("contentDisposition", contentDisposition);
    contentType = contentType == null ? null : contentType.split(";")[0];
    if (contentType != null && (contentType.startsWith("text/") || charSet != null)) {
      if (data instanceof InputStream)
        fileTarget.set("content", IOUtils.toString(new InputStreamReader((InputStream) data, charSet == null ? "UTF-8" : charSet)));
      else
        fileTarget.set("content", new String((byte[]) data, charSet == null ? "UTF-8" : charSet));
    } else {
      if (data instanceof InputStream)
        fileTarget.set("content", new BinaryData((InputStream) data));
      else
        fileTarget.set("content", new BinaryData((byte[]) data));
    }
    return fileTarget;
  }
View Full Code Here

    public Persistable next() {
      try {
        if(next == null && count++ < maxLength)
          next = traverser.nextObject();
        Persistable value = next;
        next = null;
        return value;
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
View Full Code Here

    if (target instanceof PersistableClass) {
      // if we post to a schema, we can just consider this a post to the table
      target = (Persistable) Identification.idForString(((PersistableClass) target).getId().toString() + "/").getTarget();
    }
    if (bodyData instanceof Persistable) {
      Persistable newObject = (Persistable) bodyData;
      ScriptableObject arrayProto = (ScriptableObject) ScriptableObject.getClassPrototype(GlobalData.getGlobalScope(), "Array");
      ScriptableObject objectProto = (ScriptableObject) ScriptableObject.getClassPrototype(GlobalData.getGlobalScope(), "Object");

      if ("".equals(((Persistable) target).getId().subObjectId)
          && (((Persistable) bodyData).getPrototype() == objectProto || ((Persistable) bodyData).getPrototype() == arrayProto)) {
        // this means it is a generic object or list, we need to make it be the right class
        DataSource thisSource = ((Persistable) target).getId().source;
        Class targetClass = DataSourceManager.getObjectsClass(thisSource).objectsClass;
        if (bodyData instanceof List) {
          // this means that an array was provided for a data source that takes objects; we
          //  will assume this means that the user wants to create multiple objects
          int i = 0;
          for (Object obj : (List) bodyData) {
            if (obj instanceof Persistable) {
              newObject = Persevere.newObject(((Persistable) target).getId());
              for (Map.Entry<String, Object> entry : ((Persistable) obj).entrySet(0)) {
                newObject.set(entry.getKey(), entry.getValue());
              }
              ((List) bodyData).set(i++, newObject);
            } else
              throw new RuntimeException("Bulk update arrays should only include objects");
          }
          return bodyData;
        } else {
          newObject = bodyData instanceof List ? Persevere.newArray(((Persistable) target).getId()) : Persevere
              .newObject(((Persistable) target).getId());
          for (Map.Entry<String, Object> entry : ((Persistable) bodyData).entrySet(0)) {
            newObject.set(entry.getKey(), entry.getValue());
          }
        }
      }
      Client.getCurrentObjectResponse().getConnection().changeClientSideObject((Persistable) bodyData, newObject);
      bodyData = newObject;
View Full Code Here

    public long estimatedSize(long exactWithin) throws IOException {
      // estimate the size based on the number that has been processed
      return included * small.estimatedSize(exactWithin) / smallTraversed;
    }
    public Persistable nextObject() throws IOException {
      Persistable potential;
      do{
        potential = small.nextObject();
        if(potential == null)
          return null;
        smallTraversed++;
View Full Code Here

    }
    public long size() throws IOException{
      return small.size() + big.size();
    }
    public Persistable nextObject() throws IOException {
      Persistable potential;
      if(processingBig){
        potential = big.nextObject();
        if(potential != null)
          return potential;
        processingBig = false;
View Full Code Here

    public long estimatedSize(long exactWithin) throws IOException{
      // estimate the size based on the number that has been processed
      return small.estimatedSize(exactWithin) + big.estimatedSize(exactWithin) - included * small.estimatedSize(exactWithin) / smallTraversed;
    }
    public Persistable nextObject() throws IOException {
      Persistable potential;
      if(processingBig){
        potential = big.nextObject();
        if(potential != null)
          return potential;
        processingBig = false;
View Full Code Here

    }
    long found;
    @Override
    public Persistable nextObject() throws IOException {
      while(true){
        Persistable potential = indexTraverser.nextObject();
        if(potential == null)
          return null;
        if(operand.matches(potential))
          found++;
        else
View Full Code Here

TOP

Related Classes of org.persvr.data.Persistable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.