LocalTermIdReference.java from Texai at Krugle
Show LocalTermIdReference.java syntax highlighted
/*
* TermIdReference.java
*
* Created on April 23, 2007, 12:13 PM
*
* Description: Provides a means by which KB objects in remote partitions can reference KB objects
* in the local partition via UUID lookup. Primitive int's are used as local term ids in order
* to save space and increase performance.
*
* Copyright (C) April 23, 2007 Stephen L. Reed.
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.texai.kb.entity;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.Relationship;
import com.sleepycat.persist.model.SecondaryKey;
import java.util.UUID;
import org.texai.util.ByteUtils;
/**
*
* @author reed
*/
@Entity
public class LocalTermIdReference {
/** the local partition term ID */
@PrimaryKey
private int termId; // NOPMD
@SecondaryKey(relate=Relationship.ONE_TO_ONE)
/** the UUID bytes which identify the term within the local KB partition */
private byte[] uuidBytes; // NOPMD
/** Creates a new instance of TermIdReference */
public LocalTermIdReference() {
super();
}
/** Creates a new instance of TermIdReference */
public LocalTermIdReference(final int termId, final UUID uuid) {
super();
//Preconditions
assert termId != 0 : "termId must not be zero";
assert uuid != null : "uuid must not be null";
this.termId = termId;
this.uuidBytes = ByteUtils.toBytes(uuid);
}
/** Gets the local partition term ID.
*
* @return the local partition term ID
*/
public int getTermId() {
return termId;
}
/** Gets the UUID bytes which identify the term within the local KB partition.
*
* @return the UUID bytes which identify the term within the local KB partition
*/
public UUID getUUID() {
return UUID.nameUUIDFromBytes(uuidBytes);
}
}
See more files for this project here