001: package org.andromda.cartridges.spring;
002:
003: import org.andromda.cartridges.spring.metafacades.SpringGlobals;
004:
005: /**
006: * Contains utilities used within the Spring cartridge
007: * when dealing with Hibernate.
008: *
009: * @author Chad Brandon
010: * @author Joel Kozikowski
011: */
012: public class SpringHibernateUtils {
013: /**
014: * The version of Hibernate we're generating for.
015: */
016: private String hibernateVersion = SpringGlobals.HIBERNATE_VERSION_3;
017:
018: /**
019: * Sets the version of Hibernate we're generating for.
020: *
021: * @param hibernateVersion the Hibernate version.
022: */
023: public void setHibernateVersion(final String hibernateVersion) {
024: this .hibernateVersion = hibernateVersion;
025: }
026:
027: /**
028: * Gets the appropriate hibernate package name for the given
029: * <code>version</code>.
030: *
031: * @return the base package name.
032: */
033: public String getBasePackage() {
034: return this .isVersion3() ? "org.hibernate" : "net.sf.hibernate";
035: }
036:
037: /**
038: * Gets the appropriate hibernate criterion package name for the given <code>version</code>.
039: *
040: * @return the Hibernate criterion package name.
041: */
042: public String getCriterionPackage() {
043: return this .getBasePackage()
044: + (this .isVersion3() ? ".criterion" : ".expression");
045: }
046:
047: /**
048: * Gets the appropriate Spring Hibernate package based on the given
049: * <code>version</code>.
050: *
051: * @return the spring hibernate package.
052: */
053: public String getSpringHibernatePackage() {
054: return this .isVersion3() ? "org.springframework.orm.hibernate3"
055: : "org.springframework.orm.hibernate";
056: }
057:
058: /**
059: * Retrieves the appropriate package for Hibernate user types given
060: * the version defined within this class.
061: *
062: * @return the hibernate user type package.
063: */
064: public String getEagerFetchMode() {
065: return this .isVersion3() ? "JOIN" : "EAGER";
066: }
067:
068: /**
069: * Retrieves the fully qualified name of the class that retrieves the Hibernate
070: * disjunction instance.
071: * @return the fully qualified class name.
072: */
073: public String getDisjunctionClassName() {
074: return this .getCriterionPackage()
075: + (this .isVersion3() ? ".Restrictions" : ".Expression");
076: }
077:
078: /**
079: * Indicates whether or not version 3 is the one that is currently being used.
080: *
081: * @return true/false
082: */
083: public boolean isVersion3() {
084: return isVersion3(hibernateVersion);
085: }
086:
087: public static boolean isVersion3(
088: String hibernateVersionPropertyValue) {
089: return SpringGlobals.HIBERNATE_VERSION_3
090: .equals(hibernateVersionPropertyValue);
091: }
092:
093: /**
094: * Denotes whether or not to make use of Hibernate 3 XML persistence support.
095: */
096: private String hibernateXmlPersistence;
097:
098: /**
099: * @param hibernateXmlPersistence <code>true</code> when you to make use of Hibernate 3 XML persistence support,
100: * <code>false</code> otherwise
101: */
102: public void setHibernateXMLPersistence(
103: final String hibernateXmlPersistence) {
104: this .hibernateXmlPersistence = hibernateXmlPersistence;
105: }
106:
107: public boolean isXmlPersistenceActive() {
108: return isXmlPersistenceActive(this .hibernateVersion,
109: this .hibernateXmlPersistence);
110: }
111:
112: public static boolean isXmlPersistenceActive(
113: String hibernateVersionPropertyValue,
114: String hibernateXMLPersistencePropertyValue) {
115: return isVersion3(hibernateVersionPropertyValue)
116: && "true"
117: .equalsIgnoreCase(hibernateXMLPersistencePropertyValue);
118: }
119:
120: private String hibernateMappingStrategy;
121:
122: public void setHibernateMappingStrategy(
123: String hibernateMappingStrategy) {
124: this .hibernateMappingStrategy = hibernateMappingStrategy;
125: }
126:
127: public boolean isMapSubclassesInSeparateFile() {
128: return mapSubclassesInSeparateFile(this .hibernateMappingStrategy);
129: }
130:
131: public static boolean mapSubclassesInSeparateFile(
132: String hibernateMappingStrategy) {
133: // subclass or hierarchy
134: return SpringGlobals.HIBERNATE_MAPPING_STRATEGY_SUBCLASS
135: .equalsIgnoreCase(hibernateMappingStrategy);
136: }
137: }
|