• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/db-4.8.30/java/src/com/sleepycat/db/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8
9package com.sleepycat.db;
10
11import com.sleepycat.db.internal.Db;
12import com.sleepycat.db.internal.DbConstants;
13import com.sleepycat.db.internal.DbEnv;
14import com.sleepycat.db.internal.DbTxn;
15import com.sleepycat.db.internal.DbUtil;
16
17/**
18Specify the attributes of a database.
19*/
20public class DatabaseConfig implements Cloneable {
21    /*
22     * For internal use, final to allow null as a valid value for
23     * the config parameter.
24     */
25    /**
26    An instance created using the default constructor is initialized
27    with the system's default settings.
28    */
29    public static final DatabaseConfig DEFAULT = new DatabaseConfig();
30
31    /* package */
32    static DatabaseConfig checkNull(DatabaseConfig config) {
33        return (config == null) ? DEFAULT : config;
34    }
35
36    /* Parameters */
37    private DatabaseType type = DatabaseType.UNKNOWN;
38    private int mode = 0644;
39    private int btMinKey = 0;
40    private int byteOrder = 0;
41    private long cacheSize = 0L;
42    private java.io.File createDir = null;
43    private int cacheCount = 0;
44    private java.io.OutputStream errorStream = null;
45    private String errorPrefix = null;
46    private int hashFillFactor = 0;
47    private int hashNumElements = 0;
48    private java.io.OutputStream messageStream = null;
49    private int pageSize = 0;
50    private java.io.File[] partitionDirs = null;
51    private DatabaseEntry partitionKeys = null;
52    private int partitionParts = 0;
53    private String password = null;
54    private CacheFilePriority priority = null;
55    private int queueExtentSize = 0;
56    private int recordDelimiter = 0;
57    private int recordLength = 0;
58    private int recordPad = -1;       // Zero is a valid, non-default value.
59    private java.io.File recordSource = null;
60
61    /* Flags */
62    private boolean allowCreate = false;
63    private boolean btreeRecordNumbers = false;
64    private boolean checksum = false;
65    private boolean readUncommitted = false;
66    private boolean encrypted = false;
67    private boolean exclusiveCreate = false;
68    private boolean multiversion = false;
69    private boolean noMMap = false;
70    private boolean queueInOrder = false;
71    private boolean readOnly = false;
72    private boolean renumbering = false;
73    private boolean reverseSplitOff = false;
74    private boolean sortedDuplicates = false;
75    private boolean snapshot = false;
76    private boolean unsortedDuplicates = false;
77    private boolean transactional = false;
78    private boolean transactionNotDurable = false;
79    private boolean truncate = false;
80
81    /* Callbacks */
82    private java.util.Comparator btreeComparator = null;
83    private BtreeCompressor btreeCompressor = null;
84    private BtreePrefixCalculator btreePrefixCalculator = null;
85    private java.util.Comparator duplicateComparator = null;
86    private FeedbackHandler feedbackHandler = null;
87    private ErrorHandler errorHandler = null;
88    private MessageHandler messageHandler = null;
89    private PartitionHandler partitionHandler = null;
90    private java.util.Comparator hashComparator = null;
91    private Hasher hasher = null;
92    private RecordNumberAppender recnoAppender = null;
93    private PanicHandler panicHandler = null;
94
95    /**
96    An instance created using the default constructor is initialized with
97    the system's default settings.
98    */
99    public DatabaseConfig() {
100    }
101
102    /**
103     * Returns a copy of this configuration object.
104     */
105    public DatabaseConfig cloneConfig() {
106        try {
107            return (DatabaseConfig) super.clone();
108        } catch (CloneNotSupportedException willNeverOccur) {
109            return null;
110        }
111    }
112
113    /**
114    Configure the {@link com.sleepycat.db.Environment#openDatabase Environment.openDatabase} method to create
115    the database if it does not already exist.
116    <p>
117    @param allowCreate
118    If true, configure the {@link com.sleepycat.db.Environment#openDatabase Environment.openDatabase} method to
119    create the database if it does not already exist.
120    */
121    public void setAllowCreate(final boolean allowCreate) {
122        this.allowCreate = allowCreate;
123    }
124
125    /**
126Return true if the {@link com.sleepycat.db.Environment#openDatabase Environment.openDatabase} method is configured
127    to create the database if it does not already exist.
128<p>
129This method may be called at any time during the life of the application.
130<p>
131@return
132True if the {@link com.sleepycat.db.Environment#openDatabase Environment.openDatabase} method is configured
133    to create the database if it does not already exist.
134    */
135    public boolean getAllowCreate() {
136        return allowCreate;
137    }
138
139    /**
140    By default, a byte by byte lexicographic comparison is used for
141    btree keys. To customize the comparison, supply a different
142    Comparator.
143    <p>
144    The <code>compare</code> method is passed the byte arrays representing
145    keys that are stored in the database. If you know how your data is
146    organized in the byte array, then you can write a comparison routine that
147    directly examines the contents of the arrays. Otherwise, you have to
148    reconstruct your original objects, and then perform the comparison.
149    */
150    public void setBtreeComparator(final java.util.Comparator btreeComparator) {
151        this.btreeComparator = btreeComparator;
152    }
153
154    public java.util.Comparator getBtreeComparator() {
155        return btreeComparator;
156    }
157
158    /**
159    Set the minimum number of key/data pairs intended to be stored on any
160    single Btree leaf page.
161    <p>
162    This value is used to determine if key or data items will be stored
163    on overflow pages instead of Btree leaf pages.  The value must be
164    at least 2; if the value is not explicitly set, a value of 2 is used.
165    <p>
166    This method configures a database, not only operations performed using
167the specified {@link com.sleepycat.db.Database Database} handle.
168    <p>
169    This method may not be called after the database is opened.
170If the database already exists when it is opened,
171the information specified to this method will be ignored.
172    <p>
173    @param btMinKey
174    The minimum number of key/data pairs intended to be stored on any
175    single Btree leaf page.
176    */
177    public void setBtreeMinKey(final int btMinKey) {
178        this.btMinKey = btMinKey;
179    }
180
181    /**
182Return the minimum number of key/data pairs intended to be stored
183    on any single Btree leaf page.
184<p>
185This method may be called at any time during the life of the application.
186<p>
187@return
188The minimum number of key/data pairs intended to be stored
189    on any single Btree leaf page.
190    */
191    public int getBtreeMinKey() {
192        return btMinKey;
193    }
194
195    /**
196    Set the byte order for integers in the stored database metadata.
197    <p>
198    The host byte order of the machine where the process is running will
199    be used if no byte order is set.
200    <p>
201    <b>
202    The access methods provide no guarantees about the byte ordering of the
203    application data stored in the database, and applications are
204    responsible for maintaining any necessary ordering.
205    </b>
206    <p>
207    This method configures a database, not only operations performed using
208the specified {@link com.sleepycat.db.Database Database} handle.
209    <p>
210    This method may not be called after the database is opened.
211If the database already exists when it is opened,
212the information specified to this method will be ignored.
213    If creating additional databases in a single physical file, information
214    specified to this method will be ignored and the byte order of the
215    existing databases will be used.
216    <p>
217    @param byteOrder
218    The byte order as an integer; for example, big endian order is the
219    number 4,321, and little endian order is the number 1,234.
220    */
221    public void setByteOrder(final int byteOrder) {
222        this.byteOrder = byteOrder;
223    }
224
225    /**
226Return the database byte order; a byte order of 4,321 indicates a
227    big endian order, and a byte order of 1,234 indicates a little
228    endian order.
229<p>
230This method may be called at any time during the life of the application.
231<p>
232@return
233The database byte order; a byte order of 4,321 indicates a
234    big endian order, and a byte order of 1,234 indicates a little
235    endian order.
236    */
237    public int getByteOrder() {
238        return byteOrder;
239    }
240
241    /**
242    Return if the underlying database files were created on an architecture
243    of the same byte order as the current one.
244    <p>
245    This information may be used to determine whether application data
246    needs to be adjusted for this architecture or not.
247    <p>
248    This method may not be called before the
249database has been opened.
250    <p>
251    @return
252    Return false if the underlying database files were created on an
253    architecture of the same byte order as the current one, and true if
254    they were not (that is, big-endian on a little-endian machine, or
255    vice versa).
256    */
257    public boolean getByteSwapped() {
258        return byteOrder != 0 && byteOrder != DbUtil.default_lorder();
259    }
260
261    /**
262    Set the Btree compression callbacks.
263    */
264    public void setBtreeCompressor(final BtreeCompressor btreeCompressor) {
265    	this.btreeCompressor = btreeCompressor;
266    }
267
268    /**
269    Get the Btree compression callbacks.
270    */
271    public BtreeCompressor getBtreeCompressor() {
272        return btreeCompressor;
273    }
274
275    /**
276    Set the Btree prefix callback.  The prefix callback is used to determine
277    the amount by which keys stored on the Btree internal pages can be
278    safely truncated without losing their uniqueness.  See the
279    <a href="{@docRoot}/../programmer_reference/bt_conf.html#am_conf_bt_prefix" target="_top">Btree prefix
280    comparison</a> section of the Berkeley DB Reference Guide for more
281    details about how this works.  The usefulness of this is data-dependent,
282    but can produce significantly reduced tree sizes and search times in
283    some data sets.
284    <p>
285    If no prefix callback or key comparison callback is specified by the
286    application, a default lexical comparison function is used to calculate
287    prefixes.  If no prefix callback is specified and a key comparison
288    callback is specified, no prefix function is used.  It is an error to
289    specify a prefix function without also specifying a Btree key comparison
290    function.
291    */
292    public void setBtreePrefixCalculator(
293            final BtreePrefixCalculator btreePrefixCalculator) {
294        this.btreePrefixCalculator = btreePrefixCalculator;
295    }
296
297    /**
298Return the Btree prefix callback.
299<p>
300This method may be called at any time during the life of the application.
301<p>
302@return
303The Btree prefix callback.
304    */
305    public BtreePrefixCalculator getBtreePrefixCalculator() {
306        return btreePrefixCalculator;
307    }
308
309    /**
310    Set the size of the shared memory buffer pool, that is, the size of the
311cache.
312<p>
313The cache should be the size of the normal working data set of the
314application, with some small amount of additional memory for unusual
315situations.  (Note: the working set is not the same as the number of
316pages accessed simultaneously, and is usually much larger.)
317<p>
318The default cache size is 256KB, and may not be specified as less than
31920KB.  Any cache size less than 500MB is automatically increased by 25%
320to account for buffer pool overhead; cache sizes larger than 500MB are
321used as specified.  The current maximum size of a single cache is 4GB.
322(All sizes are in powers-of-two, that is, 256KB is 2^18 not 256,000.)
323<p>
324Because databases opened within database environments use the cache
325specified to the environment, it is an error to attempt to configure a
326cache size in a database created within an environment.
327<p>
328This method may not be called after the database is opened.
329<p>
330This method may be called at any time during the life of the application.
331<p>
332@param cacheSize
333The size of the shared memory buffer pool, that is, the size of the
334cache.
335<p>
336<p>
337@throws DatabaseException if a failure occurs.
338    */
339    public void setCacheSize(final long cacheSize) {
340        this.cacheSize = cacheSize;
341    }
342
343    /**
344Return the size of the shared memory buffer pool, that is, the cache.
345<p>
346This method may be called at any time during the life of the application.
347<p>
348@return
349The size of the shared memory buffer pool, that is, the cache.
350    */
351    public long getCacheSize() {
352        return cacheSize;
353    }
354
355    /**
356Specify which directory a database should be created in or looked for.
357<p>
358@param createDir
359The directory will be used to create or locate the database file specified in
360the openDatabase method call. The directory must be one of the directories
361in the environment list specified by EnvironmentConfig.addDataDirectory.
362<p>
363<p>
364@throws DatabaseException if a failure occurs.
365    */
366    public void setCreateDir(final java.io.File createDir) {
367        this.createDir = createDir;
368    }
369
370    /**
371Return the directory a database will/has been created in or looked for.
372<p>
373This method may be called at any time during the life of the application.
374<p>
375@return
376The directory a database will/has been created in or looked for.
377    */
378    public java.io.File getCreateDir() {
379        return this.createDir;
380    }
381
382    /**
383    Set the number of shared memory buffer pools, that is, the number of
384caches.
385<p>
386It is possible to specify caches larger than 4GB and/or large enough
387they cannot be allocated contiguously on some architectures.  For
388example, some releases of Solaris limit the amount of memory that may
389be allocated contiguously by a process.  This method allows applications
390to break the cache broken up into a number of  equally sized, separate
391pieces of memory.
392<p>
393<p>
394Because databases opened within database environments use the cache
395specified to the environment, it is an error to attempt to configure
396multiple caches in a database created within an environment.
397<p>
398This method may not be called after the database is opened.
399<p>
400This method may be called at any time during the life of the application.
401<p>
402@param cacheCount
403The number of shared memory buffer pools, that is, the number of caches.
404<p>
405<p>
406@throws DatabaseException if a failure occurs.
407    */
408    public void setCacheCount(final int cacheCount) {
409        this.cacheCount = cacheCount;
410    }
411
412    /**
413Return the number of shared memory buffer pools, that is, the number
414    of caches.
415<p>
416This method may be called at any time during the life of the application.
417<p>
418@return
419The number of shared memory buffer pools, that is, the number
420    of caches.
421    */
422    public int getCacheCount() {
423        return cacheCount;
424    }
425
426    /**
427    Configure the database environment to do checksum verification of
428    pages read into the cache from the backing filestore.
429    <p>
430    Berkeley DB uses the SHA1 Secure Hash Algorithm if encryption is
431    also configured for this database, and a general hash algorithm if
432    it is not.
433    <p>
434    Calling this method only affects the specified {@link com.sleepycat.db.Database Database} handle
435(and any other library handles opened within the scope of that handle).
436    <p>
437    If the database already exists when the database is opened, any database
438configuration specified by this method
439will be ignored.
440    If creating additional databases in a file, the checksum behavior
441    specified must be consistent with the existing databases in the file or
442    an error will be returned.
443    <p>
444    @param checksum
445    If true, configure the database environment to do checksum verification
446    of pages read into the cache from the backing filestore.
447    A value of false is illegal to this method, that is, once set, the
448configuration cannot be cleared.
449    */
450    public void setChecksum(final boolean checksum) {
451        this.checksum = checksum;
452    }
453
454    /**
455Return true if the database environment is configured to do checksum
456    verification of pages read into the cache from the backing
457    filestore.
458<p>
459This method may be called at any time during the life of the application.
460<p>
461@return
462True if the database environment is configured to do checksum
463    verification of pages read into the cache from the backing
464    filestore.
465    */
466    public boolean getChecksum() {
467        return checksum;
468    }
469
470    /**
471        Configure the database to support read uncommitted.
472    <p>
473    Read operations on the database may request the return of modified
474    but not yet committed data.  This flag must be specified on all
475    {@link com.sleepycat.db.Database Database} handles used to perform read uncommitted or database
476    updates, otherwise requests for read uncommitted may not be honored and
477    the read may block.
478    <p>
479    @param readUncommitted
480    If true, configure the database to support read uncommitted.
481    */
482    public void setReadUncommitted(final boolean readUncommitted) {
483        this.readUncommitted = readUncommitted;
484    }
485
486    /**
487Return true if the database is configured to support read uncommitted.
488<p>
489This method may be called at any time during the life of the application.
490<p>
491@return
492True if the database is configured to support read uncommitted.
493    */
494    public boolean getReadUncommitted() {
495        return readUncommitted;
496    }
497
498    /**
499        Configure the database to support read uncommitted.
500    <p>
501    Read operations on the database may request the return of modified
502    but not yet committed data.  This flag must be specified on all
503    {@link com.sleepycat.db.Database Database} handles used to perform read uncommitted or database
504    updates, otherwise requests for read uncommitted may not be honored and
505    the read may block.
506    <p>
507    @param dirtyRead
508    If true, configure the database to support read uncommitted.
509        <p>
510    @deprecated This has been replaced by {@link #setReadUncommitted} to conform to ANSI
511    database isolation terminology.
512    */
513    public void setDirtyRead(final boolean dirtyRead) {
514        setReadUncommitted(dirtyRead);
515    }
516
517    /**
518Return true if the database is configured to support read uncommitted.
519<p>
520This method may be called at any time during the life of the application.
521<p>
522@return
523True if the database is configured to support read uncommitted.
524        <p>
525    @deprecated This has been replaced by {@link #getReadUncommitted} to conform to ANSI
526    database isolation terminology.
527    */
528    public boolean getDirtyRead() {
529        return getReadUncommitted();
530    }
531
532    /**
533    Set the duplicate data item comparison callback.  The comparison
534    function is called whenever it is necessary to compare a data item
535    specified by the application with a data item currently stored in the
536    database.  This comparator is only used if
537    {@link com.sleepycat.db.DatabaseConfig#setSortedDuplicates DatabaseConfig.setSortedDuplicates} is also configured.
538    <p>
539    If no comparison function is specified, the data items are compared
540    lexically, with shorter data items collating before longer data items.
541    <p>
542    The <code>compare</code> method is passed the byte arrays representing
543    data items in the database. If you know how your data is organized in
544    the byte array, then you can write a comparison routine that directly
545    examines the contents of the arrays.  Otherwise, you have to
546    reconstruct your original objects, and then perform the comparison.
547    <p>
548    @param duplicateComparator
549    the comparison callback for duplicate data items.
550    */
551    public void setDuplicateComparator(
552            final java.util.Comparator duplicateComparator) {
553        this.duplicateComparator = duplicateComparator;
554    }
555
556    public java.util.Comparator getDuplicateComparator() {
557        return duplicateComparator;
558    }
559
560    /**
561    Set the password used to perform encryption and decryption.
562    <p>
563    Because databases opened within environments use the password
564    specified to the environment, it is an error to attempt to set a
565    password in a database created within an environment.
566    <p>
567    Berkeley DB uses the Rijndael/AES (also known as the Advanced
568    Encryption Standard and Federal Information Processing
569    Standard (FIPS) 197) algorithm for encryption or decryption.
570    */
571    public void setEncrypted(final String password) {
572        this.password = password;
573    }
574
575    /**
576Return true if the database has been configured to perform encryption.
577<p>
578This method may be called at any time during the life of the application.
579<p>
580@return
581True if the database has been configured to perform encryption.
582    */
583    public boolean getEncrypted() {
584        return (password != null);
585    }
586
587    /**
588    Set the function to be called if an error occurs.
589<p>
590When an error occurs in the Berkeley DB library, an exception is thrown.
591In some cases, however, the error information returned to the
592application may be insufficient to completely describe the cause of the
593error, especially during initial application debugging.
594<p>
595The {@link com.sleepycat.db.EnvironmentConfig#setErrorHandler EnvironmentConfig.setErrorHandler} and {@link com.sleepycat.db.DatabaseConfig#setErrorHandler DatabaseConfig.setErrorHandler} methods are used to enhance the mechanism for reporting
596error messages to the application.  In some cases, when an error occurs,
597Berkeley DB will invoke the ErrorHandler's object error method.  It is
598up to this method to display the error message in an appropriate manner.
599<p>
600Alternatively, applications can use {@link com.sleepycat.db.EnvironmentConfig#setErrorStream EnvironmentConfig.setErrorStream} and {@link com.sleepycat.db.DatabaseConfig#setErrorStream DatabaseConfig.setErrorStream} to
601display the additional information via an output stream.  Applications
602should not mix these approaches.
603<p>
604This error-logging enhancement does not slow performance or significantly
605increase application size, and may be run during normal operation as well
606as during application debugging.
607<p>
608For {@link com.sleepycat.db.Database Database} handles opened inside of database environments,
609calling this method affects the entire environment and is equivalent to
610calling {@link com.sleepycat.db.EnvironmentConfig#setErrorHandler EnvironmentConfig.setErrorHandler}.
611<p>
612This method may be called at any time during the life of the application.
613<p>
614@param errorHandler
615The function to be called if an error occurs.
616    */
617    public void setErrorHandler(final ErrorHandler errorHandler) {
618        this.errorHandler = errorHandler;
619    }
620
621    /**
622Return the function to be called if an error occurs.
623<p>
624This method may be called at any time during the life of the application.
625<p>
626@return
627The function to be called if an error occurs.
628    */
629    public ErrorHandler getErrorHandler() {
630        return errorHandler;
631    }
632
633    /**
634    Set the prefix string that appears before error messages.
635<p>
636For {@link com.sleepycat.db.Database Database} handles opened inside of database environments,
637calling this method affects the entire environment and is equivalent to
638calling {@link com.sleepycat.db.EnvironmentConfig#setErrorPrefix EnvironmentConfig.setErrorPrefix}.
639<p>
640This method may be called at any time during the life of the application.
641<p>
642@param errorPrefix
643The prefix string that appears before error messages.
644    */
645    public void setErrorPrefix(final String errorPrefix) {
646        this.errorPrefix = errorPrefix;
647    }
648
649    /**
650Return the prefix string that appears before error messages.
651<p>
652This method may be called at any time during the life of the application.
653<p>
654@return
655The prefix string that appears before error messages.
656    */
657    public String getErrorPrefix() {
658        return errorPrefix;
659    }
660
661    /**
662    Set an OutputStream for displaying error messages.
663<p>
664When an error occurs in the Berkeley DB library, an exception is thrown.
665In some cases, however, the error information returned to the
666application may be insufficient to completely describe the cause of the
667error, especially during initial application debugging.
668<p>
669The {@link com.sleepycat.db.EnvironmentConfig#setErrorStream EnvironmentConfig.setErrorStream} and
670{@link com.sleepycat.db.DatabaseConfig#setErrorStream DatabaseConfig.setErrorStream} methods are used to enhance
671the mechanism for reporting error messages to the application by setting
672a OutputStream to be used for displaying additional Berkeley DB error
673messages.  In some cases, when an error occurs, Berkeley DB will output
674an additional error message to the specified stream.
675<p>
676The error message will consist of the prefix string and a colon
677("<b>:</b>") (if a prefix string was previously specified using
678{@link com.sleepycat.db.EnvironmentConfig#setErrorPrefix EnvironmentConfig.setErrorPrefix} or {@link com.sleepycat.db.DatabaseConfig#setErrorPrefix DatabaseConfig.setErrorPrefix}), an error string, and a trailing newline character.
679<p>
680Setting errorStream to null unconfigures the interface.
681<p>
682Alternatively, applications can use {@link com.sleepycat.db.EnvironmentConfig#setErrorHandler EnvironmentConfig.setErrorHandler} and {@link com.sleepycat.db.DatabaseConfig#setErrorHandler DatabaseConfig.setErrorHandler} to capture
683the additional error information in a way that does not use output
684streams.  Applications should not mix these approaches.
685<p>
686This error-logging enhancement does not slow performance or significantly
687increase application size, and may be run during normal operation as well
688as during application debugging.
689<p>
690This method may be called at any time during the life of the application.
691<p>
692@param errorStream
693The application-specified OutputStream for error messages.
694    */
695    public void setErrorStream(final java.io.OutputStream errorStream) {
696        this.errorStream = errorStream;
697    }
698
699    /**
700Return the an OutputStream for displaying error messages.
701<p>
702This method may be called at any time during the life of the application.
703<p>
704@return
705The an OutputStream for displaying error messages.
706    */
707    public java.io.OutputStream getErrorStream() {
708        return errorStream;
709    }
710
711    /**
712    Configure the {@link com.sleepycat.db.Environment#openDatabase Environment.openDatabase} method to fail if
713    the database already exists.
714    <p>
715    The exclusiveCreate mode is only meaningful if specified with the
716    allowCreate mode.
717    <p>
718    @param exclusiveCreate
719    If true, configure the {@link com.sleepycat.db.Environment#openDatabase Environment.openDatabase} method to
720    fail if the database already exists.
721    */
722    public void setExclusiveCreate(final boolean exclusiveCreate) {
723        this.exclusiveCreate = exclusiveCreate;
724    }
725
726    /**
727Return true if the {@link com.sleepycat.db.Environment#openDatabase Environment.openDatabase} method is configured
728    to fail if the database already exists.
729<p>
730This method may be called at any time during the life of the application.
731<p>
732@return
733True if the {@link com.sleepycat.db.Environment#openDatabase Environment.openDatabase} method is configured
734    to fail if the database already exists.
735    */
736    public boolean getExclusiveCreate() {
737        return exclusiveCreate;
738    }
739
740    /**
741    Set an object whose methods are called to provide feedback.
742<p>
743Some operations performed by the Berkeley DB library can take
744non-trivial amounts of time.  This method can be used by applications
745to monitor progress within these operations.  When an operation is
746likely to take a long time, Berkeley DB will call the object's methods
747with progress information.
748<p>
749It is up to the object's methods to display this information in an
750appropriate manner.
751<p>
752This method configures only operations performed using a single a
753{@link com.sleepycat.db.Environment Environment} handle
754<p>
755This method may be called at any time during the life of the application.
756<p>
757@param feedbackHandler
758An object whose methods are called to provide feedback.
759    */
760    public void setFeedbackHandler(final FeedbackHandler feedbackHandler) {
761        this.feedbackHandler = feedbackHandler;
762    }
763
764    /**
765Return the object's methods to be called to provide feedback.
766<p>
767This method may be called at any time during the life of the application.
768<p>
769@return
770The object's methods to be called to provide feedback.
771    */
772    public FeedbackHandler getFeedbackHandler() {
773        return feedbackHandler;
774    }
775
776    /**
777    Set the desired density within the hash table.
778    <p>
779    If no value is specified, the fill factor will be selected dynamically
780    as pages are filled.
781    <p>
782    The density is an approximation of the number of keys allowed to
783    accumulate in any one bucket, determining when the hash table grows or
784    shrinks.  If you know the average sizes of the keys and data in your
785    data set, setting the fill factor can enhance performance.  A reasonable
786    rule computing fill factor is to set it to the following:
787    <blockquote><pre>
788        (pagesize - 32) / (average_key_size + average_data_size + 8)
789    </pre></blockquote>
790    <p>
791    This method configures a database, not only operations performed using
792the specified {@link com.sleepycat.db.Database Database} handle.
793    <p>
794    This method may not be called after the database is opened.
795If the database already exists when it is opened,
796the information specified to this method will be ignored.
797    <p>
798    @param hashFillFactor
799    The desired density within the hash table.
800    */
801    public void setHashFillFactor(final int hashFillFactor) {
802        this.hashFillFactor = hashFillFactor;
803    }
804
805    /**
806Return the hash table density.
807<p>
808This method may be called at any time during the life of the application.
809<p>
810@return
811The hash table density.
812    */
813    public int getHashFillFactor() {
814        return hashFillFactor;
815    }
816
817    /**
818    Set the Hash key comparison function. The comparison function is called
819    whenever it is necessary to compare a key specified by the application with
820    a key currently stored in the database.
821    <p>
822    If no comparison function is specified, a byte-by-byte comparison is
823    performed.
824    <p>
825    The <code>compare</code> method is passed the byte arrays representing
826    keys that are stored in the database. If you know how your data is
827    organized in the byte array, then you can write a comparison routine that
828    directly examines the contents of the arrays. Otherwise, you have to
829    reconstruct your original objects, and then perform the comparison.
830    */
831    public void setHashComparator(final java.util.Comparator hashComparator) {
832        this.hashComparator = hashComparator;
833    }
834
835    /**
836Return the Comparator used to compare keys in a Hash database.
837<p>
838This method may be called at any time during the life of the application.
839<p>
840@return
841The Comparator used to compare keys in a Hash database.
842    */
843    public java.util.Comparator getHashComparator() {
844        return hashComparator;
845    }
846
847    /**
848    Set a database-specific hash function.
849    <p>
850    If no hash function is specified, a default hash function is used.
851    Because no hash function performs equally well on all possible data,
852    the user may find that the built-in hash function performs poorly
853    with a particular data set.
854    <p>
855    This method configures operations performed using the specified
856{@link com.sleepycat.db.Database Database} object, not all operations performed on the underlying
857database.
858    <p>
859    This method may not be called after the database is opened.
860If the database already exists when it is opened,
861the information specified to this method must be the same as that
862historically used to create the database or corruption can occur.
863    <p>
864    @param hasher
865    A database-specific hash function.
866    */
867    public void setHasher(final Hasher hasher) {
868        this.hasher = hasher;
869    }
870
871    /**
872Return the database-specific hash function.
873<p>
874This method may be called at any time during the life of the application.
875<p>
876@return
877The database-specific hash function.
878    */
879    public Hasher getHasher() {
880        return hasher;
881    }
882
883    /**
884    Set an estimate of the final size of the hash table.
885    <p>
886    In order for the estimate to be used when creating the database, the
887    {@link com.sleepycat.db.DatabaseConfig#setHashFillFactor DatabaseConfig.setHashFillFactor} method must also be called.
888    If the estimate or fill factor are not set or are set too low, hash
889    tables will still expand gracefully as keys are entered, although a
890    slight performance degradation may be noticed.
891    <p>
892    This method configures a database, not only operations performed using
893the specified {@link com.sleepycat.db.Database Database} handle.
894    <p>
895    This method may not be called after the database is opened.
896If the database already exists when it is opened,
897the information specified to this method will be ignored.
898    <p>
899    @param hashNumElements
900    An estimate of the final size of the hash table.
901    */
902    public void setHashNumElements(final int hashNumElements) {
903        this.hashNumElements = hashNumElements;
904    }
905
906    /**
907Return the estimate of the final size of the hash table.
908<p>
909This method may be called at any time during the life of the application.
910<p>
911@return
912The estimate of the final size of the hash table.
913    */
914    public int getHashNumElements() {
915        return hashNumElements;
916    }
917
918    /**
919    Set a function to be called with an informational message.
920<p>
921There are interfaces in the Berkeley DB library which either directly
922output informational messages or statistical information, or configure
923the library to output such messages when performing other operations,
924{@link com.sleepycat.db.EnvironmentConfig#setVerboseDeadlock EnvironmentConfig.setVerboseDeadlock} for example.
925<p>
926The {@link com.sleepycat.db.EnvironmentConfig#setMessageHandler EnvironmentConfig.setMessageHandler} and
927{@link com.sleepycat.db.DatabaseConfig#setMessageHandler DatabaseConfig.setMessageHandler} methods are used to display
928these messages for the application.
929<p>
930Setting messageHandler to null unconfigures the interface.
931<p>
932Alternatively, you can use {@link com.sleepycat.db.EnvironmentConfig#setMessageStream EnvironmentConfig.setMessageStream}
933and {@link com.sleepycat.db.DatabaseConfig#setMessageStream DatabaseConfig.setMessageStream} to send the additional
934information directly to an output streams.  You should not mix these
935approaches.
936<p>
937For {@link com.sleepycat.db.Database Database} handles opened inside of database environments,
938calling this method affects the entire environment and is equivalent to
939calling {@link com.sleepycat.db.EnvironmentConfig#setMessageHandler EnvironmentConfig.setMessageHandler}.
940<p>
941This method may be called at any time during the life of the application.
942<p>
943@param messageHandler
944The application-specified function for informational messages.
945    */
946    public void setMessageHandler(final MessageHandler messageHandler) {
947        this.messageHandler = messageHandler;
948    }
949
950    /**
951Return the function to be called with an informational message.
952<p>
953This method may be called at any time during the life of the application.
954<p>
955@return
956The function to be called with an informational message.
957    */
958    public MessageHandler getMessageHandler() {
959        return messageHandler;
960    }
961
962    /**
963    Set an OutputStream for displaying informational messages.
964<p>
965There are interfaces in the Berkeley DB library which either directly
966output informational messages or statistical information, or configure
967the library to output such messages when performing other operations,
968{@link com.sleepycat.db.EnvironmentConfig#setVerboseDeadlock EnvironmentConfig.setVerboseDeadlock} for example.
969<p>
970The {@link com.sleepycat.db.EnvironmentConfig#setMessageStream EnvironmentConfig.setMessageStream} and
971{@link com.sleepycat.db.DatabaseConfig#setMessageStream DatabaseConfig.setMessageStream} methods are used to display
972these messages for the application.  In this case, the message will
973include a trailing newline character.
974<p>
975Setting messageStream to null unconfigures the interface.
976<p>
977Alternatively, you can use {@link com.sleepycat.db.EnvironmentConfig#setMessageHandler EnvironmentConfig.setMessageHandler}
978and {@link com.sleepycat.db.DatabaseConfig#setMessageHandler DatabaseConfig.setMessageHandler} to capture the additional
979information in a way that does not use output streams.  You should not
980mix these approaches.
981<p>
982For {@link com.sleepycat.db.Database Database} handles opened inside of database environments,
983calling this method affects the entire environment and is equivalent to
984calling {@link com.sleepycat.db.EnvironmentConfig#setMessageStream EnvironmentConfig.setMessageStream}.
985<p>
986This method may be called at any time during the life of the application.
987<p>
988@param messageStream
989The application-specified OutputStream for informational messages.
990    */
991    public void setMessageStream(final java.io.OutputStream messageStream) {
992        this.messageStream = messageStream;
993    }
994
995    /**
996Return the an OutputStream for displaying informational messages.
997<p>
998This method may be called at any time during the life of the application.
999<p>
1000@return
1001The an OutputStream for displaying informational messages.
1002    */
1003    public java.io.OutputStream getMessageStream() {
1004        return messageStream;
1005    }
1006
1007    /**
1008    On UNIX systems or in IEEE/ANSI Std 1003.1 (POSIX) environments, files
1009    created by the database open are created with mode <code>mode</code>
1010    (as described in the <code>chmod</code>(2) manual page) and modified
1011    by the process' umask value at the time of creation (see the
1012    <code>umask</code>(2) manual page).  Created files are owned by the
1013    process owner; the group ownership of created files is based on the
1014    system and directory defaults, and is not further specified by Berkeley
1015    DB.  System shared memory segments created by the database open are
1016    created with mode <code>mode</code>, unmodified by the process' umask
1017    value.  If <code>mode</code> is 0, the database open will use a default
1018    mode of readable and writable by both owner and group.
1019    <p>
1020    On Windows systems, the mode parameter is ignored.
1021    <p>
1022    @param mode
1023    the mode used to create files
1024    */
1025    public void setMode(final int mode) {
1026        this.mode = mode;
1027    }
1028
1029    /**
1030Return the mode used to create files.
1031<p>
1032This method may be called at any time during the life of the application.
1033<p>
1034@return
1035The mode used to create files.
1036    */
1037    public long getMode() {
1038        return mode;
1039    }
1040
1041    /**
1042    Configured the database with support for multiversion concurrency control.
1043    This will cause updates to the database to follow a copy-on-write
1044    protocol, which is required to support Snapshot Isolation.  See
1045    {@link TransactionConfig#setSnapshot}) for more information.
1046    Multiversion access requires that the database be opened
1047    in a transaction and is not supported for queue databases.
1048    <p>
1049    @param multiversion
1050    If true, configure the database with support for multiversion concurrency
1051    control.
1052    */
1053    public void setMultiversion(final boolean multiversion) {
1054        this.multiversion = multiversion;
1055    }
1056
1057    /**
1058Return true if the database is configured for multiversion concurrency control.
1059<p>
1060This method may be called at any time during the life of the application.
1061<p>
1062@return
1063True if the database is configured for multiversion concurrency control.
1064    */
1065    public boolean getMultiversion() {
1066        return multiversion;
1067    }
1068
1069    /**
1070    Configure the library to not map this database into memory.
1071    <p>
1072    @param noMMap
1073    If true, configure the library to not map this database into memory.
1074    */
1075    public void setNoMMap(final boolean noMMap) {
1076        this.noMMap = noMMap;
1077    }
1078
1079    /**
1080Return true if the library is configured to not map this database into
1081    memory.
1082<p>
1083This method may be called at any time during the life of the application.
1084<p>
1085@return
1086True if the library is configured to not map this database into
1087    memory.
1088    */
1089    public boolean getNoMMap() {
1090        return noMMap;
1091    }
1092
1093    /**
1094    Set the size of the pages used to hold items in the database, in bytes.
1095    <p>
1096    The minimum page size is 512 bytes, the maximum page size is 64K bytes,
1097    and the page size must be a power-of-two.  If the page size is not
1098    explicitly set, one is selected based on the underlying filesystem I/O
1099    block size.  The automatically selected size has a lower limit of 512
1100    bytes and an upper limit of 16K bytes.
1101    <p>
1102    This method configures a database, not only operations performed using
1103the specified {@link com.sleepycat.db.Database Database} handle.
1104    <p>
1105    This method may not be called after the database is opened.
1106If the database already exists when it is opened,
1107the information specified to this method will be ignored.
1108    If creating additional databases in a file, the page size specified must
1109    be consistent with the existing databases in the file or an error will
1110    be returned.
1111    <p>
1112    @param pageSize
1113    The size of the pages used to hold items in the database, in bytes.
1114    */
1115    public void setPageSize(final int pageSize) {
1116        this.pageSize = pageSize;
1117    }
1118
1119    /**
1120Return the size of the pages used to hold items in the database, in bytes.
1121<p>
1122This method may be called at any time during the life of the application.
1123<p>
1124@return
1125The size of the pages used to hold items in the database, in bytes.
1126    */
1127    public int getPageSize() {
1128        return pageSize;
1129    }
1130
1131    /**
1132    Set the function to be called if the database environment panics.
1133<p>
1134Errors can occur in the Berkeley DB library where the only solution is
1135to shut down the application and run recovery (for example, if Berkeley
1136DB is unable to allocate heap memory).  In such cases, the Berkeley DB
1137methods will throw a {@link com.sleepycat.db.RunRecoveryException RunRecoveryException}.  It is often easier
1138to simply exit the application when such errors occur rather than
1139gracefully return up the stack.  This method specifies a function to be
1140called when {@link com.sleepycat.db.RunRecoveryException RunRecoveryException} is about to be thrown from a
1141Berkeley DB method.
1142<p>
1143For {@link com.sleepycat.db.Database Database} handles opened inside of database environments,
1144calling this method affects the entire environment and is equivalent to
1145calling {@link com.sleepycat.db.EnvironmentConfig#setPanicHandler EnvironmentConfig.setPanicHandler}.
1146<p>
1147This method may be called at any time during the life of the application.
1148<p>
1149@param panicHandler
1150The function to be called if the database environment panics.
1151    */
1152    public void setPanicHandler(final PanicHandler panicHandler) {
1153        this.panicHandler = panicHandler;
1154    }
1155
1156    /**
1157Return the function to be called if the database environment panics.
1158<p>
1159This method may be called at any time during the life of the application.
1160<p>
1161@return
1162The function to be called if the database environment panics.
1163    */
1164    public PanicHandler getPanicHandler() {
1165        return panicHandler;
1166    }
1167
1168    /**
1169    Enable or disable database partitioning, and set the callback that will
1170be used for the partitioning.
1171<p>
1172This method may only be called before opening a database.
1173<p>
1174@param parts
1175The number of partitions that will be created.
1176<p>
1177@param partitionHandler
1178The function to be called to determine which partition a key resides in.
1179    */
1180    public void setPartitionByCallback(int parts,
1181        final PartitionHandler partitionHandler) {
1182        this.partitionParts = parts;
1183        this.partitionHandler = partitionHandler;
1184    }
1185
1186    /**
1187    Enable or disable database partitioning, and set key ranges that will be
1188    used for the partitioning.
1189<p>
1190This method may only be called before opening a database.
1191<p>
1192@param parts
1193The number of partitions that will be created.
1194<p>
1195@param keys
1196A MultipleDatabaseEntry that contains the boundary keys for partitioning.
1197    */
1198    public void setPartitionByRange(int parts, MultipleDataEntry keys) {
1199        this.partitionParts = parts;
1200        this.partitionKeys = keys;
1201    }
1202
1203    /**
1204Return the function to be called to determine which partition a key resides in.
1205<p>
1206This method may be called at any time during the life of the application.
1207<p>
1208@return
1209The function to be called to determine which partition a key resides in.
1210    */
1211    public PartitionHandler getPartitionHandler() {
1212        return partitionHandler;
1213    }
1214
1215    /**
1216Return the number of partitions the database is configured for.
1217<p>
1218This method may be called at any time during the life of the application.
1219<p>
1220@return
1221The number of partitions the database is configured for.
1222    */
1223    public int getPartitionParts() {
1224        return partitionParts;
1225    }
1226
1227    /**
1228Return the array of keys the database is configured to partition with.
1229<p>
1230This method may be called at any time during the life of the application.
1231<p>
1232@return
1233The array of keys the database is configured to partition with.
1234    */
1235    public DatabaseEntry getPartitionKeys() {
1236        return partitionKeys;
1237    }
1238
1239    /**
1240Specify the array of directories the database extents should be created in or
1241looked for. If the number of directories is less than the number of partitions,
1242the directories will be used in a round robin fasion.
1243<p>
1244This method may only be called before the database is opened.
1245<p>
1246@param dirs
1247The array of directories the database extents should be created in or looked
1248for.
1249    */
1250    public void setPartitionDirs(final java.io.File[] dirs) {
1251    	partitionDirs = dirs;
1252    }
1253
1254    /**
1255Return the array of directories the database extents should be created in or
1256looked for. If the number of directories is less than the number of partitions,
1257the directories will be used in a round robin fasion.
1258<p>
1259This method may be called at any time during the life of the application.
1260<p>
1261@return
1262The array of directories the database extents should be created in or looked
1263for.
1264    */
1265    public java.io.File[] getPartitionDirs() {
1266    	return partitionDirs;
1267    }
1268
1269    /**
1270    Set the cache priority for pages referenced by the DB handle.
1271    <p>
1272    The priority of a page biases the replacement algorithm to be more or less
1273    likely to discard a page when space is needed in the buffer pool. The bias
1274    is temporary, and pages will eventually be discarded if they are not
1275    referenced again. The priority setting is only advisory, and does not
1276    guarantee pages will be treated in a specific way.
1277    <p>
1278    @param priority
1279    The desired cache priority.
1280    */
1281    public void setPriority(final CacheFilePriority priority) {
1282        this.priority = priority;
1283    }
1284
1285    /**
1286Return the the cache priority for pages referenced by this handle.
1287<p>
1288This method may be called at any time during the life of the application.
1289<p>
1290@return
1291The the cache priority for pages referenced by this handle.
1292    */
1293    public CacheFilePriority getPriority() {
1294        return priority;
1295    }
1296
1297    /**
1298    Set the size of the extents used to hold pages in a Queue database,
1299    specified as a number of pages.
1300    <p>
1301    Each extent is created as a separate physical file.  If no extent
1302    size is set, the default behavior is to create only a single
1303    underlying database file.
1304    <p>
1305    This method configures a database, not only operations performed using
1306the specified {@link com.sleepycat.db.Database Database} handle.
1307    <p>
1308    This method may not be called after the database is opened.
1309If the database already exists when it is opened,
1310the information specified to this method will be ignored.
1311    <p>
1312    @param queueExtentSize
1313    The number of pages in a Queue database extent.
1314    */
1315    public void setQueueExtentSize(final int queueExtentSize) {
1316        this.queueExtentSize = queueExtentSize;
1317    }
1318
1319    /**
1320Return the size of the extents used to hold pages in a Queue database,
1321    specified as a number of pages.
1322<p>
1323This method may be called at any time during the life of the application.
1324<p>
1325@return
1326The size of the extents used to hold pages in a Queue database,
1327    specified as a number of pages.
1328    */
1329    public int getQueueExtentSize() {
1330        return queueExtentSize;
1331    }
1332
1333    /**
1334    Configure {@link com.sleepycat.db.Database#consume Database.consume} to return key/data pairs in
1335    order, always returning the key/data item from the head of the
1336    queue.
1337    <p>
1338    The default behavior of queue databases is optimized for multiple
1339    readers, and does not guarantee that record will be retrieved in the
1340    order they are added to the queue.  Specifically, if a writing
1341    thread adds multiple records to an empty queue, reading threads may
1342    skip some of the initial records when the next call to retrieve a
1343    key/data pair returns.
1344    <p>
1345    This flag configures the {@link com.sleepycat.db.Database#consume Database.consume} method to verify
1346    that the record being returned is in fact the head of the queue.
1347    This will increase contention and reduce concurrency when there are
1348    many reading threads.
1349    <p>
1350    Calling this method only affects the specified {@link com.sleepycat.db.Database Database} handle
1351(and any other library handles opened within the scope of that handle).
1352    <p>
1353    @param queueInOrder
1354    If true, configure the {@link com.sleepycat.db.Database#consume Database.consume} method to return
1355    key/data pairs in order, always returning the key/data item from the
1356    head of the queue.
1357    A value of false is illegal to this method, that is, once set, the
1358configuration cannot be cleared.
1359    */
1360    public void setQueueInOrder(final boolean queueInOrder) {
1361        this.queueInOrder = queueInOrder;
1362    }
1363
1364    /**
1365Return true if the {@link com.sleepycat.db.Database#consume Database.consume} method is configured to return
1366    key/data pairs in order, always returning the key/data item from the
1367    head of the queue.
1368<p>
1369This method may be called at any time during the life of the application.
1370<p>
1371@return
1372True if the {@link com.sleepycat.db.Database#consume Database.consume} method is configured to return
1373    key/data pairs in order, always returning the key/data item from the
1374    head of the queue.
1375    */
1376    public boolean getQueueInOrder() {
1377        return queueInOrder;
1378    }
1379
1380    /**
1381    Configure the database in read-only mode.
1382    <p>
1383    Any attempt to modify items in the database will fail, regardless
1384    of the actual permissions of any underlying files.
1385    <p>
1386    @param readOnly
1387    If true, configure the database in read-only mode.
1388    */
1389    public void setReadOnly(final boolean readOnly) {
1390        this.readOnly = readOnly;
1391    }
1392
1393    /**
1394Return true if the database is configured in read-only mode.
1395<p>
1396This method may be called at any time during the life of the application.
1397<p>
1398@return
1399True if the database is configured in read-only mode.
1400    */
1401    public boolean getReadOnly() {
1402        return readOnly;
1403    }
1404
1405    /**
1406    Configure {@link com.sleepycat.db.Database#append Database.append} to call the function after the
1407    record number has been selected but before the data has been stored
1408    into the database.
1409    <p>
1410    This method configures operations performed using the specified
1411{@link com.sleepycat.db.Database Database} object, not all operations performed on the underlying
1412database.
1413    <p>
1414    This method may not be called after the database is opened.
1415    <p>
1416    @param recnoAppender
1417    The function to call after the record number has been selected but
1418    before the data has been stored into the database.
1419    */
1420    public void setRecordNumberAppender(
1421            final RecordNumberAppender recnoAppender) {
1422        this.recnoAppender = recnoAppender;
1423    }
1424
1425    /**
1426Return the function to call after the record number has been
1427    selected but before the data has been stored into the database.
1428<p>
1429This method may be called at any time during the life of the application.
1430<p>
1431@return
1432The function to call after the record number has been
1433    selected but before the data has been stored into the database.
1434    */
1435    public RecordNumberAppender getRecordNumberAppender() {
1436        return recnoAppender;
1437    }
1438
1439    /**
1440    Set the delimiting byte used to mark the end of a record in the backing
1441    source file for the Recno access method.
1442    <p>
1443    This byte is used for variable length records if a backing source
1444    file is specified.  If a backing source file is specified and no
1445    delimiting byte was specified, newline characters (that is, ASCII
1446    0x0a) are interpreted as end-of-record markers.
1447    <p>
1448    This method configures a database, not only operations performed using
1449the specified {@link com.sleepycat.db.Database Database} handle.
1450    <p>
1451    This method may not be called after the database is opened.
1452If the database already exists when it is opened,
1453the information specified to this method will be ignored.
1454    <p>
1455    @param recordDelimiter
1456    The delimiting byte used to mark the end of a record in the backing
1457    source file for the Recno access method.
1458    */
1459    public void setRecordDelimiter(final int recordDelimiter) {
1460        this.recordDelimiter = recordDelimiter;
1461    }
1462
1463    /**
1464Return the delimiting byte used to mark the end of a record in the
1465    backing source file for the Recno access method.
1466<p>
1467This method may be called at any time during the life of the application.
1468<p>
1469@return
1470The delimiting byte used to mark the end of a record in the
1471    backing source file for the Recno access method.
1472    */
1473    public int getRecordDelimiter() {
1474        return recordDelimiter;
1475    }
1476
1477    /**
1478    Specify the database record length, in bytes.
1479    <p>
1480    For the Queue access method, specify the record length.  For the
1481    Queue access method, the record length must be enough smaller than
1482    the database's page size that at least one record plus the database
1483    page's metadata information can fit on each database page.
1484    <p>
1485    For the Recno access method, specify the records are fixed-length,
1486    not byte-delimited, and the record length.
1487    <p>
1488    Any records added to the database that are less than the specified
1489    length are automatically padded (see
1490    {@link com.sleepycat.db.DatabaseConfig#setRecordPad DatabaseConfig.setRecordPad} for more information).
1491    <p>
1492    Any attempt to insert records into the database that are greater
1493    than the specified length will cause the call to fail.
1494    <p>
1495    This method configures a database, not only operations performed using
1496the specified {@link com.sleepycat.db.Database Database} handle.
1497    <p>
1498    This method may not be called after the database is opened.
1499If the database already exists when it is opened,
1500the information specified to this method will be ignored.
1501    <p>
1502    @param recordLength
1503    The database record length, in bytes.
1504    */
1505    public void setRecordLength(final int recordLength) {
1506        this.recordLength = recordLength;
1507    }
1508
1509    /**
1510Return the database record length, in bytes.
1511<p>
1512This method may be called at any time during the life of the application.
1513<p>
1514@return
1515The database record length, in bytes.
1516    */
1517    public int getRecordLength() {
1518        return recordLength;
1519    }
1520
1521    /**
1522    Configure the Btree to support retrieval by record number.
1523    <p>
1524    Logical record numbers in Btree databases are mutable in the face of
1525    record insertion or deletion.
1526    <p>
1527    Maintaining record counts within a Btree introduces a serious point
1528    of contention, namely the page locations where the record counts are
1529    stored.  In addition, the entire database must be locked during both
1530    insertions and deletions, effectively single-threading the database
1531    for those operations.  Configuring a Btree for retrieval by record
1532    number can result in serious performance degradation for some
1533    applications and data sets.
1534    <p>
1535    Retrieval by record number may not be configured for a Btree that also
1536    supports duplicate data items.
1537    <p>
1538    Calling this method affects the database, including all threads of
1539control accessing the database.
1540    <p>
1541    If the database already exists when the database is opened, any database
1542configuration specified by this method
1543must be the same as the existing database or an error
1544will be returned.
1545    <p>
1546    @param btreeRecordNumbers
1547    If true, configure the Btree to support retrieval by record number.
1548    A value of false is illegal to this method, that is, once set, the
1549configuration cannot be cleared.
1550    */
1551    public void setBtreeRecordNumbers(final boolean btreeRecordNumbers) {
1552        this.btreeRecordNumbers = btreeRecordNumbers;
1553    }
1554
1555    /**
1556Return true if the Btree is configured to support retrieval by record number.
1557<p>
1558This method may be called at any time during the life of the application.
1559<p>
1560@return
1561True if the Btree is configured to support retrieval by record number.
1562    */
1563    public boolean getBtreeRecordNumbers() {
1564        return btreeRecordNumbers;
1565    }
1566
1567    /**
1568    Set the padding character for short, fixed-length records for the Queue
1569    and Recno access methods.
1570    <p>
1571    If no pad character is specified, "space" characters (that is, ASCII
1572    0x20) are used for padding.
1573    <p>
1574    This method configures a database, not only operations performed using
1575the specified {@link com.sleepycat.db.Database Database} handle.
1576    <p>
1577    This method may not be called after the database is opened.
1578If the database already exists when it is opened,
1579the information specified to this method will be ignored.
1580    <p>
1581    @param recordPad
1582    The padding character for short, fixed-length records for the Queue
1583    and Recno access methods.
1584    */
1585    public void setRecordPad(final int recordPad) {
1586        this.recordPad = recordPad;
1587    }
1588
1589    /**
1590Return the padding character for short, fixed-length records for the
1591    Queue and Recno access methods.
1592<p>
1593This method may be called at any time during the life of the application.
1594<p>
1595@return
1596The padding character for short, fixed-length records for the
1597    Queue and Recno access methods.
1598    */
1599    public int getRecordPad() {
1600        return recordPad;
1601    }
1602
1603    /**
1604    Set the underlying source file for the Recno access method.
1605    <p>
1606    The purpose of the source file is to provide fast access and
1607    modification to databases that are normally stored as flat text
1608    files.
1609    <p>
1610    The recordSource parameter specifies an underlying flat text
1611    database file that is read to initialize a transient record number
1612    index.  In the case of variable length records, the records are
1613    separated, as specified by the
1614    {@link com.sleepycat.db.DatabaseConfig#setRecordDelimiter DatabaseConfig.setRecordDelimiter} method.  For example,
1615    standard UNIX byte stream files can be interpreted as a sequence of
1616    variable length records separated by newline characters (that is, ASCII
1617    0x0a).
1618    <p>
1619    In addition, when cached data would normally be written back to the
1620    underlying database file (for example, the {@link com.sleepycat.db.Database#close Database.close}
1621    or {@link com.sleepycat.db.Database#sync Database.sync} methods are called), the in-memory copy
1622    of the database will be written back to the source file.
1623    <p>
1624    By default, the backing source file is read lazily; that is, records
1625    are not read from the file until they are requested by the application.
1626    <b>
1627    If multiple processes (not threads) are accessing a Recno database
1628    concurrently, and are either inserting or deleting records, the backing
1629    source file must be read in its entirety before more than a single
1630    process accesses the database, and only that process should specify
1631    the backing source file as part of opening the database.  See the
1632    {@link com.sleepycat.db.DatabaseConfig#setSnapshot DatabaseConfig.setSnapshot} method for more information.
1633    </b>
1634    <p>
1635    <b>
1636    Reading and writing the backing source file cannot be
1637    transaction-protected because it involves filesystem operations that
1638    are not part of the {@link com.sleepycat.db.Database Database} transaction methodology.  For
1639    this reason, if a temporary database is used to hold the records,
1640    it is possible to lose the contents of the source file, for example,
1641    if the system crashes at the right instant.  If a file is used to
1642    hold the database, normal database recovery on that file can be used
1643    to prevent information loss, although it is still possible that the
1644    contents of the source file will be lost if the system crashes.
1645    </b>
1646    <p>
1647    The source file must already exist (but may be zero-length) when
1648    the database is opened.
1649    <p>
1650    It is not an error to specify a read-only source file when creating
1651    a database, nor is it an error to modify the resulting database.
1652    However, any attempt to write the changes to the backing source file
1653    using either the {@link com.sleepycat.db.Database#sync Database.sync} or {@link com.sleepycat.db.Database#close Database.close}
1654    methods will fail, of course.  Specify the noSync argument to the
1655    {@link com.sleepycat.db.Database#close Database.close} method to stop it from attempting to write
1656    the changes to the backing file; instead, they will be silently
1657    discarded.
1658    <p>
1659    For all of the previous reasons, the source file is generally used
1660    to specify databases that are read-only for Berkeley DB
1661    applications; and that are either generated on the fly by software
1662    tools or modified using a different mechanism -- for example, a text
1663    editor.
1664    <p>
1665    This method configures operations performed using the specified
1666{@link com.sleepycat.db.Database Database} object, not all operations performed on the underlying
1667database.
1668    <p>
1669    This method may not be called after the database is opened.
1670If the database already exists when it is opened,
1671the information specified to this method must be the same as that
1672historically used to create the database or corruption can occur.
1673    <p>
1674    @param recordSource
1675    The name of an underlying flat text database file that is read to
1676    initialize a transient record number index.  In the case of variable
1677    length records, the records are separated, as specified by the
1678    {@link com.sleepycat.db.DatabaseConfig#setRecordDelimiter DatabaseConfig.setRecordDelimiter} method.  For example,
1679    standard UNIX byte stream files can be interpreted as a sequence of
1680   variable length records separated by newline characters (that is, ASCII
1681    0x0a).
1682    */
1683    public void setRecordSource(final java.io.File recordSource) {
1684        this.recordSource = recordSource;
1685    }
1686
1687    /**
1688Return the name of an underlying flat text database file that is
1689    read to initialize a transient record number index.
1690<p>
1691This method may be called at any time during the life of the application.
1692<p>
1693@return
1694The name of an underlying flat text database file that is
1695    read to initialize a transient record number index.
1696    */
1697    public java.io.File getRecordSource() {
1698        return recordSource;
1699    }
1700
1701    /**
1702    Configure the logical record numbers to be mutable, and change as
1703    records are added to and deleted from the database.
1704    <p>
1705    For example, the deletion of record number 4 causes records numbered
1706    5 and greater to be renumbered downward by one.  If a cursor was
1707    positioned to record number 4 before the deletion, it will refer to
1708    the new record number 4, if any such record exists, after the
1709    deletion.  If a cursor was positioned after record number 4 before
1710    the deletion, it will be shifted downward one logical record,
1711    continuing to refer to the same record as it did before.
1712    <p>
1713    Creating new records will cause the creation of multiple records if
1714    the record number is more than one greater than the largest record
1715    currently in the database.  For example, creating record 28, when
1716    record 25 was previously the last record in the database, will
1717    create records 26 and 27 as well as 28.  Attempts to retrieve
1718    records that were created in this manner will result in an error
1719    return of {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY}.
1720    <p>
1721    If a created record is not at the end of the database, all records
1722    following the new record will be automatically renumbered upward by one.
1723    For example, the creation of a new record numbered 8 causes records
1724    numbered 8 and greater to be renumbered upward by one.  If a cursor was
1725    positioned to record number 8 or greater before the insertion, it will
1726    be shifted upward one logical record, continuing to refer to the same
1727    record as it did before.
1728    <p>
1729    For these reasons, concurrent access to a Recno database configured
1730    with mutable record numbers may be largely meaningless, although it
1731    is supported.
1732    <p>
1733    Calling this method affects the database, including all threads of
1734control accessing the database.
1735    <p>
1736    If the database already exists when the database is opened, any database
1737configuration specified by this method
1738must be the same as the existing database or an error
1739will be returned.
1740    <p>
1741    @param renumbering
1742    If true, configure the logical record numbers to be mutable, and
1743    change as records are added to and deleted from the database.
1744    A value of false is illegal to this method, that is, once set, the
1745configuration cannot be cleared.
1746    */
1747    public void setRenumbering(final boolean renumbering) {
1748        this.renumbering = renumbering;
1749    }
1750
1751    /**
1752Return true if the logical record numbers are mutable, and change as
1753    records are added to and deleted from the database.
1754<p>
1755This method may be called at any time during the life of the application.
1756<p>
1757@return
1758True if the logical record numbers are mutable, and change as
1759    records are added to and deleted from the database.
1760    */
1761    public boolean getRenumbering() {
1762        return renumbering;
1763    }
1764
1765    /**
1766    Configure the Btree to not do reverse splits.
1767    <p>
1768    As pages are emptied in a database, the Btree implementation
1769    attempts to coalesce empty pages into higher-level pages in order
1770    to keep the database as small as possible and minimize search time.
1771    This can hurt performance in applications with cyclical data
1772    demands; that is, applications where the database grows and shrinks
1773    repeatedly.  For example, because Berkeley DB does page-level locking,
1774    the maximum level of concurrency in a database of two pages is far
1775    smaller than that in a database of 100 pages, so a database that has
1776    shrunk to a minimal size can cause severe deadlocking when a new
1777    cycle of data insertion begins.
1778    <p>
1779    Calling this method only affects the specified {@link com.sleepycat.db.Database Database} handle
1780(and any other library handles opened within the scope of that handle).
1781    <p>
1782    @param reverseSplitOff
1783    If true, configure the Btree to not do reverse splits.
1784    A value of false is illegal to this method, that is, once set, the
1785configuration cannot be cleared.
1786    */
1787    public void setReverseSplitOff(final boolean reverseSplitOff) {
1788        this.reverseSplitOff = reverseSplitOff;
1789    }
1790
1791    /**
1792Return true if the Btree has been configured to not do reverse splits.
1793<p>
1794This method may be called at any time during the life of the application.
1795<p>
1796@return
1797True if the Btree has been configured to not do reverse splits.
1798    */
1799    public boolean getReverseSplitOff() {
1800        return reverseSplitOff;
1801    }
1802
1803    /**
1804    Configure the database to support sorted, duplicate data items.
1805    <p>
1806    Insertion when the key of the key/data pair being inserted already
1807    exists in the database will be successful.  The ordering of
1808    duplicates in the database is determined by the duplicate comparison
1809    function.
1810    <p>
1811    If the application does not specify a duplicate data item comparison
1812    function, a default lexical comparison will be used.
1813    <p>
1814    If a primary database is to be associated with one or more secondary
1815    databases, it may not be configured for duplicates.
1816    <p>
1817    A Btree that supports duplicate data items cannot also be configured
1818    for retrieval by record number.
1819    <p>
1820    Calling this method affects the database, including all threads of
1821control accessing the database.
1822    <p>
1823    If the database already exists when the database is opened, any database
1824configuration specified by this method
1825must be the same as the existing database or an error
1826will be returned.
1827    <p>
1828    @param sortedDuplicates
1829    If true, configure the database to support duplicate data items.
1830    A value of false is illegal to this method, that is, once set, the
1831configuration cannot be cleared.
1832    */
1833    public void setSortedDuplicates(final boolean sortedDuplicates) {
1834        this.sortedDuplicates = sortedDuplicates;
1835    }
1836
1837    /**
1838Return true if the database is configured to support sorted duplicate data
1839    items.
1840<p>
1841This method may be called at any time during the life of the application.
1842<p>
1843@return
1844True if the database is configured to support sorted duplicate data
1845    items.
1846    */
1847    public boolean getSortedDuplicates() {
1848        return sortedDuplicates;
1849    }
1850
1851    /**
1852    Configure the database to support unsorted duplicate data items.
1853    <p>
1854    Insertion when the key of the key/data pair being inserted already
1855    exists in the database will be successful.  The ordering of
1856    duplicates in the database is determined by the order of insertion,
1857    unless the ordering is otherwise specified by use of a database
1858    cursor operation.
1859    <p>
1860    If a primary database is to be associated with one or more secondary
1861    databases, it may not be configured for duplicates.
1862    <p>
1863    Sorted duplicates are preferred to unsorted duplicates for
1864    performance reasons.  Unsorted duplicates should only be used by
1865    applications wanting to order duplicate data items manually.
1866    <p>
1867    Calling this method affects the database, including all threads of
1868control accessing the database.
1869    <p>
1870    If the database already exists when the database is opened, any database
1871configuration specified by this method
1872must be the same as the existing database or an error
1873will be returned.
1874    <p>
1875    @param unsortedDuplicates
1876    If true, configure the database to support unsorted duplicate data items.
1877    A value of false is illegal to this method, that is, once set, the
1878configuration cannot be cleared.
1879    */
1880    public void setUnsortedDuplicates(final boolean unsortedDuplicates) {
1881        this.unsortedDuplicates = unsortedDuplicates;
1882    }
1883
1884    /**
1885Return true if the database is configured to support duplicate data items.
1886<p>
1887This method may be called at any time during the life of the application.
1888<p>
1889@return
1890True if the database is configured to support duplicate data items.
1891    */
1892    public boolean getUnsortedDuplicates() {
1893        return unsortedDuplicates;
1894    }
1895
1896    /**
1897    Specify that any specified backing source file be read in its entirety
1898    when the database is opened.
1899    <p>
1900    If this flag is not specified, the backing source file may be read
1901    lazily.
1902    <p>
1903    Calling this method only affects the specified {@link com.sleepycat.db.Database Database} handle
1904(and any other library handles opened within the scope of that handle).
1905    <p>
1906    @param snapshot
1907    If true, any specified backing source file will be read in its entirety
1908    when the database is opened.
1909    A value of false is illegal to this method, that is, once set, the
1910configuration cannot be cleared.
1911    */
1912    public void setSnapshot(final boolean snapshot) {
1913        this.snapshot = snapshot;
1914    }
1915
1916    /**
1917Return true if the any specified backing source file will be read in its
1918    entirety when the database is opened.
1919<p>
1920This method may be called at any time during the life of the application.
1921<p>
1922@return
1923True if the any specified backing source file will be read in its
1924    entirety when the database is opened.
1925    */
1926    public boolean getSnapshot() {
1927        return snapshot;
1928    }
1929
1930    /**
1931Return true if the database open is enclosed within a transaction.
1932<p>
1933This method may be called at any time during the life of the application.
1934<p>
1935@return
1936True if the database open is enclosed within a transaction.
1937    */
1938    public boolean getTransactional() {
1939        return transactional;
1940    }
1941
1942    /**
1943    Enclose the database open within a transaction.
1944    <p>
1945    If the call succeeds, the open operation will be recoverable.  If
1946    the call fails, no database will have been created.
1947    <p>
1948    All future operations on this database, which are not explicitly
1949    enclosed in a transaction by the application, will be enclosed in
1950    in a transaction within the library.
1951    <p>
1952    @param transactional
1953    If true, enclose the database open within a transaction.
1954    */
1955    public void setTransactional(final boolean transactional) {
1956        this.transactional = transactional;
1957    }
1958
1959    /**
1960    Configure the database environment to not write log records for this
1961    database.
1962    <p>
1963    This means that updates of this database exhibit the ACI (atomicity,
1964    consistency, and isolation) properties, but not D (durability); that
1965    is, database integrity will be maintained, but if the application
1966    or system fails, integrity will not persist.  The database file must
1967    be verified and/or restored from backup after a failure.  In order
1968    to ensure integrity after application shut down, the database
1969    must be flushed to disk before the database handles are closed,
1970    or all
1971    database changes must be flushed from the database environment cache
1972    using {@link com.sleepycat.db.Environment#checkpoint Environment.checkpoint}.
1973    <p>
1974    All database handles for a single physical file must call this method,
1975    including database handles for different databases in a physical file.
1976    <p>
1977    Calling this method only affects the specified {@link com.sleepycat.db.Database Database} handle
1978(and any other library handles opened within the scope of that handle).
1979    <p>
1980    @param transactionNotDurable
1981    If true, configure the database environment to not write log records
1982    for this database.
1983    A value of false is illegal to this method, that is, once set, the
1984configuration cannot be cleared.
1985    */
1986    public void setTransactionNotDurable(final boolean transactionNotDurable) {
1987        this.transactionNotDurable = transactionNotDurable;
1988    }
1989
1990    /**
1991Return true if the database environment is configured to not write log
1992    records for this database.
1993<p>
1994This method may be called at any time during the life of the application.
1995<p>
1996@return
1997True if the database environment is configured to not write log
1998    records for this database.
1999    */
2000    public boolean getTransactionNotDurable() {
2001        return transactionNotDurable;
2002    }
2003
2004    /**
2005    Configure the database to be physically truncated by truncating the
2006    underlying file, discarding all previous databases it might have
2007    held.
2008    <p>
2009    Underlying filesystem primitives are used to implement this
2010    configuration.  For this reason, it is applicable only to a physical
2011    file and cannot be used to discard databases within a file.
2012    <p>
2013    This configuration option cannot be lock or transaction-protected, and
2014    it is an error to specify it in a locking or transaction-protected
2015    database environment.
2016    <p>
2017    @param truncate
2018    If true, configure the database to be physically truncated by truncating
2019    the underlying file, discarding all previous databases it might have
2020    held.
2021    */
2022    public void setTruncate(final boolean truncate) {
2023        this.truncate = truncate;
2024    }
2025
2026    /**
2027Return true if the database has been configured to be physically truncated
2028    by truncating the underlying file, discarding all previous databases
2029    it might have held.
2030<p>
2031This method may be called at any time during the life of the application.
2032<p>
2033@return
2034True if the database has been configured to be physically truncated
2035    by truncating the underlying file, discarding all previous databases
2036    it might have held.
2037    */
2038    public boolean getTruncate() {
2039        return truncate;
2040    }
2041
2042    /**
2043    Configure the type of the database.
2044    <p>
2045    If they type is DB_UNKNOWN, the database must already exist.
2046    <p>
2047    @param type
2048    The type of the database.
2049    */
2050    public void setType(final DatabaseType type) {
2051        this.type = type;
2052    }
2053
2054    /**
2055    Return the type of the database.
2056    <p>
2057    This method may be used to determine the type of the database after
2058    opening it.
2059    <p>
2060    This method may not be called before the
2061database has been opened.
2062    <p>
2063    @return
2064    The type of the database.
2065    */
2066    public DatabaseType getType() {
2067        return type;
2068    }
2069
2070    /* package */
2071    Db createDatabase(final DbEnv dbenv)
2072        throws DatabaseException {
2073
2074        return new Db(dbenv, 0);
2075    }
2076
2077    /* package */
2078    Db openDatabase(final DbEnv dbenv,
2079                    final DbTxn txn,
2080                    final String fileName,
2081                    final String databaseName)
2082        throws DatabaseException, java.io.FileNotFoundException {
2083
2084        final Db db = createDatabase(dbenv);
2085        // The DB_THREAD flag is inherited from the environment
2086        // (defaulting to ON if no environment handle is supplied).
2087        boolean threaded = (dbenv == null ||
2088            (dbenv.get_open_flags() & DbConstants.DB_THREAD) != 0);
2089
2090        int openFlags = 0;
2091        openFlags |= allowCreate ? DbConstants.DB_CREATE : 0;
2092        openFlags |= readUncommitted ? DbConstants.DB_READ_UNCOMMITTED : 0;
2093        openFlags |= exclusiveCreate ? DbConstants.DB_EXCL : 0;
2094        openFlags |= multiversion ? DbConstants.DB_MULTIVERSION : 0;
2095        openFlags |= noMMap ? DbConstants.DB_NOMMAP : 0;
2096        openFlags |= readOnly ? DbConstants.DB_RDONLY : 0;
2097        openFlags |= threaded ? DbConstants.DB_THREAD : 0;
2098        openFlags |= truncate ? DbConstants.DB_TRUNCATE : 0;
2099
2100        if (transactional && txn == null)
2101            openFlags |= DbConstants.DB_AUTO_COMMIT;
2102
2103        boolean succeeded = false;
2104        try {
2105            configureDatabase(db, DEFAULT);
2106            db.open(txn, fileName, databaseName, type.getId(), openFlags, mode);
2107            succeeded = true;
2108            return db;
2109        } finally {
2110            if (!succeeded)
2111                try {
2112                    db.close(0);
2113                } catch (Throwable t) {
2114                    // Ignore it -- an exception is already in flight.
2115                }
2116        }
2117    }
2118
2119    /* package */
2120    void configureDatabase(final Db db, final DatabaseConfig oldConfig)
2121        throws DatabaseException {
2122
2123        int dbFlags = 0;
2124        dbFlags |= checksum ? DbConstants.DB_CHKSUM : 0;
2125        dbFlags |= btreeRecordNumbers ? DbConstants.DB_RECNUM : 0;
2126        dbFlags |= queueInOrder ? DbConstants.DB_INORDER : 0;
2127        dbFlags |= renumbering ? DbConstants.DB_RENUMBER : 0;
2128        dbFlags |= reverseSplitOff ? DbConstants.DB_REVSPLITOFF : 0;
2129        dbFlags |= sortedDuplicates ? DbConstants.DB_DUPSORT : 0;
2130        dbFlags |= snapshot ? DbConstants.DB_SNAPSHOT : 0;
2131        dbFlags |= unsortedDuplicates ? DbConstants.DB_DUP : 0;
2132        dbFlags |= transactionNotDurable ? DbConstants.DB_TXN_NOT_DURABLE : 0;
2133        if (!db.getPrivateDbEnv())
2134                dbFlags |= (password != null) ? DbConstants.DB_ENCRYPT : 0;
2135
2136        if (dbFlags != 0)
2137            db.set_flags(dbFlags);
2138
2139        if (btMinKey != oldConfig.btMinKey)
2140            db.set_bt_minkey(btMinKey);
2141        if (byteOrder != oldConfig.byteOrder)
2142            db.set_lorder(byteOrder);
2143        if ((cacheSize != oldConfig.cacheSize ||
2144            cacheCount != oldConfig.cacheCount) && db.getPrivateDbEnv())
2145            db.set_cachesize(cacheSize, cacheCount);
2146        if (createDir != oldConfig.createDir && createDir != null &&
2147            !createDir.equals(oldConfig.createDir))
2148            db.set_create_dir(createDir.toString());
2149        if (errorStream != oldConfig.errorStream)
2150            db.set_error_stream(errorStream);
2151        if (errorPrefix != oldConfig.errorPrefix)
2152            db.set_errpfx(errorPrefix);
2153        if (hashFillFactor != oldConfig.hashFillFactor)
2154            db.set_h_ffactor(hashFillFactor);
2155        if (hashNumElements != oldConfig.hashNumElements)
2156            db.set_h_nelem(hashNumElements);
2157        if (messageStream != oldConfig.messageStream)
2158            db.set_message_stream(messageStream);
2159        if (pageSize != oldConfig.pageSize)
2160            db.set_pagesize(pageSize);
2161
2162        if (partitionDirs != null &&
2163            partitionDirs != oldConfig.partitionDirs) {
2164            String[] partitionDirArray = new String[partitionDirs.length];
2165            for (int i = 0; i < partitionDirArray.length; i++)
2166                partitionDirArray[i] = partitionDirs[i].toString();
2167            db.set_partition_dirs(partitionDirArray);
2168        }
2169        if (password != oldConfig.password && db.getPrivateDbEnv())
2170            db.set_encrypt(password, DbConstants.DB_ENCRYPT_AES);
2171        if (priority != oldConfig.priority)
2172            db.set_priority(priority.getFlag());
2173        if (queueExtentSize != oldConfig.queueExtentSize)
2174            db.set_q_extentsize(queueExtentSize);
2175        if (recordDelimiter != oldConfig.recordDelimiter)
2176            db.set_re_delim(recordDelimiter);
2177        if (recordLength != oldConfig.recordLength)
2178            db.set_re_len(recordLength);
2179        if (recordPad != oldConfig.recordPad)
2180            db.set_re_pad(recordPad);
2181        if (recordSource != oldConfig.recordSource)
2182            db.set_re_source(
2183                (recordSource == null) ? null : recordSource.toString());
2184
2185        if (btreeComparator != oldConfig.btreeComparator)
2186            db.set_bt_compare(btreeComparator);
2187        if (btreeCompressor != oldConfig.btreeCompressor)
2188            db.set_bt_compress(btreeCompressor, btreeCompressor);
2189        if (btreePrefixCalculator != oldConfig.btreePrefixCalculator)
2190            db.set_bt_prefix(btreePrefixCalculator);
2191        if (duplicateComparator != oldConfig.duplicateComparator)
2192            db.set_dup_compare(duplicateComparator);
2193        if (feedbackHandler != oldConfig.feedbackHandler)
2194            db.set_feedback(feedbackHandler);
2195        if (errorHandler != oldConfig.errorHandler)
2196            db.set_errcall(errorHandler);
2197        if (hashComparator != oldConfig.hashComparator)
2198            db.set_h_compare(hashComparator);
2199        if (hasher != oldConfig.hasher)
2200            db.set_h_hash(hasher);
2201        if (messageHandler != oldConfig.messageHandler)
2202            db.set_msgcall(messageHandler);
2203        if (partitionHandler != oldConfig.partitionHandler ||
2204            partitionKeys != oldConfig.partitionKeys ||
2205            partitionParts != oldConfig.partitionParts)
2206            db.set_partition(partitionParts, partitionKeys, partitionHandler);
2207        if (recnoAppender != oldConfig.recnoAppender)
2208            db.set_append_recno(recnoAppender);
2209        if (panicHandler != oldConfig.panicHandler)
2210            db.set_paniccall(panicHandler);
2211    }
2212
2213    /* package */
2214    DatabaseConfig(final Db db)
2215        throws DatabaseException {
2216
2217        type = DatabaseType.fromInt(db.get_type());
2218
2219        final int openFlags = db.get_open_flags();
2220        allowCreate = (openFlags & DbConstants.DB_CREATE) != 0;
2221        readUncommitted = (openFlags & DbConstants.DB_READ_UNCOMMITTED) != 0;
2222        exclusiveCreate = (openFlags & DbConstants.DB_EXCL) != 0;
2223        multiversion = (openFlags & DbConstants.DB_MULTIVERSION) != 0;
2224        noMMap = (openFlags & DbConstants.DB_NOMMAP) != 0;
2225        readOnly = (openFlags & DbConstants.DB_RDONLY) != 0;
2226        truncate = (openFlags & DbConstants.DB_TRUNCATE) != 0;
2227
2228        final int dbFlags = db.get_flags();
2229        checksum = (dbFlags & DbConstants.DB_CHKSUM) != 0;
2230        btreeRecordNumbers = (dbFlags & DbConstants.DB_RECNUM) != 0;
2231        queueInOrder = (dbFlags & DbConstants.DB_INORDER) != 0;
2232        renumbering = (dbFlags & DbConstants.DB_RENUMBER) != 0;
2233        reverseSplitOff = (dbFlags & DbConstants.DB_REVSPLITOFF) != 0;
2234        sortedDuplicates = (dbFlags & DbConstants.DB_DUPSORT) != 0;
2235        snapshot = (dbFlags & DbConstants.DB_SNAPSHOT) != 0;
2236        unsortedDuplicates = (dbFlags & DbConstants.DB_DUP) != 0;
2237        transactionNotDurable = (dbFlags & DbConstants.DB_TXN_NOT_DURABLE) != 0;
2238
2239        if (type == DatabaseType.BTREE) {
2240            btMinKey = db.get_bt_minkey();
2241        }
2242        byteOrder = db.get_lorder();
2243        // Call get_cachesize* on the DbEnv to avoid this error:
2244        //   DB->get_cachesize: method not permitted in shared environment
2245        cacheSize = db.get_env().get_cachesize();
2246        cacheCount = db.get_env().get_cachesize_ncache();
2247        errorStream = db.get_error_stream();
2248        errorPrefix = db.get_errpfx();
2249        if (type == DatabaseType.HASH) {
2250            hashFillFactor = db.get_h_ffactor();
2251            hashNumElements = db.get_h_nelem();
2252        }
2253        messageStream = db.get_message_stream();
2254        // Not available by design
2255        password = ((dbFlags & DbConstants.DB_ENCRYPT) != 0) ? "" : null;
2256        priority = CacheFilePriority.fromFlag(db.get_priority());
2257        if (type == DatabaseType.QUEUE) {
2258            queueExtentSize = db.get_q_extentsize();
2259        }
2260        if (type == DatabaseType.QUEUE || type == DatabaseType.RECNO) {
2261            recordLength = db.get_re_len();
2262            recordPad = db.get_re_pad();
2263        }
2264        if (type == DatabaseType.RECNO) {
2265            recordDelimiter = db.get_re_delim();
2266            recordSource = (db.get_re_source() == null) ? null :
2267                new java.io.File(db.get_re_source());
2268        }
2269        transactional = db.get_transactional();
2270        createDir = (db.get_create_dir() == null) ? null:
2271            new java.io.File(db.get_create_dir());
2272
2273        String[] partitionDirArray = db.get_partition_dirs();
2274        if (partitionDirArray == null)
2275            partitionDirArray = new String[0];
2276        partitionDirs = new java.io.File[partitionDirArray.length];
2277        for (int i = 0; i < partitionDirArray.length; i++)
2278            partitionDirs[i] = new java.io.File(partitionDirArray[i]);
2279
2280        btreeComparator = db.get_bt_compare();
2281        btreeCompressor = db.get_bt_compress();
2282        btreePrefixCalculator = db.get_bt_prefix();
2283        duplicateComparator = db.get_dup_compare();
2284        feedbackHandler = db.get_feedback();
2285        errorHandler = db.get_errcall();
2286        hashComparator = db.get_h_compare();
2287        hasher = db.get_h_hash();
2288        messageHandler = db.get_msgcall();
2289        partitionParts = db.get_partition_parts();
2290        partitionKeys = db.get_partition_keys();
2291        partitionHandler = db.get_partition_callback();
2292        recnoAppender = db.get_append_recno();
2293        panicHandler = db.get_paniccall();
2294    }
2295}
2296