Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

TupleSerialFactory.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: TupleSerialFactory.java,v 12.1 2005/01/31 19:27:33 mark Exp $
00008  */
00009 
00010 package com.sleepycat.collections;
00011 
00012 import com.sleepycat.bind.EntryBinding;
00013 import com.sleepycat.bind.serial.ClassCatalog;
00014 import com.sleepycat.bind.serial.TupleSerialMarshalledBinding;
00015 import com.sleepycat.bind.serial.TupleSerialMarshalledKeyCreator;
00016 import com.sleepycat.bind.tuple.TupleBinding;
00017 import com.sleepycat.bind.tuple.TupleMarshalledBinding;
00018 import com.sleepycat.db.Database;
00019 
00029 public class TupleSerialFactory {
00030 
00031     private ClassCatalog catalog;
00032 
00036     public TupleSerialFactory(ClassCatalog catalog) {
00037 
00038         this.catalog = catalog;
00039     }
00040 
00044     public final ClassCatalog getCatalog() {
00045 
00046         return catalog;
00047     }
00048 
00065     public StoredMap newMap(Database db, Class keyClass, Class valueBaseClass,
00066                             boolean writeAllowed) {
00067 
00068         return new StoredMap(db,
00069                         getKeyBinding(keyClass),
00070                         getEntityBinding(valueBaseClass),
00071                         writeAllowed);
00072     }
00073 
00090     public StoredSortedMap newSortedMap(Database db, Class keyClass,
00091                                         Class valueBaseClass,
00092                                         boolean writeAllowed) {
00093 
00094         return new StoredSortedMap(db,
00095                         getKeyBinding(keyClass),
00096                         getEntityBinding(valueBaseClass),
00097                         writeAllowed);
00098     }
00099 
00113     public TupleSerialMarshalledKeyCreator getKeyCreator(Class valueBaseClass,
00114                                                          String keyName) {
00115 
00116         return new TupleSerialMarshalledKeyCreator(
00117                                             getEntityBinding(valueBaseClass),
00118                                             keyName);
00119     }
00120 
00121     private TupleSerialMarshalledBinding getEntityBinding(Class baseClass) {
00122 
00123         return new TupleSerialMarshalledBinding(catalog, baseClass);
00124     }
00125 
00126     private EntryBinding getKeyBinding(Class keyClass) {
00127 
00128         EntryBinding binding = TupleBinding.getPrimitiveBinding(keyClass);
00129         if (binding == null) {
00130             binding = new TupleMarshalledBinding(keyClass);
00131         }
00132         return binding;
00133     }
00134 }
00135 

Generated on Sun Dec 25 12:14:31 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2