Class SQLiteJDBCDriverConnection

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.storage.sqlite.SQLiteJDBCDriverConnection
All Implemented Interfaces:
IDebuggable, IStorage

@Singleton public final class SQLiteJDBCDriverConnection extends Object implements IStorage, IDebuggable
An implementation of IStorage for SQLite.
  • Constructor Details

  • Method Details

    • deleteStructureType

      public boolean deleteStructureType(StructureType structureType)
      Description copied from interface: IStorage
      Deletes a StructureType and all Structures of this type from the database.

      Note that the StructureType has to be registered before it can be deleted! It doesn't need to be enabled, though.

      Specified by:
      deleteStructureType in interface IStorage
      Parameters:
      structureType - The StructureType to delete.
      Returns:
      True if deletion was successful.
    • insert

      public Optional<Structure> insert(Structure structure)
      Description copied from interface: IStorage
      Inserts a new structure in the database. If the insertion was successful, a new Structure will be created with the correct structureUID.
      Specified by:
      insert in interface IStorage
      Parameters:
      structure - The structure to insert.
      Returns:
      The Structure that was just inserted if insertion was successful. This is NOT!! the same object as the one passed to this method.
    • syncStructureData

      public boolean syncStructureData(IStructureConst structure)
      Description copied from interface: IStorage
      Synchronizes an Structure structure with the database. This will synchronize both the base and the type-specific data of the Structure.
      Specified by:
      syncStructureData in interface IStorage
      Parameters:
      structure - The IStructureConst that describes the data of structure.
      Returns:
      True if the update was successful.
    • getPartialIdentifiers

      public List<DatabaseManager.StructureIdentifier> getPartialIdentifiers(String input, @Nullable @Nullable IPlayer player, PermissionLevel maxPermission, Collection<Property<?>> properties)
      Description copied from interface: IStorage
      Retrieves all DatabaseManager.StructureIdentifiers that start with the provided input.

      For example, this method can retrieve the identifiers "1", "10", "11", "100", etc. from an input of "1" or "MyDoor", "MyPortcullis", "MyOtherDoor", etc. from an input of "My".

      Specified by:
      getPartialIdentifiers in interface IStorage
      Parameters:
      input - The partial identifier to look for.
      player - The player that should own the structures. May be null to disregard ownership.
      maxPermission - The maximum level of ownership (inclusive) this player has over the structures.
      properties - The properties that the structures must have. When specified, only structures that have all of these properties will be returned.
      Returns:
      All DatabaseManager.StructureIdentifiers that start with the provided input.
    • getStructure

      public Optional<Structure> getStructure(long structureUID)
      Description copied from interface: IStorage
      Gets the structure with the given structureUID and the original creator as StructureOwner;
      Specified by:
      getStructure in interface IStorage
      Parameters:
      structureUID - The UID of the structure to retrieve.
      Returns:
      The structure with the given structureUID and the original creator.
    • getStructure

      public Optional<Structure> getStructure(UUID playerUUID, long structureUID)
      Description copied from interface: IStorage
      Gets the structure with the given UID for the given player at the level of ownership this player has over the structure, if any.
      Specified by:
      getStructure in interface IStorage
      Parameters:
      playerUUID - The UUID of the player.
      structureUID - The UID of the structure to retrieve.
      Returns:
      The structure if it exists and if the player is an owner of it.
    • removeStructure

      public boolean removeStructure(long structureUID)
      Description copied from interface: IStorage
      Delete the structure with the given structureUID from the database.
      Specified by:
      removeStructure in interface IStorage
      Parameters:
      structureUID - The UID of the structure to delete.
      Returns:
      True if at least 1 structure was successfully removed.
    • removeStructures

      public boolean removeStructures(UUID playerUUID, String structureName)
      Description copied from interface: IStorage
      Delete all structures owned by the given player with the given name.
      Specified by:
      removeStructures in interface IStorage
      Parameters:
      playerUUID - The player whose structures to delete.
      structureName - The name of the structures to delete.
      Returns:
      True if at least 1 structure was successfully removed.
    • isAnimatedArchitectureWorld

      public boolean isAnimatedArchitectureWorld(String worldName)
      Description copied from interface: IStorage
      Checks whether there are any structures in a given world.
      Specified by:
      isAnimatedArchitectureWorld in interface IStorage
      Parameters:
      worldName - The name of the world.
      Returns:
      True if there are more than 0 structures in the given world.
    • getStructureCountForPlayer

      public int getStructureCountForPlayer(UUID playerUUID)
      Description copied from interface: IStorage
      Gets the total number of structures own by the given player.
      Specified by:
      getStructureCountForPlayer in interface IStorage
      Parameters:
      playerUUID - The uuid of the player whose structures to count.
      Returns:
      The total number of structures own by the given player.
    • getStructureCountForPlayer

      public int getStructureCountForPlayer(UUID playerUUID, String structureName)
      Description copied from interface: IStorage
      Gets the number of structures own by the given player with the given name.
      Specified by:
      getStructureCountForPlayer in interface IStorage
      Parameters:
      playerUUID - The uuid of the player whose structures to count.
      structureName - The name of the structure to search for.
      Returns:
      The number of structures own by the given player with the given name.
    • getStructureCountByName

      public int getStructureCountByName(String structureName)
      Description copied from interface: IStorage
      Gets the total number of structures with the given name regardless of who owns them.
      Specified by:
      getStructureCountByName in interface IStorage
      Parameters:
      structureName - The name of the structures to search for.
      Returns:
      The total number of structures with the given name.
    • getOwnerCountOfStructure

      public int getOwnerCountOfStructure(long structureUID)
      Description copied from interface: IStorage
      Gets the total number of owners of a structure.
      Specified by:
      getOwnerCountOfStructure in interface IStorage
      Parameters:
      structureUID - The Structure.
      Returns:
      The total number of owners of this structure.
    • getStructures

      public List<Structure> getStructures(UUID playerUUID, String structureName, PermissionLevel maxPermission)
      Description copied from interface: IStorage
      Gets all the structures with the given name, owned by the player with at least a certain permission level.
      Specified by:
      getStructures in interface IStorage
      Parameters:
      playerUUID - The name of the player who owns the structures.
      structureName - The name of the structures to search for.
      maxPermission - The maximum level of ownership (inclusive) this player has over the structures.
      Returns:
      All the structures with the given name, owned the player with at least a certain permission level.
    • getStructures

      public List<Structure> getStructures(UUID playerUUID, String name)
      Description copied from interface: IStorage
      Gets all the structures owned by the given player with the given name.
      Specified by:
      getStructures in interface IStorage
      Parameters:
      playerUUID - The UUID of the player to search for.
      name - The name of the structures to search for.
      Returns:
      All structures owned by the given player with the given name.
    • getStructures

      public List<Structure> getStructures(String name)
      Description copied from interface: IStorage
      Gets all the structures with the given name, regardless of who owns them.
      Specified by:
      getStructures in interface IStorage
      Parameters:
      name - The name of the structures to search for.
      Returns:
      All structures with the given name or an empty Optional if none exist.
    • getStructures

      public List<Structure> getStructures(UUID playerUUID, PermissionLevel maxPermission)
      Description copied from interface: IStorage
      Gets all the structures owned by a given player with at least a certain permission level.
      Specified by:
      getStructures in interface IStorage
      Parameters:
      playerUUID - The name of the player who owns the structures.
      maxPermission - The maximum level of ownership (inclusive) this player has over the structures.
      Returns:
      All the structures owned by the player with at least a certain permission level.
    • getStructures

      public List<Structure> getStructures(UUID playerUUID)
      Description copied from interface: IStorage
      Gets all the structures owned by the given player.
      Specified by:
      getStructures in interface IStorage
      Parameters:
      playerUUID - The UUID of the player to search for.
      Returns:
      All structures owned by the given player.
    • getStructuresOfType

      public List<Structure> getStructuresOfType(String typeName)
      Description copied from interface: IStorage
      Obtains all structures of a given type.
      Specified by:
      getStructuresOfType in interface IStorage
      Parameters:
      typeName - The name of the type. See StructureType.getFullKey().
      Returns:
      All structures of the given type.
    • getStructuresOfType

      public List<Structure> getStructuresOfType(String typeName, int version)
      Description copied from interface: IStorage
      Obtains all structures of a specific version of a given type.
      Specified by:
      getStructuresOfType in interface IStorage
      Parameters:
      typeName - The name of the type. See StructureType.getFullKey().
      version - The version of the type.
      Returns:
      All structures of the given type.
    • updatePlayerData

      public boolean updatePlayerData(PlayerData playerData)
      Description copied from interface: IStorage
      Updates the PlayerData for a given player.
      Specified by:
      updatePlayerData in interface IStorage
      Parameters:
      playerData - The PlayerData the represents a player.
      Returns:
      True if at least 1 record was modified.
    • getPlayerData

      public Optional<PlayerData> getPlayerData(UUID uuid)
      Description copied from interface: IStorage
      Tries to find the PlayerData for a player with the given UUID.
      Specified by:
      getPlayerData in interface IStorage
      Parameters:
      uuid - The UUID of a player.
      Returns:
      The PlayerData that represents the player.
    • getPlayerData

      public List<PlayerData> getPlayerData(String playerName)
      Description copied from interface: IStorage
      Tries to get all the players with a given name. Because names are not unique, this may result in any number of matches.

      If you know the player's UUID, it is recommended to use IStorage.getPlayerData(UUID) instead.

      Specified by:
      getPlayerData in interface IStorage
      Parameters:
      playerName - The name of the player(s).
      Returns:
      All the players with the given name.
    • getPowerBlockData

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<it.unimi.dsi.fastutil.longs.LongList> getPowerBlockData(long chunkId)
      Description copied from interface: IStorage
      Gets a map of location hashes and their connected powerblocks for all structures in a chunk.

      The key is the hashed location in chunk space, the value is the list of UIDs of the structures whose powerblocks occupies that location.

      Specified by:
      getPowerBlockData in interface IStorage
      Parameters:
      chunkId - The id of the chunk the structures are in.
      Returns:
      A map of location hashes and their connected powerblocks for all structures in a chunk.
    • getStructuresInChunk

      public List<Structure> getStructuresInChunk(long chunkId)
      Description copied from interface: IStorage
      Gets a list of structure UIDs that have their rotation point in a given chunk.
      Specified by:
      getStructuresInChunk in interface IStorage
      Parameters:
      chunkId - The id of the chunk the structures are in.
      Returns:
      A list of structures that have their rotation point in a given chunk.
    • removeOwner

      public boolean removeOwner(long structureUID, UUID playerUUID)
      Description copied from interface: IStorage
      Removes an owner of a structure. Note that the original creator can never be removed.
      Specified by:
      removeOwner in interface IStorage
      Parameters:
      structureUID - The UID of the structure to modify.
      playerUUID - The UUID of the player to remove as owner of the structure.
      Returns:
      True if an owner was removed.
    • addOwner

      public boolean addOwner(long structureUID, PlayerData player, PermissionLevel permission)
      Description copied from interface: IStorage
      Adds a player as owner of a structure with at a certain permission level to a structure.

      Note that permission level 0 is reserved for the creator, and negative values are not allowed.

      Specified by:
      addOwner in interface IStorage
      Parameters:
      structureUID - The UID of the structure to modify.
      player - The player to add as owner.
      permission - The level of ownership the player will have over the structure.
      Returns:
      True if the update was successful.
    • getDebugInformation

      public String getDebugInformation()
      Description copied from interface: IDebuggable
      Gets the debug information for this object.
      Specified by:
      getDebugInformation in interface IDebuggable
      Returns:
      The debug information or null if there's nothing to log at this time.
    • getDatabaseState

      public IStorage.DatabaseState getDatabaseState()
      The IStorage.DatabaseState the database is in.
      Specified by:
      getDatabaseState in interface IStorage
      Returns:
      The IStorage.DatabaseState the database is in.