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: remove entity and queries from hbm.xml and add this info as annotation #9563

Draft
wants to merge 9 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
2 changes: 1 addition & 1 deletion java/buildconf/test/rhn.conf.postgresql-example
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.driver_proto = jdbc:postgresql
# Uncomment to log all SQL statements issued by Hibernate
# hibernate.show_sql = true
hibernate.show_sql = true
hibernate.use_outer_join = true
hibernate.jdbc.batch_size = 0
hibernate.cache.region.factory_class = org.hibernate.cache.ehcache.EhCacheRegionFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,29 +1301,6 @@ ORDER BY PN.name, PE.evr
</query>
</callable-mode>

<write-mode name="add_servers_to_server_group">
<query params="sgid">
INSERT INTO rhnServerGroupMembers(server_id, server_group_id)
SELECT S.id server_id, :sgid
FROM rhnServerGroup SG, rhnServer S
WHERE S.id IN (%s)
AND SG.id = :sgid
AND S.org_id = SG.org_id
AND NOT EXISTS (SELECT 1
FROM rhnServerGroupMembers SGM
WHERE SGM.server_id = S.id
AND SGM.server_group_id = SG.id)
</query>
</write-mode>

<write-mode name="update_current_members_of_server_group">
<query params="sgid, members_count">
UPDATE rhnServerGroup
SET current_members = current_members + (:members_count)
WHERE id = :sgid
</query>
</write-mode>

<write-mode name="delete_from_servergroup">
<query params="sgid">
DELETE FROM rhnServerGroupMembers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected void createSessionFactory() {

sessionFactory = config.buildSessionFactory();
}
catch (HibernateException e) {
catch (Exception e) {
LOG.error("FATAL ERROR creating HibernateFactory", e);
}
}
Expand Down
269 changes: 182 additions & 87 deletions java/code/src/com/redhat/rhn/common/hibernate/AnnotationRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
*/
package com.redhat.rhn.common.hibernate;

import com.redhat.rhn.domain.channel.AccessToken;
import com.redhat.rhn.domain.channel.AppStream;
import com.redhat.rhn.domain.channel.AppStreamApi;
import com.redhat.rhn.domain.channel.AppStreamApiKey;
import com.redhat.rhn.domain.channel.Channel;
import com.redhat.rhn.domain.channel.ChannelArch;
import com.redhat.rhn.domain.channel.ChannelSyncFlag;
import com.redhat.rhn.domain.channel.ClonedChannel;
import com.redhat.rhn.domain.cloudpayg.CloudRmtHost;
import com.redhat.rhn.domain.cloudpayg.PaygCredentialsProduct;
import com.redhat.rhn.domain.cloudpayg.PaygSshData;
import com.redhat.rhn.domain.common.ProvisionState;
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.contentmgmt.ContentEnvironment;
import com.redhat.rhn.domain.contentmgmt.ContentFilter;
import com.redhat.rhn.domain.contentmgmt.ContentProject;
Expand Down Expand Up @@ -53,8 +62,18 @@
import com.redhat.rhn.domain.image.ImageStoreType;
import com.redhat.rhn.domain.image.KiwiProfile;
import com.redhat.rhn.domain.image.ProfileCustomDataValue;
import com.redhat.rhn.domain.kickstart.crypto.CryptoKey;
import com.redhat.rhn.domain.kickstart.crypto.CryptoKeyType;
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.Org;
import com.redhat.rhn.domain.org.OrgAdminManagement;
import com.redhat.rhn.domain.org.OrgConfig;
import com.redhat.rhn.domain.org.TemplateString;
import com.redhat.rhn.domain.org.usergroup.UserGroupImpl;
import com.redhat.rhn.domain.org.usergroup.UserGroupMembers;
import com.redhat.rhn.domain.org.usergroup.UserGroupMembersId;
import com.redhat.rhn.domain.product.SUSEProductSCCRepository;
import com.redhat.rhn.domain.recurringactions.GroupRecurringAction;
import com.redhat.rhn.domain.recurringactions.MinionRecurringAction;
Expand All @@ -64,17 +83,22 @@
import com.redhat.rhn.domain.recurringactions.state.RecurringInternalState;
import com.redhat.rhn.domain.recurringactions.type.RecurringHighstate;
import com.redhat.rhn.domain.recurringactions.type.RecurringState;
import com.redhat.rhn.domain.rhnpackage.PackageArch;
import com.redhat.rhn.domain.rhnpackage.PackageBreaks;
import com.redhat.rhn.domain.rhnpackage.PackageCapability;
import com.redhat.rhn.domain.rhnpackage.PackageConflicts;
import com.redhat.rhn.domain.rhnpackage.PackageEnhances;
import com.redhat.rhn.domain.rhnpackage.PackageExtraTagsKeys;
import com.redhat.rhn.domain.rhnpackage.PackageFile;
import com.redhat.rhn.domain.rhnpackage.PackageFileId;
import com.redhat.rhn.domain.rhnpackage.PackageObsoletes;
import com.redhat.rhn.domain.rhnpackage.PackagePreDepends;
import com.redhat.rhn.domain.rhnpackage.PackageProvides;
import com.redhat.rhn.domain.rhnpackage.PackageRecommends;
import com.redhat.rhn.domain.rhnpackage.PackageRequires;
import com.redhat.rhn.domain.rhnpackage.PackageSuggests;
import com.redhat.rhn.domain.rhnpackage.PackageSupplements;
import com.redhat.rhn.domain.role.RoleImpl;
import com.redhat.rhn.domain.scc.SCCOrderItem;
import com.redhat.rhn.domain.scc.SCCRegCacheItem;
import com.redhat.rhn.domain.scc.SCCRepository;
Expand All @@ -84,14 +108,37 @@
import com.redhat.rhn.domain.scc.SCCRepositoryNoAuth;
import com.redhat.rhn.domain.scc.SCCRepositoryTokenAuth;
import com.redhat.rhn.domain.scc.SCCSubscription;
import com.redhat.rhn.domain.server.Capability;
import com.redhat.rhn.domain.server.ClientCapability;
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.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.Server;
import com.redhat.rhn.domain.server.ServerAppStream;
import com.redhat.rhn.domain.server.ServerGroup;
import com.redhat.rhn.domain.server.ServerGroupType;
import com.redhat.rhn.domain.server.ServerPath;
import com.redhat.rhn.domain.server.ServerPathId;
import com.redhat.rhn.domain.server.ansible.AnsiblePath;
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.task.Task;
import com.redhat.rhn.domain.token.Token;
import com.redhat.rhn.domain.token.TokenChannelAppStream;
import com.redhat.rhn.domain.user.AddressImpl;
import com.redhat.rhn.domain.user.StateChange;
import com.redhat.rhn.domain.user.legacy.PersonalInfo;
import com.redhat.rhn.domain.user.legacy.UserImpl;
import com.redhat.rhn.domain.user.legacy.UserInfo;
import com.redhat.rhn.manager.system.ServerGroupManager;

