Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * See the file LICENSE for redistribution information.
  * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
 package com.sleepycat.persist.impl;
Assigns primary keys from a Sequence. This class is used directly by PrimaryIndex, not via an interface. To avoid making a public interface, the PersistEntityBinding contains a reference to a PersistKeyAssigner, and the PrimaryIndex gets the key assigner from the binding. See the PrimaryIndex constructor for more information.

Mark Hayes
public class PersistKeyAssigner {
    /* See Store.refresh for an explanation of the use of volatile fields. */
    private volatile Catalog catalog;
    private volatile Format keyFieldFormat;
    private volatile Format entityFormat;
    private final boolean rawAccess;
    private final Sequence sequence;
                       PersistEntityBinding entityBinding,
                       Sequence sequence) {
         = keyBinding.catalog;
        /* getSequenceKeyFormat will validate the field type for a sequence. */
         = keyBinding.keyFormat.getSequenceKeyFormat();
         = entityBinding.entityFormat;
         = entityBinding.rawAccess;
        this. = sequence;
    public boolean assignPrimaryKey(Object entityDatabaseEntry key)
        throws DatabaseException {
        try {
            return assignPrimaryKeyInternal(entitykey);
        } catch (RefreshException e) {
            try {
                return assignPrimaryKeyInternal(entitykey);
            } catch (RefreshException e2) {
                throw DbCompat.unexpectedException(e2);
    private boolean assignPrimaryKeyInternal(Object entityDatabaseEntry key)
        throws DatabaseExceptionRefreshException {
         * The keyFieldFormat is the format of a simple integer field.  For a
         * composite key class it is the contained integer field.  By writing
         * the Long sequence value using that format, the output data can then
         * be read to construct the actual key instance, whether it is a simple
         * or composite key class, and assign it to the primary key field in
         * the entity object.
        if (.isPriKeyNullOrZero(entity)) {
            Long value = .get(null, 1);
            RecordOutput output = new RecordOutput();
            EntityInput input = new RecordInput
                (null, 0,
                 key.getData(), key.getOffset(), key.getSize());
            return true;
        } else {
            return false;

See Store.refresh.
    void refresh(final PersistCatalog newCatalog) {
         = newCatalog;
New to GrepCode? Check out our FAQ X