001: /*
002: * Helma License Notice
003: *
004: * The contents of this file are subject to the Helma License
005: * Version 2.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://adele.helma.org/download/helma/license.txt
008: *
009: * Copyright 1998-2003 Helma Software. All Rights Reserved.
010: *
011: * $RCSfile$
012: * $Author: root $
013: * $Revision: 8604 $
014: * $Date: 2007-09-28 15:16:38 +0200 (Fre, 28 Sep 2007) $
015: */
016:
017: package helma.objectmodel.db;
018:
019: import java.io.Serializable;
020:
021: /**
022: * This is the internal key for an object that is not - or not directly - fetched from a db,
023: * but derived from another object. This is useful for all kinds of object accessed via a
024: * symbolic name from another object, like objects mounted via a property name column,
025: * virtual nodes and groupby nodes.
026: */
027: public final class SyntheticKey implements Key, Serializable {
028:
029: // the parent key
030: private final Key parentKey;
031:
032: // the name relative to the parent key
033: private final String name;
034:
035: // lazily initialized hashcode
036: private transient int hashcode = 0;
037:
038: static final long serialVersionUID = -693454133259421857L;
039:
040: /**
041: * make a key for a persistent Object, describing its datasource and id.
042: */
043: public SyntheticKey(Key key, String name) {
044: this .parentKey = key;
045: this .name = name;
046: }
047:
048: /**
049: *
050: *
051: * @param what ...
052: *
053: * @return ...
054: */
055: public boolean equals(Object what) {
056: if (what == this ) {
057: return true;
058: }
059:
060: if (!(what instanceof SyntheticKey)) {
061: return false;
062: }
063:
064: SyntheticKey k = (SyntheticKey) what;
065:
066: return parentKey.equals(k.parentKey)
067: && ((name == k.name) || name.equalsIgnoreCase(k.name));
068: }
069:
070: /**
071: *
072: *
073: * @return ...
074: */
075: public int hashCode() {
076: if (hashcode == 0) {
077: hashcode = 17 + (37 * name.toLowerCase().hashCode())
078: + (37 * parentKey.hashCode());
079: }
080:
081: return hashcode;
082: }
083:
084: /**
085: *
086: *
087: * @return ...
088: */
089: public Key getParentKey() {
090: return parentKey;
091: }
092:
093: /**
094: *
095: *
096: * @return ...
097: */
098: public String getID() {
099: return name;
100: }
101:
102: /**
103: *
104: *
105: * @return ...
106: */
107: public String getStorageName() {
108: return null;
109: }
110:
111: /**
112: *
113: *
114: * @return ...
115: */
116: public String toString() {
117: return parentKey + "/" + name;
118: }
119: }
|