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

hibernate refactoring: Server class #9857

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
package com.redhat.rhn.common.hibernate;

import com.redhat.rhn.domain.AbstractLabelNameHelper;
import com.redhat.rhn.domain.Label;
import com.redhat.rhn.domain.access.AccessGroup;
import com.redhat.rhn.domain.access.Namespace;
import com.redhat.rhn.domain.access.WebEndpoint;
Expand Down Expand Up @@ -39,6 +41,7 @@
import com.redhat.rhn.domain.config.ConfigChannel;
import com.redhat.rhn.domain.config.ConfigChannelType;
import com.redhat.rhn.domain.config.ConfigFile;
import com.redhat.rhn.domain.config.ConfigFileType;
import com.redhat.rhn.domain.contentmgmt.ContentEnvironment;
import com.redhat.rhn.domain.contentmgmt.ContentFilter;
import com.redhat.rhn.domain.contentmgmt.ContentProject;
Expand Down Expand Up @@ -79,6 +82,7 @@
import com.redhat.rhn.domain.kickstart.crypto.SslCryptoKey;
import com.redhat.rhn.domain.notification.NotificationMessage;
import com.redhat.rhn.domain.notification.UserNotification;
import com.redhat.rhn.domain.org.CustomDataKey;
import com.redhat.rhn.domain.org.Org;
import com.redhat.rhn.domain.org.OrgAdminManagement;
import com.redhat.rhn.domain.org.OrgConfig;
Expand Down Expand Up @@ -125,20 +129,32 @@
import com.redhat.rhn.domain.server.ClientCapabilityId;
import com.redhat.rhn.domain.server.CustomDataValue;
import com.redhat.rhn.domain.server.EntitlementServerGroup;
import com.redhat.rhn.domain.server.Feature;
import com.redhat.rhn.domain.server.InstalledPackage;
import com.redhat.rhn.domain.server.ManagedServerGroup;
import com.redhat.rhn.domain.server.MinionServer;
import com.redhat.rhn.domain.server.MinionServerFactory;
import com.redhat.rhn.domain.server.MinionSummary;
import com.redhat.rhn.domain.server.NetworkInterface;
import com.redhat.rhn.domain.server.Pillar;
import com.redhat.rhn.domain.server.ProxyInfo;
import com.redhat.rhn.domain.server.Ram;
import com.redhat.rhn.domain.server.SAPWorkload;
import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.server.ServerAppStream;
import com.redhat.rhn.domain.server.ServerGroup;
import com.redhat.rhn.domain.server.ServerGroupMember;
import com.redhat.rhn.domain.server.ServerGroupType;
import com.redhat.rhn.domain.server.ServerHistoryEvent;
import com.redhat.rhn.domain.server.ServerInfo;
import com.redhat.rhn.domain.server.ServerNetAddress4;
import com.redhat.rhn.domain.server.ServerNetAddress6;
import com.redhat.rhn.domain.server.ServerPath;
import com.redhat.rhn.domain.server.ServerPathId;
import com.redhat.rhn.domain.server.VirtualInstance;
import com.redhat.rhn.domain.server.VirtualInstanceInfo;
import com.redhat.rhn.domain.server.VirtualInstanceState;
import com.redhat.rhn.domain.server.VirtualInstanceType;
import com.redhat.rhn.domain.server.ansible.AnsiblePath;
import com.redhat.rhn.domain.server.ansible.InventoryPath;
import com.redhat.rhn.domain.server.ansible.PlaybookPath;
Expand Down Expand Up @@ -190,6 +206,7 @@ private AnnotationRegistry() {

private static final List<Class<?>> ANNOTATION_CLASSES = List.of(
// do not add class at the end, but keep the alphabetical order
AbstractLabelNameHelper.class,
AccessGroup.class,
AccessToken.class,
ActionChain.class,
Expand Down Expand Up @@ -217,19 +234,23 @@ private AnnotationRegistry() {
ConfigChannel.class,
ConfigChannelType.class,
ConfigFile.class,
ConfigFileType.class,
ContentEnvironment.class,
ContentFilter.class,
ContentProject.class,
ContentProjectFilter.class,
ContentProjectHistoryEntry.class,
CryptoKey.class,
CryptoKeyType.class,
CustomDataKey.class,
CustomDataValue.class,
CustomDataValue.ServerCustomDataValueKey.class,
DeltaImageInfo.class,
DockerfileProfile.class,
EntitlementServerGroup.class,
EnvironmentTarget.class,
ErrataFilter.class,
Feature.class,
GroupRecurringAction.class,
HubSCCCredentials.class,
ImageFile.class,
Expand All @@ -253,6 +274,7 @@ private AnnotationRegistry() {
IssPeripheral.class,
IssPeripheralChannels.class,
KiwiProfile.class,
Label.class,
MaintenanceCalendar.class,
MaintenanceSchedule.class,
ManagedServerGroup.class,
Expand Down Expand Up @@ -295,8 +317,10 @@ private AnnotationRegistry() {
PlaybookPath.class,
ProfileCustomDataValue.class,
ProjectSource.class,
ProxyInfo.class,
ProvisionState.class,
PtfFilter.class,
Ram.class,
RhnConfiguration.class,
RecurringConfigChannel.class,
RecurringHighstate.class,
Expand Down Expand Up @@ -326,8 +350,16 @@ private AnnotationRegistry() {
ServerCoCoAttestationReport.class,
ServerGroup.class,
ServerGroupManager.class,
ServerGroupMember.class,
ServerGroupMember.ServerGroupMemberId.class,
ServerGroupStateRevision.class,
ServerGroupType.class,
ServerHistoryEvent.class,
ServerInfo.class,
ServerNetAddress4.class,
ServerNetAddress4.ServerNetAddress4Id.class,
ServerNetAddress6.class,
ServerNetAddress6.ServerNetAddress6Id.class,
ServerPath.class,
ServerPathId.class,
ServerStateRevision.class,
Expand All @@ -351,6 +383,10 @@ private AnnotationRegistry() {
UserInfo.class,
UserNotification.class,
VHMCredentials.class,
VirtualInstance.class,
VirtualInstanceState.class,
VirtualInstanceType.class,
VirtualInstanceInfo.class,
VirtualHostManagerNodeInfo.class,
XccdfTestResult.class,
WebEndpoint.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

/**
* AbstractLabelNameHelper - We have a set of tables in our schema
* that are basic name/label pairs. This class can be used by these tables
* to represent them.
*
*/
@MappedSuperclass
public class AbstractLabelNameHelper extends BaseDomainHelper {

@Transient
private Long id;
private String label;
private String name;

@Column(name = "label", nullable = false)
private String label = new String();

@Column(name = "name", nullable = false)
private String name = new String();

/**
* @return Returns the id.
Expand Down Expand Up @@ -77,8 +86,7 @@ public void setName(String n) {
*/
@Override
public int hashCode() {
return new HashCodeBuilder().append(this.getId())
.append(this.getName())
return new HashCodeBuilder().append(this.getName())
.append(this.getLabel())
.toHashCode();
}
Expand All @@ -91,8 +99,7 @@ public boolean equals(Object oth) {
if (!(oth instanceof AbstractLabelNameHelper other)) {
return false;
}
return new EqualsBuilder().append(this.getId(), other.getId())
.append(this.getName(), other.getName())
return new EqualsBuilder().append(this.getName(), other.getName())
.append(this.getLabel(), other.getLabel())
.isEquals();
}
Expand Down
47 changes: 14 additions & 33 deletions java/code/src/com/redhat/rhn/domain/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;


/**
Expand Down Expand Up @@ -46,13 +50,16 @@
* @see com.redhat.rhn.domain.server.VirtualInstanceType
*
*/
public abstract class Label implements Labeled {

@MappedSuperclass
public abstract class Label extends BaseDomainHelper implements Labeled {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false)
private Long id;
private String name;
private String label;
private Date created;
private Date modified;
@Column(name = "name", length = 128, nullable = false)
private String name = "";
@Column(name = "label", length = 128, nullable = false)
private String label = "";

/**
* Returns the primary key.
Expand Down Expand Up @@ -94,32 +101,6 @@ private void setLabel(String newLabel) {
label = newLabel;
}

/**
* Get the date on which this label was created.
*
* @return The date on which this label was created.
*/
public Date getCreated() {
return created;
}

private void setCreated(Date date) {
created = date;
}

/**
* Get the date of last modification.
*
* @return The date of last modification.
*/
public Date getModified() {
return modified;
}

private void setModified(Date date) {
modified = date;
}

/**
* Two labels are considered equal when they have the same name and label text.
*
Expand Down
Loading
Loading