Skip to content

Commit

Permalink
entity migration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gokulprathin8 committed Mar 29, 2024
1 parent 3db49a1 commit f332851
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 103 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
</dependency>


<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.8</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/gw/database/CheckpointRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;

import javax.transaction.Transactional;

@Transactional
public interface CheckpointRepository extends JpaRepository<Checkpoint, UUID> {
List<Checkpoint> findByWorkflowId(String workflowId);

Expand Down
17 changes: 8 additions & 9 deletions src/main/java/com/gw/database/EnvironmentRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import javax.transaction.Transactional;

/**
* The EnvironmentRepository interface provides methods for querying environment configurations from
* a database. It extends the CrudRepository interface to handle database operations for the
* Environment entity.
*/
@Transactional
public interface EnvironmentRepository extends CrudRepository<Environment, String> {

/**
Expand All @@ -22,13 +25,8 @@ public interface EnvironmentRepository extends CrudRepository<Environment, Strin
* @param basedir The base directory.
* @return A collection of environment configurations matching the specified criteria.
*/
@Query(
value =
"select * from environment where hostid = ?1 and bin = ?2 and pyenv = ?3 and basedir ="
+ " ?4",
nativeQuery = true)
Collection<Environment> findEnvByID_BIN_ENV_BaseDir(
String hostid, String bin, String pyenv, String basedir);
@Query("SELECT e FROM Environment e WHERE e.hostobj.id = :hostid AND e.bin = :bin AND e.pyenv = :pyenv AND e.basedir = :basedir")
Collection<Environment> findEnvByID_BIN_ENV_BaseDir(String hostid, String bin, String pyenv, String basedir);

/**
* Find environment configurations based on the provided host ID and binary path.
Expand All @@ -37,7 +35,7 @@ Collection<Environment> findEnvByID_BIN_ENV_BaseDir(
* @param bin The binary path.
* @return A collection of environment configurations matching the specified host and binary path.
*/
@Query(value = "select * from environment where hostid = ?1 and bin = ?2", nativeQuery = true)
@Query("SELECT e FROM Environment e WHERE e.hostobj.id = :hostid AND e.bin = :bin")
Collection<Environment> findEnvByID_BIN(String hostid, String bin);

/**
Expand All @@ -46,6 +44,7 @@ Collection<Environment> findEnvByID_BIN_ENV_BaseDir(
* @param hostid The ID of the host.
* @return A collection of environment configurations associated with the specified host.
*/
@Query(value = "select * from environment where hostid = ?1", nativeQuery = true)
@Query("SELECT e FROM Environment e WHERE e.hostobj.id = :hostid")
Collection<Environment> findEnvByHost(String hostid);

}
97 changes: 27 additions & 70 deletions src/main/java/com/gw/database/HistoryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
* The HistoryRepository interface provides methods for querying historical execution data (history)
* from a database. It extends the JpaRepository interface to handle database operations.
*/
@Transactional
public interface HistoryRepository extends JpaRepository<History, String> {

/**
Expand All @@ -19,91 +22,65 @@ public interface HistoryRepository extends JpaRepository<History, String> {
* @param limit The maximum number of history records to retrieve.
* @return A collection of recent history records for the host.
*/
@Query(
value = "select * from history where host_id = ?1 ORDER BY history_begin_time DESC limit ?2",
nativeQuery = true)
Collection<History> findRecentHistory(String hostid, int limit);
@Query(value = "SELECT * FROM history WHERE host_id = ?1 ORDER BY history_begin_time DESC LIMIT ?2", nativeQuery = true)
List<History> findRecentHistory(String hostid, int limit);

/**
* Find all running history records.
*
* @return A list of all running history records.
*/
@Query(
value = "select * from history where indicator='Running' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE indicator = 'Running' ORDER BY history_begin_time DESC", nativeQuery = true)
List<History> findAllRunningResource();

/**
* Find all running workflows.
*
* @return A list of all running workflow records with additional information.
*/
@Query(
value =
"select * from history, workflow where history.history_process = workflow.id and"
+ " history.indicator = 'Running' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, workflow WHERE history.history_process = workflow.id AND history.indicator = 'Running' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findRunningWorkflow();

/**
* Find all failed workflows.
*
* @return A list of all failed workflow records with additional information.
*/
@Query(
value =
"select * from history, workflow where history.history_process = workflow.id and"
+ " history.indicator = 'Failed' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, workflow WHERE history.history_process = workflow.id AND history.indicator = 'Failed' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findFailedWorkflow();

/**
* Find all successfully completed workflows.
*
* @return A list of all successful workflow records with additional information.
*/
@Query(
value =
"select * from history, workflow where history.history_process = workflow.id and"
+ " history.indicator = 'Done' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, workflow WHERE history.history_process = workflow.id AND history.indicator = 'Done' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findSuccessWorkflow();

/**
* Find all running processes.
*
* @return A list of all running process records with additional information.
*/
@Query(
value =
"select * from history, gwprocess where history.history_process = gwprocess.id and"
+ " history.indicator = 'Running' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_process = gwprocess.id AND history.indicator = 'Running' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findRunningProcess();


/**
* Find all failed processes.
*
* @return A list of all failed process records with additional information.
*/
@Query(
value =
"select * from history, gwprocess where history.history_process = gwprocess.id and"
+ " history.indicator = 'Failed' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_process = gwprocess.id AND history.indicator = 'Failed' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findFailedProcess();


/**
* Find all successfully completed processes.
*
* @return A list of all successful process records with additional information.
*/
@Query(
value =
"select * from history, gwprocess where history.history_process = gwprocess.id and"
+ " history.indicator = 'Done' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_process = gwprocess.id AND history.indicator = 'Done' ORDER BY history_begin_time DESC", nativeQuery = true)
List<Object[]> findSuccessProcess();

/**
Expand All @@ -112,38 +89,28 @@ public interface HistoryRepository extends JpaRepository<History, String> {
* @param pid The ID of the process.
* @return A list of history records associated with the specified process ID.
*/
@Query(
value =
"select * from history where history.history_process = ?1 ORDER BY history_begin_time"
+ " DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE history_process = ?1 ORDER BY history_begin_time DESC", nativeQuery = true)
List<History> findByProcessId(String pid);


/**
* Find history records by process ID, excluding 'Skipped' indicator.
*
* @param pid The ID of the process.
* @return A list of history records associated with the specified process ID, excluding 'Skipped'
* records.
*/
@Query(
value =
"select * from history where history.history_process = ?1 and history.history_input !="
+ " 'No code saved' ORDER BY history_begin_time DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE history_process = ?1 AND history_input != 'No code saved' ORDER BY history_begin_time DESC", nativeQuery = true)
List<History> findByProcessIdIgnoreUnknown(String pid);


/**
* Find history records by workflow ID.
*
* @param wid The ID of the workflow.
* @return A list of history records associated with the specified workflow ID.
*/
@Query(
value =
"select * from history where history.history_process = ?1 ORDER BY history_begin_time"
+ " DESC;",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE history_process = ?1 ORDER BY history_begin_time DESC", nativeQuery = true)
List<History> findByWorkflowId(String wid);

/**
Expand All @@ -152,42 +119,32 @@ public interface HistoryRepository extends JpaRepository<History, String> {
* @param limit The maximum number of recent workflow records to retrieve.
* @return A list of recent workflow records with additional information.
*/
@Query(
value =
"select * from history, workflow where workflow.id = history.history_process ORDER BY"
+ " history_begin_time DESC limit ?1",
nativeQuery = true)
@Query(value = "SELECT * FROM history, workflow WHERE workflow.id = history.history_process ORDER BY history_begin_time DESC LIMIT ?1", nativeQuery = true)
List<Object[]> findRecentWorkflow(int limit);


/**
* Find recent process records, limited by the specified count.
*
* @param limit The maximum number of recent process records to retrieve.
* @return A list of recent process records with additional information.
*/
@Query(
value =
"select * from history, gwprocess where gwprocess.id = history.history_process ORDER BY"
+ " history_begin_time DESC limit ?1",
nativeQuery = true)
@Query(value = "SELECT * FROM history, gwprocess WHERE gwprocess.id = history.history_process ORDER BY history_begin_time DESC LIMIT ?1", nativeQuery = true)
List<Object[]> findRecentProcess(int limit);


/**
* Find a history record associated with a specific history ID.
*
* @param history_id The ID of the history record.
* @return A list containing a history record and additional information about the associated
* process.
*/
@Query(
value = "select * from history where history.history_id = ?1 and history.history_process=?2",
nativeQuery = true)
@Query(value = "SELECT * FROM history WHERE history_id = ?1 AND history_process = ?2", nativeQuery = true)
List<History> findHistoryWithExecutionId(String history_id, String workflowId);

@Query(
value =
"select * from history, gwprocess where history.history_id = ?1 and"
+ " history.history_process=gwprocess.id",
nativeQuery = true)

@Query(value = "SELECT * FROM history, gwprocess WHERE history.history_id = ?1 AND history.history_process = gwprocess.id", nativeQuery = true)
List<Object[]> findOneHistoryofProcess(String history_id);

}
3 changes: 3 additions & 0 deletions src/main/java/com/gw/database/HostRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

/**
* The HostRepository interface provides methods for querying host-related information from the
* database. It extends the CrudRepository interface to handle basic CRUD operations.
*/
@Transactional
public interface HostRepository extends CrudRepository<Host, String> {

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/gw/database/LogActivityRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
import com.gw.jpa.LogActivity;
import org.springframework.data.repository.CrudRepository;

import javax.transaction.Transactional;

/** Log Activity Repository */
@Transactional
interface LogActivityRepository extends CrudRepository<LogActivity, String> {}
3 changes: 3 additions & 0 deletions src/main/java/com/gw/database/ProcessRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

/**
* The ProcessRepository interface provides methods for querying process information from a
* database. It extends the CrudRepository interface to handle database operations for the GWProcess
* entity.
*/
@Transactional
public interface ProcessRepository extends CrudRepository<GWProcess, String> {

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/gw/database/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
import com.gw.jpa.GWUser;
import org.springframework.data.repository.CrudRepository;

import javax.transaction.Transactional;

@Transactional
public interface UserRepository extends CrudRepository<GWUser, String> {}
3 changes: 3 additions & 0 deletions src/main/java/com/gw/database/WorkflowRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

/**
* The WorkflowRepository interface provides methods for querying workflow information from a
* database. It extends the CrudRepository interface to handle database operations for the Workflow
* entity.
*/
@Transactional
public interface WorkflowRepository extends CrudRepository<Workflow, String> {

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/gw/jpa/Checkpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.UUID;

@Entity
Expand Down Expand Up @@ -50,11 +50,11 @@ public class Checkpoint {
private Workflow workflow;

@Column(name = "created_at", columnDefinition = "TIMESTAMP")
private LocalDateTime createdAt;
private Date createdAt;

@PrePersist
protected void onCreate() {
createdAt = LocalDateTime.now();
createdAt = new Date();
}

}
1 change: 0 additions & 1 deletion src/main/java/com/gw/jpa/GWProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Lob;
import javax.persistence.Entity;
import javax.persistence.Id;
Expand Down
Loading

0 comments on commit f332851

Please sign in to comment.