-
Notifications
You must be signed in to change notification settings - Fork 181
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
Issv3 hibernate schema #9375
Merged
Merged
Issv3 hibernate schema #9375
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2024 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
*/ | ||
package com.suse.manager.model.hub; | ||
|
||
import com.redhat.rhn.common.hibernate.HibernateFactory; | ||
import com.redhat.rhn.domain.channel.Channel; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class HubFactory extends HibernateFactory { | ||
|
||
private static final Logger LOG = LogManager.getLogger(HubFactory.class); | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public HubFactory() { | ||
// TODO document why this constructor is empty | ||
} | ||
|
||
@Override | ||
protected Logger getLogger() { | ||
return LOG; | ||
} | ||
|
||
/** | ||
* Save a {@link IssHub} object | ||
* @param issHubIn object to save | ||
*/ | ||
public void save(IssHub issHubIn) { | ||
saveObject(issHubIn); | ||
} | ||
|
||
/** | ||
* Save a {@link IssPeripheral} object | ||
* @param issPeripheralIn object to save | ||
*/ | ||
public void save(IssPeripheral issPeripheralIn) { | ||
saveObject(issPeripheralIn); | ||
} | ||
|
||
/** | ||
* Save a {@link IssPeripheralChannels} object | ||
* @param issPeripheralChannelsIn object to save | ||
*/ | ||
public void save(IssPeripheralChannels issPeripheralChannelsIn) { | ||
saveObject(issPeripheralChannelsIn); | ||
} | ||
|
||
/** | ||
* Lookup {@link IssHub} object by its FQDN | ||
* @param fqdnIn the fqdn | ||
* @return return {@link IssHub} with the given FQDN or empty | ||
*/ | ||
public Optional<IssHub> lookupIssHubByFqdn(String fqdnIn) { | ||
return getSession().createQuery("FROM IssHub WHERE fqdn = :fqdn", IssHub.class) | ||
.setParameter("fqdn", fqdnIn) | ||
.uniqueResultOptional(); | ||
} | ||
|
||
/** | ||
* Lookup {@link IssPeripheral} object by its FQDN | ||
* @param fqdnIn the fqdn | ||
* @return return {@link IssPeripheral} with the given FQDN or empty | ||
*/ | ||
public Optional<IssPeripheral> lookupIssPeripheralByFqdn(String fqdnIn) { | ||
return getSession().createQuery("FROM IssPeripheral WHERE fqdn = :fqdn", IssPeripheral.class) | ||
.setParameter("fqdn", fqdnIn) | ||
.uniqueResultOptional(); | ||
} | ||
|
||
/** | ||
* List {@link IssPeripheralChannels} objects which reference the given {@link Channel} | ||
* @param channelIn the channel | ||
* @return return the list of {@link IssPeripheralChannels} objects | ||
*/ | ||
public List<IssPeripheralChannels> listIssPeripheralChannelsByChannels(Channel channelIn) { | ||
return getSession() | ||
.createQuery("FROM IssPeripheralChannels WHERE channel = :channel", IssPeripheralChannels.class) | ||
.setParameter("channel", channelIn) | ||
.list(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright (c) 2024 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
*/ | ||
package com.suse.manager.model.hub; | ||
|
||
import com.redhat.rhn.domain.BaseDomainHelper; | ||
import com.redhat.rhn.domain.credentials.SCCCredentials; | ||
|
||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "suseISSHub") | ||
public class IssHub extends BaseDomainHelper { | ||
private Long id; | ||
private String fqdn; | ||
private String rootCa; | ||
private SCCCredentials mirrorCredentials; | ||
|
||
protected IssHub() { | ||
// Default empty Constructor for Hibernate | ||
} | ||
|
||
/** | ||
* Constructor | ||
* @param fqdnIn the FQDN of the Hub Server | ||
*/ | ||
public IssHub(String fqdnIn) { | ||
this (fqdnIn, null); | ||
} | ||
|
||
/** | ||
* Constructor | ||
* @param fqdnIn the FQDN of the Hub Server | ||
* @param rootCaIn the root CA used by the Hub Server | ||
*/ | ||
public IssHub(String fqdnIn, String rootCaIn) { | ||
fqdn = fqdnIn; | ||
rootCa = rootCaIn; | ||
mirrorCredentials = null; | ||
} | ||
|
||
/** | ||
* @return return the ID | ||
*/ | ||
@Id | ||
@Column(name = "id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Get the FQDN of the Hub Server | ||
* @return return the FQDN of the Hub Server | ||
*/ | ||
@Column(name = "fqdn", unique = true) | ||
public String getFqdn() { | ||
return fqdn; | ||
} | ||
|
||
/** | ||
* Get the configured Root CA | ||
* @return return the root ca | ||
*/ | ||
@Column(name = "root_ca") | ||
public String getRootCa() { | ||
return rootCa; | ||
} | ||
|
||
/** | ||
* Get the mirror credentials. | ||
* @return the credentials | ||
*/ | ||
@ManyToOne(targetEntity = SCCCredentials.class) | ||
@JoinColumn(name = "mirror_creds_id") | ||
public SCCCredentials getMirrorCredentials() { | ||
return mirrorCredentials; | ||
} | ||
|
||
/* | ||
* will be autogenerated | ||
*/ | ||
protected void setId(Long idIn) { | ||
id = idIn; | ||
} | ||
|
||
/** | ||
* @param fqdnIn the FQDN | ||
*/ | ||
public void setFqdn(String fqdnIn) { | ||
fqdn = fqdnIn; | ||
} | ||
|
||
/** | ||
* @param rootCaIn the root ca | ||
*/ | ||
public void setRootCa(String rootCaIn) { | ||
rootCa = rootCaIn; | ||
} | ||
|
||
/** | ||
* @param mirrorCredentialsIn the mirror credentials | ||
*/ | ||
public void setMirrorCredentials(SCCCredentials mirrorCredentialsIn) { | ||
mirrorCredentials = mirrorCredentialsIn; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object oIn) { | ||
if (this == oIn) { | ||
return true; | ||
} | ||
if (!(oIn instanceof IssHub issHub)) { | ||
return false; | ||
} | ||
return Objects.equals(getFqdn(), issHub.getFqdn()) && | ||
Objects.equals(getRootCa(), issHub.getRootCa()) && | ||
Objects.equals(getMirrorCredentials(), issHub.getMirrorCredentials()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder().append(getFqdn()).append(getRootCa()).append(getMirrorCredentials()).toHashCode(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JFYI, since you haven't used Apache Commons for return Objects.hash(getFqdn(), getRootCa(), getMirrorCredentials()); |
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "IssHub{" + | ||
"id=" + id + | ||
", fqdn='" + fqdn + '\'' + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is currently nothing to initialize, this constructor can be removed.