/**
   * Instantiates a storage manager by loading an existing volume database.
   *
   * @param dbs the database system
   * @param db the database
   */
  public BabuDBStorageManager(BabuDB dbs, Database db) throws DatabaseException {

    this.dbMan = dbs.getDatabaseManager();
    this.snapMan = dbs.getSnapshotManager();
    this.database = db;
    this.vcListeners = new LinkedList<VolumeChangeListener>();

    volume = new BabuDBVolumeInfo();
    volume.init(this);
  }
  /**
   * Instantiates a storage manager by creating a new database.
   *
   * @param dbs the database system
   * @param volumeId the volume ID
   */
  public BabuDBStorageManager(
      BabuDB dbs,
      String volumeId,
      String volumeName,
      short fileAccessPolicyId,
      short[] osdPolicy,
      short[] replPolicy,
      String ownerId,
      String owningGroupId,
      int perms,
      ACLEntry[] acl,
      org.xtreemfs.pbrpc.generatedinterfaces.GlobalTypes.StripingPolicy rootDirDefSp,
      boolean allowSnaps,
      long volumeQuota,
      Map<String, String> attrs)
      throws DatabaseException {

    this.dbMan = dbs.getDatabaseManager();
    this.snapMan = dbs.getSnapshotManager();
    this.vcListeners = new LinkedList<VolumeChangeListener>();
    this.volume = new BabuDBVolumeInfo();

    TransactionalBabuDBUpdate update = new TransactionalBabuDBUpdate(dbMan);
    update.createDatabase(volumeId, 5);

    // atime, ctime, mtime
    int time = (int) (TimeSync.getGlobalTime() / 1000);

    // create the root directory; the name is the database name
    createDir(1, 0, volumeName, time, time, time, ownerId, owningGroupId, perms, 0, true, update);
    setLastFileId(1, update);

    volume.init(
        this,
        update.getDatabaseName(),
        volumeName,
        osdPolicy,
        replPolicy,
        fileAccessPolicyId,
        allowSnaps,
        volumeQuota,
        update);

    // set the default striping policy
    if (rootDirDefSp != null) setDefaultStripingPolicy(1, rootDirDefSp, true, update);

    if (acl != null)
      for (ACLEntry entry : acl) setACLEntry(1L, entry.getEntity(), entry.getRights(), update);

    if (attrs != null)
      for (Entry<String, String> attr : attrs.entrySet())
        setXAttr(
            1L,
            SYSTEM_UID,
            "xtreemfs.volattr." + attr.getKey(),
            attr.getValue().getBytes(),
            true,
            update);

    update.execute();

    try {
      database = dbMan.getDatabase(update.getDatabaseName());
    } catch (Exception exc) {
      throw new DatabaseException(exc);
    }

    notifyVolumeChange(volume);
  }