Examples of Persistable


Examples of org.olat.core.id.Persistable

   * @param persistables a List of Persistable objects
   * @return true if at least one of the objects in the list has the same key as the keys given.
   */
  public boolean isAtLeastOneKeyInList(List persistables) {
    for (Iterator it_per = persistables.iterator(); it_per.hasNext();) {
      Persistable per = (Persistable) it_per.next();
      Long key = per.getKey();
      if (keys.contains(key)) return true;
    }
    return false;
  }
View Full Code Here

Examples of org.olat.core.id.Persistable

   * @return the loaded Object
   */
  public Persistable loadObject(Persistable persistable, boolean forceReloadFromDB) {
    if (persistable == null) throw new AssertException("persistable must not be null");
    beginTransaction(persistable);
    Persistable ret;
    Class theClass = persistable.getClass();
    if (forceReloadFromDB) {
      // we want to reload it from the database.
      // there are 3 scenarios possible:
      // a) the object is not yet in the hibernate cache
      // b) the object is in the hibernate cache
      // c) the object is detached and there is an object with the same id in the hibernate cache
     
      if (contains(persistable)) {
        // case b - then we can use evict and load
        getDBManager().evict(persistable);
        return (Persistable) loadObject(theClass, persistable.getKey());
      } else {
        // case a or c - unfortunatelly we can't distinguish these two cases
        // and session.refresh(Object) doesn't work.
        // the only scenario that works is load/evict/load
        Persistable attachedObj = (Persistable) loadObject(theClass, persistable.getKey());
        getDBManager().evict(attachedObj);
        return (Persistable) loadObject(theClass, persistable.getKey());
      }
    } else if (!contains(persistable)) {
      // forceReloadFromDB is false - hence it is OK to take it from the cache if it would be there
View Full Code Here

Examples of org.persvr.data.Persistable

   */
  public static Persistable newObject(String className) {
    DataSource source = DataSourceManager.getSource(className);
    if(source == null)
      throw new RuntimeException("The table " + className + " was not found");
    Persistable object = newObject(source);
    ((PersistableClass)object.getSchema()).doConstruction(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), object, new Object[]{});
    return object;
  }
View Full Code Here

Examples of org.persvr.data.Persistable

   * persisted in the class's table (when the current transaction is committed).
   * @param queryId The id of the table
   * @return the newly created instance object
   */
  public static Persistable newObject(ObjectId queryId) {
    Persistable object = newObject(queryId.source);
    ((PersistableClass)object.getSchema()).doConstruction(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), object, new Object[]{});
    return object;
  }
View Full Code Here

Examples of org.persvr.data.Persistable

    if(!UserSecurity.hasPermission(SystemPermission.createTables)){
      throw new SecurityException("You do not have permission to create new tables");
    }
    if (name.matches("[^\\w$_]"))
      throw new RuntimeException("Illegal character in table");
    Persistable newSource = Persevere.newObject(DataSourceManager.getMetaClassSource());
    newSource.set("id", name);
    newSource.set("extends", superType instanceof String ? ObjectId.idForObject(DataSourceManager.getMetaClassSource(), superType) : ObjectId.idForObject(DataSourceManager.getMetaClassSource(),"Object"));

  }
View Full Code Here

