Skip to content
Open

Dev #10

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
98699e7
[AKAZ] Modified jdk version to 11
Ammar96399 Sep 7, 2022
8578c82
[HMNG] Added two business layer classes provided by the labs in packa…
polymorph233 Sep 7, 2022
0770cfe
[HMNG] Auto generated IDEA files
polymorph233 Sep 7, 2022
f0504ad
[HMNG] Updated .gitignore
polymorph233 Sep 7, 2022
6501e77
[HMNG] Added DAO (corresponding to Q3) and tasks to be completed.
polymorph233 Sep 7, 2022
d0a02b6
[AKAZ] Fixed no persistence provider exception
Ammar96399 Sep 8, 2022
aeac1e8
[AKAZ] Added .idea to gitignore
Ammar96399 Sep 8, 2022
680a3da
Delete .idea directory
Ammar96399 Sep 8, 2022
bcc2a4c
[HMNG] Added Professional class to model
polymorph233 Sep 8, 2022
941f5c3
[AKAZ] Created patient class
Ammar96399 Sep 8, 2022
93f5f67
[HMNG] Finished implementation of model and fixed several issues
polymorph233 Sep 8, 2022
050fd0d
[AKAZ] Added DAO for Entities and completed PatientDAO
Ammar96399 Sep 9, 2022
7d9f313
[HMNG] Typed DAO queries
polymorph233 Sep 9, 2022
1a07458
[AKAZ] Fixed entitymanager problem in PatientDAO
Ammar96399 Sep 9, 2022
8bd409c
Merge remote-tracking branch 'origin/dev' into dev
polymorph233 Sep 9, 2022
d132cf2
[HMNG] Removed unused domain definitions, added generic DAO
polymorph233 Sep 9, 2022
e2fcddc
[AKAZ] Implemented ProfessionalDAO v0
Ammar96399 Sep 9, 2022
4290fc3
[HMNG] Minor updates in DAO
polymorph233 Sep 9, 2022
fdda459
[AKAZ] Implement AppointmentDAO
Ammar96399 Sep 9, 2022
2b7e217
[AKAZ] Fixed minor bugs in AppointmentDAO
Ammar96399 Sep 9, 2022
22dd903
[AKAZ] Added remove and update methods in AppointmentDAO
Ammar96399 Sep 9, 2022
e1f54cb
[HWAN] Added remove and update methods in DAO
polymorph233 Sep 9, 2022
77e38fd
[HWAN] Added Child to represent inheritance
polymorph233 Sep 9, 2022
20641d3
[AKAZ] v0 of ChildDAO
Ammar96399 Sep 11, 2022
4f46963
[AKAZ] Minor changes
Ammar96399 Sep 12, 2022
7b38d10
[AKAZ] Return type is now a list
Ammar96399 Sep 12, 2022
9572bc3
Update README.md
Ammar96399 Sep 25, 2022
b767755
Update README.md
Ammar96399 Sep 25, 2022
ec32472
Update README.md
Ammar96399 Sep 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 215 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
# Created by https://www.toptal.com/developers/gitignore/api/linux,java,maven,macos,intellij
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,java,maven,macos,intellij

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

.idea
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

# End of https://www.toptal.com/developers/gitignore/api/linux,java,maven,macos,intellij

# Data folder generated by DB is expected to be ignored

data
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# Template de projet pour le TP JPA 2021 UniR
# Report TP1 - TAA:

## Presentation:

This repository is the code of the first lab of the class TAA. It was written by Ammar Kazem and Heming Wang during our second year of master's degree in software engineering at the University of Rennes 1.

The goal of this lab was to create a small back-end application with "Models" and the "DAO" that goes with it. We created a very basic representation the famous website "Doctolib".

You can see a representation of our models and the links between them in the image (1).

![image](https://user-images.githubusercontent.com/50889372/192132477-9ab58e95-0b87-4bc7-9d03-ea11c18d57e3.png)

*Image (1) : Class diagram*


For the DAOs we created a generic DAO with the basic methods from which the other DAOs inherited. Requests were written in JAP.

## How to run

To run the project you first need to start the hsql server like this:

Windows:

`.\run-hsqldb-server.bat`

Linux / Macos:

`./run-hsqldb-server.sh`

After starting the database server you can launch the main class `JPATest.java` with your ide or from a terminal. Methods have to be called manually in the main class. A small scenario was written but feel free to add calls to it.
7 changes: 2 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<version>0.0.1-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -37,8 +37,5 @@
<version>8.0.28</version>
</dependency>

<!-- <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId>
<version>1.9.0.RELEASE</version> </dependency> -->

</dependencies>
</project>
2 changes: 1 addition & 1 deletion src/main/java/jpa/EntityManagerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EntityManagerHelper {
public final class EntityManagerHelper {

private static final EntityManagerFactory emf;
private static final ThreadLocal<EntityManager> threadLocal;
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/jpa/JpaTest.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
package jpa;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceContext;
import jpa.dao.ChildDAO;
import jpa.dao.PatientDAO;

public class JpaTest {

/**
* @param args
*/
public static void main(String[] args) {

EntityManager manager = EntityManagerHelper.getEntityManager();
EntityTransaction tx = manager.getTransaction();
var manager = EntityManagerHelper.getEntityManager();
var tx = manager.getTransaction();
var patientDAO = new PatientDAO();
var childDAO = new ChildDAO();
tx.begin();


try {
patientDAO.createPatients("Cambria", "Alpha");
patientDAO.createPatients("Maria", "Beta");
patientDAO.createPatients("Jean", "Citron");
childDAO.createChild("firstChild", "good", "parent", 12);

patientDAO.getPatientList().forEach(System.out::println);

System.out.println(patientDAO.getPatientByName("Maria", "Beta"));
} catch (Exception e) {
e.printStackTrace();
}
tx.commit();


manager.close();
EntityManagerHelper.closeEntityManagerFactory();
// factory.close();
System.out.println("done ...");
}


}
43 changes: 43 additions & 0 deletions src/main/java/jpa/dao/AppointmentDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package jpa.dao;

import jpa.po.Appointment;
import jpa.po.Patient;
import jpa.po.Professional;

import java.time.LocalDateTime;
import java.util.List;

public class AppointmentDAO extends GenericJpaDAO<Appointment, Long> {
public AppointmentDAO() {
super(Appointment.class);
}

public void addAppointment(String reason, LocalDateTime startingTime, Patient patient, Professional professional) {
manager.persist(new Appointment(reason, startingTime, patient, professional));
}
// Access appointments
public List<Appointment> getAppointmentsByProfessionalId(Long id) {
return manager.createQuery("SELECT p FROM Appointment p WHERE p.professional.id = :id", Appointment.class)
.setParameter("id", id)
.getResultList();
}

public List<Appointment> getAppointmentsByPatientId(Long id) {
return manager.createQuery("SELECT p FROM Appointment p WHERE p.patient.id = :id", Appointment.class)
.setParameter("id", id)
.getResultList();
}

//update
public void updateStartingTime(Long id, LocalDateTime startingTime) {
manager.createQuery("UPDATE Appointment a SET a.startingTime = :startingTime WHERE a.id = :id")
.setParameter("startingTime", startingTime)
.setParameter("id", id);
}

//remove
public void removeById(Long id) {
manager.createQuery("DELETE FROM Appointment a WHERE a.id = :id")
.setParameter("id", id);
}
}
Loading