Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the inverse relations in the job entities #408

Merged
merged 1 commit into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions genie-client/src/test/resources/application-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ spring:
hibernate:
ddl-auto: update
naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
properties:
hibernate:
show_sql: true
type: trace
datasource:
url: jdbc:hsqldb:mem:genie-int-db;shutdown=true
username: SA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import javax.annotation.Nullable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
Expand All @@ -36,6 +35,8 @@
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
Expand All @@ -58,7 +59,17 @@
@Setter
@Entity
@Table(name = "jobs")
@NamedQueries({
@NamedQuery(
name = JobEntity.QUERY_GET_STATUS_BY_ID,
query = "select j.status from JobEntity j where j.id = :id"
)
})
public class JobEntity extends CommonFieldsEntity {
/**
* Query name to get job status.
*/
public static final String QUERY_GET_STATUS_BY_ID = "getStatusById";
/**
* Used as default version when one not entered.
*/
Expand Down Expand Up @@ -111,14 +122,6 @@ public class JobEntity extends CommonFieldsEntity {
@MapsId
private JobRequestEntity request;

@OneToOne(
mappedBy = "job",
fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
orphanRemoval = true
)
private JobExecutionEntity execution;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "cluster_id")
private ClusterEntity cluster;
Expand Down Expand Up @@ -278,20 +281,10 @@ protected JobRequestEntity getRequest() {
*
* @param request The job request. Not null.
*/
protected void setRequest(final JobRequestEntity request) {
public void setRequest(final JobRequestEntity request) {
this.request = request;
}

/**
* Set the job execution for this job.
*
* @param execution The execution. Not null.
*/
public void setExecution(@NotNull(message = "Execution can't be null") final JobExecutionEntity execution) {
this.execution = execution;
execution.setJob(this);
}

/**
* Set the cluster this job ran on.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
Expand All @@ -49,8 +51,25 @@
@Setter
@Entity
@Table(name = "job_executions")
@NamedQueries({
@NamedQuery(
name = JobExecutionEntity.QUERY_FIND_BY_STATUS_HOST,
query = "select e.job from JobExecutionEntity e where e.job.status in :statuses and e.hostName = :hostName"
),
@NamedQuery(
name = JobExecutionEntity.QUERY_FIND_HOSTS_BY_STATUS,
query = "select distinct e.hostName from JobExecutionEntity e where e.job.status in :statuses"
)
})
public class JobExecutionEntity extends BaseEntity {

/**
* Query name to find jobs by statuses and host.
*/
public static final String QUERY_FIND_BY_STATUS_HOST = "findByStatusHost";
/**
* Query name to find hosts by statuses.
*/
public static final String QUERY_FIND_HOSTS_BY_STATUS = "findHostsByStatus";
private static final long serialVersionUID = -5073493356472801960L;
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");

Expand Down Expand Up @@ -154,7 +173,7 @@ public void setTimeout(@NotNull final Date timeout) {
*
* @param job The job
*/
protected void setJob(final JobEntity job) {
public void setJob(final JobEntity job) {
this.job = job;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -117,22 +113,6 @@ public class JobRequestEntity extends SetupFileEntity {
@Min(value = 1)
private Integer timeout;

@OneToOne(
mappedBy = "request",
fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
orphanRemoval = true
)
private JobEntity job;

@OneToOne(
mappedBy = "request",
fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
orphanRemoval = true
)
private JobMetadataEntity jobMetadata;

/**
* Gets the group name of the user who submitted the job.
*
Expand Down Expand Up @@ -334,35 +314,6 @@ protected void setApplications(final String applications) {
this.applications = applications;
}

/**
* Get the job associated with this job request.
*
* @return The job
*/
public JobEntity getJob() {
return this.job;
}

/**
* Set the job for this request.
*
* @param job The job
*/
public void setJob(@NotNull final JobEntity job) {
this.job = job;
job.setRequest(this);
}

/**
* Set the additional metadata for this request.
*
* @param jobMetadata The metadata
*/
public void setJobMetadata(@NotNull final JobMetadataEntity jobMetadata) {
this.jobMetadata = jobMetadata;
this.jobMetadata.setRequest(this);
}

/**
* Get a DTO representing this job request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
* Job repository.
*
Expand All @@ -28,4 +31,10 @@
*/
@Repository
public interface JpaJobExecutionRepository extends JpaRepository<JobExecutionEntity, String>, JpaSpecificationExecutor {
/**
* Deletes all job executions for the given ids.
* @param ids list of ids for which the job requests should be deleted
* @return no. of executions deleted
*/
Long deleteByIdIn(@NotNull final List<String> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
* Job Metadata repository.
*
Expand All @@ -28,4 +31,10 @@
*/
@Repository
public interface JpaJobMetadataRepository extends JpaRepository<JobMetadataEntity, String>, JpaSpecificationExecutor {
/**
* Deletes all job metadatas for the given ids.
* @param ids list of ids for which the job requests should be deleted
* @return no. of metadatas deleted
*/
Long deleteByIdIn(@NotNull final List<String> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
* Job repository.
*
* @author tgianos
*/
@Repository
public interface JpaJobRepository extends JpaRepository<JobEntity, String>, JpaSpecificationExecutor {
/**
* Deletes all jobs for the given ids.
* @param ids list of ids for which the jobs should be deleted
* @return no. of jobs deleted
*/
Long deleteByIdIn(@NotNull final List<String> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
* Job repository.
Expand All @@ -33,10 +34,17 @@
public interface JpaJobRequestRepository extends JpaRepository<JobRequestEntity, String>, JpaSpecificationExecutor {

/**
* Delete all job requests created before the given date.
* Returns all job requests created before the given date.
*
* @param date The date before which all job requests should be deleted.
* @return The number of deleted records
* @param date The date before which all job requests were created.
* @return List of job requests
*/
Long deleteByCreatedBefore(@NotNull final Date date);
List<JobRequestEntity> findByCreatedBefore(@NotNull final Date date);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed my only concern here is memory if this list becomes too large. Currently this method is called daily as part of a task so we should be ok but it's something we might want to improve going forward either by returning just the Id's or paginating this list.


/**
* Deletes all job requests for the given ids.
* @param ids list of ids for which the job requests should be deleted
* @return no. of requests deleted
*/
Long deleteByIdIn(@NotNull final List<String> ids);
}