1 8 9 package com.sleepycat.persist.impl; 10 11 import com.sleepycat.bind.tuple.TupleBase; 12 import com.sleepycat.je.DatabaseEntry; 13 import com.sleepycat.je.DatabaseException; 14 import com.sleepycat.je.Sequence; 15 16 26 public class PersistKeyAssigner { 27 28 private Catalog catalog; 29 private Format keyFormat; 30 private Format entityFormat; 31 private boolean rawAccess; 32 private Sequence sequence; 33 34 PersistKeyAssigner(PersistKeyBinding keyBinding, 35 PersistEntityBinding entityBinding, 36 Sequence sequence) { 37 catalog = keyBinding.catalog; 38 keyFormat = keyBinding.keyFormat; 39 entityFormat = entityBinding.entityFormat; 40 rawAccess = entityBinding.rawAccess; 41 this.sequence = sequence; 42 } 43 44 public boolean assignPrimaryKey(Object entity, DatabaseEntry key) 45 throws DatabaseException { 46 47 if (entityFormat.isPriKeyNullOrZero(entity, rawAccess)) { 48 Long value = sequence.get(null, 1); 49 RecordOutput output = new RecordOutput(catalog, rawAccess); 50 keyFormat.writeObject(value, output, rawAccess); 51 TupleBase.outputToEntry(output, key); 52 EntityInput input = new RecordInput 53 (catalog, rawAccess, null, 0, 54 key.getData(), key.getOffset(), key.getSize()); 55 entityFormat.getReader().readPriKey(entity, input, rawAccess); 56 return true; 57 } else { 58 return false; 59 } 60 } 61 } 62 | Popular Tags |