Compare commits

..

1 Commits

Author SHA1 Message Date
dd1357ec1d DB Table erstellt + Get All Tours 2021-04-14 00:37:00 +02:00
11 changed files with 160 additions and 187 deletions

12
.idea/dataSources.xml generated Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="postgres@postgres.dergeorg.at" uuid="304c5f90-6427-4696-beb2-a9a4e6b29a05">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://postgres.dergeorg.at:5432/postgres</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="org.postgresql:postgresql:42.2.19" type="repository">
<properties maven-id="org.postgresql:postgresql:42.2.19" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/postgresql/postgresql/42.2.19/postgresql-42.2.19.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

7
.idea/sqldialects.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/src/tourplaner/data/PostgresHelper.java" dialect="GenericSQL" />
<file url="PROJECT" dialect="PostgreSQL" />
</component>
</project>

20
TourplanerTabellen.sql Normal file
View File

@ -0,0 +1,20 @@
// Tour Tabelle
create table tour
(
tourname varchar not null,
dauer decimal,
mapjson varchar,
start varchar,
ziel varchar,
strecke decimal
);
create unique index tour_tourname_uindex
on tour (tourname);
alter table tour add constraint tour_pk primary key (tourname);
#// Log Table
create table log(tourname varchar constraint log_tour_tourname_fk references tour,id varchar,bemerkung varchar,datum date,strecke decimal,avg decimal,hightmeter decimal,pause decimal,gegangen decimal,dauer decimal);

Binary file not shown.

View File

@ -1,179 +0,0 @@
2021-04-15 00:36:26 ERROR FileNotFoundException:33 - D:\FH_OFFLINE\tourplaner\conf.ini (Das System kann die angegebene Datei nicht finden)
2021-04-15 00:36:26 ERROR NullPointerException:33 -
2021-04-15 00:37:18 ERROR FileNotFoundException:33 - D:\FH_OFFLINE\tourplaner\conf.ini (Das System kann die angegebene Datei nicht finden)
2021-04-15 00:37:18 ERROR NullPointerException:33 -
2021-04-15 00:38:24 ERROR PSQLException:33 - Der Verbindungsversuch schlug fehl.
2021-04-15 00:38:31 ERROR SQLException:33 - No suitable driver found for jdbc:postgresql://http://postgres.dergeorg.at:5432/tourplaner
2021-04-15 00:38:38 INFO PostgresHelper:15 - Tour Table created
2021-04-15 00:38:38 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 00:38:38 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 00:38:38 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 00:38:38 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 00:38:38 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 00:38:38 INFO PostgresHelper:15 - Log Table created
2021-04-15 00:38:38 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 00:40:43 INFO PostgresHelper:15 - Tour Table created
2021-04-15 00:40:43 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 00:40:43 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 00:40:43 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 00:40:43 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 00:40:43 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 00:40:43 INFO PostgresHelper:15 - Log Table created
2021-04-15 00:40:43 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 00:44:11 INFO PostgresHelper:15 - Tour Table created
2021-04-15 00:44:11 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 00:44:11 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 00:44:11 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 00:44:11 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 00:44:11 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 00:44:11 INFO PostgresHelper:15 - Log Table created
2021-04-15 00:44:11 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 16:30:08 INFO PostgresHelper:15 - Tour Table created
2021-04-15 16:30:08 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 16:30:08 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 16:30:08 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 16:30:08 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 16:30:08 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 16:30:08 INFO PostgresHelper:15 - Log Table created
2021-04-15 16:30:08 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 16:33:57 INFO PostgresHelper:15 - Tour Table created
2021-04-15 16:33:57 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 16:33:57 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 16:33:57 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 16:33:57 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 16:33:57 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 16:33:57 INFO PostgresHelper:15 - Log Table created
2021-04-15 16:33:57 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 16:38:55 INFO PostgresHelper:15 - Tour Table created
2021-04-15 16:38:55 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 16:38:55 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 16:38:55 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 16:38:55 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 16:38:55 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 16:38:55 INFO PostgresHelper:15 - Log Table created
2021-04-15 16:38:55 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 16:50:23 INFO PostgresHelper:15 - Tour Table created
2021-04-15 16:50:23 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 16:50:23 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 16:50:23 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 16:50:23 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 16:50:23 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 16:50:23 INFO PostgresHelper:15 - Log Table created
2021-04-15 16:50:23 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 16:51:01 INFO PostgresHelper:15 - Tour Table created
2021-04-15 16:51:01 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 16:51:01 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 16:51:01 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 16:51:01 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 16:51:01 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 16:51:01 INFO PostgresHelper:15 - Log Table created
2021-04-15 16:51:01 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:08:17 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:08:17 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:08:17 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:08:17 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:08:17 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:08:17 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:08:17 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:08:17 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:08:21 ERROR FileNotFoundException:33 - .\reports\Tour 1.pdf (Das System kann den angegebenen Pfad nicht finden)
2021-04-15 17:21:48 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:21:48 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:21:48 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:21:48 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:21:48 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:21:48 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:21:48 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:21:48 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:21:57 ERROR FileNotFoundException:33 - .\reports\Tour 1.pdf (Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird)
2021-04-15 17:31:40 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:31:40 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:31:40 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:31:40 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:31:40 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:31:40 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:31:40 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:31:40 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:32:30 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:32:30 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:32:30 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:32:30 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:32:30 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:32:30 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:32:30 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:32:30 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:37:57 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:37:57 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:37:57 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:37:58 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:37:58 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:37:58 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:37:58 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:37:58 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:38:41 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:38:41 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:38:41 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:38:41 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:38:41 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:38:41 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:38:41 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:38:41 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:40:30 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:40:30 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:40:30 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:40:30 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:40:30 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:40:30 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:40:30 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:40:30 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:48:48 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:48:48 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:48:48 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:48:48 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:48:48 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:48:48 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:48:48 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:48:48 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 17:49:14 INFO PostgresHelper:15 - Tour Table created
2021-04-15 17:49:14 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 17:49:14 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 17:49:14 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 17:49:14 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 17:49:14 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 17:49:14 INFO PostgresHelper:15 - Log Table created
2021-04-15 17:49:14 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 18:00:58 INFO PostgresHelper:15 - Tour Table created
2021-04-15 18:00:58 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 18:00:58 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 18:00:58 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 18:00:58 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 18:00:59 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 18:00:59 INFO PostgresHelper:15 - Log Table created
2021-04-15 18:00:59 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 18:09:56 ERROR FileNotFoundException:33 - .\reports\Tour 1.pdf (Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird)
2021-04-15 18:10:01 INFO PostgresHelper:15 - Tour Table created
2021-04-15 18:10:01 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 18:10:01 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 18:10:01 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 18:10:01 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 18:10:01 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 18:10:01 INFO PostgresHelper:15 - Log Table created
2021-04-15 18:10:01 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 18:10:06 ERROR FileNotFoundException:33 - .\reports\Tour 1.pdf (Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird)
2021-04-15 18:12:47 INFO PostgresHelper:15 - Tour Table created
2021-04-15 18:12:47 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 18:12:47 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 18:12:47 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 18:12:47 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 18:12:47 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 18:12:47 INFO PostgresHelper:15 - Log Table created
2021-04-15 18:12:47 ERROR PSQLException:33 - ERROR: relation "log" already exists
2021-04-15 18:13:38 ERROR FileNotFoundException:33 - .\reports\Tour 1.pdf (Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird)
2021-04-15 19:20:34 INFO PostgresHelper:15 - Tour Table created
2021-04-15 19:20:34 ERROR PSQLException:33 - ERROR: relation "tour" already exists
2021-04-15 19:20:34 INFO PostgresHelper:15 - Tour Table unique created
2021-04-15 19:20:34 ERROR PSQLException:33 - ERROR: relation "tour_tourname_uindex" already exists
2021-04-15 19:20:34 INFO PostgresHelper:15 - Tour Table primary created
2021-04-15 19:20:34 ERROR PSQLException:33 - ERROR: multiple primary keys for table "tour" are not allowed
2021-04-15 19:20:34 INFO PostgresHelper:15 - Log Table created
2021-04-15 19:20:34 ERROR PSQLException:33 - ERROR: relation "log" already exists

View File

@ -1,2 +1,34 @@
package tourplaner.business;public class Reporter {
package tourplaner.business;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import java.io.IOException;
public class Reporter {
public static void createTourReport(String tourname) throws IOException, COSVisitorException {
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDFont font = PDType1Font.HELVETICA;
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.moveTextPositionByAmount(100,700);
contentStream.drawString(tourname);
// contentStream.drawString();
contentStream.endText();
contentStream.close();
document.save(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "report", "path") + "test.pdf");
document.close();
}
}

View File

@ -2,6 +2,10 @@ package tourplaner.business;
import org.apache.log4j.Logger;
import tourplaner.data.DbConnect;
import tourplaner.data.PostgresHelper;
import tourplaner.object.Tour;
import java.util.ArrayList;
/**
* Haupt Logik des Tourplaners
@ -10,12 +14,18 @@ public class TourPlaner{
private Logger logger;
public TourPlaner(){
LogHelper.info(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "message"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "app"));
// LogHelper.info(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "message"),
// ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "app"));
new DbConnect().init();
}
public ArrayList<Tour> getAllTours(){
DbConnect dbConnect = new DbConnect();
ArrayList<Tour> touren = dbConnect.getAllTouren();
return touren;
}
public String getMapJson(String start, String ziel){
return start + " " + ziel;
}

View File

@ -1,6 +1,9 @@
package tourplaner.data;
import tourplaner.object.Tour;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
@ -26,10 +29,49 @@ public class DbConnect {
* @return True bei erfolg, sonst error
*/
public boolean init() {
// TODO: 26.02.2021 Alle sql im init sind noch falsch
ArrayList<Boolean> errors = new ArrayList<>();
errors.add(PostgresHelper.executeUpdateMessage("CREATE TABLE IF NOT EXISTS USERS (username TEXT PRIMARY KEY NOT NULL, nachname TEXT NOT NULL, email TEXT NOT NULL, password TEXT NOT NULL, bio TEXT, image TEXT, coins integer default 20 not null)", "User Table created"));
errors.add(PostgresHelper.executeUpdateMessage("create table tour ( tourname varchar not null, dauer decimal, mapjson varchar, start varchar, ziel varchar, strecke decimal);", "Tour Table created"));
errors.add(PostgresHelper.executeUpdateMessage("create unique index tour_tourname_uindex on tour (tourname);", "Tour Table unique created"));
errors.add(PostgresHelper.executeUpdateMessage("alter table tour add constraint tour_pk primary key (tourname);", "Tour Table primary created"));
errors.add(PostgresHelper.executeUpdateMessage("create table log(tourname varchar constraint log_tour_tourname_fk references tour,id varchar,bemerkung varchar,datum date,strecke decimal,avg decimal,hightmeter decimal,pause decimal,gegangen decimal,dauer decimal);", "Log Table created"));
return !errors.contains(false);
}
/**
* Holt alle Touren aus der Datenbank
* @return Null bei fehler, sonst eine List aus den IDs
*/
public ArrayList<Tour> getAllTouren(){
this.c = PostgresHelper.con();
String tourname, mapjson, start, ziel;
double dauer, strecke;
ArrayList<Tour> touren = new ArrayList<>();
try {
stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("select tourname, dauer, mapjson, start, ziel, strecke from tour;");
while (rs.next()) {
tourname = rs.getString("tourname");
mapjson = rs.getString("mapjson");
start = rs.getString("start");
ziel = rs.getString("ziel");
dauer = rs.getDouble("dauer");
strecke = rs.getDouble("strecke");
if (!tourname.isEmpty()) {
touren.add(new Tour(tourname, dauer + "", mapjson, strecke, start, ziel));
}else {
return null;
}
}
rs.close();
stmt.close();
this.c.close();
return touren;
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
return null;
}
}
}

View File

@ -3,16 +3,20 @@ package tourplaner.data;
import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper;
import tourplaner.object.Tour;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
/**
* Hilfsfunktionen für die verwendung der Postgres DB
*/
public class PostgresHelper {
private Connection c;
private Statement stmt;
/**
* Verbindet mit der Datenbank
* @return Das Connection Objekt
@ -21,6 +25,8 @@ public class PostgresHelper {
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
System.out.println("jdbc:postgresql://" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "url") + ":" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "port") + "/" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "dbname")+
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "user")+ ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "pw"));
c = DriverManager
.getConnection("jdbc:postgresql://" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "url") + ":" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "port") + "/" + ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "dbname"),
ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "user"), ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "db", "pw"));

View File

@ -4,6 +4,8 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.apache.pdfbox.exceptions.COSVisitorException;
import tourplaner.business.Reporter;
import tourplaner.business.TourPlaner;
import tourplaner.data.DbConnect;
import tourplaner.ui.AlertHelper;
import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper;
@ -15,14 +17,15 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
public class ViewModel {
//Tour
private final ObservableList<Tour> tourData = FXCollections.observableArrayList(new Tour("Test 1", "120", "json dings", 22.3, "Wien", "Graz"),new Tour("Test 2", "210", "json dings", 42.3, "Da", "Dort"));
private final ObservableList<String> tourNamen = FXCollections.observableArrayList("Test 1", "Test 2");
private final ObservableList<Tour> tourData = FXCollections.observableArrayList();
private final ObservableList<String> tourNamen = FXCollections.observableArrayList();
private Tour selectedTour;
private String neueTourName, neueTourStart, neueTourZiel, neueBemerkung;
//Log
@ -452,6 +455,12 @@ public class ViewModel {
}
public ObservableList<String> getTourNamen() {
ArrayList<String> namen = new ArrayList<>();
getTourData().forEach(s -> {
namen.add(s.getName());
});
tourNamen.removeAll();
tourNamen.addAll(namen);
return tourNamen;
}
@ -472,6 +481,9 @@ public class ViewModel {
}
public ObservableList<Tour> getTourData() {
tourData.removeAll();
// ObservableList<Tour> data = ;
tourData.addAll(new TourPlaner().getAllTours());
return tourData;
}