private IQueryResult queryFetch(ICompiledQuery code, UserInformation user) {

    // TODO check rights for channel

    String id = code.getString(1);

    try {
      Properties current = new Properties();
      Reader reader = driver.getFileStore().get(IType.TYPE_OBJECT)[0].getReader(id);
      current.load(reader);
      reader.close();

      String typeName = current.getProperty(IAttribute.M_TYPE);
      if (typeName == null) throw new MorseException(MorseException.OBJECT_NOT_FOUND, id);

      IType type = typeProvider.get(typeName);
      if (type == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);

      ObjectFileStore[] store = fileStore.get(typeName);
      if (store == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);

      if (!aclManager.hasRead(user, type.getAccessAcl()))
        throw new MorseException(
            MorseException.ACCESS_DENIED_READ,
            new String[] {"type", typeName, type.getAccessAcl()});

      LinkedList<Attr> attr = new LinkedList<Attr>();
      for (Iterator<IAttribute> i = type.getAttributes(); i.hasNext(); ) {
        Attr a = new Attr();
        a.attr = i.next();
        a.attrName = a.attrAlias = a.attr.getName();
        if (aclManager.hasRead(user, a.attr.getAccessAcl())) attr.add(a);
      }

      return new FileAbstractSelectResult(
          driver,
          type,
          store[0],
          IAttribute.M_ID,
          id,
          (Attr[]) attr.toArray(new Attr[attr.size()]));

    } catch (Exception e) {
      log.error(e);
      return new ErrorResult(1, 1, e.toString());
    }
  }
  public void unlock(String id, boolean force, UserInformation user) throws MorseException {

    if (log.t4()) log.info("UNLOCK: " + id + ' ' + user);

    ObjectUtil.assetId(id);
    if (!force && user == null) throw new MorseException(MorseException.UNKNOWN_USER);

    // create lock file
    ObjectFileStore ofs = driver.getFileStore().get(IType.TYPE_OBJECT)[0];

    try {
      if (log.t4()) log.debug("xLOCK: " + id + ' ' + user);
      if (!ofs.lock(id)) throw new MorseException(MorseException.ERROR);
    } catch (IOException e) {
      throw new MorseException(MorseException.ERROR, e);
    }

    try {

      IQueryResult res = fetch(id, user, false);
      if (!res.next()) {
        res.close();
        throw new MorseException(MorseException.ACCESS_DENIED, id);
      }
      String lock = res.getString(IAttribute.M_LOCK);
      res.close();

      if (!force && ObjectUtil.validateId(lock) && !lock.equals(user.getUserId())) {
        throw new MorseException(MorseException.NOT_OWNER, id);
      }

      Properties p = new Properties();
      Reader reader = ofs.getReader(id);
      p.load(reader);
      reader.close();
      p.setProperty(IAttribute.M_LOCK, "");
      Writer writer = ofs.getWriter(id);
      p.store(writer);
      writer.close();

    } catch (Exception e) {
      log.error(e);
    } finally {
      if (log.t4()) log.debug("xUNLOCK: " + id + ' ' + user);
      ofs.unlock(id);
    }
  }
  private IQueryResult querySave(ICompiledQuery code, UserInformation user) throws MorseException {

    String parentId = code.getString(4);
    String format = code.getString(6);
    String typeName = code.getString(2);
    IType type = typeProvider.get(typeName);
    if (type == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);
    ObjectFileStore[] fs = fileStore.get(typeName);
    if (fs == null) throw new MorseException(MorseException.TABLE_NOT_FOUND, typeName);

    if (!aclManager.hasCreate(user, type.getAccessAcl()))
      throw new MorseException(
          MorseException.ACCESS_DENIED_CREATE,
          new String[] {"type", type.getName(), type.getAccessAcl()});

    IQueryResult parent = getConnection().fetch(parentId, user, false);
    if (!parent.next()) {
      parent.close();
      throw new MorseException(MorseException.OBJECT_NOT_FOUND, parentId);
    }
    String parentType = parent.getString(IAttribute.M_TYPE);
    parent.close();

    String newId = objectManager.newObjectId(typeProvider.get(IType.TYPE_MC_CONTENT), driver);

    Btc obj = ServerTypesUtil.createBtc(getConnection(), type);
    obj.initObject(type, connection, null, typeProvider, user, aclManager);
    obj.setString(IAttribute.MC_FORMAT, format);
    obj.setString(IAttribute.M_ACL, aclManager.getNewContentAcl(user, type));
    obj.doInsertCheck();

    try {

      driver.storeObject(type, obj, newId);
      // TODO create files in m_object etc.
      return new FileAbstractSaveResult(this, newId, obj, fs, parentId, parentType);

    } catch (Exception e) {
      log.error(e);
      // TODO rollback !!!!
    }
    return null;
  }
  private IQueryResult queryLoad(ICompiledQuery code, UserInformation user) {

    String id = code.getString(1);
    boolean shared = code.size() > 2 && code.getInteger(2) == CMql.SHARED;

    try {
      Properties current = new Properties();
      Reader reader = driver.getFileStore().get(IType.TYPE_OBJECT)[0].getReader(id);
      current.load(reader);
      reader.close();

      String typeName = current.getProperty(IAttribute.M_TYPE);
      if (typeName == null) throw new MorseException(MorseException.OBJECT_NOT_FOUND, id);

      IType type = typeProvider.get(typeName);
      if (type == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);

      ObjectFileStore[] store = fileStore.get(typeName);
      if (store == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);

      if (!aclManager.hasRead(user, type.getAccessAcl()))
        throw new MorseException(
            MorseException.ACCESS_DENIED_READ,
            new String[] {"type", typeName, type.getAccessAcl()});

      if (!shared) return new FileAbstractLoadResultStream(this, id, store[1]);
      else {
        return new SingleRowResult(
            new IAttribute[] {IAttributeDefault.ATTR_OBJ_STRING, IAttributeDefault.ATTR_OBJ_STRING},
            new String[] {"channel", "path"},
            new String[] {getName(), store[1].getRelativePath(id)});
      }

    } catch (Exception e) {
      log.error(e);
      return new ErrorResult(1, 1, e.toString());
    }
  }
 public IQueryResult fetch(String id, UserInformation user, boolean stamp) throws MorseException {
   ObjectFileStore[] store = driver.getFileStore().get(IType.TYPE_OBJECT);
   if (store == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, IType.TYPE_OBJECT);
   Reader reader = null;
   Properties prop = new Properties();
   try {
     reader = store[0].getReader(id);
     prop.load(reader);
     reader.close();
   } catch (IOException e) {
     // throw new MorseException( MorseException.ERROR, e );
     if (log.t3()) log.error(e);
     throw new MorseException(MorseException.OBJECT_NOT_FOUND, id);
   }
   if (stamp)
     return new SingleRowResult(
         new IAttribute[] {IAttributeDefault.ATTR_OBJ_INT},
         new String[] {IAttribute.M_STAMP},
         new String[] {prop.getProperty(IAttribute.M_STAMP)});
   String typeName = prop.getProperty(IAttribute.M_TYPE);
   IType type = typeProvider.get(typeName);
   if (type == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);
   LinkedList<Attr> attr = new LinkedList<Attr>();
   for (Iterator<IAttribute> i = type.getAttributes(); i.hasNext(); ) {
     Attr a = new Attr();
     a.attr = i.next();
     a.attrAlias = a.attrName = a.attr.getName();
     attr.add(a);
   }
   return new FileAbstractSelectResult(
       driver,
       type,
       driver.getFileStore().get(typeName)[0],
       IAttribute.M_ID,
       id,
       attr.toArray(new Attr[attr.size()]));
 }
 public QueryParser getParser() {
   if (queryParser == null) {
     try {
       qd.load(
           getClass()
               .getClassLoader()
               .getResourceAsStream(config.getProperty("resource.package") + "/idx.properties"));
       qd.load(
           getClass()
               .getClassLoader()
               .getResourceAsStream(config.getProperty("resource.package") + "/exec.properties"));
       qd.load(
           getClass()
               .getClassLoader()
               .getResourceAsStream(config.getProperty("resource.package") + "/fs.properties"));
       qd.load(
           getClass()
               .getClassLoader()
               .getResourceAsStream(config.getProperty("resource.package") + "/db.properties"));
       qd.load(
           getClass()
               .getClassLoader()
               .getResourceAsStream(
                   config.getProperty("resource.package") + "/statics.properties"));
       qd.load(
           getClass()
               .getClassLoader()
               .getResourceAsStream(
                   config.getProperty("resource.package") + "/default.properties"));
     } catch (IOException e) {
       log.error(e);
     }
     queryParser = new QueryParser(qd);
   }
   return queryParser;
 }