Skip to content
Snippets Groups Projects
Commit a401efa3 authored by TB's avatar TB :writing_hand_tone2:
Browse files

Merge branch 'JPA' into 'grademanager_v1.0'

Jpa

See merge request !2
parents 597a9d0b f6032468
No related branches found
No related tags found
1 merge request!2Jpa
Showing
with 1812 additions and 0 deletions
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig" ddlActionDbType="maria">
<option name="defaultUnitInitialized" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" project-jdk-name="18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="0d616560-06e0-45af-8dd9-ccab83963a0f" name="Changes" comment="Hibernate ORM for DB">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/Application.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/Application.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/classes/Course.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/classes/Course.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/classes/CoursesOfStudy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/classes/CoursesOfStudy.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/classes/Enrollment.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/classes/Enrollment.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/classes/Lecturer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/classes/Lecturer.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="JpbToolWindowState">
<option name="myId2FirstActivated">
<map>
<entry key="com.haulmont.jpb.jpaInspector" value="true" />
<entry key="com.haulmont.jpb.jpaPalette" value="true" />
<entry key="com.haulmont.jpb.jpaStructure" value="true" />
</map>
</option>
<option name="myId2Visible">
<map>
<entry key="com.haulmont.jpb.jpaInspector" value="false" />
<entry key="com.haulmont.jpb.jpaPalette" value="false" />
<entry key="com.haulmont.jpb.jpaStructure" value="false" />
</map>
</option>
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="CurrentFile" />
</component>
<component name="ProjectId" id="2AA7EXVwC9qbqrXYGnaxyK7xE03" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;project.structure.last.edited&quot;: &quot;Modules&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;DBNavigator.Project.ConnectionSettings&quot;
}
}</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\tayfu\IdeaProjects\jpa-hibernate\src\main" />
</key>
</component>
<component name="RunManager">
<configuration name="Application" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Application" />
<module name="jpa-hibernate" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Application" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="0d616560-06e0-45af-8dd9-ccab83963a0f" name="Changes" comment="" />
<created>1654440427551</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1654440427551</updated>
</task>
<task id="LOCAL-00001" summary="Hibernate ORM for DB">
<created>1655210036433</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1655210036433</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="Hibernate ORM for DB" />
<option name="LAST_COMMIT_MESSAGE" value="Hibernate ORM for DB" />
</component>
</project>
\ No newline at end of file
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>jpa-hibernate</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
<version>5.6.8.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
import classes.*;
import enumeration.*;
import java.time.Duration;
/**
* Defines the entry point of the Java application.
*/
public class Application
{
private static JpaService jpaService = JpaService.getInstance();
public static void main(String[] args)
{
try
{
jpaService.runInTransaction(entityManager -> {
// name, semester, courseType, sws, ects, examType, isCredited
//entityManager.persist(new Course("Numerische Methoden", Semester.SIXTH.getSemester(), CourseType.REQUIRED.getCourseType(), 4, 5, ExamType.WRITTEN.getExamType(), null));
//entityManager.persist(new Course("Echtzeitsysteme", Semester.SIXTH.getSemester(), CourseType.REQUIRED.getCourseType(), 4, 5, ExamType.WRITTEN.getExamType(), null));
//entityManager.persist(new Course("Digitale Signalverarbeitung", Semester.SIXTH.getSemester(), CourseType.REQUIRED.getCourseType(), 4, 5, ExamType.WRITTEN.getExamType(), null));
//int id, String name, String degree, int duration, int fees, String fieldOfStudy
CoursesOfStudy coursesOfStudy = new CoursesOfStudy("Angewandte Informatik", Degree.BACHELOR_OF_SCIENCE.getDegree(), 7, 62, FieldOfStudy.B_ACS_EMBEDDED_SYSTEMS.getFieldOfStudy());
coursesOfStudy.addCourse(new Course("Systemprogrammierung", Semester.SIXTH.getSemester(), CourseType.REQUIRED.getCourseType(), 4, 5, ExamType.WRITTEN.getExamType(), null));
entityManager.persist(coursesOfStudy);
return null;
});
}
finally
{
jpaService.closeResource();
}
}
}
\ No newline at end of file
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.Persistence;
import java.util.function.Function;
/**
* A singleton implementation that encapsulates the JPA logic.
* You can configure the database connection in the
* {@link /src/main/resources/META-INF/persistence.xml} file.
*/
public class JpaService
{
private static JpaService instance;
private EntityManagerFactory entityManagerFactory;
private JpaService()
{
entityManagerFactory = Persistence.createEntityManagerFactory("jpa-hibernate-notenmanager");
}
public static synchronized JpaService getInstance()
{
return instance == null ? instance = new JpaService() : instance;
}
public void closeResource()
{
if(entityManagerFactory != null)
{
entityManagerFactory.close();
}
}
public EntityManagerFactory getEntityManagerFactory()
{
return entityManagerFactory;
}
/**
* Runs the specified function inside a transaction boundary. The function has
* access to a ready to use {@link EntityManager} and can return any type of
* value ({@code T}).
*
* @param function The function to run.
* @param <T> The function's return type.
* @return the value returned by the specified function.
*/
public <T> T runInTransaction(Function <EntityManager, T> function)
{
EntityManager entityManager = entityManagerFactory.createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
boolean isPersisted = false;
entityTransaction.begin();
try
{
T returnValue = function.apply(entityManager);
isPersisted = true;
return returnValue;
}
finally
{
if(isPersisted)
{
entityTransaction.commit();
}
else
{
entityTransaction.rollback();
}
}
}
}
package abstractClasses;
import enumeration.Gender;
import jakarta.persistence.*;
import java.util.Objects;
@MappedSuperclass
@Table(name = "Hochschulmitglied")
public abstract class UniversityMember
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;
@Column(name = "Geschlecht")
private String gender;
@Column(name = "Vorname")
private String firstName;
@Column(name = "Nachname")
private String lastName;
@Column(name = "Wohnort")
private String placeOfResidence;
@Column(name = "Geburtsort")
private String birthPlace;
@Column(name = "Hochschul E-Mail")
private String officialEmail;
@Column(name = "Private E-Mail")
private String privateEmail;
@Column(name = "Angemeldet")
private Boolean isSignedUpForCourse;
protected UniversityMember()
{
}
protected UniversityMember(int id, String gender, String firstName, String lastName, String placeOfResidence, String birthPlace,
String officialEmail, String privateEmail, Boolean isSignedUpForCourse)
{
this.id = id;
this.gender = gender;
this.firstName = firstName;
this.lastName = lastName;
this.placeOfResidence = placeOfResidence;
this.birthPlace = birthPlace;
this.officialEmail = officialEmail;
this.privateEmail = privateEmail;
this.isSignedUpForCourse = isSignedUpForCourse;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UniversityMember that = (UniversityMember) o;
return id == that.id;
}
@Override
public int hashCode()
{
return Objects.hash(id);
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getGender()
{
return gender;
}
public void setGender(String gender)
{
this.gender = gender;
}
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getPlaceOfResidence()
{
return placeOfResidence;
}
public void setPlaceOfResidence(String placeOfResidence)
{
this.placeOfResidence = placeOfResidence;
}
public String getBirthPlace()
{
return birthPlace;
}
public void setBirthPlace(String birthPlace)
{
this.birthPlace = birthPlace;
}
public String getOfficialEmail()
{
return officialEmail;
}
public void setOfficialEmail(String officialEmail)
{
this.officialEmail = officialEmail;
}
public String getPrivateEmail()
{
return privateEmail;
}
public void setPrivateEmail(String privateEmail)
{
this.privateEmail = privateEmail;
}
public Boolean getSignedUpForCourse()
{
return isSignedUpForCourse;
}
public void setSignedUpForCourse(Boolean signedUpForCourse)
{
isSignedUpForCourse = signedUpForCourse;
}
}
package classes;
import jakarta.persistence.*;
import java.util.Objects;
@Entity
@Table(name = "Kurs")
public class Course
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;
@Column(name = "Name")
private String name;
@Column(name = "Semester")
private int semester;
@Column(name = "Typ")
private String courseType;
@Column(name = "SWS")
private int sws;
@Column(name = "ECTS")
private double ects;
@Column(name = "Prüfungstyp")
private String examType;
@Column(name = "Anrechnung")
private Boolean isCredited;
@ManyToOne(fetch = FetchType.LAZY)
private CoursesOfStudy coursesOfStudy;
public Course()
{
}
public Course(String name, int semester, String courseType, int sws, double ects, String examType, Boolean isCredited)
{
this.name = name;
this.semester = semester;
this.courseType = courseType;
this.sws = sws;
this.ects = ects;
this.examType = examType;
this.isCredited = isCredited;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Course course = (Course) o;
return id == course.id;
}
@Override
public int hashCode()
{
return Objects.hash(id);
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getSemester()
{
return semester;
}
public void setSemester(int semester)
{
this.semester = semester;
}
public String getCourseType()
{
return courseType;
}
public void setCourseType(String courseType)
{
this.courseType = courseType;
}
public int getSws()
{
return sws;
}
public void setSws(int sws)
{
this.sws = sws;
}
public double getEcts()
{
return ects;
}
public void setEcts(double ects)
{
this.ects = ects;
}
public String getExamType()
{
return examType;
}
public void setExamType(String examType)
{
this.examType = examType;
}
public Boolean isCredited()
{
return isCredited;
}
public void setCredited(Boolean credited)
{
isCredited = credited;
}
public void setCoursesOfStudy(CoursesOfStudy coursesOfStudy)
{
this.coursesOfStudy = coursesOfStudy;
}
}
package classes;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "Studiengang")
public class CoursesOfStudy
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;
@Column(name = "Name")
private String name;
@Column(name = "Abschluss")
private String degree;
@Column(name = "Dauer")
private int duration;
@Column(name = "Studiengebühr")
private int fees;
@Column(name = "Schwerpunkt")
private String fieldOfStudy;
@OneToMany(
mappedBy = "coursesOfStudy",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<Course> courses = new ArrayList<>();
@ManyToOne
@JoinColumn(name = "courses_of_study_id")
private CoursesOfStudy coursesOfStudy;
public CoursesOfStudy getCoursesOfStudy() {
return coursesOfStudy;
}
/*
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "courses_of_study_id")
private CoursesOfStudy coursesOfStudy;
*/
public CoursesOfStudy()
{
}
public CoursesOfStudy(String name, String degree, int duration, int fees, String fieldOfStudy)
{
this.name = name;
this.degree = degree;
this.duration = duration;
this.fees = fees;
this.fieldOfStudy = fieldOfStudy;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CoursesOfStudy that = (CoursesOfStudy) o;
return id == that.id;
}
@Override
public int hashCode()
{
return Objects.hash(id);
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getDegree()
{
return degree;
}
public void setDegree(String degree)
{
this.degree = degree;
}
public int getDuration()
{
return duration;
}
public void setDuration(int duration)
{
this.duration = duration;
}
public int getFees()
{
return fees;
}
public void setFees(int fees)
{
this.fees = fees;
}
public String getFieldOfStudy()
{
return fieldOfStudy;
}
public void setFieldOfStudy(String fieldOfStudy)
{
this.fieldOfStudy = fieldOfStudy;
}
public void addCourse(Course course)
{
courses.add(course);
course.setCoursesOfStudy(this);
}
public void removeCourse(Course course)
{
courses.remove(course);
course.setCoursesOfStudy(null);
}
}
package classes;
import jakarta.persistence.*;
import java.time.LocalDateTime;
import java.util.Objects;
@Entity
@Table(name = "Kursanmeldung")
public class Enrollment
{
@Id
@Column(name = "ID")
private int id;
@ManyToOne
@JoinColumn(name = "Matrikelnummer")
Student student;
@ManyToOne
@JoinColumn(name = "Kursnummer")
Course course;
@Column(name = "Datum der Anmeldung")
private LocalDateTime enrollmentDate;
@Column(name = "Note")
private double grade;
public Enrollment()
{
}
public Enrollment(Student student, Course course, LocalDateTime enrollmentDate)
{
this.student = student;
this.course = course;
this.enrollmentDate = enrollmentDate;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Enrollment that = (Enrollment) o;
return student == that.student && course == that.course;
}
@Override
public int hashCode()
{
return Objects.hash(student, course);
}
public Student getStudent()
{
return student;
}
public void setStudent(Student student)
{
this.student = student;
}
public Course getCourse()
{
return course;
}
public void setCourse(Course course)
{
this.course = course;
}
public LocalDateTime getEnrollmentDate()
{
return enrollmentDate;
}
public void setEnrollmentDate(LocalDateTime enrollmentDate)
{
this.enrollmentDate = enrollmentDate;
}
public double getGrade()
{
return grade;
}
public void setGrade(double grade)
{
this.grade = grade;
}
}
package classes;
import abstractClasses.UniversityMember;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
@Entity
@Table(name = "Dozent")
public class Lecturer extends UniversityMember
{
@Column(name = "Fakultaet")
String faculty;
public Lecturer()
{
}
public Lecturer(int id, String gender, String firstName, String lastName, String placeOfResidence, String birthPlace,
String officialEmail, String privateEmail, Boolean isSignedUpForCourse, String faculty)
{
super(id, gender, firstName, lastName, placeOfResidence, birthPlace,
officialEmail, privateEmail, isSignedUpForCourse);
this.faculty = faculty;
}
public String getFaculty()
{
return faculty;
}
public void setFaculty(String faculty)
{
this.faculty = faculty;
}
}
package classes;
import abstractClasses.UniversityMember;
import interfaces.Calculable;
import jakarta.persistence.*;
import java.util.Set;
@Entity
@Table(name = "Student")
public class Student extends UniversityMember implements Calculable
{
@Column(name = "Status")
private String status;
@Column(name = "Gebühren bezahlt")
private boolean paidFees;
@Column(name = "Semester")
private int semester;
@OneToMany(mappedBy = "student")
Set<Enrollment> enrollments;
public Student()
{
}
public Student(int id, String gender, String firstName, String lastName, String placeOfResidence, String birthPlace,
String officialEmail, String privateEmail, Boolean isSignedUpForCourse, String status,
boolean paidFess, int semester)
{
super(id, gender, firstName, lastName, placeOfResidence, birthPlace,
officialEmail, privateEmail, isSignedUpForCourse);
this.status = status;
this.paidFees = paidFess;
this.semester = semester;
}
@Override
public double calculateAverage()
{
return 0;
}
@Override
public int calculateMedian()
{
return 0;
}
public String getStatus()
{
return status;
}
public void setStatus(String status)
{
this.status = status;
}
public boolean isPaidFees()
{
return paidFees;
}
public void setPaidFees(boolean paidFees)
{
this.paidFees = paidFees;
}
public int getSemester()
{
return semester;
}
public void setSemester(int semester)
{
this.semester = semester;
}
}
\ No newline at end of file
package enumeration;
public enum CourseType
{
COMPULSORY("FWP"),
ELECTIVE("AWP"),
PLV("PLV"),
REQUIRED("Required"),
VOLUNTARY("Voluntary");
private String courseType;
private CourseType(String courseType)
{
this.courseType = courseType;
}
public String getCourseType()
{
return courseType;
}
}
package enumeration;
public enum Degree
{
BACHELOR_OF_ARTS("B.A."),
BACHELOR_OF_ENGINEERING("B.Eng."),
BACHELOR_OF_SCIENCE("B.Sc."),
MASTER_OF_ARTS("M.A."),
MASTER_OF_ENGINEERING("M.Eng."),
MASTER_OF_SCIENCE("M.Sc.");
private String degree;
private Degree(String degree)
{
this.degree = degree;
}
public String getDegree()
{
return degree;
}
}
package enumeration;
public enum ExamType
{
BACHELOR_THESIS("BA"),
INTERNSHIP("Pr"),
MASTER_THESIS("MA"),
ORAL("mdlP"),
PERFORMANCE_RECORD("LN"),
PROOF_OF_PARTICIPATION("TN"),
RESEARCH_PROJECT("PStA"),
WRITTEN("schrP");
private String examType;
private ExamType(String examType)
{
this.examType = examType;
}
public String getExamType()
{
return examType;
}
}
package enumeration;
public enum FieldOfStudy
{
B_ACS_EMBEDDED_SYSTEMS("Embedded Systems"),
B_ACS_MOBILE_AND_SPATIAL_SYSTEMS("Mobile and Spatial Systems");
private String fieldOfStudy;
private FieldOfStudy(String fieldOfStudy)
{
this.fieldOfStudy = fieldOfStudy;
}
public String getFieldOfStudy()
{
return fieldOfStudy;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment