worked on dbcontroller part 2
fixed a few bugs but still a lot to do
This commit is contained in:
		
										
											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,7 +1,7 @@ | ||||
| /** | ||||
|  * DBController for Project HomeFlix | ||||
|  *  | ||||
|  * TODO fav and defav | ||||
|  * connection is in manual commit! | ||||
|  */ | ||||
|  | ||||
| package application; | ||||
| @ -24,56 +24,43 @@ import java.io.IOException; | ||||
|  | ||||
| public class DBController { | ||||
|  | ||||
| 	public DBController(MainWindowController m){ | ||||
| 		mainWindowController=m; | ||||
| 	public DBController(MainWindowController m) { | ||||
| 		mainWindowController = m; | ||||
| 	} | ||||
|  | ||||
| 	private MainWindowController mainWindowController; | ||||
| 	private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; // der Pfad der Datenbank-Datei | ||||
| 	Connection connection = null; | ||||
|  | ||||
| 	public void main()  | ||||
|     { | ||||
| 		 | ||||
| 		System.out.println("Hallo"); | ||||
| 		 | ||||
|       try | ||||
|       { | ||||
| 	public void main() { | ||||
| 		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 | ||||
|  | ||||
|  | ||||
| 			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 | ||||
|  | ||||
| 			connection.setAutoCommit(false);	//Autocommit to false -> manual commit is active! | ||||
| 			fuelleDatenbank(); | ||||
| //			ausgeben(); | ||||
|        getFavStatus("House of Cards"); | ||||
|        favorisieren("House of Cards"); | ||||
|        getFavStatus("House of Cards"); | ||||
|        defavorisieren("House of Cards"); | ||||
|        getFavStatus("House of Cards"); | ||||
| //			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 | ||||
| 		} 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(); | ||||
|         } | ||||
|         catch(SQLException e) | ||||
|         { | ||||
|           // connection close failed. | ||||
|           System.err.println(e); | ||||
|         } | ||||
|       } | ||||
| //		finally { | ||||
| //			try { | ||||
| //				if (connection != null) | ||||
| //					connection.close(); | ||||
| //			} catch (SQLException e) { | ||||
| //				// connection close failed. | ||||
| //				System.err.println(e); | ||||
| //			} | ||||
| //		} | ||||
| 	} | ||||
| 	 | ||||
| 	public void fuelleDatenbank() {  | ||||
| @ -92,7 +79,6 @@ public class DBController { | ||||
| 			PreparedStatement psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?)"); // SQL Befehl | ||||
|  | ||||
| 			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 | ||||
| 			{ | ||||
| @ -104,9 +90,7 @@ public class DBController { | ||||
| 			} | ||||
| 			 | ||||
| 			 | ||||
| 			System.out.println("Erstelle Eintr<74>ge streaming"); | ||||
|  | ||||
| 			System.out.println(mainWindowController.getStreamingPath()); | ||||
| 			System.out.println("Erstelle Eintr<74>ge streaming \n"); | ||||
| 			if(mainWindowController.getStreamingPath().equals("")||mainWindowController.getStreamingPath().equals(null)){ | ||||
| 				System.out.println("Kein Pfad angegeben");	//falls der Pfad null oder "" ist | ||||
| 			}else{ | ||||
| @ -131,16 +115,16 @@ public class DBController { | ||||
| 				} | ||||
| 			} | ||||
| 			} | ||||
| 			connection.setAutoCommit(false);  | ||||
| //			connection.setAutoCommit(false);  | ||||
| 			ps.executeBatch();  // scheibt alle Eintr<74>ge in die Datenbank | ||||
| 			psS.executeBatch();			 | ||||
| 			connection.setAutoCommit(true); | ||||
| 			connection.commit(); | ||||
| 			ps.close(); | ||||
| 			psS.close(); | ||||
| 			//connection.close();  | ||||
| 		} catch (SQLException e) {  | ||||
| 		} catch (SQLException ea) {  | ||||
| 			System.err.println("Konnte nicht ausgef<65>hrt werden");  | ||||
| 			e.printStackTrace();  | ||||
| 			ea.printStackTrace();  | ||||
| 		}  | ||||
| 	} | ||||
| 	 | ||||
| @ -200,8 +184,11 @@ public class DBController { | ||||
| 		try{ | ||||
| 			Statement stmt = connection.createStatement();  | ||||
| 			stmt.executeUpdate("UPDATE film_local SET rating=0 WHERE titel='"+name+"';"); | ||||
| 			connection.commit();	//TODO hier kommt es zu fehlern mit dem autocommit | ||||
| 			connection.commit(); | ||||
| 		}catch(SQLException e){ | ||||
| 			System.out.println("Ups! an error occured!"); | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
| 		try { | ||||
| 			Statement stmtS = connection.createStatement();  | ||||
| 			stmtS.executeUpdate("UPDATE film_streaming SET rating=0 WHERE titel='"+name+"';"); | ||||
| @ -211,15 +198,17 @@ public class DBController { | ||||
| 			e1.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| 	} | ||||
| //setzt die Favorisierung eines bestimmten Films | ||||
| 	public void favorisieren(String name){ | ||||
| 		System.out.println("favorisieren ..."); | ||||
| 		try{ | ||||
| 			Statement stmt = connection.createStatement();  | ||||
| 			stmt.executeUpdate("UPDATE film_local SET rating=1 WHERE titel='"+name+"';"); | ||||
| 			connection.commit();	//TODO hier kommt es zu fehlern mit dem autocommit | ||||
| 			connection.commit(); | ||||
| 		}catch(SQLException e){ | ||||
| 			System.out.println("Ups! an error occured!"); | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
| 		try { | ||||
| 			Statement stmtS = connection.createStatement();  | ||||
| 			stmtS.executeUpdate("UPDATE film_streaming SET rating=1 WHERE titel='"+name+"';"); | ||||
| @ -229,7 +218,6 @@ public class DBController { | ||||
| 			e1.printStackTrace(); | ||||
| 		} | ||||
| 	} | ||||
| 	} | ||||
| 	 | ||||
| //entfernt die Endung | ||||
| 	private String ohneEndung (String str) { | ||||
|  | ||||
| @ -425,7 +425,12 @@ public class MainWindowController { | ||||
| 	 | ||||
| 	@FXML | ||||
| 	private void debugBtnclicked(){ | ||||
| 		dbController.main(); | ||||
| 		dbController.main();	//TODO das muss vor einen anderen Befehl warum auch immer | ||||
| 		dbController.getFavStatus("House of Cards"); | ||||
| 		dbController.favorisieren("House of Cards"); | ||||
| 		dbController.getFavStatus("House of Cards"); | ||||
| //		dbController.defavorisieren("House of Cards"); | ||||
| //		dbController.getFavStatus("House of Cards"); | ||||
| 		//for testing | ||||
| 	} | ||||
|  | ||||
| @ -514,7 +519,7 @@ public class MainWindowController { | ||||
| 		 | ||||
| 		System.out.println("Mode: "+mode); | ||||
| 		 | ||||
| //		dbController.ausgeben(); | ||||
| //		dbController.main(); | ||||
| 		 | ||||
| 		debugBtn.setDisable(false); 	//debugging btn for tests | ||||
| 		debugBtn.setVisible(true); | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								src/recources/icons/ic_favorite_black_18dp_1x.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/recources/icons/ic_favorite_black_18dp_1x.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 214 B | 
							
								
								
									
										
											BIN
										
									
								
								src/recources/icons/ic_favorite_border_black_18dp_1x.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/recources/icons/ic_favorite_border_black_18dp_1x.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 261 B | 
		Reference in New Issue
	
	Block a user