Class Table

java.lang.Object
me.mrnavastar.sqlib.Table

public class Table extends Object
This class acts as a wrapper for a table in a Database
  • Field Details

    • autoIncrement

      protected boolean autoIncrement
  • Constructor Details

  • Method Details

    • setAutoIncrement

      public Table setAutoIncrement()
      Make this table use auto incremented ids. See createDataContainerAutoID()
    • addColumn

      public Table addColumn(@NonNull @NonNull String name, @NonNull @NonNull SQLDataType dataType)
      Adds a column to the table definition
      Parameters:
      name - The name of the column
      dataType - The SQLDataType of this column
    • finish

      public Table finish()
      Call this function when you are done configuring your table.
      Returns:
      The finished table
    • getNoConflictName

      public String getNoConflictName()
    • beginTransaction

      public void beginTransaction()
      Create a transactional lock on this database. No data will be written until you call endTransaction()
    • endTransaction

      public void endTransaction()
      Close the transactional lock on this database and write the data.
    • isInTransaction

      public boolean isInTransaction()
      Checks if this Table is in a transaction
    • getIds

      public List<String> getIds()
      Returns:
      A list of all the DataContainer ids in this table.
    • getIdsAsUUIDs

      public ArrayList<UUID> getIdsAsUUIDs()
      Returns:
      A list of all the DataContainer ids in this table.
    • getIdsAsInts

      public ArrayList<Integer> getIdsAsInts()
      Returns:
      A list of all the DataContainer ids in this table.
    • createDataContainer

      public DataContainer createDataContainer(@NonNull @NonNull String id)
      Creates a new DataContainer
    • createDataContainer

      public DataContainer createDataContainer(@NonNull @NonNull UUID id)
      Creates a new DataContainer
    • createDataContainer

      public DataContainer createDataContainer(int id)
      Creates a new DataContainer
    • getOrCreateDataContainer

      public DataContainer getOrCreateDataContainer(@NonNull @NonNull String id)
      Tries to get a DataContainer or creates a new DataContainer if it is missing
    • getOrCreateDataContainer

      public DataContainer getOrCreateDataContainer(@NonNull @NonNull UUID id)
      Tries to get a DataContainer or creates a new DataContainer if it is missing
    • getOrCreateDataContainer

      public DataContainer getOrCreateDataContainer(int id)
      Tries to get a DataContainer or creates a new DataContainer if it is missing
    • createDataContainerAutoID

      public DataContainer createDataContainerAutoID()
      Creates a new row in the database and creates a handy wrapper class
      Returns:
      DataContainer or null if the table is not configured for autoIncrementing.
    • drop

      public void drop(@NonNull @NonNull DataContainer dataContainer)
      Delete the DataContainer from the database
      Parameters:
      dataContainer - The DataContainer to delete
    • drop

      public void drop(@NonNull @NonNull String id)
      Delete the DataContainer from the database
      Parameters:
      id - The id of the DataContainer to delete
    • drop

      public void drop(@NonNull @NonNull UUID id)
      Delete the DataContainer from the database
      Parameters:
      id - The id of the DataContainer to delete
    • drop

      public void drop(int id)
      Delete the DataContainer from the database
      Parameters:
      id - The id of the DataContainer to delete
    • get

      public DataContainer get(@NonNull @NonNull String id)
      Tries to get a DataContainer
      Returns:
      The DataContainer or null if it is missing
    • get

      public DataContainer get(@NonNull @NonNull UUID id)
      Tries to get a DataContainer
      Returns:
      The DataContainer or null if it is missing
    • get

      public DataContainer get(int id)
      Tries to get a DataContainer
      Returns:
      The DataContainer or null if it is missing
    • contains

      public boolean contains(@NonNull @NonNull String id)
      Checks if the table contains a DataContainer
      Parameters:
      id - The id of the DataContainer to look for
    • contains

      public boolean contains(@NonNull @NonNull UUID id)
      Checks if the table contains a DataContainer
      Parameters:
      id - The id of the DataContainer to look for
    • contains

      public boolean contains(int id)
      Checks if the table contains a DataContainer
      Parameters:
      id - The id of the DataContainer to look for
    • getDataContainers

      public ArrayList<DataContainer> getDataContainers()
      Returns:
      A list of all the DataContainer's in this table
    • getModId

      @NonNull public @NonNull String getModId()
    • getName

      @NonNull public @NonNull String getName()
    • getDatabase

      @NonNull public @NonNull Database getDatabase()
    • getColumns

      public HashMap<String,SQLDataType> getColumns()