modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java | 8
modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleDeployment.java | 14
modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java | 4
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PluginConfigurationUpdate.java | 4
modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java | 6
modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceType.java | 2
modules/core/domain/src/main/java/org/rhq/core/domain/content/InstalledPackageHistory.java | 10
modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageType.java | 10
modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java | 42
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleDeploymentCriteria.java | 5
modules/core/domain/src/main/java/org/rhq/core/domain/dashboard/Dashboard.java | 10
modules/core/domain/src/main/java/org/rhq/core/domain/discovery/ResourceSyncInfo.java | 4
modules/core/domain/src/main/java/org/rhq/core/domain/event/Event.java | 2
modules/core/domain/src/main/java/org/rhq/core/domain/event/EventDefinition.java | 2
modules/core/domain/src/main/java/org/rhq/core/domain/event/EventSource.java | 2
modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java | 582 +++++-----
modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java | 2
modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java | 54
modules/core/domain/src/main/java/org/rhq/core/domain/measurement/ResourceAvailability.java | 390 +++---
modules/core/domain/src/main/java/org/rhq/core/domain/measurement/calltime/CallTimeDataKey.java | 218 +--
modules/core/domain/src/main/java/org/rhq/core/domain/operation/OperationHistory.java | 4
modules/core/domain/src/main/java/org/rhq/core/domain/operation/ResourceOperationHistory.java | 8
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java | 8
modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java | 24
modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java | 55
modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/SelectBundleVersionStep.java | 1
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java | 1
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java | 1
29 files changed, 734 insertions(+), 741 deletions(-)
New commits:
commit 48bf82fcfaaf7cd9d3aa7549de7d49d793964b5f
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue May 10 15:14:44 2011 -0400
Related to [BZ 702390 - Large number of BundleDeployments for a single Bundle causes fetch serialization issues]
Ensure (optional=false) set for LAZY load required (i.e. nullable = false) associations.
This should ensure efficient lazy load.
For clarity, and to give Hibernate as many hints as possible, mark all
XxxToOne associations with the 'optional' attribute, whether true or false,
lazy or not. And set nullable on the JoinColumn annotations as well.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java
index 640648b..355c854 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java
@@ -299,8 +299,8 @@ public class AlertCondition implements Serializable {
@Enumerated(EnumType.STRING)
private AlertConditionCategory category;
- @JoinColumn(name = "MEASUREMENT_DEFINITION_ID", referencedColumnName = "ID")
- @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "MEASUREMENT_DEFINITION_ID", referencedColumnName = "ID", nullable = true)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
@XmlTransient
private MeasurementDefinition measurementDefinition;
@@ -319,8 +319,8 @@ public class AlertCondition implements Serializable {
@Column(name = "TRIGGER_ID")
private Integer triggerId;
- @JoinColumn(name = "ALERT_DEFINITION_ID", referencedColumnName = "ID")
- @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "ALERT_DEFINITION_ID", referencedColumnName = "ID", nullable = true)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
@XmlTransient
private AlertDefinition alertDefinition;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
index cfbb9d7..31fc9ab 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
@@ -111,11 +111,11 @@ public class BundleVersion implements Serializable {
private String recipe;
@JoinColumn(name = "BUNDLE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
private Bundle bundle;
@JoinColumn(name = "CONFIG_DEF_ID", referencedColumnName = "ID", nullable = true)
- @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
private ConfigurationDefinition configurationDefinition;
@OneToMany(mappedBy = "bundleVersion", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PluginConfigurationUpdate.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PluginConfigurationUpdate.java
index e7c5845..32a526e 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PluginConfigurationUpdate.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PluginConfigurationUpdate.java
@@ -139,12 +139,12 @@ public class PluginConfigurationUpdate extends AbstractResourceConfigurationUpda
public static final String QUERY_DELETE_GROUP_UPDATE = "pluginConfigurationUpdate.deleteGroupUpdate";
@JoinColumn(name = "PLUGIN_CONFIG_RES_ID", referencedColumnName = "ID", nullable = true)
- @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
+ @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY, optional = true)
@XmlTransient
private Resource resource;
@JoinColumn(name = "AGG_PLUGIN_UPDATE_ID", referencedColumnName = "ID", nullable = true)
- @ManyToOne
+ @ManyToOne(optional = true)
private GroupPluginConfigurationUpdate groupConfigurationUpdate;
protected PluginConfigurationUpdate() {
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java
index 00877bd..a94c4ab 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSource.java
@@ -59,7 +59,7 @@ import org.rhq.core.domain.configuration.Configuration;
* @author Jason Dobies
*/
@Entity
-@NamedQueries({
+@NamedQueries( {
@NamedQuery(name = ContentSource.QUERY_FIND_ALL, query = "SELECT cs FROM ContentSource cs "),
@NamedQuery(name = ContentSource.QUERY_FIND_ALL_WITH_CONFIG, query = "SELECT cs FROM ContentSource cs LEFT JOIN FETCH cs.configuration"),
@NamedQuery(name = ContentSource.QUERY_FIND_BY_NAME_AND_TYPENAME, query = "SELECT cs " + " FROM ContentSource cs "
@@ -94,7 +94,7 @@ public class ContentSource implements Serializable {
private int id;
@JoinColumn(name = "CONTENT_SOURCE_TYPE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne
+ @ManyToOne(optional = false)
private ContentSourceType contentSourceType;
@Column(name = "NAME", nullable = false)
@@ -117,7 +117,7 @@ public class ContentSource implements Serializable {
private String loadErrorMessage;
@JoinColumn(name = "CONFIGURATION_ID", referencedColumnName = "ID", nullable = true)
- @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
private Configuration configuration;
@Column(name = "CREATION_TIME", nullable = false)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceType.java
index 2c6b41d..52e6cce 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceType.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/ContentSourceType.java
@@ -100,7 +100,7 @@ public class ContentSourceType implements Serializable {
private String defaultSyncSchedule = "0 0 3 * * ?";
@JoinColumn(name = "SOURCE_CONFIG_DEF_ID", nullable = true)
- @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
@XmlTransient
private ConfigurationDefinition contentSourceConfigurationDefinition;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/InstalledPackageHistory.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/InstalledPackageHistory.java
index 9b21fe2..5d52d7f 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/InstalledPackageHistory.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/InstalledPackageHistory.java
@@ -54,7 +54,7 @@ import org.rhq.core.domain.resource.Resource;
* @author Jason Dobies
*/
@Entity
-@NamedQueries({
+@NamedQueries( {
@NamedQuery(name = InstalledPackageHistory.QUERY_FIND_CONFIG_BY_PACKAGE_VERSION_AND_REQ, query = "SELECT dcv FROM InstalledPackageHistory iph JOIN iph.deploymentConfigurationValues dcv "
+ "WHERE iph.packageVersion = :packageVersion "
+ "AND iph.contentServiceRequest = :contentServiceRequest "
@@ -92,7 +92,7 @@ public class InstalledPackageHistory implements Serializable {
private int id;
@JoinColumn(name = "PACKAGE_VERSION_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne
+ @ManyToOne(optional = false)
private PackageVersion packageVersion;
@Column(name = "STATUS", nullable = false)
@@ -115,7 +115,7 @@ public class InstalledPackageHistory implements Serializable {
* case that the package type does not define any deploy time properties.
*/
@JoinColumn(name = "DEPLOYMENT_CONFIG_ID", referencedColumnName = "ID", nullable = true)
- @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+ @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
private Configuration deploymentConfigurationValues;
/**
@@ -132,11 +132,11 @@ public class InstalledPackageHistory implements Serializable {
* This history item described a package that was on this resource.
*/
@JoinColumn(name = "RESOURCE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne
+ @ManyToOne(optional = false)
private Resource resource;
@JoinColumn(name = "CONTENT_SERVICE_REQUEST_ID", referencedColumnName = "ID", nullable = true)
- @ManyToOne
+ @ManyToOne(optional = true)
private ContentServiceRequest contentServiceRequest;
public int getId() {
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageType.java
index d9e3ea3..9c78af5 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageType.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageType.java
@@ -41,7 +41,6 @@ import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
-import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlTransient;
@@ -72,8 +71,7 @@ import org.rhq.core.domain.resource.ResourceType;
+ "JOIN pt.resourceType rt "
+ "LEFT JOIN FETCH pt.deploymentConfigurationDefinition cd "
+ "LEFT JOIN FETCH cd.templates cts " + "WHERE rt.id = :typeId AND pt.isCreationData = true"),
- @NamedQuery(name = PackageType.QUERY_DYNAMIC_CONFIG_VALUES, query = "SELECT pt.resourceType.plugin || ' - ' || pt.resourceType.name || ' - ' || pt.displayName, pt.name FROM PackageType AS pt")
-})
+ @NamedQuery(name = PackageType.QUERY_DYNAMIC_CONFIG_VALUES, query = "SELECT pt.resourceType.plugin || ' - ' || pt.resourceType.name || ' - ' || pt.displayName, pt.name FROM PackageType AS pt") })
@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_PACKAGE_TYPE_ID_SEQ")
@Table(name = "RHQ_PACKAGE_TYPE")
@XmlAccessorType(XmlAccessType.FIELD)
@@ -121,18 +119,18 @@ public class PackageType implements Serializable {
private boolean supportsArchitecture;
@JoinColumn(name = "DEPLOYMENT_CONFIG_DEF_ID", referencedColumnName = "ID", nullable = true)
- @OneToOne(fetch = FetchType.LAZY, cascade = { CascadeType.ALL })
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, optional = true)
private ConfigurationDefinition deploymentConfigurationDefinition;
@JoinColumn(name = "PACKAGE_EXTRA_CONFIG_ID", referencedColumnName = "ID", nullable = true)
- @OneToOne(fetch = FetchType.LAZY, cascade = { CascadeType.ALL })
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, optional = true)
private ConfigurationDefinition packageExtraPropertiesDefinition;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "packageType", cascade = { CascadeType.REMOVE })
private Set<Package> packages;
@JoinColumn(name = "RESOURCE_TYPE_ID", referencedColumnName = "ID", nullable = true)
- @ManyToOne
+ @ManyToOne(optional = true)
@XmlTransient
private ResourceType resourceType;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java
index 76dbff4..d64d8a5 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java
@@ -78,7 +78,7 @@ import org.rhq.core.domain.util.OSGiVersionComparator;
+ " WHERE pv.generalPackage.name = :packageName "
+ " AND pv.generalPackage.packageType.name = :packageTypeName "
+ " AND pv.generalPackage.packageType.resourceType = :resourceType "
- + " AND pv.architecture.name = :architectureName " + " AND pv.version = :version "),
+ + " AND pv.architecture.name = :architectureName " + " AND pv.version = :version "),
@NamedQuery(name = PackageVersion.QUERY_FIND_ID_BY_PACKAGE_DETAILS_KEY_AND_RES_ID, query = "SELECT pv.id "
+ " FROM PackageVersion AS pv " + " JOIN pv.generalPackage.packageType.resourceType.resources r "
+ " WHERE pv.generalPackage.name = :packageName "
@@ -251,17 +251,13 @@ import org.rhq.core.domain.util.OSGiVersionComparator;
+ "WHERE p.id IN (SELECT pv.generalPackage.id FROM PackageVersion AS pv WHERE pv.fileName = :rpmName)"),
@NamedQuery(name = PackageVersion.QUERY_FIND_PACKAGEVERSION_BY_FILENAME, query = "SELECT pv FROM PackageVersion AS pv WHERE pv.fileName = :rpmName)"),
@NamedQuery(name = PackageVersion.QUERY_FIND_BY_PACKAGE_AND_REPO_ID, query = "SELECT pv"
- + " FROM PackageVersion pv"
- + " JOIN pv.repoPackageVersions rpv"
- + " WHERE pv.generalPackage.id = :packageId"
+ + " FROM PackageVersion pv" + " JOIN pv.repoPackageVersions rpv" + " WHERE pv.generalPackage.id = :packageId"
+ " AND rpv.repo.id = :repoId"),
- @NamedQuery(name = PackageVersion.QUERY_FIND_DELETEABLE_IDS_IN_REPO, query = "SELECT pv.id FROM PackageVersion pv"
+ @NamedQuery(name = PackageVersion.QUERY_FIND_DELETEABLE_IDS_IN_REPO, query = "SELECT pv.id FROM PackageVersion pv"
+ " WHERE (pv.id, 1) IN"
+ " (SELECT pv2.id, (SELECT COUNT(rpv) FROM RepoPackageVersion rpv WHERE rpv.packageVersion.id = pv2.id)"
- + " FROM PackageVersion pv2"
- + " WHERE pv2.id IN ( :packageVersionIds )"
- + " AND pv2.id IN (SELECT rpv.packageVersion.id FROM RepoPackageVersion rpv WHERE rpv.repo.id = :repoId))")
-})
+ + " FROM PackageVersion pv2" + " WHERE pv2.id IN ( :packageVersionIds )"
+ + " AND pv2.id IN (SELECT rpv.packageVersion.id FROM RepoPackageVersion rpv WHERE rpv.repo.id = :repoId))") })
@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_PACKAGE_VERSION_ID_SEQ")
@Table(name = "RHQ_PACKAGE_VERSION")
public class PackageVersion implements Serializable {
@@ -300,7 +296,7 @@ public class PackageVersion implements Serializable {
public static final String QUERY_FIND_PACKAGE_BY_FILENAME = "PackageVersion.findPackageByFilename";
public static final String QUERY_FIND_PACKAGEVERSION_BY_FILENAME = "PackageVersion.findPackageVersionByFilename";
public static final String QUERY_FIND_DELETEABLE_IDS_IN_REPO = "PackageVersion.findDeleteableVersionIds";
-
+
/**
* This is a default {@link Comparator} implementation for package versions.
* If the package versions being compared both have non-null {@link PackageVersion#getVersion() versions}
@@ -319,9 +315,9 @@ public class PackageVersion implements Serializable {
public int compare(PackageVersion p1, PackageVersion p2) {
String v1 = p1.getVersion();
String v2 = p2.getVersion();
-
+
OSGiVersionComparator c = new OSGiVersionComparator();
-
+
if (v1 != null && v2 != null) {
try {
return c.compare(v1, v2);
@@ -329,23 +325,23 @@ public class PackageVersion implements Serializable {
//well, this can happen.. not all packages have OSGi type versions.
}
}
-
+
if (p1.getFileCreatedDate() != null && p2.getFileCreatedDate() != null) {
return p1.getFileCreatedDate().compareTo(p2.getFileCreatedDate());
}
-
+
//hmm... there's actually nothing we can sort these two by..
//let's compare them by id - the one inserted sooner will have a lower id
-
+
return Integer.valueOf(p1.getId()).compareTo(p2.getId());
}
};
-
+
/**
* @see DefaultPackageVersionComparator
*/
public static final DefaultPackageVersionComparator DEFAULT_COMPARATOR = new DefaultPackageVersionComparator();
-
+
// Attributes --------------------------------------------
@Column(name = "ID", nullable = false)
@@ -354,7 +350,7 @@ public class PackageVersion implements Serializable {
private int id;
@JoinColumn(name = "PACKAGE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST })
+ @ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST }, optional = false)
private Package generalPackage;
@Column(name = "DISPLAY_NAME", nullable = true)
@@ -373,7 +369,7 @@ public class PackageVersion implements Serializable {
private String displayVersion;
@JoinColumn(name = "ARCHITECTURE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
+ @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST, optional = false)
private Architecture architecture;
@Column(name = "FILE_NAME", nullable = true)
@@ -401,7 +397,7 @@ public class PackageVersion implements Serializable {
private byte[] metadata;
@JoinColumn(name = "CONFIG_ID", referencedColumnName = "ID", nullable = true)
- @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+ @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
private Configuration extraProperties;
@OneToMany(mappedBy = "packageVersion", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@@ -415,11 +411,11 @@ public class PackageVersion implements Serializable {
@OneToMany(mappedBy = "packageVersion", fetch = FetchType.LAZY)
private Set<InstalledPackageHistory> installedPackageHistory;
- // No longer use cascade PERSIST on this. We'll associate it manually due to intracacies in blob handling
+ // No longer use cascade PERSIST on this. We'll associate it manually due to intracacies in blob handling
@JoinColumn(name = "PACKAGE_BITS_ID", referencedColumnName = "ID", nullable = true)
- @OneToOne(cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
+ @OneToOne(cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY, optional = true)
@XmlTransient
- private PackageBits packageBits; // do NOT eager load this - is has the BLOB contents of the package
+ private PackageBits packageBits;
@OneToMany(mappedBy = "packageVersion", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
private Set<ProductVersionPackageVersion> productVersionPackageVersions;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/dashboard/Dashboard.java b/modules/core/domain/src/main/java/org/rhq/core/domain/dashboard/Dashboard.java
index 2f5d41e..601d817 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/dashboard/Dashboard.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/dashboard/Dashboard.java
@@ -88,20 +88,20 @@ public class Dashboard implements Serializable {
@Column(name = "SHARED", nullable = false)
private boolean shared = false;
- @JoinColumn(name = "CONFIGURATION_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL })
+ @JoinColumn(name = "CONFIGURATION_ID", referencedColumnName = "ID", nullable = true)
+ @OneToOne(cascade = { CascadeType.ALL }, optional = true)
private Configuration configuration = new Configuration();
@JoinColumn(name = "SUBJECT_ID", nullable = false)
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
private Subject owner;
@JoinColumn(name = "RESOURCE_ID", nullable = true)
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
private Resource resource;
@JoinColumn(name = "GROUP_ID", nullable = true)
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
private ResourceGroup group;
@OneToMany(mappedBy = "dashboard", fetch = FetchType.EAGER)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/discovery/ResourceSyncInfo.java b/modules/core/domain/src/main/java/org/rhq/core/domain/discovery/ResourceSyncInfo.java
index 4bcc267..eb3b97d 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/discovery/ResourceSyncInfo.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/discovery/ResourceSyncInfo.java
@@ -72,8 +72,8 @@ public class ResourceSyncInfo implements Serializable {
@Enumerated(EnumType.STRING)
private InventoryStatus inventoryStatus;
- @JoinColumn(name = "PARENT_RESOURCE_ID")
- @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "PARENT_RESOURCE_ID", nullable = true)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
private ResourceSyncInfo parent;
@OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/event/Event.java b/modules/core/domain/src/main/java/org/rhq/core/domain/event/Event.java
index dfb8d34..f0df086 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/event/Event.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/event/Event.java
@@ -112,7 +112,7 @@ public class Event implements Serializable {
private int id;
@JoinColumn(name = "EVENT_SOURCE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
private EventSource source;
@Column(name = "TIMESTAMP", nullable = false)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/event/EventDefinition.java b/modules/core/domain/src/main/java/org/rhq/core/domain/event/EventDefinition.java
index 75f7b73..5db91bb 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/event/EventDefinition.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/event/EventDefinition.java
@@ -58,7 +58,7 @@ public class EventDefinition implements Serializable {
private int id;
@JoinColumn(name = "RESOURCE_TYPE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
private ResourceType resourceType;
@Column(name = "RESOURCE_TYPE_ID", insertable = false, updatable = false)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/event/EventSource.java b/modules/core/domain/src/main/java/org/rhq/core/domain/event/EventSource.java
index 2424edb..f1d8108 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/event/EventSource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/event/EventSource.java
@@ -74,7 +74,7 @@ public class EventSource implements Serializable {
private EventDefinition eventDefinition;
@JoinColumn(name = "RESOURCE_ID", nullable = false)
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
private Resource resource;
@Column(name = "RESOURCE_ID", insertable = false, updatable = false)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java
index 260adc5..9647632 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java
@@ -1,292 +1,292 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.rhq.core.domain.measurement;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
-
-import org.rhq.core.domain.resource.Resource;
-
-/**
- * This Entity Bean stores information about resource availability. The actual data is run-length encoded. This means
- * that the {@link #getAvailabilityType() availability state} (e.g. UP or DOWN) changed at the
- * {@link #getStartTime() start time}.
- *
- * This provides historical data regarding when a resource was up or down. To get the current availability
- * of a resource, it is best to use the {@link ResourceAvailability} entity instead.
- *
- * @see ResourceAvailability
- *
- * @author Heiko W. Rupp
- * @author John Mazzitelli
- */
-@Entity
-@NamedQueries( { @NamedQuery(name = Availability.FIND_CURRENT_BY_RESOURCE, query = "" //
- + " SELECT av " //
- + " FROM Availability av " //
- + " WHERE av.resource.id = :resourceId " //
- + " AND av.endTime IS NULL " //
- + "ORDER BY av.startTime ASC "), // this order by is on purpose - for handling NonUniqueResultException problems
- @NamedQuery(name = Availability.FIND_BY_RESOURCE, query = "" //
- + " SELECT av " //
- + " FROM Availability av " //
- + " WHERE av.resource.id = :resourceId " //
- + "ORDER BY av.startTime ASC"), //
- @NamedQuery(name = Availability.FIND_BY_RESOURCE_NO_SORT, query = "" //
- + "SELECT av " //
- + " FROM Availability av " //
- + " WHERE av.resource.id = :resourceId "), //
-
- // get all current resource availabilities for those that do not match a given availability type
- @NamedQuery(name = Availability.FIND_NONMATCHING_WITH_RESOURCE_ID_BY_AGENT_AND_TYPE, query = "" //
- + "SELECT new org.rhq.core.domain.resource.composite.ResourceIdWithAvailabilityComposite(av.resource.id, av) " //
- + " FROM Availability av " //
- + " WHERE av.resource.agent.id = :agentId " //
- + " AND ((av.availabilityType <> :availabilityType AND :availabilityType IS NOT NULL) " //
- + " OR (av.availabilityType IS NOT NULL AND :availabilityType IS NULL) " //
- + " OR (av.availabilityType IS NULL AND :availabilityType IS NOT NULL))" //
- + " AND av.endTime IS NULL"), //
- @NamedQuery(name = Availability.FIND_FOR_RESOURCE_WITHIN_INTERVAL, query = "" //
- + "SELECT av FROM Availability av " //
- + " WHERE av.resource.id = :resourceId " //
- + " AND ((av.startTime <= :start AND (av.endTime >= :start OR av.endTime IS NULL) ) " /* availability straddles :start */
- + " OR (av.startTime BETWEEN :start AND :end)) " /* interval straddles availability.startTime */
- + "ORDER BY av.startTime ASC"), //
- @NamedQuery(name = Availability.FIND_FOR_RESOURCE_GROUP_WITHIN_INTERVAL, query = "" //
- + "SELECT av FROM Availability av " //
- + " WHERE av.resource.id IN ( SELECT ires.id " //
- + " FROM ResourceGroup rg " //
- + " JOIN rg.implicitResources ires " //
- + " WHERE rg.id = :groupId ) " //
- + " AND ((av.startTime <= :start AND (av.endTime >= :start OR av.endTime IS NULL) ) " /* availability straddles :start */
- + " OR (av.startTime BETWEEN :start AND :end)) " /* interval straddles availability.startTime */
- + "ORDER BY av.startTime ASC"), //
- @NamedQuery(name = Availability.FIND_FOR_AUTO_GROUP_WITHIN_INTERVAL, query = "" //
- + " SELECT av FROM Availability av " //
- + " JOIN av.resource res JOIN res.parentResource parent JOIN res.resourceType type " //
- + " WHERE parent.id = :parentId " //
- + " AND type.id = :typeId " //
- + " AND ((av.startTime <= :start AND (av.endTime >= :start OR av.endTime IS NULL)) " /* availability straddles :start */
- + " OR (av.startTime BETWEEN :start AND :end)) " /* interval straddles availability.startTime */
- + "ORDER BY av.startTime ASC"), //
- @NamedQuery(name = Availability.FIND_BY_RESOURCE_AND_DATE, query = "" //
- + "SELECT av FROM Availability av " //
- + " WHERE av.resource.id = :resourceId " //
- + " AND av.startTime <= :aTime " //
- + " AND ( av.endTime >= :aTime OR av.endTime IS NULL ) "), //
- @NamedQuery(name = Availability.QUERY_DELETE_BY_RESOURCES, query = "" //
- + " DELETE Availability a " //
- + " WHERE a.resource.id IN ( :resourceIds )") })
-@SequenceGenerator(name = "Generator", sequenceName = "RHQ_AVAILABILITY_ID_SEQ")
-@Table(name = "RHQ_AVAILABILITY")
-public class Availability implements Serializable {
- private static final long serialVersionUID = 1L;
-
- public static final String FIND_CURRENT_BY_RESOURCE = "Availability.findCurrentByResource";
- public static final String FIND_BY_RESOURCE = "Availability.findByResource";
- public static final String FIND_BY_RESOURCE_NO_SORT = "Availability.findByResourceNoSort";
- public static final String FIND_NONMATCHING_WITH_RESOURCE_ID_BY_AGENT_AND_TYPE = "Availability.findNonmatchingWithResourceIdByAgentAndType";
- public static final String FIND_FOR_RESOURCE_WITHIN_INTERVAL = "Availability.findForResourceWithinInterval";
- public static final String FIND_FOR_RESOURCE_GROUP_WITHIN_INTERVAL = "Availability.findForResourceGroupWithinInterval";
- public static final String FIND_FOR_AUTO_GROUP_WITHIN_INTERVAL = "Availability.findForAutoGroupWithinInterval";
- public static final String FIND_BY_RESOURCE_AND_DATE = "Availability.findByResourceAndDate";
- public static final String QUERY_DELETE_BY_RESOURCES = "Availability.deleteByResources";
-
- public static final String NATIVE_QUERY_PURGE = "DELETE FROM RHQ_AVAILABILITY WHERE END_TIME < ?";
-
- @Column(name = "ID", nullable = false)
- @GeneratedValue(strategy = GenerationType.AUTO, generator = "Generator")
- @Id
- private int id;
-
- /**
- * Start time of this availability state
- */
- @Column(name = "START_TIME", nullable = false)
- private long startTime;
-
- /**
- * End time of this availability state (which is the start of the next availability time period)
- */
- @Column(name = "END_TIME", nullable = true)
- private Long endTime;
-
- /**
- * Availability state for this time period
- */
- @Column(name = "AVAILABILITY_TYPE", nullable = true)
- @Enumerated(EnumType.ORDINAL)
- private AvailabilityType availabilityType;
-
- @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne(fetch = FetchType.LAZY)
- private Resource resource;
-
- protected Availability() {
- // for JPA use only
- }
-
- /**
- * Constructor for {@link Availability}. If <code>type</code> is <code>null</code>, it will be considered unknown.
- *
- * @param resource
- * @param startTime
- * @param type
- */
- public Availability(Resource resource, Date startTime, AvailabilityType type) {
- if (resource == null) {
- throw new IllegalArgumentException("resource==null");
- }
-
- this.resource = resource;
- this.availabilityType = type;
- this.startTime = (startTime != null) ? startTime.getTime() : new Date().getTime();
- this.endTime = null;
- }
-
- public int getId() {
- return id;
- }
-
- public Resource getResource() {
- return resource;
- }
-
- public Date getStartTime() {
- return new Date(startTime);
- }
-
- public void setStartTime(Date startTime) {
- this.startTime = startTime.getTime();
- }
-
- /**
- * The end time of this availability period. This will be <code>null</code> if this represents the last known
- * availability.
- *
- * @return end of the availability period
- */
- public Date getEndTime() {
- return (endTime != null) ? new Date(endTime.longValue()) : null;
- }
-
- public void setEndTime(Date endTime) {
- this.endTime = (endTime != null) ? endTime.getTime() : null;
- }
-
- /**
- * Indicates the availability status as either UP or DOWN; if <code>null</code> is returned, the status is unknown.
- *
- * @return availability status
- */
- public AvailabilityType getAvailabilityType() {
- return availabilityType;
- }
-
- /**
- * Sets the availability status. This can be <code>null</code> to indicate an "unknown" availability status.
- *
- * @param availabilityType
- */
- public void setAvailabilityType(AvailabilityType availabilityType) {
- this.availabilityType = availabilityType;
- }
-
- @Override
- public String toString() {
- return "Availability[id=" + id + ",type=" + this.availabilityType + ",start-time=" + getStartTime()
- + ",end-time=" + getEndTime() + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = (prime * result) + ((availabilityType == null) ? 0 : availabilityType.hashCode());
- result = (prime * result) + ((endTime == null) ? 0 : endTime.hashCode());
- result = (prime * result) + ((resource == null) ? 0 : resource.hashCode());
- result = (prime * result) + (int) (startTime ^ (startTime >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (obj == null) {
- return false;
- }
-
- if (!(obj instanceof Availability)) {
- return false;
- }
-
- final Availability other = (Availability) obj;
- if (availabilityType == null) {
- if (other.availabilityType != null) {
- return false;
- }
- } else if (!availabilityType.equals(other.availabilityType)) {
- return false;
- }
-
- if (endTime == null) {
- if (other.endTime != null) {
- return false;
- }
- } else if (!endTime.equals(other.endTime)) {
- return false;
- }
-
- if (resource == null) {
- if (other.resource != null) {
- return false;
- }
- } else if (!resource.equals(other.resource)) {
- return false;
- }
-
- if (startTime != other.startTime) {
- return false;
- }
-
- return true;
- }
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.core.domain.measurement;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import org.rhq.core.domain.resource.Resource;
+
+/**
+ * This Entity Bean stores information about resource availability. The actual data is run-length encoded. This means
+ * that the {@link #getAvailabilityType() availability state} (e.g. UP or DOWN) changed at the
+ * {@link #getStartTime() start time}.
+ *
+ * This provides historical data regarding when a resource was up or down. To get the current availability
+ * of a resource, it is best to use the {@link ResourceAvailability} entity instead.
+ *
+ * @see ResourceAvailability
+ *
+ * @author Heiko W. Rupp
+ * @author John Mazzitelli
+ */
+@Entity
+@NamedQueries( { @NamedQuery(name = Availability.FIND_CURRENT_BY_RESOURCE, query = "" //
+ + " SELECT av " //
+ + " FROM Availability av " //
+ + " WHERE av.resource.id = :resourceId " //
+ + " AND av.endTime IS NULL " //
+ + "ORDER BY av.startTime ASC "), // this order by is on purpose - for handling NonUniqueResultException problems
+ @NamedQuery(name = Availability.FIND_BY_RESOURCE, query = "" //
+ + " SELECT av " //
+ + " FROM Availability av " //
+ + " WHERE av.resource.id = :resourceId " //
+ + "ORDER BY av.startTime ASC"), //
+ @NamedQuery(name = Availability.FIND_BY_RESOURCE_NO_SORT, query = "" //
+ + "SELECT av " //
+ + " FROM Availability av " //
+ + " WHERE av.resource.id = :resourceId "), //
+
+ // get all current resource availabilities for those that do not match a given availability type
+ @NamedQuery(name = Availability.FIND_NONMATCHING_WITH_RESOURCE_ID_BY_AGENT_AND_TYPE, query = "" //
+ + "SELECT new org.rhq.core.domain.resource.composite.ResourceIdWithAvailabilityComposite(av.resource.id, av) " //
+ + " FROM Availability av " //
+ + " WHERE av.resource.agent.id = :agentId " //
+ + " AND ((av.availabilityType <> :availabilityType AND :availabilityType IS NOT NULL) " //
+ + " OR (av.availabilityType IS NOT NULL AND :availabilityType IS NULL) " //
+ + " OR (av.availabilityType IS NULL AND :availabilityType IS NOT NULL))" //
+ + " AND av.endTime IS NULL"), //
+ @NamedQuery(name = Availability.FIND_FOR_RESOURCE_WITHIN_INTERVAL, query = "" //
+ + "SELECT av FROM Availability av " //
+ + " WHERE av.resource.id = :resourceId " //
+ + " AND ((av.startTime <= :start AND (av.endTime >= :start OR av.endTime IS NULL) ) " /* availability straddles :start */
+ + " OR (av.startTime BETWEEN :start AND :end)) " /* interval straddles availability.startTime */
+ + "ORDER BY av.startTime ASC"), //
+ @NamedQuery(name = Availability.FIND_FOR_RESOURCE_GROUP_WITHIN_INTERVAL, query = "" //
+ + "SELECT av FROM Availability av " //
+ + " WHERE av.resource.id IN ( SELECT ires.id " //
+ + " FROM ResourceGroup rg " //
+ + " JOIN rg.implicitResources ires " //
+ + " WHERE rg.id = :groupId ) " //
+ + " AND ((av.startTime <= :start AND (av.endTime >= :start OR av.endTime IS NULL) ) " /* availability straddles :start */
+ + " OR (av.startTime BETWEEN :start AND :end)) " /* interval straddles availability.startTime */
+ + "ORDER BY av.startTime ASC"), //
+ @NamedQuery(name = Availability.FIND_FOR_AUTO_GROUP_WITHIN_INTERVAL, query = "" //
+ + " SELECT av FROM Availability av " //
+ + " JOIN av.resource res JOIN res.parentResource parent JOIN res.resourceType type " //
+ + " WHERE parent.id = :parentId " //
+ + " AND type.id = :typeId " //
+ + " AND ((av.startTime <= :start AND (av.endTime >= :start OR av.endTime IS NULL)) " /* availability straddles :start */
+ + " OR (av.startTime BETWEEN :start AND :end)) " /* interval straddles availability.startTime */
+ + "ORDER BY av.startTime ASC"), //
+ @NamedQuery(name = Availability.FIND_BY_RESOURCE_AND_DATE, query = "" //
+ + "SELECT av FROM Availability av " //
+ + " WHERE av.resource.id = :resourceId " //
+ + " AND av.startTime <= :aTime " //
+ + " AND ( av.endTime >= :aTime OR av.endTime IS NULL ) "), //
+ @NamedQuery(name = Availability.QUERY_DELETE_BY_RESOURCES, query = "" //
+ + " DELETE Availability a " //
+ + " WHERE a.resource.id IN ( :resourceIds )") })
+@SequenceGenerator(name = "Generator", sequenceName = "RHQ_AVAILABILITY_ID_SEQ")
+@Table(name = "RHQ_AVAILABILITY")
+public class Availability implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public static final String FIND_CURRENT_BY_RESOURCE = "Availability.findCurrentByResource";
+ public static final String FIND_BY_RESOURCE = "Availability.findByResource";
+ public static final String FIND_BY_RESOURCE_NO_SORT = "Availability.findByResourceNoSort";
+ public static final String FIND_NONMATCHING_WITH_RESOURCE_ID_BY_AGENT_AND_TYPE = "Availability.findNonmatchingWithResourceIdByAgentAndType";
+ public static final String FIND_FOR_RESOURCE_WITHIN_INTERVAL = "Availability.findForResourceWithinInterval";
+ public static final String FIND_FOR_RESOURCE_GROUP_WITHIN_INTERVAL = "Availability.findForResourceGroupWithinInterval";
+ public static final String FIND_FOR_AUTO_GROUP_WITHIN_INTERVAL = "Availability.findForAutoGroupWithinInterval";
+ public static final String FIND_BY_RESOURCE_AND_DATE = "Availability.findByResourceAndDate";
+ public static final String QUERY_DELETE_BY_RESOURCES = "Availability.deleteByResources";
+
+ public static final String NATIVE_QUERY_PURGE = "DELETE FROM RHQ_AVAILABILITY WHERE END_TIME < ?";
+
+ @Column(name = "ID", nullable = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "Generator")
+ @Id
+ private int id;
+
+ /**
+ * Start time of this availability state
+ */
+ @Column(name = "START_TIME", nullable = false)
+ private long startTime;
+
+ /**
+ * End time of this availability state (which is the start of the next availability time period)
+ */
+ @Column(name = "END_TIME", nullable = true)
+ private Long endTime;
+
+ /**
+ * Availability state for this time period
+ */
+ @Column(name = "AVAILABILITY_TYPE", nullable = true)
+ @Enumerated(EnumType.ORDINAL)
+ private AvailabilityType availabilityType;
+
+ @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "ID", nullable = false)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
+ private Resource resource;
+
+ protected Availability() {
+ // for JPA use only
+ }
+
+ /**
+ * Constructor for {@link Availability}. If <code>type</code> is <code>null</code>, it will be considered unknown.
+ *
+ * @param resource
+ * @param startTime
+ * @param type
+ */
+ public Availability(Resource resource, Date startTime, AvailabilityType type) {
+ if (resource == null) {
+ throw new IllegalArgumentException("resource==null");
+ }
+
+ this.resource = resource;
+ this.availabilityType = type;
+ this.startTime = (startTime != null) ? startTime.getTime() : new Date().getTime();
+ this.endTime = null;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public Date getStartTime() {
+ return new Date(startTime);
+ }
+
+ public void setStartTime(Date startTime) {
+ this.startTime = startTime.getTime();
+ }
+
+ /**
+ * The end time of this availability period. This will be <code>null</code> if this represents the last known
+ * availability.
+ *
+ * @return end of the availability period
+ */
+ public Date getEndTime() {
+ return (endTime != null) ? new Date(endTime.longValue()) : null;
+ }
+
+ public void setEndTime(Date endTime) {
+ this.endTime = (endTime != null) ? endTime.getTime() : null;
+ }
+
+ /**
+ * Indicates the availability status as either UP or DOWN; if <code>null</code> is returned, the status is unknown.
+ *
+ * @return availability status
+ */
+ public AvailabilityType getAvailabilityType() {
+ return availabilityType;
+ }
+
+ /**
+ * Sets the availability status. This can be <code>null</code> to indicate an "unknown" availability status.
+ *
+ * @param availabilityType
+ */
+ public void setAvailabilityType(AvailabilityType availabilityType) {
+ this.availabilityType = availabilityType;
+ }
+
+ @Override
+ public String toString() {
+ return "Availability[id=" + id + ",type=" + this.availabilityType + ",start-time=" + getStartTime()
+ + ",end-time=" + getEndTime() + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = (prime * result) + ((availabilityType == null) ? 0 : availabilityType.hashCode());
+ result = (prime * result) + ((endTime == null) ? 0 : endTime.hashCode());
+ result = (prime * result) + ((resource == null) ? 0 : resource.hashCode());
+ result = (prime * result) + (int) (startTime ^ (startTime >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (!(obj instanceof Availability)) {
+ return false;
+ }
+
+ final Availability other = (Availability) obj;
+ if (availabilityType == null) {
+ if (other.availabilityType != null) {
+ return false;
+ }
+ } else if (!availabilityType.equals(other.availabilityType)) {
+ return false;
+ }
+
+ if (endTime == null) {
+ if (other.endTime != null) {
+ return false;
+ }
+ } else if (!endTime.equals(other.endTime)) {
+ return false;
+ }
+
+ if (resource == null) {
+ if (other.resource != null) {
+ return false;
+ }
+ } else if (!resource.equals(other.resource)) {
+ return false;
+ }
+
+ if (startTime != other.startTime) {
+ return false;
+ }
+
+ return true;
+ }
}
\ No newline at end of file
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java
index 9b3e9ec..020eb0b 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementBaseline.java
@@ -215,7 +215,7 @@ public class MeasurementBaseline implements Serializable {
private long computeTime;
@JoinColumn(name = "SCHEDULE_ID", nullable = false)
- @OneToOne(fetch = FetchType.LAZY)
+ @OneToOne(fetch = FetchType.LAZY, optional = false)
private MeasurementSchedule schedule;
// we need this to support autobaseline insertion queries
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java
index 2c99f85..d0d26ab 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java
@@ -1,25 +1,25 @@
- /*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.core.domain.measurement;
import java.io.Serializable;
@@ -36,9 +36,9 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
- /**
- * Represents data that was collected either due to a schedule or an on-demand, live collection.
- */
+/**
+* Represents data that was collected either due to a schedule or an on-demand, live collection.
+*/
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@XmlAccessorType(XmlAccessType.FIELD)
@@ -50,8 +50,8 @@ public abstract class MeasurementData implements Serializable {
@EmbeddedId
MeasurementDataPK id;
- @JoinColumn(name = "SCHEDULE_ID", insertable = false, updatable = false)
- @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "SCHEDULE_ID", insertable = false, updatable = false, nullable = false)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
MeasurementSchedule schedule;
@Transient
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/ResourceAvailability.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/ResourceAvailability.java
index 6a9b0fb..4e008f9 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/ResourceAvailability.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/ResourceAvailability.java
@@ -1,196 +1,196 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.rhq.core.domain.measurement;
-
-import java.io.Serializable;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.OneToOne;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
-
-import org.rhq.core.domain.resource.Resource;
-
-/**
- * This entity represents the latest known availability data for a resource.
- *
- * @author Joseph Marques
- */
-@Entity
-@Table(name = ResourceAvailability.TABLE_NAME)
-@NamedQueries( //
-{ @NamedQuery(name = ResourceAvailability.QUERY_FIND_BY_RESOURCE_ID, query = "" //
- + " SELECT ra FROM ResourceAvailability ra WHERE ra.resourceId = :resourceId "),
- @NamedQuery(name = ResourceAvailability.UPDATE_BY_AGENT_ID, query = "" //
- + " UPDATE ResourceAvailability " //
- + " SET availabilityType = :availabilityType " //
- + " WHERE resourceId IN ( SELECT res.id " //
- + " FROM Resource res " //
- + " WHERE res.agent.id = :agentId ) "),
- @NamedQuery(name = ResourceAvailability.INSERT_BY_RESOURCE_IDS, query = "" //
- + " INSERT INTO ResourceAvailability ( resourceId ) " //
- + " SELECT res.id " //
- + " FROM Resource res " //
- + " LEFT JOIN res.currentAvailability avail " //
- + " WHERE res.id IN ( :resourceIds ) " //
- + " AND avail IS NULL "),
- /*
- * Platform plugins always return up for availability. Platforms are
- * only down if the check-suspect-agent's backfiller sets them down.
- * Thus this agent has been backfilled if it's platform is not up.
- *
- * Returns 0 if the agent has NOT been backfilled, non-zero if it is.
- */
- @NamedQuery(name = ResourceAvailability.QUERY_IS_AGENT_BACKFILLED, query = "" //
- + "SELECT COUNT(avail.id) " // return count of
- + " FROM Resource res " //
- + " JOIN res.currentAvailability avail " // we only want the current availability
- + " WHERE res.agent.id = :agentId " // use id not name to prevent an unnecessary join to agent table
- + " AND res.parentResource IS NULL " // we only want platforms
- + " AND avail.availabilityType <> 1") // get all DOWN or UNKNOWN
-})
-@SequenceGenerator(name = "RHQ_RESOURCE_AVAIL_SEQ", sequenceName = "RHQ_RESOURCE_AVAIL_ID_SEQ", allocationSize = 100)
-public class ResourceAvailability implements Serializable {
- private static final long serialVersionUID = 1L;
-
- public static final String TABLE_NAME = "RHQ_RESOURCE_AVAIL";
-
- public static final String QUERY_FIND_BY_RESOURCE_ID = "ResourceAvailability.findByResourceId";
- public static final String UPDATE_BY_AGENT_ID = "ResourceAvailability.updateByAgentId";
- public static final String INSERT_BY_RESOURCE_IDS = "ResourceAvailability.insertByResourceIds";
- public static final String QUERY_IS_AGENT_BACKFILLED = "ResourceAvailability.isAgentBackfilled";
-
- @SuppressWarnings("unused")
- @Column(name = "ID", nullable = false)
- @GeneratedValue(strategy = GenerationType.AUTO, generator = "RHQ_RESOURCE_AVAIL_SEQ")
- @Id
- private int id;
-
- @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "ID", nullable = false)
- @OneToOne(fetch = FetchType.LAZY)
- private Resource resource;
-
- @Column(name = "RESOURCE_ID", insertable = false, updatable = false)
- private int resourceId;
-
- /**
- * Availability state for this time period
- */
- @Column(name = "AVAILABILITY_TYPE", nullable = true)
- @Enumerated(EnumType.ORDINAL)
- private AvailabilityType availabilityType;
-
- protected ResourceAvailability() {
- // for JPA use only
- }
-
- /**
- * Constructor for {@link ResourceAvailability}. If <code>type</code> is <code>null</code>, it will be
- * considered unknown.
- *
- * @param resource
- * @param type
- */
- public ResourceAvailability(Resource resource, AvailabilityType type) {
- if (resource == null) {
- throw new IllegalArgumentException("resource==null");
- }
-
- this.resource = resource;
- this.resourceId = resource.getId();
- this.availabilityType = type;
- }
-
- public Resource getResource() {
- return resource;
- }
-
- /**
- * Indicates the availability status as either UP or DOWN; if <code>null</code> is returned, the status is unknown.
- *
- * @return availability status
- */
- public AvailabilityType getAvailabilityType() {
- return availabilityType;
- }
-
- /**
- * Sets the availability status. This can be <code>null</code> to indicate an "unknown" availability status.
- *
- * @param availabilityType
- */
- public void setAvailabilityType(AvailabilityType availabilityType) {
- this.availabilityType = availabilityType;
- }
-
- @Override
- public String toString() {
- return "Availability[resourceId=" + resourceId + ", avail=" + this.availabilityType + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = (prime * result) + ((availabilityType == null) ? 0 : availabilityType.hashCode());
- result = (prime * result) + resourceId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (obj == null || !(obj instanceof ResourceAvailability)) {
- return false;
- }
-
- final ResourceAvailability other = (ResourceAvailability) obj;
-
- if (resourceId != other.resourceId) {
- return false;
- }
-
- if (availabilityType == null) {
- if (other.availabilityType != null) {
- return false;
- }
- } else if (!availabilityType.equals(other.availabilityType)) {
- return false;
- }
-
- return true;
- }
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.core.domain.measurement;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import org.rhq.core.domain.resource.Resource;
+
+/**
+ * This entity represents the latest known availability data for a resource.
+ *
+ * @author Joseph Marques
+ */
+@Entity
+@Table(name = ResourceAvailability.TABLE_NAME)
+@NamedQueries( //
+{ @NamedQuery(name = ResourceAvailability.QUERY_FIND_BY_RESOURCE_ID, query = "" //
+ + " SELECT ra FROM ResourceAvailability ra WHERE ra.resourceId = :resourceId "),
+ @NamedQuery(name = ResourceAvailability.UPDATE_BY_AGENT_ID, query = "" //
+ + " UPDATE ResourceAvailability " //
+ + " SET availabilityType = :availabilityType " //
+ + " WHERE resourceId IN ( SELECT res.id " //
+ + " FROM Resource res " //
+ + " WHERE res.agent.id = :agentId ) "),
+ @NamedQuery(name = ResourceAvailability.INSERT_BY_RESOURCE_IDS, query = "" //
+ + " INSERT INTO ResourceAvailability ( resourceId ) " //
+ + " SELECT res.id " //
+ + " FROM Resource res " //
+ + " LEFT JOIN res.currentAvailability avail " //
+ + " WHERE res.id IN ( :resourceIds ) " //
+ + " AND avail IS NULL "),
+ /*
+ * Platform plugins always return up for availability. Platforms are
+ * only down if the check-suspect-agent's backfiller sets them down.
+ * Thus this agent has been backfilled if it's platform is not up.
+ *
+ * Returns 0 if the agent has NOT been backfilled, non-zero if it is.
+ */
+ @NamedQuery(name = ResourceAvailability.QUERY_IS_AGENT_BACKFILLED, query = "" //
+ + "SELECT COUNT(avail.id) " // return count of
+ + " FROM Resource res " //
+ + " JOIN res.currentAvailability avail " // we only want the current availability
+ + " WHERE res.agent.id = :agentId " // use id not name to prevent an unnecessary join to agent table
+ + " AND res.parentResource IS NULL " // we only want platforms
+ + " AND avail.availabilityType <> 1") // get all DOWN or UNKNOWN
+})
+@SequenceGenerator(name = "RHQ_RESOURCE_AVAIL_SEQ", sequenceName = "RHQ_RESOURCE_AVAIL_ID_SEQ", allocationSize = 100)
+public class ResourceAvailability implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public static final String TABLE_NAME = "RHQ_RESOURCE_AVAIL";
+
+ public static final String QUERY_FIND_BY_RESOURCE_ID = "ResourceAvailability.findByResourceId";
+ public static final String UPDATE_BY_AGENT_ID = "ResourceAvailability.updateByAgentId";
+ public static final String INSERT_BY_RESOURCE_IDS = "ResourceAvailability.insertByResourceIds";
+ public static final String QUERY_IS_AGENT_BACKFILLED = "ResourceAvailability.isAgentBackfilled";
+
+ @SuppressWarnings("unused")
+ @Column(name = "ID", nullable = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "RHQ_RESOURCE_AVAIL_SEQ")
+ @Id
+ private int id;
+
+ @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "ID", nullable = false)
+ @OneToOne(fetch = FetchType.LAZY, optional = false)
+ private Resource resource;
+
+ @Column(name = "RESOURCE_ID", insertable = false, updatable = false)
+ private int resourceId;
+
+ /**
+ * Availability state for this time period
+ */
+ @Column(name = "AVAILABILITY_TYPE", nullable = true)
+ @Enumerated(EnumType.ORDINAL)
+ private AvailabilityType availabilityType;
+
+ protected ResourceAvailability() {
+ // for JPA use only
+ }
+
+ /**
+ * Constructor for {@link ResourceAvailability}. If <code>type</code> is <code>null</code>, it will be
+ * considered unknown.
+ *
+ * @param resource
+ * @param type
+ */
+ public ResourceAvailability(Resource resource, AvailabilityType type) {
+ if (resource == null) {
+ throw new IllegalArgumentException("resource==null");
+ }
+
+ this.resource = resource;
+ this.resourceId = resource.getId();
+ this.availabilityType = type;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ /**
+ * Indicates the availability status as either UP or DOWN; if <code>null</code> is returned, the status is unknown.
+ *
+ * @return availability status
+ */
+ public AvailabilityType getAvailabilityType() {
+ return availabilityType;
+ }
+
+ /**
+ * Sets the availability status. This can be <code>null</code> to indicate an "unknown" availability status.
+ *
+ * @param availabilityType
+ */
+ public void setAvailabilityType(AvailabilityType availabilityType) {
+ this.availabilityType = availabilityType;
+ }
+
+ @Override
+ public String toString() {
+ return "Availability[resourceId=" + resourceId + ", avail=" + this.availabilityType + "]";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = (prime * result) + ((availabilityType == null) ? 0 : availabilityType.hashCode());
+ result = (prime * result) + resourceId;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null || !(obj instanceof ResourceAvailability)) {
+ return false;
+ }
+
+ final ResourceAvailability other = (ResourceAvailability) obj;
+
+ if (resourceId != other.resourceId) {
+ return false;
+ }
+
+ if (availabilityType == null) {
+ if (other.availabilityType != null) {
+ return false;
+ }
+ } else if (!availabilityType.equals(other.availabilityType)) {
+ return false;
+ }
+
+ return true;
+ }
}
\ No newline at end of file
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/calltime/CallTimeDataKey.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/calltime/CallTimeDataKey.java
index 1691a59..6e05fca 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/calltime/CallTimeDataKey.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/calltime/CallTimeDataKey.java
@@ -1,110 +1,110 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.rhq.core.domain.measurement.calltime;
-
-import java.io.Serializable;
-
-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.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import org.rhq.core.domain.measurement.MeasurementSchedule;
-
-/**
- * A key used to lookup all call-time data ((i.e. a set of {@link CallTimeDataValue}s)) for a particular destination
- * (e.g. a URL or an EJB method name).
- *
- * @author Ian Springer
- */
-@Entity
-@NamedQueries( { @NamedQuery(name = CallTimeDataKey.QUERY_DELETE_BY_RESOURCES, query = "DELETE CallTimeDataKey ctdk WHERE ctdk.schedule IN ( SELECT ms FROM MeasurementSchedule ms WHERE ms.resource.id IN ( :resourceIds ) )") })
-@SequenceGenerator(name = "idGenerator", sequenceName = "RHQ_CALLTIME_DATA_KEY_ID_SEQ")
-@Table(name = "RHQ_CALLTIME_DATA_KEY")
-public class CallTimeDataKey implements Serializable {
- private static final long serialVersionUID = 1L;
-
- public static final String QUERY_DELETE_BY_RESOURCES = "CallTimeDataKey.deleteByResources";
-
- public static final int DESTINATION_MAX_LENGTH = 4000;
-
- @GeneratedValue(strategy = GenerationType.AUTO, generator = "idGenerator")
- @Id
- private int id;
-
- @JoinColumn(name = "SCHEDULE_ID", insertable = false, updatable = false, nullable = false)
- @ManyToOne(fetch = FetchType.LAZY)
- private MeasurementSchedule schedule;
-
- @Column(name = "CALL_DESTINATION", length = DESTINATION_MAX_LENGTH, nullable = false)
- private String callDestination;
-
- /**
- * Create a new <code>CallTimeDataKey</code>.
- *
- * @param schedule the collection schedule corresponding to this call-time data
- * @param callDestination the call destination (e.g. a URL or an EJB name)
- */
- public CallTimeDataKey(@NotNull MeasurementSchedule schedule, @NotNull String callDestination) {
- this.schedule = schedule;
- this.callDestination = callDestination;
- }
-
- protected CallTimeDataKey() {
- /* for JPA use only */
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- @Nullable
- public MeasurementSchedule getSchedule() {
- return this.schedule;
- }
-
- @NotNull
- public String getCallDestination() {
- return this.callDestination;
- }
-
- @Override
- public String toString() {
- return "MeasurementCallDestination[" + "id=" + this.id + ", " + "value=" + this.callDestination + "]";
- }
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.core.domain.measurement.calltime;
+
+import java.io.Serializable;
+
+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.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import org.rhq.core.domain.measurement.MeasurementSchedule;
+
+/**
+ * A key used to lookup all call-time data ((i.e. a set of {@link CallTimeDataValue}s)) for a particular destination
+ * (e.g. a URL or an EJB method name).
+ *
+ * @author Ian Springer
+ */
+@Entity
+@NamedQueries( { @NamedQuery(name = CallTimeDataKey.QUERY_DELETE_BY_RESOURCES, query = "DELETE CallTimeDataKey ctdk WHERE ctdk.schedule IN ( SELECT ms FROM MeasurementSchedule ms WHERE ms.resource.id IN ( :resourceIds ) )") })
+@SequenceGenerator(name = "idGenerator", sequenceName = "RHQ_CALLTIME_DATA_KEY_ID_SEQ")
+@Table(name = "RHQ_CALLTIME_DATA_KEY")
+public class CallTimeDataKey implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public static final String QUERY_DELETE_BY_RESOURCES = "CallTimeDataKey.deleteByResources";
+
+ public static final int DESTINATION_MAX_LENGTH = 4000;
+
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "idGenerator")
+ @Id
+ private int id;
+
+ @JoinColumn(name = "SCHEDULE_ID", insertable = false, updatable = false, nullable = false)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
+ private MeasurementSchedule schedule;
+
+ @Column(name = "CALL_DESTINATION", length = DESTINATION_MAX_LENGTH, nullable = false)
+ private String callDestination;
+
+ /**
+ * Create a new <code>CallTimeDataKey</code>.
+ *
+ * @param schedule the collection schedule corresponding to this call-time data
+ * @param callDestination the call destination (e.g. a URL or an EJB name)
+ */
+ public CallTimeDataKey(@NotNull MeasurementSchedule schedule, @NotNull String callDestination) {
+ this.schedule = schedule;
+ this.callDestination = callDestination;
+ }
+
+ protected CallTimeDataKey() {
+ /* for JPA use only */
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ @Nullable
+ public MeasurementSchedule getSchedule() {
+ return this.schedule;
+ }
+
+ @NotNull
+ public String getCallDestination() {
+ return this.callDestination;
+ }
+
+ @Override
+ public String toString() {
+ return "MeasurementCallDestination[" + "id=" + this.id + ", " + "value=" + this.callDestination + "]";
+ }
}
\ No newline at end of file
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/operation/OperationHistory.java b/modules/core/domain/src/main/java/org/rhq/core/domain/operation/OperationHistory.java
index 55c0086..d5aee06 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/operation/OperationHistory.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/operation/OperationHistory.java
@@ -168,8 +168,8 @@ public abstract class OperationHistory implements Serializable {
@ManyToOne(fetch = FetchType.EAGER)
private OperationDefinition operationDefinition;
- @JoinColumn(name = "PARAMETERS_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
+ @JoinColumn(name = "PARAMETERS_CONFIG_ID", referencedColumnName = "ID", nullable = true)
+ @OneToOne(cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY, optional = true)
private Configuration parameters;
protected OperationHistory() {
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/operation/ResourceOperationHistory.java b/modules/core/domain/src/main/java/org/rhq/core/domain/operation/ResourceOperationHistory.java
index 4b002b1..08c29be 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/operation/ResourceOperationHistory.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/operation/ResourceOperationHistory.java
@@ -115,12 +115,12 @@ public class ResourceOperationHistory extends OperationHistory {
@XmlTransient
private Resource resource;
- @JoinColumn(name = "RESULTS_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ @JoinColumn(name = "RESULTS_CONFIG_ID", referencedColumnName = "ID", nullable = true)
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, optional = true)
private Configuration results;
- @JoinColumn(name = "GROUP_HISTORY_ID", referencedColumnName = "ID")
- @ManyToOne
+ @JoinColumn(name = "GROUP_HISTORY_ID", referencedColumnName = "ID", nullable = true)
+ @ManyToOne(optional = true)
private GroupOperationHistory groupOperationHistory;
protected ResourceOperationHistory() {
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
index a0b3d3d..34d2f17 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
@@ -262,12 +262,12 @@ public class ServerPlugin extends AbstractPlugin {
public static final String QUERY_GET_CONFIG_MTIMES = "ServerPlugin.getConfigMTimes";
public static final String UPDATE_PLUGIN_ENABLED_BY_ID = "ServerPlugin.updatePluginEnabledById";
- @JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ @JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName = "ID", nullable = true)
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, optional = true)
private Configuration scheduledJobsConfiguration;
- @JoinColumn(name = "PLUGIN_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ @JoinColumn(name = "PLUGIN_CONFIG_ID", referencedColumnName = "ID", nullable = true)
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, optional = true)
private Configuration pluginConfiguration;
@Column(name = "PTYPE")
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
index d58abfa..e31b9ef 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
@@ -941,12 +941,11 @@ public class Resource implements Comparable<Resource>, Serializable {
private String location;
@JoinColumn(name = "RESOURCE_TYPE_ID", referencedColumnName = "ID", nullable = false)
- @ManyToOne
+ @ManyToOne(optional = false)
// TODO GH: It would be preferable for this to be lazy, but will need cleanup throughout the app (fetch = FetchType.LAZY)
@Summary(index = 4)
private ResourceType resourceType;
- // LAZY fetch otherwise this will recursively call all parents until null is found
// do not cascade remove - would take forever to delete a full platform hierarchy
// we will manually delete the children ourselves
@OneToMany(mappedBy = "parentResource", fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST })
@@ -954,21 +953,22 @@ public class Resource implements Comparable<Resource>, Serializable {
// primary key
private Set<Resource> childResources = new LinkedHashSet<Resource>();
- @JoinColumn(name = "PARENT_RESOURCE_ID")
- @ManyToOne(fetch = FetchType.LAZY)
+ // LAZY fetch otherwise this will recursively call all parents until null is found
+ @JoinColumn(name = "PARENT_RESOURCE_ID", nullable = true)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
@XmlTransient
private Resource parentResource;
- @JoinColumn(name = "RES_CONFIGURATION_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ @JoinColumn(name = "RES_CONFIGURATION_ID", referencedColumnName = "ID", nullable = true)
+ @OneToOne(cascade = { CascadeType.ALL }, optional = true)
private Configuration resourceConfiguration = new Configuration();
- @JoinColumn(name = "PLUGIN_CONFIGURATION_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ @JoinColumn(name = "PLUGIN_CONFIGURATION_ID", referencedColumnName = "ID", nullable = true)
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, optional = true)
private Configuration pluginConfiguration = new Configuration();
- @JoinColumn(name = "AGENT_ID", referencedColumnName = "ID")
- @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "AGENT_ID", referencedColumnName = "ID", nullable = true)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
private Agent agent;
// bulk delete @OneToMany(mappedBy = "resource", cascade = { CascadeType.ALL })
@@ -1050,8 +1050,8 @@ public class Resource implements Comparable<Resource>, Serializable {
@OneToMany(mappedBy = "resource", fetch = FetchType.LAZY)
private Set<EventSource> eventSources = new HashSet<EventSource>();
- @JoinColumn(name = "PRODUCT_VERSION_ID", referencedColumnName = "ID")
- @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "PRODUCT_VERSION_ID", referencedColumnName = "ID", nullable = true)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
private ProductVersion productVersion;
// not currently needed, but could be added if we find a need to get deployment info via the resource
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
index 9e0ce28..0562890 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
@@ -79,15 +79,15 @@ import org.rhq.core.domain.util.Summary;
@Table(name = ResourceType.TABLE_NAME)
@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_RESOURCE_TYPE_ID_SEQ")
@NamedQueries( {
- @NamedQuery(name = ResourceType.QUERY_FIND_BY_PLUGIN, query = "SELECT rt FROM ResourceType AS rt " +
- "WHERE rt.plugin = :plugin AND rt.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_PLUGIN, query = "SELECT rt FROM ResourceType AS rt "
+ + "WHERE rt.plugin = :plugin AND rt.deleted = false"),
@NamedQuery(name = ResourceType.QUERY_FIND_BY_NAME_AND_PLUGIN, // TODO: QUERY: names are case-sensitive
- query = "SELECT rt FROM ResourceType AS rt WHERE LOWER(rt.name) = LOWER(:name) AND rt.plugin = :plugin " +
- "AND rt.deleted = false"),
+ query = "SELECT rt FROM ResourceType AS rt WHERE LOWER(rt.name) = LOWER(:name) AND rt.plugin = :plugin "
+ + "AND rt.deleted = false"),
@NamedQuery(name = ResourceType.QUERY_FIND_ALL, query = "SELECT rt FROM ResourceType AS rt where rt.deleted = false"),
@NamedQuery(name = ResourceType.QUERY_FIND_BY_PARENT_AND_NAME, // TODO: QUERY: Not looking up by the full key, get rid of this query
- query = "SELECT rt FROM ResourceType AS rt WHERE :parent MEMBER OF rt.parentResourceTypes AND rt.name = :name " +
- "AND rt.deleted = false"),
+ query = "SELECT rt FROM ResourceType AS rt WHERE :parent MEMBER OF rt.parentResourceTypes AND rt.name = :name "
+ + "AND rt.deleted = false"),
/* authz'ed queries for ResourceTypeManagerBean */
@NamedQuery(name = ResourceType.QUERY_FIND_CHILDREN, query = "SELECT c "
@@ -111,8 +111,7 @@ import org.rhq.core.domain.util.Summary;
@NamedQuery(name = ResourceType.QUERY_FIND_UTILIZED_BY_CATEGORY, query = "SELECT DISTINCT res.resourceType "
+ "FROM Resource res, IN (res.implicitGroups) g, IN (g.roles) r, IN (r.subjects) s " //
+ "WHERE s = :subject " //
- + "AND res.resourceType.category = :category "
- + "AND res.resourceType.deleted = false "
+ + "AND res.resourceType.category = :category " + "AND res.resourceType.deleted = false "
+ "AND (UPPER(res.name) LIKE :nameFilter ESCAPE :escapeChar OR :nameFilter is null) "
+ "AND (res.resourceType.plugin = :pluginName OR :pluginName is null) "
+ "AND (:inventoryStatus = res.inventoryStatus OR :inventoryStatus is null) "
@@ -144,8 +143,7 @@ import org.rhq.core.domain.util.Summary;
+ " JOIN rg.resourceType rt" //
+ " JOIN rg.roles r JOIN r.subjects s " //
+ " WHERE s = :subject " //
- + " AND rt.deleted = false "
- + " AND ( rt.plugin = :pluginName OR :pluginName is null ) "),
+ + " AND rt.deleted = false " + " AND ( rt.plugin = :pluginName OR :pluginName is null ) "),
@NamedQuery(name = ResourceType.QUERY_FIND_BY_RESOURCE_GROUP_admin, query = "" //
+ "SELECT DISTINCT rt " //
+ " FROM ResourceGroup rg " //
@@ -153,12 +151,10 @@ import org.rhq.core.domain.util.Summary;
+ " WHERE rt.deleted = false AND ( rt.plugin = :pluginName OR :pluginName is null ) "),
@NamedQuery(name = ResourceType.QUERY_GET_EXPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP, query = "SELECT type.id, type.name, COUNT(type.id) "
+ "FROM ResourceGroup rg JOIN rg.explicitResources res JOIN res.resourceType type "
- + "WHERE rg.id = :groupId AND res.resourceType.deleted = false "
- + "GROUP BY type.id, type.name "),
+ + "WHERE rg.id = :groupId AND res.resourceType.deleted = false " + "GROUP BY type.id, type.name "),
@NamedQuery(name = ResourceType.QUERY_GET_IMPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP, query = "SELECT type.id, type.name, COUNT(type.id) "
+ "FROM ResourceGroup rg JOIN rg.implicitResources res JOIN res.resourceType type "
- + "WHERE rg.id = :groupId AND res.resourceType.deleted = false "
- + "GROUP BY type.id, type.name "),
+ + "WHERE rg.id = :groupId AND res.resourceType.deleted = false " + "GROUP BY type.id, type.name "),
@NamedQuery(name = ResourceType.QUERY_FIND_BY_SUBCATEGORY, query = "SELECT rt " + "FROM ResourceType rt "
+ "WHERE rt.subCategory = :subCategory AND rt.deleted = false"),
@NamedQuery(name = ResourceType.QUERY_FIND_BY_ID_WITH_ALL_OPERATIONS, query = "SELECT DISTINCT rt "
@@ -183,18 +179,13 @@ import org.rhq.core.domain.util.Summary;
@NamedQuery(name = ResourceType.QUERY_FIND_DUPLICATE_TYPE_NAMES, query = "" //
+ " SELECT rt.name " //
+ " FROM ResourceType rt " //
- + " WHERE rt.deleted = false "
- + " GROUP BY rt.name " //
+ + " WHERE rt.deleted = false " + " GROUP BY rt.name " //
+ " HAVING COUNT(rt.name) > 1"), //
@NamedQuery(name = ResourceType.QUERY_DYNAMIC_CONFIG_WITH_PLUGIN, query = "" //
+ "SELECT rt.plugin || ' - ' || rt.name, rt.plugin || '-' || rt.name FROM ResourceType rt WHERE rt.deleted = false"), //
- @NamedQuery(name = ResourceType.QUERY_MARK_TYPES_DELETED, query =
- "UPDATE ResourceType t SET t.deleted = true WHERE t.id IN (:resourceTypeIds)"),
- @NamedQuery(name = ResourceType.QUERY_FIND_IDS_BY_PLUGIN, query =
- "SELECT t.id FROM ResourceType t WHERE t.plugin = :plugin AND t.deleted = false"),
- @NamedQuery(name = ResourceType.QUERY_FIND_COUNT_BY_PLUGIN, query =
- "SELECT COUNT(t) FROM ResourceType t WHERE t.plugin = :plugin AND t.deleted = false")
-})
+ @NamedQuery(name = ResourceType.QUERY_MARK_TYPES_DELETED, query = "UPDATE ResourceType t SET t.deleted = true WHERE t.id IN (:resourceTypeIds)"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_IDS_BY_PLUGIN, query = "SELECT t.id FROM ResourceType t WHERE t.plugin = :plugin AND t.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_COUNT_BY_PLUGIN, query = "SELECT COUNT(t) FROM ResourceType t WHERE t.plugin = :plugin AND t.deleted = false") })
@NamedNativeQueries( {
// TODO: Add authz conditions to the below query.
@NamedNativeQuery(name = ResourceType.QUERY_FIND_CHILDREN_BY_CATEGORY, query = "" //
@@ -218,9 +209,9 @@ import org.rhq.core.domain.util.Summary;
+ "AND 0 = "
+ "(SELECT COUNT(rtp2.resource_type_id) "
+ "FROM RHQ_resource_type_parents rtp2 "
- + "WHERE rtp2.resource_type_id = crt2.id) "
- + "AND crt2.deleted = false "
- + "AND crt2.category = ? " + " ) ORDER BY name", resultSetMapping = ResourceType.MAPPING_FIND_CHILDREN_BY_CATEGORY),
+ + "WHERE rtp2.resource_type_id = crt2.id) " + "AND crt2.deleted = false "
+ + "AND crt2.category = ? "
+ + " ) ORDER BY name", resultSetMapping = ResourceType.MAPPING_FIND_CHILDREN_BY_CATEGORY),
@NamedNativeQuery(name = ResourceType.QUERY_FIND_CHILDREN_BY_CATEGORY_admin, query = "" //
+ "(SELECT crt.id, crt.name, crt.category, crt.creation_data_type, crt.create_delete_policy, crt.singleton, crt.supports_manual_add, crt.description, crt.plugin, crt.ctime, crt.mtime, crt.deleted, crt.subcategory_id, crt.plugin_config_def_id, crt.res_config_def_id "
+ "FROM RHQ_resource_type crt, RHQ_resource res, RHQ_resource_type rt, RHQ_resource_type_parents rtp "
@@ -347,18 +338,18 @@ public class ResourceType implements Serializable, Comparable<ResourceType> {
//@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
private Set<ResourceType> parentResourceTypes;
- @JoinColumn(name = "PLUGIN_CONFIG_DEF_ID")
- @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @JoinColumn(name = "PLUGIN_CONFIG_DEF_ID", nullable = true)
+ @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
//@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
private ConfigurationDefinition pluginConfigurationDefinition;
- @JoinColumn(name = "RES_CONFIG_DEF_ID")
- @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @JoinColumn(name = "RES_CONFIG_DEF_ID", nullable = true)
+ @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
//@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
private ConfigurationDefinition resourceConfigurationDefinition;
- @JoinColumn(name = "SUBCATEGORY_ID")
- @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "SUBCATEGORY_ID", nullable = true)
+ @ManyToOne(fetch = FetchType.LAZY, optional = true)
private ResourceSubCategory subCategory;
@OneToMany(mappedBy = "resourceType", cascade = CascadeType.ALL)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java b/modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java
index b517d59..181e322 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java
@@ -89,7 +89,7 @@ public class SavedSearch implements Serializable {
private Long resultCount;
@JoinColumn(name = "SUBJECT_ID", nullable = false)
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, optional = false)
private Subject subject;
@Column(name = "SUBJECT_ID", insertable = false, updatable = false)
commit 9ef17a26f0ff774c9bd4fb15e87c215fd8041202
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue May 10 13:42:56 2011 -0400
Related to [BZ 702390 - Large number of BundleDeployments for a single Bundle causes fetch serialization issues]
Revert some of the work done in commit 976c5fc6ed. Add back the LAZY load
on Configuration. Although, I think, it does need to perform additional
querying for the 'null' value determination, it can still proxy a non-null
value on optional XxxToOne associations.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleDeployment.java b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleDeployment.java
index dcf6c27..637bf22 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleDeployment.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleDeployment.java
@@ -74,8 +74,8 @@ import org.rhq.core.domain.tagging.Tag;
+ " WHERE innerbd.destination.id = :destinationId ) "),
@NamedQuery(name = BundleDeployment.QUERY_UPDATE_FOR_VERSION_REMOVE, query = "" //
+ "UPDATE BundleDeployment bd " //
- + " SET bd.replacedBundleDeploymentId = NULL " //
- + " WHERE bd.replacedBundleDeploymentId IN " //
+ + " SET bd.replacedBundleDeploymentId = NULL " //
+ + " WHERE bd.replacedBundleDeploymentId IN " //
+ " ( SELECT innerbd.id FROM BundleDeployment innerbd " //
+ " WHERE innerbd.bundleVersion.id = :bundleVersionId ) ") })
@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_BUNDLE_DEPLOYMENT_ID_SEQ")
@@ -118,15 +118,15 @@ public class BundleDeployment implements Serializable {
@Column(name = "MTIME")
private Long mtime = System.currentTimeMillis();
- // This is not a join column on purpose. Since it is nullable the OneToOne association would be forced to EAGER
- // fetch. That leads to basically fetching every BundleDeployment every time, in a deeply recursive way if you
- // have a lot deployments.
+ // This is intentionally not annotated as a OneToOne association for a BundleDeployment field. If done that way
+ // then a fetch could result in a very deep recursive fetch of all replaced deployments (for many deployments
+ // to a single destination), which is typically not what we want. And, it can cause fits in HibernateDetach
+ // which does not like extreme depth in its recursive scrubbing [BZ 702390].
@Column(name = "REPLACED_BUNDLE_DEPLOYMENT_ID", nullable = true)
private Integer replacedBundleDeploymentId;
- // note - eager fetch, can not lazy fetch an optional OneToOne
@JoinColumn(name = "CONFIG_ID", referencedColumnName = "ID", nullable = true)
- @OneToOne(cascade = CascadeType.ALL, optional = true)
+ @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
private Configuration configuration;
@JoinColumn(name = "BUNDLE_VERSION_ID", referencedColumnName = "ID", nullable = false)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleDeploymentCriteria.java b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleDeploymentCriteria.java
index aa437e3..8449905 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleDeploymentCriteria.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/BundleDeploymentCriteria.java
@@ -49,6 +49,7 @@ public class BundleDeploymentCriteria extends TaggedCriteria {
private String filterSubjectName;
private boolean fetchBundleVersion;
+ private boolean fetchConfiguration;
private boolean fetchDestination;
private boolean fetchResourceDeployments;
@@ -108,6 +109,10 @@ public class BundleDeploymentCriteria extends TaggedCriteria {
this.fetchBundleVersion = fetchBundleVersion;
}
+ public void fetchConfiguration(boolean fetchConfiguration) {
+ this.fetchConfiguration = fetchConfiguration;
+ }
+
public void fetchDestination(boolean fetchDestination) {
this.fetchDestination = fetchDestination;
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/SelectBundleVersionStep.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/SelectBundleVersionStep.java
index b13df74..e1367e8 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/SelectBundleVersionStep.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/SelectBundleVersionStep.java
@@ -143,6 +143,7 @@ public class SelectBundleVersionStep extends AbstractWizardStep {
criteria.addFilterDestinationId(wizard.getDestination().getId());
criteria.addFilterIsLive(true);
criteria.fetchBundleVersion(true);
+ criteria.fetchConfiguration(true);
bundleServer.findBundleDeploymentsByCriteria(criteria, //
new AsyncCallback<PageList<BundleDeployment>>() {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
index 73ea70c..3542481 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deployment/BundleDeploymentView.java
@@ -421,6 +421,7 @@ public class BundleDeploymentView extends LocatableVLayout implements Bookmarkab
BundleDeploymentCriteria criteria = new BundleDeploymentCriteria();
criteria.addFilterId(bundleDeploymentId);
criteria.fetchBundleVersion(true);
+ criteria.fetchConfiguration(true);
criteria.fetchResourceDeployments(true);
criteria.fetchDestination(true);
criteria.fetchTags(true);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
index 7b45a70..5738c64 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
@@ -1110,6 +1110,7 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
BundleDeploymentCriteria bdc = new BundleDeploymentCriteria();
bdc.addFilterId(resourceDeployment.getBundleDeployment().getId());
bdc.fetchBundleVersion(true);
+ bdc.fetchConfiguration(true);
bdc.fetchDestination(true);
BundleDeployment deployment = bundleManager.findBundleDeploymentsByCriteria(subject, bdc).get(0);