-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ibtissamelhani/dev
Dev
- Loading branch information
Showing
35 changed files
with
1,108 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package org.example; | ||
|
||
import org.example.schedulers.ResetTokenScheduler; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
// Create an instance of the ResetTokenScheduler | ||
ResetTokenScheduler resetTokenScheduler = new ResetTokenScheduler(); | ||
// ResetTokenScheduler resetTokenScheduler = new ResetTokenScheduler(); | ||
// | ||
// resetTokenScheduler.run(); | ||
// | ||
// System.out.println("Token reset executed successfully."); | ||
|
||
// Execute the run method to test the token reset functionality | ||
resetTokenScheduler.run(); | ||
// CheckPendingRequestsScheduler scheduler = new CheckPendingRequestsScheduler(); | ||
// scheduler.run(); | ||
// System.out.println("Token double executed successfully."); | ||
|
||
// Optional: You could log or print out information to confirm tokens were reset | ||
System.out.println("Token reset executed successfully."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 36 additions & 7 deletions
43
src/main/java/org/example/repository/implementation/RequestRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,84 @@ | ||
package org.example.repository.implementation; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import jakarta.persistence.*; | ||
import org.example.model.entities.Request; | ||
import org.example.model.entities.Tag; | ||
import org.example.model.enums.RequestStatus; | ||
import org.example.repository.interfaces.RequestRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class RequestRepositoryImpl implements RequestRepository { | ||
|
||
private final EntityManagerFactory entityManagerFactory; | ||
EntityManagerFactory entityManagerFactory; | ||
EntityManager entityManager; | ||
|
||
public RequestRepositoryImpl(EntityManagerFactory entityManagerFactory) { | ||
this.entityManagerFactory = entityManagerFactory; | ||
this.entityManager = entityManagerFactory.createEntityManager(); | ||
} | ||
|
||
@Override | ||
public Request save(Request request) { | ||
try (EntityManager entityManager = entityManagerFactory.createEntityManager()) { | ||
try { | ||
entityManager.getTransaction().begin(); | ||
entityManager.persist(request); | ||
entityManager.getTransaction().commit(); | ||
return request; | ||
} catch (PersistenceException e) { | ||
if (entityManager.getTransaction().isActive()) { | ||
entityManager.getTransaction().rollback(); | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<Request> findById(long id) { | ||
try (EntityManager entityManager = entityManagerFactory.createEntityManager()) { | ||
try { | ||
Request request = entityManager.find(Request.class, id); | ||
return Optional.ofNullable(request); | ||
} catch (NoResultException e) { | ||
System.out.println(e.getMessage()); | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Request> findAll() { | ||
try (EntityManager entityManager = entityManagerFactory.createEntityManager()) { | ||
try { | ||
return entityManager.createQuery("SELECT r FROM Request r", Request.class) | ||
.getResultList(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Request update(Request request) { | ||
try (EntityManager entityManager = entityManagerFactory.createEntityManager()) { | ||
try { | ||
entityManager.getTransaction().begin(); | ||
entityManager.merge(request); | ||
entityManager.getTransaction().commit(); | ||
return request; | ||
}catch (Exception e) { | ||
if (entityManager.getTransaction().isActive()) { | ||
entityManager.getTransaction().rollback(); | ||
} | ||
throw e; | ||
} | ||
} | ||
|
||
@Override | ||
public List<Request> findRequestsByStatus(RequestStatus status) { | ||
try { | ||
TypedQuery<Request> query = entityManager.createQuery( | ||
"SELECT r FROM Request r WHERE r.status = :status", Request.class); | ||
query.setParameter("status", status); | ||
return query.getResultList(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.