| 1 | /** |
| 2 | * Copyright (C) 2007 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; |
| 20 | |
| 21 | /** |
| 22 | * Represents a persistent object identifier. The identifier |
| 23 | * consists of two parts, one identifies the class the object |
| 24 | * belongs to, and the rest is for unique identification in |
| 25 | * that class. |
| 26 | * @author Brautigam Robert |
| 27 | * @version CVS Revision: $Revision$ |
| 28 | */ |
| 29 | public class Identifier |
| 30 | { |
| 31 | private Long id; |
| 32 | private Integer classId; |
| 33 | |
| 34 | /** |
| 35 | * Construct with the two parts given. |
| 36 | * @param classId The class' id the object belongs to. |
| 37 | * @param partId The identifier <strong>inside</strong> the class. |
| 38 | */ |
| 39 | public Identifier(Integer classId, Long partId) |
| 40 | { |
| 41 | this.classId=classId; |
| 42 | this.id = new Long((((long)classId.intValue())<<45)+partId.longValue()); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Construct with the full identifier. |
| 47 | */ |
| 48 | public Identifier(Long id) |
| 49 | { |
| 50 | this.id=id; |
| 51 | this.classId = new Integer((int) (id.longValue()>>45)); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get the class id only. |
| 56 | */ |
| 57 | public Integer getClassId() |
| 58 | { |
| 59 | return classId; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get the full id this object represents. |
| 64 | */ |
| 65 | public Long getId() |
| 66 | { |
| 67 | return id; |
| 68 | } |
| 69 | |
| 70 | public String toString() |
| 71 | { |
| 72 | return "Id: "+id+" ("+classId+")"; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | |