/*
 * Copyright (c) 2015-2022, Antonio Gabriel Muñoz Conejo <antoniogmc at gmail dot com>
 * Distributed under the terms of the MIT License
 */
package com.github.tonivade.claudb;

public class DBConfig {

  private static final int DEFAULT_SYNC_PERIOD = 60;
  private static final int DEFAULT_CLEAN_PERIOD = 30;
  private static final int DEFAULT_DATABASES = 10;
  private static final String DUMP_FILE = "dump.rdb";
  private static final String REDO_FILE = "redo.aof";

  private int numDatabases = DEFAULT_DATABASES;

  private boolean persistenceActive;
  private boolean notificationsActive;
  private boolean offHeapActive;
  private boolean h2StorageActive;

  private String rdbFile;
  private String aofFile;

  private int syncPeriod = DEFAULT_SYNC_PERIOD;
  private int cleanPeriod = DEFAULT_CLEAN_PERIOD;

  public boolean isPersistenceActive() {
    return persistenceActive;
  }

  public void setPersistenceActive(boolean persistenceActive) {
    this.persistenceActive = persistenceActive;
  }

  public boolean isNotificationsActive() {
    return notificationsActive;
  }

  public void setNotificationsActive(boolean notificationsActive) {
    this.notificationsActive = notificationsActive;
  }

  public boolean isOffHeapActive() {
    return offHeapActive;
  }

  public void setOffHeapActive(boolean offHeapActive) {
    this.offHeapActive = offHeapActive;
  }

  public boolean isH2StorageActive() {
    return h2StorageActive;
  }

  public void setH2StorageActive(boolean h2StorageActive) {
    this.h2StorageActive = h2StorageActive;
  }

  public String getRdbFile() {
    return rdbFile;
  }

  public void setRdbFile(String rdbFile) {
    this.rdbFile = rdbFile;
  }

  public String getAofFile() {
    return aofFile;
  }

  public void setAofFile(String aofFile) {
    this.aofFile = aofFile;
  }

  public int getSyncPeriod() {
    return syncPeriod;
  }

  public void setSyncPeriod(int syncPeriod) {
    this.syncPeriod = syncPeriod;
  }

  public int getNumDatabases() {
    return numDatabases;
  }

  public void setNumDatabases(int numDatabases) {
    this.numDatabases = numDatabases;
  }

  public long getCleanPeriod() {
    return this.cleanPeriod;
  }

  public void setCleanPeriod(int cleanPeriod) {
    this.cleanPeriod = cleanPeriod;
  }

  public static Builder builder() {
    return new Builder();
  }

  public static class Builder {

    private final DBConfig config = new DBConfig();

    public Builder withoutPersistence() {
      config.setPersistenceActive(false);
      return this;
    }

    public Builder withPersistence() {
      config.setPersistenceActive(true);
      config.setRdbFile(DUMP_FILE);
      config.setAofFile(REDO_FILE);
      return this;
    }

    public Builder withOffHeapCache() {
      config.setOffHeapActive(true);
      return this;
    }

    public Builder withH2Storage() {
      config.setH2StorageActive(true);
      return this;
    }

    public Builder withNotifications() {
      config.setNotificationsActive(true);
      return this;
    }

    public DBConfig build() {
      return config;
    }
  }
}

@@ -203,61 +203,8 @@
  %7B%0A%0A
-  private static final int DEFAULT_SYNC_PERIOD = 60;%0A
   pr
@@ -307,116 +307,8 @@
  10;
-%0A  private static final String DUMP_FILE = %22dump.rdb%22;%0A  private static final String REDO_FILE = %22redo.aof%22;
 %0A%0A  
@@ -503,109 +503,8 @@
 e;%0A%0A
-  private String rdbFile;%0A  private String aofFile;%0A%0A  private int syncPeriod = DEFAULT_SYNC_PERIOD;%0A
   pr
@@ -1302,416 +1302,8 @@
  %7D%0A%0A
-  public String getRdbFile() %7B%0A    return rdbFile;%0A  %7D%0A%0A  public void setRdbFile(String rdbFile) %7B%0A    this.rdbFile = rdbFile;%0A  %7D%0A%0A  public String getAofFile() %7B%0A    return aofFile;%0A  %7D%0A%0A  public void setAofFile(String aofFile) %7B%0A    this.aofFile = aofFile;%0A  %7D%0A%0A  public int getSyncPeriod() %7B%0A    return syncPeriod;%0A  %7D%0A%0A  public void setSyncPeriod(int syncPeriod) %7B%0A    this.syncPeriod = syncPeriod;%0A  %7D%0A%0A
   pu
@@ -1957,80 +1957,8 @@
 e);%0A
-      config.setRdbFile(DUMP_FILE);%0A      config.setAofFile(REDO_FILE);%0A
     

remove useless configuration values