import com.suse.cloud.domain.PaygDimensionComputation;
import com.suse.cloud.domain.PaygDimensionResult;
Expand All @@ -117,93 +164,141 @@ private AnnotationRegistry() {
}

private static final List<Class<?>> ANNOTATION_CLASSES = List.of(
ImageStore.class,
ImageStoreType.class,
DockerfileProfile.class,
KiwiProfile.class,
ImageProfile.class,
ProfileCustomDataValue.class,
DeltaImageInfo.class,
ImageFile.class,
ImageInfo.class,
ImageInfoCustomDataValue.class,
ImageOverview.class,
ImagePackage.class,
ImageRepoDigest.class,
VirtualHostManagerNodeInfo.class,
NotificationMessage.class,
UserNotification.class,
SCCRepository.class,
SCCSubscription.class,
SCCOrderItem.class,
SUSEProductSCCRepository.class,
SCCRepositoryAuth.class,
SCCRepositoryNoAuth.class,
SCCRepositoryBasicAuth.class,
SCCRepositoryTokenAuth.class,
SCCRepositoryCloudRmtAuth.class,
ContentProject.class,
ContentEnvironment.class,
ProjectSource.class,
SoftwareProjectSource.class,
ContentFilter.class,
ContentProjectFilter.class,
PackageFilter.class,
ErrataFilter.class,
ModuleFilter.class,
PtfFilter.class,
EnvironmentTarget.class,
SoftwareEnvironmentTarget.class,
ContentProjectHistoryEntry.class,
PackageExtraTagsKeys.class,
PackageProvides.class,
PackageRequires.class,
PackageRecommends.class,
PackageObsoletes.class,
PackageBreaks.class,
PackageSupplements.class,
PackageConflicts.class,
PackageSuggests.class,
PackagePreDepends.class,
PackageEnhances.class,
MinionRecurringAction.class,
GroupRecurringAction.class,
OrgRecurringAction.class,
MaintenanceSchedule.class,
MaintenanceCalendar.class,
SCCRegCacheItem.class,
AnsiblePath.class,
InventoryPath.class,
PlaybookPath.class,
Pillar.class,
CloudRmtHost.class,
PaygSshData.class,
PaygCredentialsProduct.class,
Task.class,
RecurringHighstate.class,
RecurringState.class,
RecurringConfigChannel.class,
RecurringInternalState.class,
InternalState.class,
PaygDimensionComputation.class,
PaygDimensionResult.class,
BaseCredentials.class,
CloudRMTCredentials.class,
RegistryCredentials.class,
ReportDBCredentials.class,
RHUICredentials.class,
SCCCredentials.class,
VHMCredentials.class,
ChannelSyncFlag.class,
ServerCoCoAttestationConfig.class,
ServerCoCoAttestationReport.class,
CoCoEnvironmentTypeConverter.class,
CoCoAttestationResult.class,
CoCoResultTypeConverter.class,
ServerAppStream.class,
AppStream.class,
AppStreamApi.class,
TokenChannelAppStream.class
// AvailableChannelsView.class,
AccessToken.class,
AddressImpl.class,
AnsiblePath.class,
AppStreamApi.class,
AppStreamApiKey.class,
AppStream.class,
BaseCredentials.class,
Capability.class,
ChannelArch.class,
Channel.class,
ChannelSyncFlag.class,
ClientCapability.class,
ClientCapabilityId.class,
ClonedChannel.class,
CloudRMTCredentials.class,
CloudRmtHost.class,
CoCoAttestationResult.class,
CoCoEnvironmentTypeConverter.class,
CoCoResultTypeConverter.class,
ConfigChannel.class,
ConfigChannelType.class,
ConfigFile.class,
ContentEnvironment.class,
ContentFilter.class,
ContentProject.class,
ContentProjectFilter.class,
ContentProjectHistoryEntry.class,
CryptoKey.class,
CryptoKeyType.class,
CustomDataValue.class,
DeltaImageInfo.class,
DockerfileProfile.class,
EntitlementServerGroup.class,
EnvironmentTarget.class,
ErrataFilter.class,
GroupRecurringAction.class,
ImageFile.class,
ImageInfo.class,
ImageInfoCustomDataValue.class,
ImageOverview.class,
ImagePackage.class,
ImageProfile.class,
ImageRepoDigest.class,
ImageStore.class,
ImageStoreType.class,
InstalledPackage.class,
InternalState.class,
InventoryPath.class,
KiwiProfile.class,
MaintenanceCalendar.class,
MaintenanceSchedule.class,
ManagedServerGroup.class,
MinionRecurringAction.class,
MinionServer.class,
MinionServerFactory.class,
MinionSummary.class,
ModuleFilter.class,
NetworkInterface.class,
NotificationMessage.class,
OrgAdminManagement.class,
Org.class,
OrgConfig.class,
OrgRecurringAction.class,
PackageArch.class,
PackageBreaks.class,
PackageCapability.class,
PackageConflicts.class,
PackageEnhances.class,
PackageExtraTagsKeys.class,
PackageFile.class,
PackageFileId.class,
PackageFilter.class,
PackageObsoletes.class,
PackagePreDepends.class,
PackageProvides.class,
PackageRecommends.class,
PackageRequires.class,
PackageSuggests.class,
PackageSupplements.class,
PaygCredentialsProduct.class,
PaygDimensionComputation.class,
PaygDimensionResult.class,
PaygSshData.class,
PersonalInfo.class,
Pillar.class,
PlaybookPath.class,
ProfileCustomDataValue.class,
ProjectSource.class,
ProvisionState.class,
PtfFilter.class,
RecurringConfigChannel.class,
RecurringHighstate.class,
RecurringInternalState.class,
RecurringState.class,
RegistryCredentials.class,
ReportDBCredentials.class,
RHUICredentials.class,
RoleImpl.class,
SCCCredentials.class,
SCCOrderItem.class,
SCCRegCacheItem.class,
SCCRepositoryAuth.class,
SCCRepositoryBasicAuth.class,
SCCRepository.class,
SCCRepositoryCloudRmtAuth.class,
SCCRepositoryNoAuth.class,
SCCRepositoryTokenAuth.class,
SCCSubscription.class,
ServerAppStream.class,
Server.class,
ServerCoCoAttestationConfig.class,
ServerCoCoAttestationReport.class,
ServerGroup.class,
ServerGroupManager.class,
ServerGroupType.class,
ServerPath.class,
ServerPathId.class,
SoftwareEnvironmentTarget.class,
SoftwareProjectSource.class,
SslCryptoKey.class,
StateChange.class,
SUSEProductSCCRepository.class,
Task.class,
TemplateString.class,
TokenChannelAppStream.class,
Token.class,
UserGroupImpl.class,
UserGroupMembers.class,
UserGroupMembersId.class,
UserImpl.class,
UserInfo.class,
UserNotification.class,
VHMCredentials.class,
VirtualHostManagerNodeInfo.class
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.EmptyInterceptor;
import org.hibernate.type.StringType;
import org.hibernate.type.Type;

import java.io.Serializable;
Expand Down Expand Up @@ -59,8 +58,7 @@ protected static boolean emptyStringToNull(Object entity, Serializable id,
boolean modified = false;

for (int i = 0; i < types.length; i++) {
// type is string (VARCHAR) and state is empty string
if ((types[i] instanceof StringType) && "".equals(state[i])) {
if ("".equals(state[i])) {
if (LOG.isDebugEnabled()) {
LOG.debug("Object {} is setting empty string {}", entity.getClass().getCanonicalName(),
propertyNames[i]);
Expand Down
Loading
Loading