Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/hotelview/NewsList.java

42 lines
1.2 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.hotelview;
import com.eu.habbo.Emulator;
2020-05-04 22:24:09 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2018-07-06 15:30:00 +02:00
2018-09-28 21:25:00 +02:00
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
2018-11-17 14:28:00 +01:00
import java.util.ArrayList;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class NewsList {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(NewsList.class);
2018-11-17 14:28:00 +01:00
private final ArrayList<NewsWidget> newsWidgets;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public NewsList() {
2018-11-17 14:28:00 +01:00
this.newsWidgets = new ArrayList<>();
2018-07-06 15:30:00 +02:00
this.reload();
}
2018-07-08 23:32:00 +02:00
2019-05-26 20:14:53 +02:00
public void reload() {
synchronized (this.newsWidgets) {
2018-07-06 15:30:00 +02:00
this.newsWidgets.clear();
2019-05-26 20:14:53 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM hotelview_news ORDER BY id DESC LIMIT 10")) {
while (set.next()) {
2018-07-06 15:30:00 +02:00
this.newsWidgets.add(new NewsWidget(set));
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught SQL exception", e);
2018-07-06 15:30:00 +02:00
}
}
}
2018-07-08 23:32:00 +02:00
2019-05-26 20:14:53 +02:00
public ArrayList<NewsWidget> getNewsWidgets() {
2019-03-18 02:22:00 +01:00
return this.newsWidgets;
2018-07-06 15:30:00 +02:00
}
}