| 1 | /** |
| 2 | * Copyright (C) 2008 NetMind Consulting Bt. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
| 19 | package hu.netmind.beankeeper.object.impl; |
| 20 | |
| 21 | import java.io.Serializable; |
| 22 | import java.util.Date; |
| 23 | import hu.netmind.beankeeper.object.PersistenceMetaData; |
| 24 | import hu.netmind.beankeeper.serial.Serial; |
| 25 | |
| 26 | /** |
| 27 | * An object of this class represents all persistence related information |
| 28 | * about an object, which BeanKeeper is aware of. |
| 29 | * @author Brautigam Robert |
| 30 | * @version CVS Revision: $Revision$ |
| 31 | */ |
| 32 | public class PersistenceMetaDataImpl implements PersistenceMetaData |
| 33 | { |
| 34 | private Long persistenceId; |
| 35 | private Long persistenceStart; |
| 36 | private Long persistenceEnd; |
| 37 | private Long registrationSerial; |
| 38 | private Long lastCurrentSerial; |
| 39 | private Class objectClass; |
| 40 | |
| 41 | public String toString() |
| 42 | { |
| 43 | return "[Meta: "+objectClass+":"+persistenceId+" at "+registrationSerial+"]"; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get the creation date of <strong>this version</strong> |
| 48 | * of the object. If the object is not yet saved, this |
| 49 | * value is null. Only committed creation dates are given. |
| 50 | * If the object is saved in a transaction, but the |
| 51 | * transaction did not yet commit, then this date will reflect |
| 52 | * the last committed creation date of the object (before |
| 53 | * the transaction).<br> |
| 54 | * Selecting the object later with this date will give |
| 55 | * the same version only if this version of the object |
| 56 | * lived at least 1 millisecond (it was not deleted |
| 57 | * or superseded in that time). If it didn't, then the next |
| 58 | * version of the object is selected which lived at least |
| 59 | * 1 millisecond. |
| 60 | */ |
| 61 | public Date getCreationDate() |
| 62 | { |
| 63 | if ( getPersistenceStart() == null ) |
| 64 | return null; |
| 65 | return new Serial(getPersistenceStart()).getDate(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get the deletion date of <strong>this version</strong> |
| 70 | * of the object. If the object was not yet saved, then |
| 71 | * this value is null. If the object was not yet deleted, |
| 72 | * but it exists in the database, then this date is an extremal |
| 73 | * big date. Selecting the object on this date |
| 74 | * will select the next version of the object which lived at least |
| 75 | * 1 millisecond. |
| 76 | */ |
| 77 | public Date getRemoveDate() |
| 78 | { |
| 79 | if ( getPersistenceEnd() == null ) |
| 80 | return null; |
| 81 | return new Serial(getPersistenceEnd()).getDate(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get the persistence id of the object. This id is |
| 86 | * available to non-existent objects too, and it does |
| 87 | * not ever change. Not if the object does not exist |
| 88 | * yet, and not if a new version is saved or the object |
| 89 | * is deleted. |
| 90 | */ |
| 91 | public Long getPersistenceId() |
| 92 | { |
| 93 | return persistenceId; |
| 94 | } |
| 95 | |
| 96 | void setPersistenceId(Long persistenceId) |
| 97 | { |
| 98 | this.persistenceId=persistenceId; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Get the creation serial number of this version. This is |
| 103 | * a unique number based on dates. All versions will have different |
| 104 | * serial numbers. |
| 105 | */ |
| 106 | public Long getPersistenceStart() |
| 107 | { |
| 108 | return persistenceStart; |
| 109 | } |
| 110 | void setPersistenceStart(Long persistenceStart) |
| 111 | { |
| 112 | this.persistenceStart=persistenceStart; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get the end serial. If the object is not deleted, then |
| 117 | * this is Long.MAX_VALUE. |
| 118 | */ |
| 119 | public Long getPersistenceEnd() |
| 120 | { |
| 121 | return persistenceEnd; |
| 122 | } |
| 123 | void setPersistenceEnd(Long persistenceEnd) |
| 124 | { |
| 125 | this.persistenceEnd=persistenceEnd; |
| 126 | } |
| 127 | |
| 128 | public Long getRegistrationSerial() |
| 129 | { |
| 130 | return registrationSerial; |
| 131 | } |
| 132 | void setRegistrationSerial(Long registrationSerial) |
| 133 | { |
| 134 | this.registrationSerial=registrationSerial; |
| 135 | } |
| 136 | |
| 137 | public Class getObjectClass() |
| 138 | { |
| 139 | return objectClass; |
| 140 | } |
| 141 | |
| 142 | void setObjectClass(Class objectClass) |
| 143 | { |
| 144 | this.objectClass=objectClass; |
| 145 | } |
| 146 | |
| 147 | public Long getLastCurrentSerial() |
| 148 | { |
| 149 | return lastCurrentSerial; |
| 150 | } |
| 151 | void setLastCurrentSerial(Long lastCurrentSerial) |
| 152 | { |
| 153 | this.lastCurrentSerial=lastCurrentSerial; |
| 154 | } |
| 155 | |
| 156 | } |
| 157 | |
| 158 | |