2 * This is a common dao with basic CRUD operations and is not limited to any
3 * persistent layer implementation
5 * Copyright (C) 2008 Imran M Yousuf (imyousuf@smartitengineering.com)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 package com
.smartitengineering
.domain
;
21 import java
.io
.Serializable
;
27 public abstract class AbstractGenericPersistentDTO
<Template
extends PersistentDTO
, IdType
extends Comparable
<IdType
> & Serializable
, VersionType
extends Comparable
<VersionType
> & Serializable
>
29 PersistentDTO
<PersistentDTO
, IdType
, VersionType
> {
32 private VersionType version
;
34 protected AbstractGenericPersistentDTO() {
38 public IdType
getId() {
43 public void setId(IdType id
) {
48 public VersionType
getVersion() {
53 public void setVersion(VersionType version
) {
54 this.version
= version
;
58 public int compareTo(PersistentDTO o
) {
60 throw new IllegalArgumentException();
62 if (o
.getId() == null && id
== null) {
65 if (o
.getId() == null && id
!= null) {
68 if (o
.getId() != null && id
== null) {
71 if (id
.getClass().isAssignableFrom(o
.getId().getClass())) {
72 IdType tmp
= (IdType
) o
.getId();
73 return tmp
.compareTo(id
);
76 return o
.getId().toString().compareTo(id
.toString());
81 public int compare(PersistentDTO o1
, PersistentDTO o2
) {
82 if (o1
== null && o2
== null) {
85 if (o1
== null && o2
!= null) {
88 if (o1
!= null && o2
== null) {
91 return o1
.compareTo(o2
);
95 public boolean equals(Object obj
) {
99 if (!PersistentDTO
.class.isAssignableFrom(obj
.getClass())) {
102 final PersistentDTO other
= (PersistentDTO
) obj
;
103 return compareTo(other
) == 0;
107 public int hashCode() {
109 hash
= 23 * hash
+ (this.id
!= null ?
this.id
.hashCode() : 0);
110 hash
= 23 * hash
+ (this.version
!= null ?
this.version
.hashCode() : 0);
114 protected void clone(Template template
) {
115 if (template
== null) {
119 template
.setVersion(version
);