@Override public int addMasterKey(String key) throws MetaException{ LOG.debug("Begin executing addMasterKey"); boolean committed = false; MMasterKey masterKey = new MMasterKey(key); try{ openTransaction(); pm.makePersistent(masterKey); committed = commitTransaction(); } finally { if(!committed) { rollbackTransaction(); } } LOG.debug("Done executing addMasterKey with status : {}", committed); if (committed) { return ((IntIdentity)pm.getObjectId(masterKey)).getKey(); } else { throw new MetaException("Failed to add master key."); } }
/** Constructor with class and key. * @param pcClass the class * @param key the key */ public IntIdentity (Class pcClass, int key) { super(pcClass); construct(key); }
/** Constructor with class and key. * @param pcClass the target class * @param key the key */ public ByteIdentity(Class pcClass, byte key) { super(pcClass); construct(key); }
/** Return the key as an Object. The method is synchronized to avoid * race conditions in multi-threaded environments. * @return the key as an Object. * @since 2.0 */ public synchronized Object getKeyAsObject() { if (keyAsObject == null) { keyAsObject = createKeyAsObject(); } return keyAsObject; }
/** Constructor with class and key. * @param pcClass the class * @param key the key */ public ShortIdentity (Class pcClass, short key) { super(pcClass); construct(key); }
/** Construct this instance with the key value. */ private void construct(byte key) { this.key = key; hashCode = super.hashClassName() ^ key; }
/** Constructor with class and key. * @param pcClass the target class * @param key the key */ public CharIdentity (Class pcClass, char key) { super (pcClass); construct(key); }
/** Set the given key as the key for this instance. * Compute the hash code for the instance. * @since 2.0 */ protected void setKeyAsObject(Object key) { assertKeyNotNull(key); keyAsObject = key; }
/** Constructor with class and key. * @param pcClass the class * @param key the key */ public LongIdentity (Class pcClass, long key) { super (pcClass); construct(key); }
private void construct(char key) { this.key = key; hashCode = hashClassName() ^ key; }
private void construct(long key) { this.key = key; hashCode = hashClassName() ^ (int)key; }
private void construct(short key) { this.key = key; hashCode = hashClassName() ^ key; }
/** Constructor with class and key. * @param pcClass the class * @param key the key */ public IntIdentity (Class pcClass, int key) { super(pcClass); construct(key); }
/** Constructor with class and key. * @param pcClass the target class * @param key the key */ public ByteIdentity(Class pcClass, byte key) { super(pcClass); construct(key); }
/** Return the key as an Object. The method is synchronized to avoid * race conditions in multi-threaded environments. * @return the key as an Object. * @since 2.0 */ public synchronized Object getKeyAsObject() { if (keyAsObject == null) { keyAsObject = createKeyAsObject(); } return keyAsObject; }
/** Constructor with class and key. * @param pcClass the class * @param key the key */ public ShortIdentity (Class pcClass, short key) { super(pcClass); construct(key); }
/** Construct this instance with the key value. */ private void construct(byte key) { this.key = key; hashCode = super.hashClassName() ^ key; }
/** Constructor with class and key. * @param pcClass the target class * @param key the key */ public CharIdentity (Class pcClass, char key) { super (pcClass); construct(key); }
/** Set the given key as the key for this instance. * Compute the hash code for the instance. * @param key The key to use * @since 2.0 */ protected void setKeyAsObject(Object key) { assertKeyNotNull(key); keyAsObject = key; }
/** Constructor with class and key. * @param pcClass the class * @param key the key */ public LongIdentity (Class pcClass, long key) { super (pcClass); construct(key); }