Examples of org.persvr.data.Persistable

    if (value instanceof Identification)
      return ((Identification<? extends Object>)value).getTarget();
    return value;
  }
  public void handleRPC(Object targetObject,  Map rpcObject) {
    Persistable target = (targetObject instanceof ObjectId) ? ((ObjectId)targetObject).getTarget() : (Persistable)targetObject;
    List params = (List) rpcObject.get("params");
    Object[] paramValues;
    if (params == null) {
      paramValues = new Object[0];
    }
View Full Code Here

Examples of org.persvr.data.Persistable

  }
  public Identification<? extends Object> idFromJSPONObject(Map<String,Object> object, ObjectId targetId, boolean mustMatchId)  {
    //TODO: This needs be rearranged so that when you do a put (specifically an alteration), that we use the object
    // returned by the put instead of what the id indicates, because it is possible for a aliasId to indicate that we
    // should use a new object, when really we should use an existing object (from the childMods list)
      Persistable target;
    try {
      String key;
      target = null;
      Date changesSince=null;
      if (object.containsKey("update") && ((Map) object.get("update")).containsKey("changesSince")) {
        String value = (String) ((Map) object.get("update")).get("changesSince");
        changesSince = new Date(Long.parseLong(value.substring(1,value.length()-1))); // handle dates     
      }
      if (object.containsKey("$ref")) {
       
        return Identification.idForRelativeString(path, (String) object.get("$ref"));
      }
      if (object.containsKey("id")) {
        Identification currentId = Identification.idForRelativeString(path, object.remove("id").toString());

        if (currentId.source instanceof ClientData) // TODO: Surely we can do this more consistently
          target = Client.getCurrentObjectResponse().getConnection().clientSideObject(currentId.toString(),createInitialObject(object));
        else {
          if (currentId instanceof ObjectId){
            if(mustMatchId){
              if(targetId != currentId){
                throw new RuntimeException("id does not match location");
              }
            }
            else {
              targetId = (ObjectId) currentId;
            }
           
          }
          else {
            target = (Persistable) currentId.getTarget();
            if(mustMatchId && target.getId() != targetId){
              throw new RuntimeException("id does not match location");
            }
          }
        }
      }
      if (targetId == null) {
        if (target == null)
          target = createInitialObject(object);
      }
      else {
        target= targetId.getOrCreateTarget();
      }
      PersistableObject.checkSecurity(target, PermissionLevel.WRITE_LEVEL.level);

      for (Map.Entry<String,Object> oldEntry : target.entrySet(0)) {
        String oldKey = oldEntry.getKey();
        if (!object.containsKey(oldKey) && !oldKey.equals("parent"))
          target.delete(oldKey);
      }
      for (Map.Entry<String,Object> entry : object.entrySet()) {
        key = entry.getKey()// TODO: This needs to be limited to alteration lists, so we don't get a conflict with fields that start with c$.  This may need to be identified on the client side
        Object value = entry.getValue();
        if (key.startsWith("client/")) // This is a client id alteration which needs be changed a
        {
          key = Client.getCurrentObjectResponse().getConnection().clientSideObject(key,object.containsKey("array") ?
                Persevere.newArray() : Persevere.newObject()).getId().toString();
        }
        /*String valueModOriginal = null;
        if (GlobalData.CHILDMODS_FIELD.equals(key))
          valueModOriginal = GlobalData.CHILDMODS_FIELD;

        if (target!=null && (GlobalData.CHILDMODS_FIELD.equals(childModOriginalId) || target.isChildMods()) && !GlobalData.PARENT_FIELD.equals(key))
          valueModOriginal = key;*/
/*        if ("update".equals(key)) {
          if ("delete".equals(value))
            return getErasureEntity();
          if (value instanceof Map)
            updateList(target,(Map) value);
        }
        else {*/
        Object oldValue = target.get(key);
          value = idOrValueFromJSON(value, oldValue instanceof Persistable ? ((Persistable)oldValue).getId() : null);
          if (value instanceof ObjectNotFoundId)
            throw new RuntimeException("Can not set value to an undefined id");
          if (key.equals(FUNCTION_CODE_KEY)) {
            value = functionCompression((String) value);
            }
          if (target != null) {
              value = convertIdIfNeeded(value);
              if (!(oldValue == null ? value == null : oldValue.equals(value))){
                PersistableObject.checkSecurity(target, PermissionLevel.WRITE_LEVEL.level);
                target.set(key,value);
              }
          }
        //}
      }
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }
/*    if (parentValue != null) // we will do it at the end so that if it is an append list entry it can be done without security problems
      target.set(GlobalData.PARENT_FIELD, parentValue);*/
      return target.getId();
  }
View Full Code Here

Examples of org.persvr.data.Persistable

        public Object run() {
          List correctUsers = (List) JsonPath.query(usersTable(),"$[?(@.name=$1)]", username);
              if (correctUsers.size() == 0) {
                  return new LoginException("user " + username + " not found");
              }
              Persistable userObject = (Persistable) correctUsers.get(0);
              boolean alreadyHashed = false;
              boolean passwordMatch = password.equals(userObject.get(PASSWORD_FIELD));
              if (!passwordMatch) {
                  try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(((String) userObject.get(PASSWORD_FIELD)).getBytes());
            passwordMatch = password.equals(new String(new Base64().encode(md.digest())));
            } catch (NoSuchAlgorithmException e) {
              throw new RuntimeException(e);
            }
            alreadyHashed = true;         
View Full Code Here

Examples of org.persvr.data.Persistable

            throw new RuntimeException("You are not a part of the su capable group, so you can not su");
        List correctUsers = (List) JsonPath.query(usersTable(),"$[?(@.name=$1)]", username);
        if (correctUsers.size() == 0) {
            throw new RuntimeException("user " + username + " not found");
        }
        Persistable userObject = (Persistable) correctUsers.get(0);
        return (CapabilityUser) userObject;
    }
View Full Code Here

Examples of org.persvr.data.Persistable

  public void execute() {
    try {
      List customers = (List) Persevere.load("Customer/");
      Transaction transaction = Transaction.startTransaction();
      if(customers.size() == 0){
        Persistable customer1 = Persevere.newObject("Customer");
        customer1.set("firstName", "John");
        customer1.set("lastName", "Doe");
        customer1.set("age", 41);
        Persistable customer2 = Persevere.newObject("Customer");
        customer2.set("firstName", "Jim");
        customer2.set("lastName", "Jones");
        customer2.set("age", 33);
      }
      transaction.commit();
    }
    catch (ObjectNotFoundException e){
     
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.