| 1 | #copyrightHeader() |
|---|
| 2 | |
|---|
| 3 | package ${package}; |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | #set($imports = $cmpgen.buildHelperImportList($stmt)) |
|---|
| 7 | #foreach($import in $imports) |
|---|
| 8 | import ${import}; |
|---|
| 9 | #end |
|---|
| 10 | |
|---|
| 11 | import org.jcoderz.commons.util.HashCodeUtil; |
|---|
| 12 | import org.jcoderz.commons.util.ObjectUtil; |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * Read only view to a typed $baseName. |
|---|
| 16 | * |
|---|
| 17 | * If the members of this class are immutable instances of this class |
|---|
| 18 | * are also immutable. |
|---|
| 19 | * |
|---|
| 20 | * @author fawkeZ (jCoderZ.org) $cmpgen.getVersion() |
|---|
| 21 | */ |
|---|
| 22 | public final class ${baseName}ValueImpl |
|---|
| 23 | implements ${baseName}Value |
|---|
| 24 | { |
|---|
| 25 | /** use this serialVersionUID for serialization. */ |
|---|
| 26 | static final long serialVersionUID = 1L; |
|---|
| 27 | |
|---|
| 28 | private transient int mLazyHashCode; |
|---|
| 29 | private transient String mLazyStringRepresentation; |
|---|
| 30 | |
|---|
| 31 | #foreach($column in $stmt.getColumns()) |
|---|
| 32 | #computeFields() |
|---|
| 33 | #if(!$column.isSkipInInterface()) |
|---|
| 34 | #if(!$column.isPeriodDefined()) |
|---|
| 35 | /** The $javaFieldName field of this entity. */ |
|---|
| 36 | #if($column.getLoadMethod()) |
|---|
| 37 | final $complexType m${javaFieldName}; |
|---|
| 38 | #else |
|---|
| 39 | final $javaType m${javaFieldName}; |
|---|
| 40 | #end |
|---|
| 41 | #else |
|---|
| 42 | /** The $column.getPeriodFieldName() field of this entity. */ |
|---|
| 43 | final Period m$column.getPeriodFieldName(); |
|---|
| 44 | #end |
|---|
| 45 | #end |
|---|
| 46 | #end |
|---|
| 47 | |
|---|
| 48 | /** |
|---|
| 49 | * The public constructor of this ${baseName}ValueImpl. |
|---|
| 50 | #set($colCount = 0) |
|---|
| 51 | #foreach($column in $stmt.getColumns()) |
|---|
| 52 | #if(!$column.isSkipInInterface()) |
|---|
| 53 | #computeFields() |
|---|
| 54 | #if(!$column.isPeriodDefined()) |
|---|
| 55 | * @param $lcJavaFieldName the $javaFieldName of this entity |
|---|
| 56 | #else |
|---|
| 57 | #set ($t1 = $column.getPeriodFieldName().substring(0,1).toLowerCase()) |
|---|
| 58 | #set ($t2 = $column.getPeriodFieldName().substring(1)) |
|---|
| 59 | * @param $t1$t2 the $column.getPeriodFieldName() of this entity |
|---|
| 60 | #end |
|---|
| 61 | #set($colCount = $colCount + 1) |
|---|
| 62 | #end |
|---|
| 63 | #end |
|---|
| 64 | */ |
|---|
| 65 | public ${baseName}ValueImpl ( |
|---|
| 66 | #set($count = 1) |
|---|
| 67 | #foreach($column in $stmt.getColumns()) |
|---|
| 68 | #if(!$column.isSkipInInterface()) |
|---|
| 69 | #computeFields() |
|---|
| 70 | #if(!$column.isPeriodDefined()) |
|---|
| 71 | #if($column.getLoadMethod()) |
|---|
| 72 | final $complexType $lcJavaFieldName#if($count < $colCount),#end |
|---|
| 73 | |
|---|
| 74 | #else |
|---|
| 75 | final $javaType $lcJavaFieldName#if($count < $colCount),#end |
|---|
| 76 | |
|---|
| 77 | #end |
|---|
| 78 | #else |
|---|
| 79 | #set ($t1 = $column.getPeriodFieldName().substring(0,1).toLowerCase()) |
|---|
| 80 | #set ($t2 = $column.getPeriodFieldName().substring(1)) |
|---|
| 81 | final Period $t1$t2#if($count < $colCount),#end |
|---|
| 82 | |
|---|
| 83 | #end |
|---|
| 84 | #set($count = $count + 1) |
|---|
| 85 | #end |
|---|
| 86 | #end |
|---|
| 87 | ) |
|---|
| 88 | { |
|---|
| 89 | #foreach($column in $stmt.getColumns()) |
|---|
| 90 | #if(!$column.isSkipInInterface()) |
|---|
| 91 | #computeFields() |
|---|
| 92 | #if(!$column.isPeriodDefined()) |
|---|
| 93 | m${javaFieldName} = ${lcJavaFieldName}; |
|---|
| 94 | #else |
|---|
| 95 | #set ($t1 = $column.getPeriodFieldName().substring(0,1).toLowerCase()) |
|---|
| 96 | #set ($t2 = $column.getPeriodFieldName().substring(1)) |
|---|
| 97 | m$column.getPeriodFieldName() = $t1$t2; |
|---|
| 98 | #end |
|---|
| 99 | #end |
|---|
| 100 | #end |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | #foreach($column in $stmt.getColumns()) |
|---|
| 104 | #if(!$column.isSkipInInterface()) |
|---|
| 105 | #computeFields() |
|---|
| 106 | #if(!$column.isPeriodDefined()) |
|---|
| 107 | /** |
|---|
| 108 | * Returns the ${javaFieldName}. |
|---|
| 109 | * @return the ${javaFieldName}. |
|---|
| 110 | */ |
|---|
| 111 | #if($column.getLoadMethod()) |
|---|
| 112 | public $complexType get$javaFieldName () |
|---|
| 113 | #else |
|---|
| 114 | public $javaType $simpleGetterName () |
|---|
| 115 | #end |
|---|
| 116 | { |
|---|
| 117 | return m${javaFieldName}; |
|---|
| 118 | } |
|---|
| 119 | #else |
|---|
| 120 | /** |
|---|
| 121 | * Returns the period. |
|---|
| 122 | * @return An instance of type {@link org.jcoderz.commons.types.Period}. |
|---|
| 123 | */ |
|---|
| 124 | public Period get$column.getPeriodFieldName() () |
|---|
| 125 | { |
|---|
| 126 | return m$column.getPeriodFieldName(); |
|---|
| 127 | } |
|---|
| 128 | #end |
|---|
| 129 | |
|---|
| 130 | #end |
|---|
| 131 | #end |
|---|
| 132 | /** |
|---|
| 133 | * Override hashCode. |
|---|
| 134 | * @return the Object's hashcode. |
|---|
| 135 | */ |
|---|
| 136 | public int hashCode () |
|---|
| 137 | { |
|---|
| 138 | if (mLazyHashCode == 0) |
|---|
| 139 | { |
|---|
| 140 | mLazyHashCode = HashCodeUtil.SEED; |
|---|
| 141 | #foreach($column in $stmt.getColumns()) |
|---|
| 142 | #computeFields() |
|---|
| 143 | #if(!$column.isSkipInInterface()) |
|---|
| 144 | #if(!$column.isPeriodDefined()) |
|---|
| 145 | mLazyHashCode = HashCodeUtil.hash(mLazyHashCode, m${javaFieldName}); |
|---|
| 146 | #else |
|---|
| 147 | mLazyHashCode = HashCodeUtil.hash(mLazyHashCode, m$column.getPeriodFieldName()); |
|---|
| 148 | #end |
|---|
| 149 | #end |
|---|
| 150 | #end |
|---|
| 151 | } |
|---|
| 152 | return mLazyHashCode; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | /** |
|---|
| 156 | * Returns true if this ${baseName}ValueImpl |
|---|
| 157 | * is equal to object. |
|---|
| 158 | * @param object the object to compare to. |
|---|
| 159 | * @return true if this ${baseName}ValueImpl |
|---|
| 160 | * is equal to object. |
|---|
| 161 | */ |
|---|
| 162 | public boolean equals (Object object) |
|---|
| 163 | { |
|---|
| 164 | final boolean result; |
|---|
| 165 | if (this == object) |
|---|
| 166 | { |
|---|
| 167 | result = true; |
|---|
| 168 | } |
|---|
| 169 | else if (object instanceof ${baseName}ValueImpl) |
|---|
| 170 | { |
|---|
| 171 | final ${baseName}ValueImpl o |
|---|
| 172 | = (${baseName}ValueImpl) object; |
|---|
| 173 | result = true |
|---|
| 174 | #foreach($column in $stmt.getColumns()) |
|---|
| 175 | #computeFields() |
|---|
| 176 | #if(!$column.isSkipInInterface()) |
|---|
| 177 | #if(!$column.isPeriodDefined()) |
|---|
| 178 | && ObjectUtil.equals(m${javaFieldName}, o.m${javaFieldName}) |
|---|
| 179 | #else |
|---|
| 180 | && ObjectUtil.equals(m$column.getPeriodFieldName(), o.m$column.getPeriodFieldName()) |
|---|
| 181 | #end |
|---|
| 182 | #end |
|---|
| 183 | #end |
|---|
| 184 | ; |
|---|
| 185 | } |
|---|
| 186 | else |
|---|
| 187 | { |
|---|
| 188 | result = false; |
|---|
| 189 | } |
|---|
| 190 | return result; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | /** |
|---|
| 194 | * Returns a string representation of this object. |
|---|
| 195 | * @return a string representation of this object. |
|---|
| 196 | */ |
|---|
| 197 | public String toString() |
|---|
| 198 | { |
|---|
| 199 | if (mLazyStringRepresentation == null) |
|---|
| 200 | { |
|---|
| 201 | final StringBuffer sbuf = new StringBuffer(); |
|---|
| 202 | sbuf.append("[${baseName}ValueImpl:"); |
|---|
| 203 | #foreach($column in $stmt.getColumns()) |
|---|
| 204 | #computeFields() |
|---|
| 205 | #if(!$column.isSkipInInterface()) |
|---|
| 206 | #if(!$column.isPeriodDefined()) |
|---|
| 207 | sbuf.append(" m${javaFieldName}:"); |
|---|
| 208 | sbuf.append(m${javaFieldName}); |
|---|
| 209 | #else |
|---|
| 210 | sbuf.append(" m$column.getPeriodFieldName():"); |
|---|
| 211 | sbuf.append(m$column.getPeriodFieldName()); |
|---|
| 212 | #end |
|---|
| 213 | #end |
|---|
| 214 | #end |
|---|
| 215 | sbuf.append("]"); |
|---|
| 216 | mLazyStringRepresentation = sbuf.toString(); |
|---|
| 217 | } |
|---|
| 218 | return mLazyStringRepresentation; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | /** |
|---|
| 222 | * Converts this ${baseName}ValueImpl to the XDoclet-generated |
|---|
| 223 | * data object. |
|---|
| 224 | * @return the XDoclet generated data object representing this entity |
|---|
| 225 | */ |
|---|
| 226 | public ${baseName}Data toData () |
|---|
| 227 | { |
|---|
| 228 | final ${baseName}Data result = new ${baseName}Data(); |
|---|
| 229 | #foreach($column in $stmt.getColumns()) |
|---|
| 230 | #computeFields() |
|---|
| 231 | #if(!$column.isSkipInInterface()) |
|---|
| 232 | #if(!$column.isPeriodDefined()) |
|---|
| 233 | result.set${javaFieldName}(m${javaFieldName}); |
|---|
| 234 | #else |
|---|
| 235 | result.set$column.getPeriodFieldName()(m$column.getPeriodFieldName()); |
|---|
| 236 | #end |
|---|
| 237 | #end |
|---|
| 238 | #end |
|---|
| 239 | return result; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | /** |
|---|
| 243 | * Builds a ${baseName}Value from an XDoclet-generated |
|---|
| 244 | * data object. |
|---|
| 245 | * @return a ${baseName}Value representing this entity |
|---|
| 246 | */ |
|---|
| 247 | public static ${baseName}Value fromData (${baseName}Data data) |
|---|
| 248 | { |
|---|
| 249 | return new ${baseName}ValueImpl ( |
|---|
| 250 | #set($count = 1) |
|---|
| 251 | #foreach($column in $stmt.getColumns()) |
|---|
| 252 | #computeFields() |
|---|
| 253 | #if(!$column.isSkipInInterface()) |
|---|
| 254 | #if(!$column.isPeriodDefined()) |
|---|
| 255 | data.get${javaFieldName}()#if($count < $colCount),#end |
|---|
| 256 | |
|---|
| 257 | #else |
|---|
| 258 | data.get$column.getPeriodFieldName()()#if($count < $colCount),#end |
|---|
| 259 | |
|---|
| 260 | #end |
|---|
| 261 | #set($count = $count + 1) |
|---|
| 262 | #end |
|---|
| 263 | #end |
|---|
| 264 | ); |
|---|
| 265 | } |
|---|
| 266 | } |
|---|