# Database (ShopChest 1.12 API)
Date: 2017-06-08

de.epiceric.shopchest.sql

## Class Database

- java.lang.Object
- - de.epiceric.shopchest.sql.Database

Direct Known Subclasses:
  MySQL, SQLite

    public abstract class Database
    extends Object

### Nested Class Summary

Nested Classes
`static class` `Database.DatabaseType`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`void` `addShop(Shop shop, Callback callback)` Adds a shop to the database
`void` `connect(Callback callback)` (Re-)Connects to the the database and initializes it.
`void` `disconnect()` Closes the connection to the database
`abstract Connection` `getConnection()`
`void` `getLastLogout(org.bukkit.entity.Player player, Callback callback)` Get the last logout of a player
`void` `getRevenue(org.bukkit.entity.Player player, long logoutTime, Callback callback)` Get the revenue a player got while he was offline
`void` `getShops(boolean showConsoleMessages, Callback callback)` Get all shops from the database
`void` `isShop(int id, Callback callback)`
`void` `logEconomy(org.bukkit.entity.Player executor, org.bukkit.inventory.ItemStack product, org.bukkit.OfflinePlayer vendor, Shop.ShopType shopType, org.bukkit.Location location, double price, ShopBuySellEvent.Type type, Callback callback)` Log an economy transaction to the database
`void` `logLogout(org.bukkit.entity.Player player, long timestamp, Callback callback)` Log a logout to the database
`void` `removeShop(Shop shop, Callback callback)` Remove a shop from the database

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### getConnection

    public abstract Connection getConnection()

Returns:
  New connection to the database

#### connect

    public void connect(Callback callback)

(Re-)Connects to the the database and initializes it.
Creates the table (if doesn't exist) and tests the connection

Parameters:
  `callback` - Callback that - if succeeded - returns the amount of shops that were found (as `int`)

#### removeShop

    public void removeShop(Shop shop,
                           Callback callback)

Remove a shop from the database

Parameters:
  `shop` - Shop to remove
  `callback` - Callback that - if succeeded - returns `null`

#### isShop

    public void isShop(int id,
                       Callback callback)

Parameters:
  `id` - ID of the shop
  `callback` - Callback that - if succeeded - returns whether a shop with the given ID exists (as `boolean`)

#### getShops

    public void getShops(boolean showConsoleMessages,
                         Callback callback)

Get all shops from the database

Parameters:
  `callback` - Callback that - if succeeded - returns an array of all shops (as `Shop[]`)
  `showConsoleMessages` - Whether console messages (errors or warnings) should be shown

#### addShop

    public void addShop(Shop shop,
                        Callback callback)

Adds a shop to the database

Parameters:
  `shop` - Shop to add
  `callback` - Callback that - if succeeded - returns the ID the shop was given (as `int`)

#### logEconomy

    public void logEconomy(org.bukkit.entity.Player executor,
                           org.bukkit.inventory.ItemStack product,
                           org.bukkit.OfflinePlayer vendor,
                           Shop.ShopType shopType,
                           org.bukkit.Location location,
                           double price,
                           ShopBuySellEvent.Type type,
                           Callback callback)

Log an economy transaction to the database

Parameters:
  `executor` - Player who bought/sold something
  `product` - ItemStack that was bought/sold
  `vendor` - Vendor of the shop
  `location` - Location of the shop
  `price` - Price (buyprice or sellprice, depends on `type`)
  `type` - Whether the player bought or sold something
  `callback` - Callback that - if succeeded - returns `null`

#### getRevenue

    public void getRevenue(org.bukkit.entity.Player player,
                           long logoutTime,
                           Callback callback)

Get the revenue a player got while he was offline

Parameters:
  `player` - Player whose revenue to get
  `logoutTime` - Time in milliseconds when he logged out the last time
  `callback` - Callback that - if succeeded - returns the revenue the player made while offline (as `double`)

#### logLogout

    public void logLogout(org.bukkit.entity.Player player,
                          long timestamp,
                          Callback callback)

Log a logout to the database

Parameters:
  `player` - Player who logged out
  `timestamp` - Time in milliseconds when the player logged out
  `callback` - Callback that - if succeeded - returns `null`

#### getLastLogout

    public void getLastLogout(org.bukkit.entity.Player player,
                              Callback callback)

Get the last logout of a player

Parameters:
  `player` - Player who logged out
  `callback` - Callback that - if succeeded - returns the time in milliseconds the player logged out (as `long`)

#### disconnect

    public void disconnect()

Closes the connection to the database