Package org.persvr.data

Examples of org.persvr.data.ObjectId


        }
        messages.add(message);
      }

      public boolean shouldSerialize(Persistable obj) {
        ObjectId objId = obj.getId();
        if (objId.source == requestedSource || requestedSource == null || objId.subObjectId == null || objId.source == null || objId.hidden()){
          int level = obj.getAccessLevel();
          String id = idString(obj.getId());
          List<String> sameLevel =accessLevels[level];
          if (sameLevel == null)
            sameLevel = accessLevels[level] = new ArrayList<String>();
View Full Code Here


      String table = internedStrings.get(tableId);
//      if (table == null)
//        throw new IllegalStateException("Can not find table");
      Object objectId = readEntity(input, false, true);
      int versionNumber = (int) readVarLong(input);
      ObjectId id;
      if (table == null){
        // this means the table was deleted
        id = new NewObjectId(null);
      }
      else if (table.indexOf('.') > -1) {
        id = ObjectId.idForObject(header == HEADER_ARRAY ? arraySource : objectSource, tableId + "-" + objectId
            + (historic ? "-v" + versionNumber : ""), true);
      } else {
        id = ObjectId.idForObject(DataSourceManager.getSource(table), historic ? objectId + "-v" + versionNumber : objectId.toString());
      }
      if (id.isLoaded() && !mustFinish)
        return id.getTarget();
      long previousVersionReference = readVarLong(input);
      long lastTableChange = readVarLong(input);
      Date lastModified = (Date) readEntity(input, false, true);
      if("Transaction".equals(table))
        // transactions are always historic
        historic = true;
      synchronized (id) {
        PersistableInitializer initializer = DataSourceHelper.initializeObject(id);

        byte attributes;
        try {
          if (header == HEADER_ARRAY) {
            List<Object> list = new ArrayList<Object>();
            ObjectId parentId = null;
            while ((attributes = input.readByte()) != HEADER_END) {
              Object value = readEntity(input, historic, true);
              if(attributes == PARENT_ATTRIBUTE_ID){
                parentId = (ObjectId)value;
               
View Full Code Here

      return id;
    }
  }
  //FileOutputStream fos = new FileOutputStream("C:\\temp\\test.log");
  void writeObject(final Persistable object, DataOutput raf, WriteState state, final String defaultTableName, final ObjectId parentId) throws IOException {
    ObjectId objId = object.getId();
    String tableName = objId.source == null ? defaultTableName : objId.source.getId();
    String subObjectId = objId.subObjectId;
    int splitPoint = subObjectId.indexOf('-');
    final Integer tableId;
    if(splitPoint > -1 && ("Array".equals(tableName) || "Object".equals(tableName))){
      if(subObjectId.indexOf('v') > -1){
        throw new RuntimeException("Can not modify a history object");
      }
      tableId = Integer.parseInt(subObjectId.substring(0,splitPoint));
      subObjectId = subObjectId.substring(splitPoint + 1);
    }
    else
      tableId = getTableId(tableName);
    final Object id = objId.source == null ? getNextId(tableId, true) : parseIfPossible(subObjectId);
    if (objId.source == null)
      objId.persistIfNeeded(new StartAsEmptyPersister() {

        public String getObjectId() {
          //        if(id > -1)
          return tableId + "-" + id;
          /*
 
View Full Code Here

   *
   * @param value
   */
  void writeEntity(Object value, DataOutput raf, WriteState state) throws IOException {
    if (value instanceof ObjectId || value instanceof Persistable) {
      ObjectId objId;
      if (value instanceof Persistable)
        objId = ((Persistable) value).getId();
      else
        objId = (ObjectId) value;
      String sourceName = objId.source == null ? null : objId.source.getId();
      Integer tableId = tableNameIds.get(sourceName);
      if (tableId == null) {
        raf.writeByte(HEADER_FOREIGN_REFERENCE);
        writeString(raf, objId.toString());
      } else {
        if (objId.source == arraySource) {
          switch (state) {
          case HISTORY:
            throw new IllegalStateException("Transaction instance can't be an array");
          case FROZEN_VERSION:
          case CHANGED:
            Persistable object = value instanceof Persistable ? (Persistable) value : objId.getTarget();
            writeObject(object, raf, state, null, null);
            break;
          case REFERENCE_IF_EXISTS:
            if (objId.isPersisted()) {
              raf.writeByte(HEADER_REFERENCE_ARRAY);
              InternalId internalId = convertIdToInternalObject(objId);
              raf.writeInt(internalId.tableId);
              writeEntity(internalId.subObjectId, raf, null);
            } else {
              throw new IllegalStateException();
            }

          }

        } else {
          switch (state) {
          case FROZEN_VERSION:
          case CHANGED:
          case HISTORY:
            Persistable object = value instanceof Persistable ? (Persistable) value : objId.getTarget();
            writeObject(object, raf, state, null, null);
            break;
          case REFERENCE_IF_EXISTS:
            if (objId.isPersisted()) {
              raf.writeByte(HEADER_REFERENCE);
              InternalId internalId = convertIdToInternalObject(objId);
              raf.writeInt(internalId.tableId);
              writeEntity(internalId.subObjectId, raf, null);
            } else {
View Full Code Here

    }
    long thisCommit;
    boolean writeIntegrity = false;
    List<Runnable> localOnCommitTasks = new ArrayList<Runnable>();
    try {
      ObjectId transactionId = ObjectId.idForObject(transactionSource, Long.toString(getNextId(getTableId("Transaction"), true)));
      synchronized (transactionId) {
        PersistableInitializer historyInitializer = DataSourceHelper.initializeObject(transactionId);

        Object currentUser = UserSecurity.currentUser();
        if (currentUser instanceof UserSecurity.PriviledgedUser)
View Full Code Here

    int fieldType = 0;
    long fieldValue = -1;
    if (value instanceof Persistable)
      value = ((Persistable) value).getId();
    if (value instanceof ObjectId) {
      ObjectId id = (ObjectId) value;
        id.persistIfNeeded(id.isPersisted() ? null
            : recordNewObject((ObjectId) value, convertToObjectId(referrer))); // persist into Object if we need to persist
      if (id.source instanceof DynaObjectDBSource && id.subObjectId != null && !"".equals(id.subObjectId)) {
        fieldType = OBJECT_TYPE;
        fieldValue = ((DynaObjectDBSource) id.source).convertId(id.subObjectId);
      } else
View Full Code Here

        }
      }
      if(value instanceof Persistable){
        Persistable clazz = ((Persistable)value).getSchema();
        if(clazz != null) {
          ObjectId classId = clazz.getId();
          if(classId.subObjectId != null){
            if("Class".equals(classId.subObjectId))
              response.setContentType(response.getContentType() + ";schema=" + request.idString(classId) + ";schema=http://json-schema.org/hyper-schema");
            else
              response.setContentType(response.getContentType() + ";schema=" + request.idString(classId));
View Full Code Here

  protected class Serialization {
    Set<String> alreadyFulfilled = new HashSet<String>(100);

    public Request request;
    String getDisplayId(Persistable obj){
      ObjectId objId = obj.getId();
      if(objId.source == null || !objId.hidden())
        return request.idString(obj.getId());
      Persistable parent = obj.getParent();
      if (parent != null) {
       
        if(parent instanceof List){
View Full Code Here

            + value.getClass() + " to JSON");
        writer.write("\"Can not serialize " + value.getClass() + "\"");
      }
    }
    protected boolean canReference(Persistable obj, Persistable referrer) {
      ObjectId id = obj.getId();
      return id.source != null && !referrer.equals(obj.getParent());// || !id.hidden();
          /* ||
          (objId.source == null && referrer.getId().toString().equals("root"))*/
    }
 
View Full Code Here

    }
    void serializeObject(Writer writer, Persistable obj, Boolean lazy, Persistable referrer, boolean parentHasId) throws IOException {
      StringBuffer buffer = new StringBuffer();
      try {
        depth++;
        ObjectId objId = obj.getId();
        boolean persisted = false;
        String idString = null;
        if (objId != null) {
          persisted = objId.isAssignedId();
          idString = JSON.quote(request.idString(objId));
        }
        ObjectId refId;
        if (objId != null && referrer != null &&
              (!((refId = referrer.getId()) instanceof Query || !parentHasId || // want all the items in a query to be included
                  (referrer instanceof List && request instanceof IndividualRequest && ((IndividualRequest)request).requestRoot == referrer) ||
                (refId.subObjectId == null && refId.source == DataSourceManager.getMetaClassSource())) && // and want children of the root to be included as well
                !Boolean.FALSE.equals(lazy) &&
View Full Code Here

TOP

Related Classes of org.persvr.data.ObjectId

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.