2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.hotelview ;
import com.eu.habbo.Emulator ;
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
public class NewsList
{
2018-11-17 14:28:00 +01:00
private final ArrayList < NewsWidget > newsWidgets ;
2018-07-06 15:30:00 +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
2018-07-06 15:30:00 +02:00
public void reload ( )
{
synchronized ( this . newsWidgets )
{
this . newsWidgets . clear ( ) ;
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 ( ) )
{
this . newsWidgets . add ( new NewsWidget ( set ) ) ;
}
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
}
2018-07-08 23:32:00 +02:00
2018-11-17 14:28:00 +01:00
public ArrayList < NewsWidget > getNewsWidgets ( )
2018-07-06 15:30:00 +02:00
{
return newsWidgets ;
}
}