Class DataStore

java.lang.Object
me.mrnavastar.sqlib.api.DataStore

public class DataStore extends Object
This class represents a table in a Database.
  • Constructor Details

    • DataStore

      public DataStore(@NonNull @NonNull String modId, @NonNull @NonNull String name, @NonNull @NonNull Database database, @NonNull @NonNull SQLConnection connection)
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createContainer

      public DataContainer createContainer()
      Creates a new DataContainer with a unique id.
    • getOrCreateContainer

      public DataContainer getOrCreateContainer(int id)
      Tries to get a DataContainer or creates a new DataContainer if it is missing. Note that the created DataContainer is not guaranteed to have the same id as the one passed in.
    • getOrCreateContainer

      public DataContainer getOrCreateContainer(int id, Consumer<DataContainer> onCreate)
      Tries to get a DataContainer or creates a new DataContainer if it is missing. Note that the created DataContainer is not guaranteed to have the same id as the one passed in.
      Parameters:
      onCreate - A function that gets run only when the container is created. This is useful for setting things such as a container id or other elements that are only set once.
    • getOrCreateContainer

      public DataContainer getOrCreateContainer(@NonNull @NonNull String field, @NonNull @NonNull Object value)
      Tries to get a DataContainer with a matching key value pair or creates a new DataContainer if it is missing.
    • getOrCreateContainer

      public DataContainer getOrCreateContainer(@NonNull @NonNull String field, @NonNull @NonNull Object value, Consumer<DataContainer> onCreate)
      Tries to get a DataContainer with a matching key value pair or creates a new DataContainer if it is missing.
      Parameters:
      onCreate - A function that gets run only when the container is created. This is useful for setting things such as a container id or other elements that are only set once.
    • getOrCreateDefaultContainer

      public <T> DataContainer getOrCreateDefaultContainer(@NonNull @NonNull SQLibType<T> type, @NonNull @NonNull String field, @NonNull T value)
      Tries to get a DataContainer with a matching key value pair or creates a new DataContainer with a matching key value pair if it is missing.
    • getContainer

      public Optional<DataContainer> getContainer(@NonNull @NonNull String field, @NonNull @NonNull Object value)
      Returns:
      A DataContainer's with a matching key value pair or null if one does not exist.
    • getContainer

      public Optional<DataContainer> getContainer(int id)
      Returns:
      A DataContainer or null if it is missing.
    • getContainers

      public List<DataContainer> getContainers()
      Returns:
      A list of all the DataContainer's in this table.
    • getContainers

      public List<DataContainer> getContainers(@NonNull @NonNull String field, @NonNull @NonNull Object value)
      Returns:
      A list of all the DataContainer's with a matching key value pair.
    • getKeys

      public List<String> getKeys()
      Returns:
      A list of every key present in this DataStore.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getModId

      public String getModId()
    • getName

      public String getName()
    • getDatabase

      public Database getDatabase()