2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.rooms ;
import com.eu.habbo.Emulator ;
import java.sql.Connection ;
import java.sql.PreparedStatement ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
2019-05-26 20:14:53 +02:00
public class RoomPromotion {
2018-07-06 15:30:00 +02:00
private final Room room ;
2019-05-26 20:14:53 +02:00
public boolean needsUpdate ;
2018-07-06 15:30:00 +02:00
private String title ;
private String description ;
private int endTimestamp ;
2019-05-26 20:14:53 +02:00
public RoomPromotion ( Room room , String title , String description , int endTimestamp ) {
2018-07-06 15:30:00 +02:00
this . room = room ;
this . title = title ;
this . description = description ;
this . endTimestamp = endTimestamp ;
}
2019-05-26 20:14:53 +02:00
public RoomPromotion ( Room room , ResultSet set ) throws SQLException {
2018-07-06 15:30:00 +02:00
this . room = room ;
this . title = set . getString ( " title " ) ;
this . description = set . getString ( " description " ) ;
this . endTimestamp = set . getInt ( " end_timestamp " ) ;
}
2019-05-26 20:14:53 +02:00
public void save ( ) {
if ( this . needsUpdate ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " UPDATE room_promotions SET title = ?, description = ? WHERE room_id = ? " ) ) {
2018-07-06 15:30:00 +02:00
statement . setString ( 1 , this . title ) ;
statement . setString ( 2 , this . description ) ;
statement . setInt ( 3 , this . room . getId ( ) ) ;
statement . executeUpdate ( ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2018-07-06 15:30:00 +02:00
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
this . needsUpdate = false ;
}
}
2019-05-26 20:14:53 +02:00
public Room getRoom ( ) {
2018-07-06 15:30:00 +02:00
return this . room ;
}
2019-05-26 20:14:53 +02:00
public String getTitle ( ) {
2018-07-06 15:30:00 +02:00
return this . title ;
}
2019-05-26 20:14:53 +02:00
public void setTitle ( String title ) {
2018-07-06 15:30:00 +02:00
this . title = title ;
}
2019-05-26 20:14:53 +02:00
public String getDescription ( ) {
2018-07-06 15:30:00 +02:00
return this . description ;
}
2019-05-26 20:14:53 +02:00
public void setDescription ( String description ) {
2018-07-06 15:30:00 +02:00
this . description = description ;
}
2019-05-26 20:14:53 +02:00
public int getEndTimestamp ( ) {
2018-07-06 15:30:00 +02:00
return this . endTimestamp ;
}
2019-05-26 20:14:53 +02:00
public void setEndTimestamp ( int endTimestamp ) {
2018-07-06 15:30:00 +02:00
this . endTimestamp = endTimestamp ;
}
2019-05-26 20:14:53 +02:00
public void addEndTimestamp ( int time ) {
2018-07-06 15:30:00 +02:00
this . endTimestamp + = time ;
}
}