@Override
  public <DB extends ODatabase> DB open(final String iUserName, final String iUserPassword) {
    setCurrentDatabaseinThreadLocal();

    try {
      super.open(iUserName, iUserPassword);
      level1Cache.startup();

      metadata = new OMetadata();
      metadata.load();

      recordFormat = DEF_RECORD_FORMAT;

      if (getStorage() instanceof OStorageEmbedded) {
        user = getMetadata().getSecurity().authenticate(iUserName, iUserPassword);
        registerHook(new OUserTrigger());
        registerHook(new OClassIndexManager());
      } else
        // CREATE DUMMY USER
        user =
            new OUser(iUserName, OUser.encryptPassword(iUserPassword))
                .addRole(new ORole("passthrough", null, ORole.ALLOW_MODES.ALLOW_ALL_BUT));

      checkSecurity(ODatabaseSecurityResources.DATABASE, ORole.PERMISSION_READ);
    } catch (OException e) {
      close();
      throw e;
    } catch (Exception e) {
      close();
      throw new ODatabaseException("Cannot open database", e);
    }
    return (DB) this;
  }