worked on the dbcontroller
first part of upcoming database for homeflix (still a lot of work to do)
This commit is contained in:
parent
7a92bb452f
commit
f4e2fd2234
|
@ -6,5 +6,6 @@
|
||||||
<classpathentry kind="lib" path="C:/Users/Jannik/workspace/Project HomeFlix/src/libraries/jfoenix.jar"/>
|
<classpathentry kind="lib" path="C:/Users/Jannik/workspace/Project HomeFlix/src/libraries/jfoenix.jar"/>
|
||||||
<classpathentry kind="lib" path="C:/Users/Jannik/workspace/Project HomeFlix/src/libraries/minimal-json-0.9.4.jar"/>
|
<classpathentry kind="lib" path="C:/Users/Jannik/workspace/Project HomeFlix/src/libraries/minimal-json-0.9.4.jar"/>
|
||||||
<classpathentry kind="lib" path="C:/Users/Jannik/workspace/Project HomeFlix/src/libraries/commons-lang3-3.5.jar"/>
|
<classpathentry kind="lib" path="C:/Users/Jannik/workspace/Project HomeFlix/src/libraries/commons-lang3-3.5.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Jannik/workspace/Project HomeFlix/src/libraries/sqlite-jdbc-3.15.1.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,9 @@
|
||||||
|
/**
|
||||||
|
* DBController for Project HomeFlix
|
||||||
|
*
|
||||||
|
* TODO fav and defav
|
||||||
|
*/
|
||||||
|
|
||||||
package application;
|
package application;
|
||||||
|
|
||||||
import java.sql.Connection; //für Datenbank
|
import java.sql.Connection; //für Datenbank
|
||||||
|
@ -6,100 +12,131 @@ import java.sql.PreparedStatement; //f
|
||||||
import java.sql.ResultSet; //für Datenbank
|
import java.sql.ResultSet; //für Datenbank
|
||||||
import java.sql.SQLException; //für Datenbank
|
import java.sql.SQLException; //für Datenbank
|
||||||
import java.sql.Statement; //für Datenbank
|
import java.sql.Statement; //für Datenbank
|
||||||
import java.io.File;//für Dateien einlesen
|
|
||||||
|
|
||||||
class DBController {
|
import com.eclipsesource.json.Json;
|
||||||
|
import com.eclipsesource.json.JsonArray;
|
||||||
|
import com.eclipsesource.json.JsonObject;
|
||||||
|
import com.eclipsesource.json.JsonValue;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DBController {
|
||||||
|
|
||||||
|
public DBController(MainWindowController m){
|
||||||
|
mainWindowController=m;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private static final DBController dbcontroller = new DBController();
|
private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; // der Pfad der Datenbank-Datei
|
||||||
private static Connection connection;
|
Connection connection = null;
|
||||||
private static final String DB_PATH = System.getProperty("user.dir") + "/" + "Homeflix.db"; // der Pfad der Datenbank-Datei
|
|
||||||
private String path;
|
|
||||||
File f;
|
|
||||||
File file[]; //ArrayList für die Dateien
|
|
||||||
|
|
||||||
static {
|
public void main()
|
||||||
try {
|
{
|
||||||
Class.forName("org.sqlite.JDBC"); //Datenbanktreiber
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
System.err.println("Fehler beim Laden des JDBC-Treibers");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String input) {
|
System.out.println("Hallo");
|
||||||
DBController datenbank = DBController.getInstance(); //neues Datenbank-Objekt wird erstellt
|
|
||||||
datenbank.setPath(input); // Pfad zuweisen
|
|
||||||
datenbank.f = new File(datenbank.getPath()); // für Datenbank-Datei einlesen
|
|
||||||
datenbank.file = datenbank.f.listFiles(); // für Datenbank-Datei einlesen
|
|
||||||
datenbank.verbindeDatenbank();
|
|
||||||
datenbank.fuelleDatenbank();
|
|
||||||
//datenbank.defavorisieren("Frozen");
|
|
||||||
//datenbank.favorisieren("Frozen");
|
|
||||||
//datenbank.ausgebenTitel();
|
|
||||||
//System.out.println("Pfad: " + datenbank.getPfad("Frozen"));
|
|
||||||
//System.out.println("Bewertung: " + datenbank.getFavStatus("Frozen"));
|
|
||||||
}
|
|
||||||
|
|
||||||
DBController(){
|
try
|
||||||
}
|
{
|
||||||
|
// create a database connection
|
||||||
|
connection = DriverManager.getConnection("jdbc:sqlite:"+DB_PATH);
|
||||||
|
// Statement statement = connection.createStatement();
|
||||||
|
// statement.setQueryTimeout(30); // set timeout to 30 sec. TODO don't know wath to do with this
|
||||||
|
|
||||||
private static DBController getInstance(){
|
|
||||||
return dbcontroller;
|
|
||||||
}
|
|
||||||
// Die Datenbak wird mit Hilfe des JDBC-Treibers eingebunden
|
|
||||||
public void verbindeDatenbank() {
|
|
||||||
try {
|
|
||||||
if (connection != null)
|
|
||||||
return;
|
|
||||||
System.out.println("Erstelle Verbindung zur Datenbank...");
|
|
||||||
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
|
|
||||||
if (!connection.isClosed())
|
|
||||||
System.out.println("...Verbindung hergestellt");
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
|
||||||
public void run() {
|
fuelleDatenbank();
|
||||||
try {
|
// ausgeben();
|
||||||
if (!connection.isClosed() && connection != null) {
|
getFavStatus("House of Cards");
|
||||||
|
favorisieren("House of Cards");
|
||||||
|
getFavStatus("House of Cards");
|
||||||
|
defavorisieren("House of Cards");
|
||||||
|
getFavStatus("House of Cards");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(SQLException e)
|
||||||
|
{
|
||||||
|
// if the error message is "out of memory",
|
||||||
|
// it probably means no database file is found
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(connection != null)
|
||||||
connection.close();
|
connection.close();
|
||||||
if (connection.isClosed())
|
|
||||||
System.out.println("Verbindung getrennt");
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
catch(SQLException e)
|
||||||
e.printStackTrace();
|
{
|
||||||
|
// connection close failed.
|
||||||
|
System.err.println(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// Die Dateien werden in die Datenbank geschrieben
|
|
||||||
public void fuelleDatenbank() {
|
public void fuelleDatenbank() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println("Erstelle Einträge");
|
System.out.println("Erstelle Einträge local");
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("DROP TABLE IF EXISTS filme;");
|
Statement stmtS = connection.createStatement();
|
||||||
stmt.executeUpdate("CREATE TABLE filme (titel, pfad, bewertung);"); // Tabelle "filme" und die Spalten "titel", "pfad", "bewertung" erstellen
|
stmt.executeUpdate("drop table if exists film_local");
|
||||||
|
stmtS.executeUpdate("drop table if exists film_streaming");
|
||||||
|
stmt.executeUpdate("create table film_local (rating, titel, streamUrl)"); // Tabelle "filme" und die Spalten "titel", "pfad", "bewertung" erstellen
|
||||||
|
stmtS.executeUpdate("create table film_streaming (year, season, episode, rating, resolution, titel, streamUrl)"); // Tabelle "filme" und die Spalten "titel", "pfad", "bewertung" erstellen
|
||||||
|
|
||||||
PreparedStatement ps = connection.prepareStatement("INSERT INTO filme VALUES (?, ?, ?);"); // SQL Befehl
|
|
||||||
|
|
||||||
//System.out.println(file.length);
|
PreparedStatement ps = connection.prepareStatement("insert into film_local values (?, ?, ?)"); // SQL Befehl
|
||||||
|
PreparedStatement psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?)"); // SQL Befehl
|
||||||
|
|
||||||
for(int i=0;i!=file.length;i++) // Geht alle Dateien im Verzeichniss durch
|
String[] entries = new File(mainWindowController.getPath()).list();
|
||||||
|
System.out.println("Size: "+entries.length);
|
||||||
|
|
||||||
|
for(int i=0;i!=entries.length;i++) // Geht alle Dateien im Verzeichniss durch
|
||||||
{
|
{
|
||||||
//System.out.println(file[i].getName());
|
//System.out.println(file[i].getName());
|
||||||
ps.setString(1, ohneEndung(file[i].getName())); // definiert Name als String in der ersten Spalte
|
ps.setInt(1, 0); // definiert Bewertung als Integer in der dritten Spalte
|
||||||
ps.setString(2,file[i].getName()); // definiert Pfad als String in der zweiten Spalte
|
ps.setString(2, ohneEndung(entries[i])); // definiert Name als String in der ersten Spalte
|
||||||
ps.setInt(3, 0); // definiert Bewertung als Integer in der dritten Spalte
|
ps.setString(3,entries[i]); // definiert Pfad als String in der zweiten Spalte
|
||||||
ps.addBatch(); // fügt den Eintrag hinzu
|
ps.addBatch(); // fügt den Eintrag hinzu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Erstelle Einträge streaming");
|
||||||
|
|
||||||
|
System.out.println(mainWindowController.getStreamingPath());
|
||||||
|
if(mainWindowController.getStreamingPath().equals("")||mainWindowController.getStreamingPath().equals(null)){
|
||||||
|
System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist
|
||||||
|
}else{
|
||||||
|
for(int i=0; i< mainWindowController.streamingData.size(); i++){
|
||||||
|
String fileName = mainWindowController.getStreamingPath()+"/"+mainWindowController.streamingData.get(i).getStreamUrl();
|
||||||
|
try {
|
||||||
|
JsonObject object = Json.parse(new FileReader(fileName)).asObject();
|
||||||
|
JsonArray items = object.get("entries").asArray();
|
||||||
|
for (JsonValue item : items) {
|
||||||
|
psS.setInt(1, item.asObject().getInt("year", 0));
|
||||||
|
psS.setInt(2, item.asObject().getInt("season", 0));
|
||||||
|
psS.setInt(3, item.asObject().getInt("episode", 0));
|
||||||
|
psS.setInt(4, 0);
|
||||||
|
psS.setString(5, item.asObject().getString("resolution", ""));
|
||||||
|
psS.setString(6, item.asObject().getString("titel",""));
|
||||||
|
psS.setString(7, item.asObject().getString("streamUrl", ""));
|
||||||
|
psS.addBatch(); // fügt den Eintrag hinzu
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
//Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
ps.executeBatch(); // scheibt alle Einträge in die Datenbank
|
ps.executeBatch(); // scheibt alle Einträge in die Datenbank
|
||||||
|
psS.executeBatch();
|
||||||
connection.setAutoCommit(true);
|
connection.setAutoCommit(true);
|
||||||
|
ps.close();
|
||||||
|
psS.close();
|
||||||
//connection.close();
|
//connection.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.err.println("Konnte nicht ausgeführt werden");
|
System.err.println("Konnte nicht ausgeführt werden");
|
||||||
|
@ -108,97 +145,94 @@ class DBController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ausgeben(){
|
public void ausgeben(){
|
||||||
System.out.println("Einträge ausgeben");
|
System.out.println("Einträge ausgeben ... \n");
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
mainWindowController = new MainWindowController();
|
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM filme;");
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
// MainWindowController mainWindowController = new MainWindowController();
|
System.out.println(rs.getString(1));
|
||||||
|
System.out.println(rs.getString(2));
|
||||||
|
System.out.println(rs.getString(3)+"\n");
|
||||||
}
|
}
|
||||||
//rs.close();
|
rs.close();
|
||||||
// mainWindowController.initTabel();
|
|
||||||
|
|
||||||
|
System.out.println("Streaming Entries: \n");
|
||||||
|
|
||||||
|
ResultSet rsS = stmt.executeQuery("SELECT * FROM film_streaming;");
|
||||||
|
while (rsS.next()) {
|
||||||
|
System.out.println(rsS.getString(1));
|
||||||
|
System.out.println(rsS.getString(2));
|
||||||
|
System.out.println(rsS.getString(3));
|
||||||
|
System.out.println(rsS.getString(4));
|
||||||
|
System.out.println(rsS.getString(5));
|
||||||
|
System.out.println(rsS.getString(6));
|
||||||
|
System.out.println(rsS.getString(7)+"\n");
|
||||||
|
}
|
||||||
|
rsS.close();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.err.println("Konnte nicht ausgeführt werden");
|
System.err.println("Konnte nicht ausgeführt werden");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
mainWindowController.ta1.setText("Hallo");
|
||||||
|
}
|
||||||
|
|
||||||
|
//gibt die Favorisierung eines bestimmten Films
|
||||||
}
|
public void getFavStatus(String name){
|
||||||
// Kontroll Methode, ob ein Film wirklich in der Datenbank ist
|
try{
|
||||||
public String getTitel(String name){
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT titel, pfad FROM filme WHERE titel = '"+name+"';" );
|
ResultSet rs = stmt.executeQuery("SELECT titel, rating FROM film_local WHERE titel = '"+name+"';" ); //SQL Befehl
|
||||||
return rs.getString("titel");
|
System.out.println("local:"+rs.getInt("rating"));
|
||||||
} catch (SQLException e) {
|
}catch(SQLException e){
|
||||||
System.err.println("Konnte nicht ausgeführt werden");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return "Error 404";
|
|
||||||
}
|
|
||||||
// gibt den Pfad eines bestimmten Films
|
|
||||||
public String getPfad(String name){
|
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmtS = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT titel, pfad FROM filme WHERE titel = '"+name+"';" ); //SQL Befehl
|
ResultSet rsS = stmtS.executeQuery("SELECT titel, rating FROM film_streaming WHERE titel = '"+name+"';" );
|
||||||
return rs.getString("pfad");
|
System.out.println("streaming:"+rsS.getInt("rating"));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e1) {
|
||||||
System.err.println("Konnte nicht ausgeführt werden");
|
System.out.println("Ups! an error occured!");
|
||||||
e.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
|
||||||
return "Error 404";
|
|
||||||
}
|
|
||||||
// gibt die Favorisierung eines bestimmten Films
|
|
||||||
public boolean getFavStatus(String name){
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT titel, bewertung FROM filme WHERE titel = '"+name+"';" ); //SQL Befehl
|
|
||||||
System.out.println(rs.getInt("bewertung"));
|
|
||||||
if((rs.getInt("bewertung")) == 1){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
System.err.println("Konnte nicht ausgeführt werden");
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// setzt die Defavorisierung eines bestimmten Films
|
}
|
||||||
|
//setzt die Defavorisierung eines bestimmten Films
|
||||||
public void defavorisieren(String name){
|
public void defavorisieren(String name){
|
||||||
System.out.println("setze Bewertung");
|
System.out.println("defavorisieren ...");
|
||||||
try {
|
try{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
String sql = ("UPDATE filme SET bewertung=0 WHERE titel='"+name+"';"); //SQL Befehl
|
stmt.executeUpdate("UPDATE film_local SET rating=0 WHERE titel='"+name+"';");
|
||||||
stmt.executeUpdate(sql);
|
connection.commit(); //TODO hier kommt es zu fehlern mit dem autocommit
|
||||||
connection.setAutoCommit(false);
|
}catch(SQLException e){
|
||||||
connection.setAutoCommit(true);
|
try {
|
||||||
} catch (SQLException e) {
|
Statement stmtS = connection.createStatement();
|
||||||
System.err.println("Konnte nicht ausgeführt werden");
|
stmtS.executeUpdate("UPDATE film_streaming SET rating=0 WHERE titel='"+name+"';");
|
||||||
e.printStackTrace();
|
connection.commit();
|
||||||
|
} catch (SQLException e1) {
|
||||||
|
System.out.println("Ups! an error occured!");
|
||||||
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// setzt die Favorisierung eines bestimmten Films
|
}
|
||||||
|
//setzt die Favorisierung eines bestimmten Films
|
||||||
public void favorisieren(String name){
|
public void favorisieren(String name){
|
||||||
System.out.println("setze Bewertung");
|
System.out.println("favorisieren ...");
|
||||||
try {
|
try{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
String sql = ("UPDATE filme SET bewertung=1 WHERE titel='"+name+"';"); //SQL Befehl
|
stmt.executeUpdate("UPDATE film_local SET rating=1 WHERE titel='"+name+"';");
|
||||||
stmt.executeUpdate(sql);
|
connection.commit(); //TODO hier kommt es zu fehlern mit dem autocommit
|
||||||
connection.setAutoCommit(false);
|
}catch(SQLException e){
|
||||||
connection.setAutoCommit(true);
|
try {
|
||||||
} catch (SQLException e) {
|
Statement stmtS = connection.createStatement();
|
||||||
System.err.println("Konnte nicht ausgeführt werden");
|
stmtS.executeUpdate("UPDATE film_streaming SET rating=1 WHERE titel='"+name+"';");
|
||||||
e.printStackTrace();
|
connection.commit();
|
||||||
|
} catch (SQLException e1) {
|
||||||
|
System.out.println("Ups! an error occured!");
|
||||||
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//entfernt die Endung
|
//entfernt die Endung
|
||||||
private static String ohneEndung (String str) {
|
private String ohneEndung (String str) {
|
||||||
|
|
||||||
if (str == null) return null;
|
if (str == null) return null;
|
||||||
int pos = str.lastIndexOf(".");
|
int pos = str.lastIndexOf(".");
|
||||||
|
@ -206,11 +240,256 @@ class DBController {
|
||||||
return str.substring(0, pos);
|
return str.substring(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPath(String path) {
|
|
||||||
this.path = path.replace("\\", "\\\\");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private static final DBController dbcontroller = new DBController();
|
||||||
|
// private static Connection connection;
|
||||||
|
// private static final String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; // der Pfad der Datenbank-Datei
|
||||||
|
// private String path;
|
||||||
|
// File f;
|
||||||
|
// File file[]; //ArrayList für die Dateien
|
||||||
|
//
|
||||||
|
// public DBController(MainWindowController m){
|
||||||
|
// mainWindowController=m;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private MainWindowController mainWindowController;
|
||||||
|
//
|
||||||
|
// static {
|
||||||
|
// try {
|
||||||
|
// Class.forName("org.sqlite.JDBC"); //Datenbanktreiber
|
||||||
|
// } catch (ClassNotFoundException e) {
|
||||||
|
// System.err.println("Fehler beim Laden des JDBC-Treibers");
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static void main(String input) {
|
||||||
|
// DBController datenbank = DBController.getInstance(); //neues Datenbank-Objekt wird erstellt
|
||||||
|
// datenbank.setPath(input); // Pfad zuweisen
|
||||||
|
// datenbank.f = new File(datenbank.getPath()); // für Datenbank-Datei einlesen
|
||||||
|
// datenbank.file = datenbank.f.listFiles(); // für Datenbank-Datei einlesen
|
||||||
|
// datenbank.verbindeDatenbank();
|
||||||
|
// datenbank.fuelleDatenbank();
|
||||||
|
// //datenbank.defavorisieren("Frozen");
|
||||||
|
// //datenbank.favorisieren("Frozen");
|
||||||
|
// //datenbank.ausgebenTitel();
|
||||||
|
// //System.out.println("Pfad: " + datenbank.getPfad("Frozen"));
|
||||||
|
// //System.out.println("Bewertung: " + datenbank.getFavStatus("Frozen"));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// DBController(){
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private static DBController getInstance(){
|
||||||
|
// return dbcontroller;
|
||||||
|
// }
|
||||||
|
//// Die Datenbak wird mit Hilfe des JDBC-Treibers eingebunden
|
||||||
|
// public void verbindeDatenbank() {
|
||||||
|
// try {
|
||||||
|
// if (connection != null)
|
||||||
|
// return;
|
||||||
|
// System.out.println("Erstelle Verbindung zur Datenbank...");
|
||||||
|
// connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
|
||||||
|
// if (!connection.isClosed())
|
||||||
|
// System.out.println("...Verbindung hergestellt");
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
|
// public void run() {
|
||||||
|
// try {
|
||||||
|
// if (!connection.isClosed() && connection != null) {
|
||||||
|
// connection.close();
|
||||||
|
// if (connection.isClosed())
|
||||||
|
// System.out.println("Verbindung getrennt");
|
||||||
|
// }
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
//// Die Dateien werden in die Datenbank geschrieben
|
||||||
|
// public void fuelleDatenbank() {
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// System.out.println("Erstelle Einträge local");
|
||||||
|
// Statement stmt = connection.createStatement();
|
||||||
|
// stmt.executeUpdate("DROP TABLE IF EXISTS film_local;");
|
||||||
|
// stmt.executeUpdate("CREATE TABLE film_local (rating, titel, streamUrl);"); // Tabelle "filme" und die Spalten "titel", "pfad", "bewertung" erstellen
|
||||||
|
//
|
||||||
|
// PreparedStatement ps = connection.prepareStatement("INSERT INTO film_local VALUES (?, ?, ?);"); // SQL Befehl
|
||||||
|
// PreparedStatement psS = connection.prepareStatement("INSERT INTO film_streaming VALUES (?, ?, ?, ?, ?, ?, ?);"); // SQL Befehl
|
||||||
|
//
|
||||||
|
// System.out.println("Size: "+file.length);
|
||||||
|
//
|
||||||
|
// for(int i=0;i!=file.length;i++) // Geht alle Dateien im Verzeichniss durch
|
||||||
|
// {
|
||||||
|
// //System.out.println(file[i].getName());
|
||||||
|
// ps.setInt(1, 0); // definiert Bewertung als Integer in der dritten Spalte
|
||||||
|
// ps.setString(2, ohneEndung(file[i].getName())); // definiert Name als String in der ersten Spalte
|
||||||
|
// ps.setString(3,file[i].getName()); // definiert Pfad als String in der zweiten Spalte
|
||||||
|
// ps.addBatch(); // fügt den Eintrag hinzu
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// System.out.println("Erstelle Einträge streaming");
|
||||||
|
// Statement stmtS = connection.createStatement();
|
||||||
|
// stmtS.executeUpdate("DROP TABLE IF EXISTS film_streaming;");
|
||||||
|
// stmtS.executeUpdate("CREATE TABLE film_streaming (year, season, episode, rating, resolution, titel, streamUrl);"); // Tabelle "filme" und die Spalten "titel", "pfad", "bewertung" erstellen
|
||||||
|
//
|
||||||
|
// System.out.println(mainWindowController.getStreamingPath());
|
||||||
|
// if(mainWindowController.getStreamingPath().equals("")||mainWindowController.getStreamingPath().equals(null)){
|
||||||
|
// System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist
|
||||||
|
// }else{
|
||||||
|
// for(int i=0; i< mainWindowController.streamingData.size(); i++){
|
||||||
|
// String fileName = mainWindowController.getStreamingPath()+"/"+mainWindowController.streamingData.get(i).getStreamUrl();
|
||||||
|
// try {
|
||||||
|
// JsonObject object = Json.parse(new FileReader(fileName)).asObject();
|
||||||
|
// JsonArray items = object.get("entries").asArray();
|
||||||
|
// for (JsonValue item : items) {
|
||||||
|
// psS.setInt(1, item.asObject().getInt("year", 0));
|
||||||
|
// psS.setInt(2, item.asObject().getInt("season", 0));
|
||||||
|
// psS.setInt(3, item.asObject().getInt("episode", 0));
|
||||||
|
// psS.setInt(4, 0);
|
||||||
|
// psS.setString(5, item.asObject().getString("resolution", ""));
|
||||||
|
// psS.setString(6, item.asObject().getString("titel",""));
|
||||||
|
// psS.setString(7, item.asObject().getString("streamUrl", ""));
|
||||||
|
// psS.addBatch(); // fügt den Eintrag hinzu
|
||||||
|
// }
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// //Auto-generated catch block
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// connection.setAutoCommit(false);
|
||||||
|
// ps.executeBatch(); // scheibt alle Einträge in die Datenbank
|
||||||
|
// psS.executeBatch();
|
||||||
|
// connection.setAutoCommit(true);
|
||||||
|
// //connection.close();
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// System.err.println("Konnte nicht ausgeführt werden");
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void ausgeben(){
|
||||||
|
// System.out.println("Einträge ausgeben ... \n");
|
||||||
|
// try {
|
||||||
|
// Statement stmt = connection.createStatement();
|
||||||
|
// mainWindowController = new MainWindowController();
|
||||||
|
// ResultSet rs = stmt.executeQuery("SELECT * FROM film_local;");
|
||||||
|
// while (rs.next()) {
|
||||||
|
// System.out.println(rs.getString(1));
|
||||||
|
// System.out.println(rs.getString(2));
|
||||||
|
// System.out.println(rs.getString(3)+"\n");
|
||||||
|
// }
|
||||||
|
// rs.close();
|
||||||
|
//
|
||||||
|
// ResultSet rsS = stmt.executeQuery("SELECT * FROM film_streaming;");
|
||||||
|
// while (rsS.next()) {
|
||||||
|
// System.out.println(rsS.getString(1));
|
||||||
|
// System.out.println(rsS.getString(2));
|
||||||
|
// System.out.println(rsS.getString(3)+"\n");
|
||||||
|
// }
|
||||||
|
// rsS.close();
|
||||||
|
//// mainWindowController.initTabel();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// System.err.println("Konnte nicht ausgeführt werden");
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//// Kontroll Methode, ob ein Film wirklich in der Datenbank ist
|
||||||
|
// public String getTitel(String name){
|
||||||
|
// try {
|
||||||
|
// Statement stmt = connection.createStatement();
|
||||||
|
// ResultSet rs = stmt.executeQuery("SELECT titel, pfad FROM filme WHERE titel = '"+name+"';" );
|
||||||
|
// return rs.getString("titel");
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// System.err.println("Konnte nicht ausgeführt werden");
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return "Error 404";
|
||||||
|
// }
|
||||||
|
//// gibt den Pfad eines bestimmten Films
|
||||||
|
// public String getPfad(String name){
|
||||||
|
// try {
|
||||||
|
// Statement stmt = connection.createStatement();
|
||||||
|
// ResultSet rs = stmt.executeQuery("SELECT titel, pfad FROM filme WHERE titel = '"+name+"';" ); //SQL Befehl
|
||||||
|
// return rs.getString("pfad");
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// System.err.println("Konnte nicht ausgeführt werden");
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return "Error 404";
|
||||||
|
// }
|
||||||
|
//// gibt die Favorisierung eines bestimmten Films
|
||||||
|
// public boolean getFavStatus(String name){
|
||||||
|
// try {
|
||||||
|
// Statement stmt = connection.createStatement();
|
||||||
|
// ResultSet rs = stmt.executeQuery("SELECT titel, bewertung FROM filme WHERE titel = '"+name+"';" ); //SQL Befehl
|
||||||
|
// System.out.println(rs.getInt("bewertung"));
|
||||||
|
// if((rs.getInt("bewertung")) == 1){
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// System.err.println("Konnte nicht ausgeführt werden");
|
||||||
|
// e.printStackTrace();
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//// setzt die Defavorisierung eines bestimmten Films
|
||||||
|
// public void defavorisieren(String name){
|
||||||
|
// System.out.println("setze Bewertung");
|
||||||
|
// try {
|
||||||
|
// Statement stmt = connection.createStatement();
|
||||||
|
// String sql = ("UPDATE filme SET bewertung=0 WHERE titel='"+name+"';"); //SQL Befehl
|
||||||
|
// stmt.executeUpdate(sql);
|
||||||
|
// connection.setAutoCommit(false);
|
||||||
|
// connection.setAutoCommit(true);
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// System.err.println("Konnte nicht ausgeführt werden");
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//// setzt die Favorisierung eines bestimmten Films
|
||||||
|
// public void favorisieren(String name){
|
||||||
|
// System.out.println("setze Bewertung");
|
||||||
|
// try {
|
||||||
|
// Statement stmt = connection.createStatement();
|
||||||
|
// String sql = ("UPDATE filme SET bewertung=1 WHERE titel='"+name+"';"); //SQL Befehl
|
||||||
|
// stmt.executeUpdate(sql);
|
||||||
|
// connection.setAutoCommit(false);
|
||||||
|
// connection.setAutoCommit(true);
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// System.err.println("Konnte nicht ausgeführt werden");
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
////entfernt die Endung
|
||||||
|
// private static String ohneEndung (String str) {
|
||||||
|
//
|
||||||
|
// if (str == null) return null;
|
||||||
|
// int pos = str.lastIndexOf(".");
|
||||||
|
// if (pos == -1) return str;
|
||||||
|
// return str.substring(0, pos);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public String getPath() {
|
||||||
|
// return path;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setPath(String path) {
|
||||||
|
// this.path = path.replace("\\", "\\\\");
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
|
@ -239,7 +239,7 @@ public class MainWindowController {
|
||||||
private ObservableList<streamUiData> filterData = FXCollections.observableArrayList();
|
private ObservableList<streamUiData> filterData = FXCollections.observableArrayList();
|
||||||
private ObservableList<streamUiData> streamData = FXCollections.observableArrayList();
|
private ObservableList<streamUiData> streamData = FXCollections.observableArrayList();
|
||||||
private ObservableList<String> locals = FXCollections.observableArrayList("english", "deutsch");
|
private ObservableList<String> locals = FXCollections.observableArrayList("english", "deutsch");
|
||||||
private ObservableList<streamUiData> streamingData = FXCollections.observableArrayList();
|
ObservableList<streamUiData> streamingData = FXCollections.observableArrayList();
|
||||||
private ImageView menu_icon_black = new ImageView(new Image("recources/icons/menu_icon_black.png"));
|
private ImageView menu_icon_black = new ImageView(new Image("recources/icons/menu_icon_black.png"));
|
||||||
private ImageView menu_icon_white = new ImageView(new Image("recources/icons/menu_icon_white.png"));
|
private ImageView menu_icon_white = new ImageView(new Image("recources/icons/menu_icon_white.png"));
|
||||||
private ImageView skip_previous_white = new ImageView(new Image("recources/icons/ic_skip_previous_white_18dp_1x.png"));
|
private ImageView skip_previous_white = new ImageView(new Image("recources/icons/ic_skip_previous_white_18dp_1x.png"));
|
||||||
|
@ -253,6 +253,7 @@ public class MainWindowController {
|
||||||
|
|
||||||
private updater Updater;
|
private updater Updater;
|
||||||
private apiQuery ApiQuery;
|
private apiQuery ApiQuery;
|
||||||
|
private DBController dbController;
|
||||||
|
|
||||||
//wenn menubtn clicked
|
//wenn menubtn clicked
|
||||||
/**
|
/**
|
||||||
|
@ -424,6 +425,7 @@ public class MainWindowController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void debugBtnclicked(){
|
private void debugBtnclicked(){
|
||||||
|
dbController.main();
|
||||||
//for testing
|
//for testing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,11 +510,14 @@ public class MainWindowController {
|
||||||
|
|
||||||
Updater = new updater(this);
|
Updater = new updater(this);
|
||||||
ApiQuery = new apiQuery(this);
|
ApiQuery = new apiQuery(this);
|
||||||
|
dbController = new DBController(this);
|
||||||
|
|
||||||
System.out.println("Mode: "+mode);
|
System.out.println("Mode: "+mode);
|
||||||
|
|
||||||
debugBtn.setDisable(true); //debugging btn for tests
|
// dbController.ausgeben();
|
||||||
debugBtn.setVisible(false);
|
|
||||||
|
debugBtn.setDisable(false); //debugging btn for tests
|
||||||
|
debugBtn.setVisible(true);
|
||||||
|
|
||||||
tfPath.setText(getPath());
|
tfPath.setText(getPath());
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue