Commit 29159520 authored by Stefan Michel's avatar Stefan Michel

anfrage schicken funktioniert nun

parent c502b194
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/out/production/StefanMichelSimulator" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
......
......@@ -47,6 +47,7 @@ public class ChooseEntryDialogBox {
ComboBox<String> comboBox = new ComboBox<>(FXCollections.observableArrayList(exampleList));
comboBox.setPromptText(exampleList.get(0));
comboBox.setValue(exampleList.get(0)); // erstes element soll immer ausgewaehlt sein
grid.add(new Label("Tag:"), 0, 0);
grid.add(comboBox, 1, 0);
......
......@@ -90,6 +90,7 @@ public class TerrainController {
public void parseXML(String terrainName) {
try (FileOutputStream fileOutputStream = new FileOutputStream("terrains/" + terrainName + ".xml")) {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(fileOutputStream);
writer.writeStartDocument("UTF-8", "1.0");
......@@ -145,7 +146,6 @@ public class TerrainController {
}
writer.writeEndElement();
writer.writeEndElement();
} catch (XMLStreamException e) {
e.printStackTrace();
......
......@@ -155,17 +155,23 @@ public class DerbyDatabase {
public boolean updateExample(String code, String terrain, String... tags) {
Connection conn;
PreparedStatement preparedStatement;
ResultSet resultSet;
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(connectionURL);
conn = DriverManager.getConnection(connectionURL);
// check ob beispiel bereits in datenbank existiert
PreparedStatement preparedStatement = conn.prepareStatement(queryExampleId);
preparedStatement = conn.prepareStatement(queryExampleId);
preparedStatement.setString(1, code);
preparedStatement.setString(2, terrain);
ResultSet resultSet = preparedStatement.executeQuery();
resultSet = preparedStatement.executeQuery();
// wenn es bereits existiert wird false zurueckgeben und das speichern schlaegt fehl
if (resultSet.next()) {
conn.close();
preparedStatement.close();
resultSet.close();
return false;
}
......@@ -211,6 +217,10 @@ public class DerbyDatabase {
preparedStatement.execute();
}
conn.close();
preparedStatement.close();
resultSet.close();
return true;
} catch (Exception e) {
e.printStackTrace();
......@@ -233,8 +243,11 @@ public class DerbyDatabase {
String terrain = resultSet.getString(2);
entry = new AbstractMap.SimpleEntry<>(code, terrain);
conn.close();
preparedStatement.close();
resultSet.close();
} catch (Exception e) {
e.printStackTrace();
}
return entry;
}
......
package network;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.UUID;
public interface ITutor extends Remote {
UUID sendCodeTerrain(CodeTerrain codeTerrain);
UUID sendCodeTerrain(CodeTerrain codeTerrain) throws RemoteException;
CodeTerrain getAnswer(UUID id);
CodeTerrain getAnswer(UUID id) throws RemoteException;
}
package network;
import java.rmi.ConnectException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
......@@ -28,7 +29,7 @@ public class Student {
Registry registry = LocateRegistry.getRegistry(host, port);
tutor = (ITutor) registry.lookup("Tutor");
} catch (RemoteException e) {
e.printStackTrace();
System.out.println("keine Verbindung zum Tutor!");
} catch (NotBoundException e) {
e.printStackTrace();
}
......@@ -36,11 +37,20 @@ public class Student {
}
public void sendRequest(CodeTerrain codeTerrain) {
requestId = tutor.sendCodeTerrain(codeTerrain);
try {
requestId = tutor.sendCodeTerrain(codeTerrain);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public CodeTerrain getRequest() {
return tutor.getAnswer(requestId);
try {
return tutor.getAnswer(requestId);
} catch (RemoteException e) {
e.printStackTrace();
}
return null;
}
}
......@@ -18,14 +18,14 @@ public class Tutor extends UnicastRemoteObject implements ITutor {
// METHODS FROM INTERFACE
@Override
public UUID sendCodeTerrain(CodeTerrain codeTerrain) {
public UUID sendCodeTerrain(CodeTerrain codeTerrain) throws RemoteException {
requests.add(codeTerrain);
lastId = UUID.randomUUID();
return lastId;
}
@Override
public CodeTerrain getAnswer(UUID id) {
public CodeTerrain getAnswer(UUID id) throws RemoteException {
return answerMap.remove(id);
}
......
......@@ -203,8 +203,10 @@ public class MainViewCreationFX extends VBox implements Observer {
MenuItem anfrageLaden = new MenuItem("Anfrage _laden");
anfrageLaden.setOnAction(event -> {
CodeTerrain codeTerrain = networkManager.loadRequest();
textArea.setText(codeTerrain.getCode());
terrainController.loadTerrainFromString(codeTerrain.getTerrain());
if (codeTerrain != null) {
textArea.setText(codeTerrain.getCode());
terrainController.loadTerrainFromString(codeTerrain.getTerrain());
}
});
MenuItem anfrageBeantworten = new MenuItem("Anfrage _beantworten");
anfrageBeantworten.setOnAction(event -> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment