@ -32,6 +32,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet ;
import java.sql.SQLException ;
import java.sql.Statement ;
import java.time.LocalDate ;
import java.util.ArrayList ;
import java.util.List ;
@ -130,7 +131,7 @@ public class DBController {
while ( rs . next ( ) ) {
databaseStreams . add ( new DatabaseDataType ( rs . getString ( "streamUrl" ) ,
rs . getString ( "title" ) , rs . getString ( "season" ) , rs . getString ( "episode" ) ,
rs . getInt ( "favorite" ) , rs . getDate ( "cached" ) , rs . getD ouble ( "currentTime" ) ) ) ;
rs . getInt ( "favorite" ) , rs . getDouble ( "currentTime" ) ) ) ;
}
stmt . close ( ) ;
rs . close ( ) ;
@ -140,7 +141,7 @@ public class DBController {
}
/ * *
* load all sources
* load all source stream s
* /
private void loadSources ( ) {
SourcesController sourcesController = new SourcesController ( ) ;
@ -163,7 +164,7 @@ public class DBController {
ImageView imageView = rs . getBoolean ( "favorite" ) ? new ImageView ( favorite_black ) : new ImageView ( favorite_border_black ) ;
filmsList . add ( new FilmTabelDataType ( rs . getString ( "streamUrl" ) ,
rs . getString ( "title" ) , rs . getString ( "season" ) , rs . getString ( "episode" ) , rs . getBoolean ( "favorite" ) ,
rs . getDate ( "cached" ) . toLocalDate ( ) , imageView ) ) ;
imageView ) ) ;
}
stmt . close ( ) ;
rs . close ( ) ;
@ -191,7 +192,7 @@ public class DBController {
ImageView imageView = rs . getBoolean ( "favorite" ) ? new ImageView ( favorite_black ) : new ImageView ( favorite_border_black ) ;
film = new FilmTabelDataType ( rs . getString ( "streamUrl" ) ,
rs . getString ( "title" ) , rs . getString ( "season" ) , rs . getString ( "episode" ) , rs . getBoolean ( "favorite" ) ,
rs . getDate ( "cached" ) . toLocalDate ( ) , imageView ) ;
imageView ) ;
}
rs . close ( ) ;
ps . close ( ) ;
@ -322,7 +323,7 @@ public class DBController {
ps . setString ( 3 , sourceStreamEntry . getSeason ( ) ) ;
ps . setString ( 4 , sourceStreamEntry . getEpisode ( ) ) ;
ps . setInt ( 5 , sourceStreamEntry . getFavorite ( ) ) ;
ps . setDate ( 6 , sourceStreamEntry . getCached ( ) ) ;
ps . setDate ( 6 , new Date ( 0 ) ) ;
ps . setDouble ( 7 , sourceStreamEntry . getCurrentTime ( ) ) ;
ps . addBatch ( ) ; / / adds the entry
LOGGER . info ( "Added \"" + sourceStreamEntry . getTitle ( ) + "\" to database" ) ;
@ -411,6 +412,30 @@ public class DBController {
}
}
/ * *
* get the cached date for the film
* @param streamUrl URL of the film
* /
public LocalDate getCached ( String streamUrl ) {
LocalDate cacheDate = LocalDate . now ( ) . minusDays ( 31 ) ;
try {
PreparedStatement ps = connection . prepareStatement ( "SELECT cached FROM films WHERE streamUrl = ?" ) ;
ps . setString ( 1 , streamUrl ) ;
ResultSet rs = ps . executeQuery ( ) ;
while ( rs . next ( ) ) {
cacheDate = rs . getDate ( "cached" ) . toLocalDate ( ) ;
}
rs . close ( ) ;
ps . close ( ) ;
} catch ( SQLException e ) {
LOGGER . error ( "Ups! an error occured!" , e ) ;
}
return cacheDate ;
}
/ * *
* add the received data to the cache table
* @param streamUrl URL of the film
@ -537,7 +562,7 @@ public class DBController {
while ( rs . next ( ) ) {
notCachedEntries . add ( new FilmTabelDataType ( rs . getString ( "streamUrl" ) ,
rs . getString ( "title" ) , rs . getString ( "season" ) , rs . getString ( "episode" ) , rs . getBoolean ( "favorite" ) ,
rs . getDate ( "cached" ) . toLocalDate ( ) , new ImageView ( favorite_border_black ) ) ) ;
new ImageView ( favorite_border_black ) ) ) ;
}
stmt . close ( ) ;
rs . close ( ) ;
@ -622,7 +647,7 @@ public class DBController {
/ / at this point we have found the correct episode
nextFilm = new FilmTabelDataType ( rs . getString ( "streamUrl" ) , rs . getString ( "title" ) ,
rs . getString ( "season" ) , rs . getString ( "episode" ) , rs . getBoolean ( "favorite" ) ,
rs . getDate ( "cached" ) . toLocalDate ( ) , new ImageView ( ) ) ;
new ImageView ( ) ) ;
rs . close ( ) ;
ps . close ( ) ;
@ -648,7 +673,7 @@ public class DBController {
while ( rs . next ( ) ) {
nextFilm = new FilmTabelDataType ( rs . getString ( "streamUrl" ) , rs . getString ( "title" ) ,
rs . getString ( "season" ) , rs . getString ( "episode" ) , rs . getBoolean ( "favorite" ) ,
rs . getDate ( "cached" ) . toLocalDate ( ) , new ImageView ( ) ) ;
new ImageView ( ) ) ;
/ / get the first episode where currentTime ! = 0
if ( rs . getDouble ( "currentTime" ) > lastCurrentTime ) {
break ;