2018-01-13 12:23:34 +01:00
|
|
|
/*
|
2018-10-28 09:10:56 +01:00
|
|
|
* This file is part of Player Analytics (Plan).
|
|
|
|
*
|
|
|
|
* Plan is free software: you can redistribute it and/or modify
|
2018-11-11 19:55:11 +01:00
|
|
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
2018-10-28 09:10:56 +01:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Plan is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-11-11 19:55:11 +01:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-10-28 09:10:56 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
2017-08-20 12:06:39 +02:00
|
|
|
*/
|
2019-08-30 22:14:54 +02:00
|
|
|
package com.djrapitops.plan.storage.database.sql.tables;
|
2018-01-11 13:17:04 +01:00
|
|
|
|
2019-08-30 22:14:54 +02:00
|
|
|
import com.djrapitops.plan.identification.Server;
|
2021-07-17 11:19:33 +02:00
|
|
|
import com.djrapitops.plan.identification.ServerUUID;
|
2019-08-30 22:14:54 +02:00
|
|
|
import com.djrapitops.plan.storage.database.DBType;
|
2019-12-05 19:22:33 +01:00
|
|
|
import com.djrapitops.plan.storage.database.sql.building.CreateTableBuilder;
|
|
|
|
import com.djrapitops.plan.storage.database.sql.building.Insert;
|
|
|
|
import com.djrapitops.plan.storage.database.sql.building.Sql;
|
|
|
|
import com.djrapitops.plan.storage.database.sql.building.Update;
|
2021-07-17 11:19:33 +02:00
|
|
|
import org.apache.commons.text.TextStringBuilder;
|
2024-03-10 09:25:42 +01:00
|
|
|
import org.intellij.lang.annotations.Language;
|
2021-07-17 11:19:33 +02:00
|
|
|
|
|
|
|
import java.util.Collection;
|
2017-08-20 15:09:52 +02:00
|
|
|
|
2019-12-05 19:22:33 +01:00
|
|
|
import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
2019-02-15 08:44:36 +01:00
|
|
|
|
2017-08-20 12:06:39 +02:00
|
|
|
/**
|
2019-02-15 08:44:36 +01:00
|
|
|
* Table information about 'plan_servers'.
|
2017-08-20 12:06:39 +02:00
|
|
|
*
|
2021-02-13 14:16:03 +01:00
|
|
|
* @author AuroraLS3
|
2018-03-01 11:01:14 +01:00
|
|
|
* @see Server
|
2017-08-20 12:06:39 +02:00
|
|
|
*/
|
2019-02-15 08:44:36 +01:00
|
|
|
public class ServerTable {
|
2017-08-20 15:09:52 +02:00
|
|
|
|
2018-04-07 10:19:39 +02:00
|
|
|
public static final String TABLE_NAME = "plan_servers";
|
|
|
|
|
2022-04-09 19:52:29 +02:00
|
|
|
public static final String ID = "id";
|
2019-01-22 19:33:54 +01:00
|
|
|
public static final String SERVER_UUID = "uuid";
|
|
|
|
public static final String NAME = "name";
|
|
|
|
public static final String WEB_ADDRESS = "web_address";
|
|
|
|
public static final String INSTALLED = "is_installed";
|
2021-01-01 10:26:07 +01:00
|
|
|
public static final String PROXY = "is_proxy";
|
2022-04-07 17:24:40 +02:00
|
|
|
public static final String PLAN_VERSION = "plan_version";
|
2019-01-22 19:33:54 +01:00
|
|
|
|
2019-01-24 18:38:13 +01:00
|
|
|
public static final String INSERT_STATEMENT = Insert.values(TABLE_NAME,
|
|
|
|
SERVER_UUID, NAME,
|
2022-04-07 17:24:40 +02:00
|
|
|
WEB_ADDRESS, INSTALLED, PROXY, PLAN_VERSION);
|
2019-01-24 18:38:13 +01:00
|
|
|
|
2019-02-15 08:01:23 +01:00
|
|
|
public static final String UPDATE_STATEMENT = Update.values(TABLE_NAME,
|
2022-04-07 17:24:40 +02:00
|
|
|
SERVER_UUID,
|
|
|
|
NAME,
|
|
|
|
WEB_ADDRESS,
|
|
|
|
INSTALLED,
|
|
|
|
PROXY,
|
|
|
|
PLAN_VERSION)
|
2019-02-15 08:01:23 +01:00
|
|
|
.where(SERVER_UUID + "=?")
|
|
|
|
.toString();
|
|
|
|
|
2024-03-10 09:25:42 +01:00
|
|
|
@Language("SQL")
|
2022-04-09 19:52:29 +02:00
|
|
|
public static final String SELECT_SERVER_ID =
|
|
|
|
'(' + SELECT + TABLE_NAME + '.' + ID +
|
2019-02-15 08:44:36 +01:00
|
|
|
FROM + TABLE_NAME +
|
2022-04-09 19:52:29 +02:00
|
|
|
WHERE + TABLE_NAME + '.' + SERVER_UUID + "=?" + LIMIT + "1)";
|
2019-01-24 18:11:21 +01:00
|
|
|
|
2019-02-15 08:44:36 +01:00
|
|
|
private ServerTable() {
|
|
|
|
/* Static information class */
|
2018-03-01 11:01:14 +01:00
|
|
|
}
|
2018-02-28 14:47:37 +01:00
|
|
|
|
2019-01-22 19:33:54 +01:00
|
|
|
public static String createTableSQL(DBType dbType) {
|
2019-12-05 19:22:33 +01:00
|
|
|
return CreateTableBuilder.create(TABLE_NAME, dbType)
|
2022-04-09 19:52:29 +02:00
|
|
|
.column(ID, Sql.INT).primaryKey()
|
2019-01-22 19:33:54 +01:00
|
|
|
.column(SERVER_UUID, Sql.varchar(36)).notNull().unique()
|
|
|
|
.column(NAME, Sql.varchar(100))
|
|
|
|
.column(WEB_ADDRESS, Sql.varchar(100))
|
|
|
|
.column(INSTALLED, Sql.BOOL).notNull().defaultValue(true)
|
2021-01-01 10:26:07 +01:00
|
|
|
.column(PROXY, Sql.BOOL).notNull().defaultValue(false)
|
2022-04-07 17:24:40 +02:00
|
|
|
.column(PLAN_VERSION, Sql.varchar(18))
|
2019-01-22 19:33:54 +01:00
|
|
|
.toString();
|
|
|
|
}
|
2021-07-17 11:19:33 +02:00
|
|
|
|
|
|
|
public static String selectServerIds(Collection<ServerUUID> serverUUIDs) {
|
2022-04-09 19:52:29 +02:00
|
|
|
return '(' + SELECT + TABLE_NAME + '.' + ID +
|
2021-07-17 11:19:33 +02:00
|
|
|
FROM + TABLE_NAME +
|
|
|
|
WHERE + TABLE_NAME + '.' + SERVER_UUID + " IN ('" +
|
|
|
|
new TextStringBuilder().appendWithSeparators(serverUUIDs, "','").build() +
|
|
|
|
"'))";
|
|
|
|
}
|
2018-06-12 20:28:40 +02:00
|
|
|
}
|