Skip to content

Commit

Permalink
annotation for StateRevision
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Jan 24, 2025
1 parent 4b54e3b commit a08c4b6
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
import com.redhat.rhn.domain.server.ansible.InventoryPath;
import com.redhat.rhn.domain.server.ansible.PlaybookPath;
import com.redhat.rhn.domain.server.virtualhostmanager.VirtualHostManagerNodeInfo;
import com.redhat.rhn.domain.state.OrgStateRevision;
import com.redhat.rhn.domain.state.ServerGroupStateRevision;
import com.redhat.rhn.domain.state.ServerStateRevision;
import com.redhat.rhn.domain.state.StateRevision;
import com.redhat.rhn.domain.task.Task;
import com.redhat.rhn.domain.token.Token;
import com.redhat.rhn.domain.token.TokenChannelAppStream;
Expand Down Expand Up @@ -233,6 +237,7 @@ private AnnotationRegistry() {
Org.class,
OrgConfig.class,
OrgRecurringAction.class,
OrgStateRevision.class,
PackageArch.class,
PackageBreaks.class,
PackageCapability.class,
Expand Down Expand Up @@ -283,13 +288,16 @@ private AnnotationRegistry() {
ServerCoCoAttestationReport.class,
ServerGroup.class,
ServerGroupManager.class,
ServerGroupStateRevision.class,
ServerGroupType.class,
ServerPath.class,
ServerPathId.class,
ServerStateRevision.class,
SoftwareEnvironmentTarget.class,
SoftwareProjectSource.class,
SslCryptoKey.class,
StateChange.class,
StateRevision.class,
Task.class,
TaskoBunch.class,
TaskoTask.class,
Expand Down
2 changes: 1 addition & 1 deletion java/code/src/com/redhat/rhn/domain/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public void storeConfigChannels() {
/**
* Protected constructor
*/
protected Server() {
public Server() {
devices = new HashSet<>();
notes = new HashSet<>();
networkInterfaces = new HashSet<>();
Expand Down
14 changes: 13 additions & 1 deletion java/code/src/com/redhat/rhn/domain/state/OrgStateRevision.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
* A state revision that is assigned to a group.
*/
public class OrgStateRevision extends StateRevision {
@Entity
@Table(name = "suseOrgStateRevision")
@PrimaryKeyJoinColumn(name = "state_revision_id")
public class OrgStateRevision extends StateRevision {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "org_id", nullable = false)
private Org org;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
* A state revision that is assigned to a group.
*/
@Entity
@Table(name = "suseServerGroupStateRevision")
@PrimaryKeyJoinColumn(name = "state_revision_id")
public class ServerGroupStateRevision extends StateRevision {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_id", nullable = false)
private ServerGroup group;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,32 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
* A state revision that is assigned to a server.
*/
@Entity
@Table(name = "suseServerStateRevision")
@PrimaryKeyJoinColumn(name = "state_revision_id")
public class ServerStateRevision extends StateRevision {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "server_id", nullable = false)
private Server server;

/**
* Instantiates a new Server state revision.
*/
public ServerStateRevision() { }
public ServerStateRevision() {
super();
server = new Server();
}

/**
* Instantiates a new Server state revision.
Expand Down
41 changes: 0 additions & 41 deletions java/code/src/com/redhat/rhn/domain/state/StateRevision.hbm.xml
Original file line number Diff line number Diff line change
@@ -1,47 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.redhat.rhn.domain.state.StateRevision" table="suseStateRevision">
<id name="id" type="long" column="id">
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="sequence_name">suse_state_revision_id_seq</param>
<param name="increment_size">1</param>
</generator>
</id>
<set name="packageStates" lazy="true" inverse="true" cascade="all">
<key column="state_revision_id"/>
<one-to-many class="com.redhat.rhn.domain.state.PackageState"/>
</set>

<list name="configChannels" lazy="true" table="suseStateRevisionConfigChannel"
cascade="save-update" where="(position > 0)"
collection-type="com.redhat.rhn.common.hibernate.ForceRecreationListType">
<key column="state_revision_id"/>
<list-index column="position" base="1"/>
<many-to-many
class="com.redhat.rhn.domain.config.ConfigChannel"
column="config_channel_id"/>
</list>

<property name="created" column="created" type="timestamp" insert="false" update="false"/>
<many-to-one name="creator" column="creator_id" class="com.redhat.rhn.domain.user.legacy.UserImpl" lazy="proxy"/>

<joined-subclass name="com.redhat.rhn.domain.state.ServerStateRevision" table="suseServerStateRevision">
<key column="state_revision_id"/>
<many-to-one name="server" column="server_id" class="com.redhat.rhn.domain.server.Server"/>
</joined-subclass>

<joined-subclass name="com.redhat.rhn.domain.state.ServerGroupStateRevision" table="suseServerGroupStateRevision">
<key column="state_revision_id"/>
<many-to-one name="group" column="group_id" class="com.redhat.rhn.domain.server.ServerGroup"/>
</joined-subclass>

<joined-subclass name="com.redhat.rhn.domain.state.OrgStateRevision" table="suseOrgStateRevision">
<key column="state_revision_id"/>
<many-to-one name="org" column="org_id" class="com.redhat.rhn.domain.org.Org"/>
</joined-subclass>

</class>
<query name="StateRevision.deleteAll">
<![CDATA[delete from com.redhat.rhn.domain.state.StateRevision]]>
</query>
Expand Down
55 changes: 47 additions & 8 deletions java/code/src/com/redhat/rhn/domain/state/StateRevision.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,66 @@

import com.redhat.rhn.domain.config.ConfigChannel;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.domain.user.legacy.UserImpl;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.Where;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
* A generic state revision to be subclassed for instance as {@link ServerStateRevision}.
*/
@Entity
@Table(name = "suseStateRevision")
@Inheritance(strategy = InheritanceType.JOINED)
public class StateRevision {

private long id;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "state_revision_seq")
@SequenceGenerator(name = "state_revision_seq", sequenceName = "suse_state_revision_id_seq", allocationSize = 1)
private Long id;

@OneToMany(mappedBy = "stateRevision", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<PackageState> packageStates;

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(
name = "suseStateRevisionConfigChannel",
joinColumns = @JoinColumn(name = "state_revision_id"),
inverseJoinColumns = @JoinColumn(name = "config_channel_id")
)
@Where(clause = "(position > 0)")
@OrderColumn(name = "position")
private List<ConfigChannel> configChannels = List.of();

@Column(name = "created", insertable = false, updatable = false)
private Date created;
private User creator;
private Set<PackageState> packageStates = new HashSet<>();
private List<ConfigChannel> configChannels = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "creator_id")
private UserImpl creator;

/**
* @return the id
Expand Down Expand Up @@ -69,15 +108,15 @@ public void setCreated(Date createdIn) {
/**
* @return the creator
*/
public User getCreator() {
public UserImpl getCreator() {
return creator;
}

/**
* @param creatorIn the creator to set
*/
public void setCreator(User creatorIn) {
this.creator = creatorIn;
this.creator = (UserImpl) creatorIn;
}

/**
Expand Down

0 comments on commit a08c4b6

Please sign in to comment.