File: Curia.java

package info (click to toggle)
qdbm 1.8.78-6.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,952 kB
  • ctags: 5,454
  • sloc: ansic: 31,454; cpp: 3,623; perl: 2,167; java: 2,079; ruby: 1,690; makefile: 1,318; sh: 396
file content (727 lines) | stat: -rw-r--r-- 29,840 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
/*************************************************************************************************
 * Java API of Curia, the extended API of QDBM
 *                                                      Copyright (C) 2000-2006 Mikio Hirabayashi
 * This file is part of QDBM, Quick Database Manager.
 * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU
 * Lesser General Public License as published by the Free Software Foundation; either version
 * 2.1 of the License or any later version.  QDBM is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 * You should have received a copy of the GNU Lesser General Public License along with QDBM; if
 * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307 USA.
 *************************************************************************************************/


package qdbm;



/**
 * The Java API of Curia, the extended API of QDBM.
 * This class depends on the native library `jqdbm'.
 */
public class Curia implements ADBM {
  //----------------------------------------------------------------
  // error codes
  //----------------------------------------------------------------
  /** error code: no error */
  public static final int ENOERR = 0;
  /** error code: with fatal error */
  public static final int EFATAL = 1;
  /** error code: invalid mode */
  public static final int EMODE = 2;
  /** error code: broken database file */
  public static final int EBROKEN = 3;
  /** error code: existing record */
  public static final int EKEEP = 4;
  /** error code: no item found */
  public static final int ENOITEM = 5;
  /** error code: memory allocation error */
  public static final int EALLOC = 6;
  /** error code: memory mapping error */
  public static final int EMAP = 7;
  /** error code: open error */
  public static final int EOPEN = 8;
  /** error code: close error */
  public static final int ECLOSE = 9;
  /** error code: trunc error */
  public static final int ETRUNC = 10;
  /** error code: sync error */
  public static final int ESYNC = 11;
  /** error code: stat error */
  public static final int ESTAT = 12;
  /** error code: seek error */
  public static final int ESEEK = 13;
  /** error code: read error */
  public static final int EREAD = 14;
  /** error code: write error */
  public static final int EWRITE = 15;
  /** error code: lock error */
  public static final int ELOCK = 16;
  /** error code: unlink error */
  public static final int EUNLINK = 17;
  /** error code: mkdir error */
  public static final int EMKDIR = 18;
  /** error code: rmdir error */
  public static final int ERMDIR = 19;
  /** error code: miscellaneous error */
  public static final int EMISC = 20;
  //----------------------------------------------------------------
  // open modes
  //----------------------------------------------------------------
  /** open mode: open as a reader */
  public static final int OREADER = 1 << 0;
  /** open mode: open as a writer */
  public static final int OWRITER = 1 << 1;
  /** open mode: writer creating */
  public static final int OCREAT = 1 << 2;
  /** open mode: writer truncating */
  public static final int OTRUNC = 1 << 3;
  /** open mode: open without locking */
  public static final int ONOLCK = 1 << 4;
  /** open mode: lock without blocking */
  public static final int OLCKNB = 1 << 5;
  /** open mode: create as sparse files */
  public static final int OSPARSE = 1 << 6;
  //----------------------------------------------------------------
  // write modes
  //----------------------------------------------------------------
  /** write mode: overwrite the existing value */
  public static final int DOVER = 0;
  /** write mode: keep the existing value */
  public static final int DKEEP = 1;
  /** write mode: concatenate values */
  public static final int DCAT = 2;
  //----------------------------------------------------------------
  // static initializer
  //----------------------------------------------------------------
  static {
    try {
      System.loadLibrary("jqdbm");
    } catch(UnsatisfiedLinkError e){
      e.printStackTrace();
    }
    crinit();
  }
  //----------------------------------------------------------------
  // public static methods
  //----------------------------------------------------------------
  /**
   * Get the version information.
   * @return a string of the version information.
   */
  public static synchronized String version(){
    return crversion();
  }
  /**
   * Get an error message.
   * @param ecode an error code.
   * @return the message string of the error code.
   */
  public static synchronized String errmsg(int ecode){
    return crerrmsg(ecode);
  }
  /**
   * Remove a database directory.
   * @param name the name of a database directory.
   * @throws CuriaException if an error occurs.
   */
  public static void remove(String name) throws CuriaException {
    synchronized(ADBM.class){
      if(crremove(name) == 0) throw new CuriaException(crecode());
    }
  }
  /**
   * Retrieve a record directly from a database directory.
   * @param name the name of a database directory.
   * @param key a byte array of a key.
   * @throws CuriaException if an error occurs or no record corresponds.
   * @note Although this method can be used even while the database directory is locked by
   * another process, it is not assured that recent updated is reflected.
   */
  public static byte[] snaffle(String name, byte[] key) throws CuriaException {
    synchronized(ADBM.class){
      byte[] val = crsnaffle(name, key, key.length);
      if(val == null) throw new CuriaException(crecode());
      return val;
    }
  }
  //----------------------------------------------------------------
  // instance fields
  //----------------------------------------------------------------
  /** Whether to repress frequent exceptions. */
  public boolean silent;
  /** Index of the native table for database handles. */
  private int index;
  //----------------------------------------------------------------
  // public or protected methods
  //----------------------------------------------------------------
  /**
   * Get the database handle.
   * @param name the name of a database directory.
   * @param omode the connection mode: `Curia.OWRITER' as a writer, `Curia.OREADER' as
   * a reader.  If the mode is `Curia.OWRITER', the following may be added by bitwise or:
   * `Curia.OCREAT', which means it creates a new database if not exist, `Curia.OTRUNC',
   * which means it creates a new database regardless if one exists.  Both of `Curia.OREADER'
   * and `Curia.OWRITER' can be added to by bitwise or: `Curia.ONOLCK', which means it opens a
   * database directory without file locking, or `Curia.OLCKNB', which means locking is performed
   * without blocking.  `Curia.OCREAT' can be added to by bitwise or: `Curia.OSPARSE', which
   * means it creates database files as sparse files.
   * @param bnum the number of elements of the each bucket array.  If it is not more than 0,
   * the default value is specified.  The size of each bucket array is determined on creating,
   * and can not be changed except for by optimization of the database.  Suggested size of each
   * bucket array is about from 0.5 to 4 times of the number of all records to store.
   * @param dnum the number of division of the database.  If it is not more than 0, the default
   * value is specified.  The number of division can not be changed from the initial value.  The
   * max number of division is 512.
   * @throws CuriaException if an error occurs.
   * @note While connecting as a writer, an exclusive lock is invoked to the database directory.
   * While connecting as a reader, a shared lock is invoked to the database directory.
   * The thread blocks until the lock is achieved.  If `Curia.ONOLCK' is used, the application
   * is responsible for exclusion control.
   */
  public Curia(String name, int omode, int bnum, int dnum) throws CuriaException {
    synchronized(ADBM.class){
      silent = false;
      if((index = cropen(name, omode, bnum, dnum)) == -1) throw new CuriaException(crecode());
    }
  }
  /**
   * Get the database handle as a reader.
   * The same as `Curia(name, Curia.OREADER, -1)'.
   * @see #Curia(java.lang.String, int, int, int)
   */
  public Curia(String name) throws CuriaException {
    this(name, OREADER, -1, -1);
  }
  /**
   * Release the resources.
   * @note If the database handle is not closed yet, it is closed.  Every database should be
   * closed explicitly.  Do not cast the duty on the gerbage collection.
   */
  protected void finalize() throws Throwable {
    try {
      if(index < 0) return;
      synchronized(ADBM.class){
        crclose(index);
        index = -1;
      }
    } finally {
      super.finalize();
    }
  }
  /**
   * Close the database handle.
   * @throws CuriaException if an error occurs.
   * @note Updating a database is assured to be written when the handle is closed.  If a
   * writer opens a database but does not close it appropriately, the database will be broken.
   */
  public void close() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      int rv = crclose(index);
      index = -1;
      if(rv == 0) throw new CuriaException(crecode());
    }
  }
  /**
   * Store a record.
   * @param key a byte array of a key.
   * @param val a byte array of a value.
   * @param dmode behavior when the key overlaps, by the following values: `Curia.DOVER',
   * which means the specified value overwrites the existing one, `Curia.DKEEP', which means the
   * existing value is kept, `Curia.DCAT', which means the specified value is concatenated at
   * the end of the existing value.
   * @return always true.  However, if the silent flag is true and replace is cancelled, false is
   * returned instead of exception.
   * @throws CuriaException if an error occurs or replace is cancelled.
   */
  public boolean put(byte[] key, byte[] val, int dmode) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(crput(index, key, key.length, val, val.length, dmode) == 0){
        if(silent && crecode() == EKEEP) return false;
        throw new CuriaException(crecode());
      }
      return true;
    }
  }
  /**
   * Store a record with overwrite.
   * The same as `put(key, val, Curia.DOVER)'.
   * @see #put(byte[], byte[], int)
   */
  public boolean put(byte[] key, byte[] val) throws CuriaException {
    return put(key, val, DOVER);
  }
  /**
   * Delete a record.
   * @param key a byte array of a key.
   * @return always true.  However, if the silent flag is true and no record corresponds, false
   * is returned instead of exception.
   * @throws CuriaException if an error occurs or no record corresponds.
   */
  public boolean out(byte[] key) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(crout(index, key, key.length) == 0){
        if(silent && crecode() == ENOITEM) return false;
        throw new CuriaException(crecode());
      }
      return true;
    }
  }
  /**
   * Retrieve a record.
   * @param key a byte array of a key.
   * @param start the array index of the beginning of the value to be read.
   * @param max the max size to read with.  If it is negative, the size is unlimited.
   * @return a byte array of the value of the corresponding record.  If the silent flag is true
   * and no record corresponds, `null' is returned instead of exception.
   * @throws CuriaException if an error occurs, no record corresponds, or the size of the value
   * of the corresponding record is less than the index specified by the parameter `start'.
   */
  public byte[] get(byte[] key, int start, int max) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      byte[] val = crget(index, key, key.length, start, max);
      if(val == null){
        if(silent && crecode() == ENOITEM) return null;
        throw new CuriaException(crecode());
      }
      return val;
    }
  }
  /**
   * Retrieve whole value of a record.
   * The same as `get(key, 0, -1)'.
   * @see #get(byte[], int, int)
   */
  public byte[] get(byte[] key) throws CuriaException {
    return get(key, 0, -1);
  }
  /**
   * Get the size of the value of a record.
   * @param key a byte array of a key.
   * @return the size of the value of the corresponding record.  If the silent flag is true and
   * no record corresponds, -1 is returned instead of exception.
   * @throws CuriaException if an error occurs or no record corresponds.
   * @note Because this method does not read the entity of a record, it is faster than `get'.
   */
  public int vsiz(byte[] key) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      int rv = crvsiz(index, key, key.length);
      if(rv == -1){
        if(silent && crecode() == ENOITEM) return -1;
        throw new CuriaException(crecode());
      }
      return rv;
    }
  }
  /**
   * Initialize the iterator of the database handle.
   * @throws CuriaException if an error occurs.
   * @note The iterator is used in order to access the key of every record stored in a database.
   */
  public void iterinit() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(criterinit(index) == 0) throw new CuriaException(crecode());
    }
  }
  /**
   * Get the next key of the iterator.
   * @return a byte array of the key of the next record.  If the silent flag is true and no
   * record corresponds, `null' is returned instead of exception.
   * @throws CuriaException if an error occurs or no record corresponds.
   * @note It is possible to access every record by iteration of calling this method.
   * However, it is not assured if updating the database is occurred while the iteration.
   * Besides, the order of this traversal access method is arbitrary, so it is not assured
   * that the order of storing matches the one of the traversal access.
   */
  public byte[] iternext() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      byte[] val = criternext(index);
      if(val == null){
        if(silent && crecode() == ENOITEM) return null;
        throw new CuriaException(crecode());
      }
      return val;
    }
  }
  /**
   * Set alignment of the database handle.
   * @param align the basic size of alignment.
   * @throws CuriaException if an error occurs.
   * @note If alignment is set to a database, the efficiency of overwriting values is improved.
   * The size of alignment is suggested to be average size of the values of the records to be
   * stored.  If alignment is positive, padding whose size is multiple number of the alignment
   * is placed.  If alignment is negative, as `vsiz' is the size of a value, the size of padding
   * is calculated with `(vsiz / pow(2, abs(align) - 1))'.  Because alignment setting is not
   * saved in a database, you should specify alignment every opening a database.
   */
  public void setalign(int align) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(crsetalign(index, align) == 0) throw new CuriaException(crecode());
    }
  }
  /**
   * Set the size of the free block pool.
   * @param size the size of the free block pool of a database.
   * @throws CuriaException if an error occurs.
   * @note The default size of the free block pool is 16.  If the size is greater, the space
   * efficiency of overwriting values is improved with the time efficiency sacrificed.
   */
  public void setfbpsiz(int size) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(crsetfbpsiz(index, size) == 0) throw new CuriaException(crecode());
    }
  }
  /**
   * Synchronize updating contents with the files and the devices.
   * @throws CuriaException if an error occurs.
   * @note This method is useful when another process uses the connected database directory.
   */
  public void sync() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(crsync(index) == 0) throw new CuriaException(crecode());
    }
  }
  /**
   * Optimize the database.
   * @param bnum the number of the elements of each bucket array.  If it is not more than 0, the
   * default value is specified.
   * @throws CuriaException if an error occurs.
   * @note In an alternating succession of deleting and storing with overwrite or concatenate,
   * dispensable regions accumulate.  This method is useful to do away with them.
   */
  public void optimize(int bnum) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(croptimize(index, bnum) == 0) throw new CuriaException(crecode());
    }
  }
  /**
   * Get the name of the database.
   * @return the string of the name of the database.
   * @throws CuriaException if an error occurs.
   */
  public String name() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      String buf = crname(index);
      if(buf == null) throw new CuriaException(crecode());
      return buf;
    }
  }
  /**
   * Get the total size of the database files.
   * @return the total size of the database files.
   * @throws CuriaException if an error occurs.
   */
  public long fsiz() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      long rv = (long)crfsizd(index);
      if(rv == -1) throw new CuriaException(crecode());
      return rv;
    }
  }
  /**
   * Get the total number of the elements of each bucket array.
   * @return the total number of the elements of each bucket array.
   * @throws CuriaException if an error occurs.
   */
  public int bnum() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      int rv = crbnum(index);
      if(rv == -1) throw new CuriaException(crecode());
      return rv;
    }
  }
  /**
   * Get the total number of the used elements of each bucket array.
   * @return the total number of the used elements of each bucket array.
   * @throws CuriaException if an error occurs.
   * @note This method is inefficient because it accesses all elements of each bucket array.
   */
  public int busenum() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      int rv = crbusenum(index);
      if(rv == -1) throw new CuriaException(crecode());
      return rv;
    }
  }
  /**
   * Get the number of the records stored in the database.
   * @return the number of the records stored in the database.
   * @throws CuriaException if an error occurs.
   */
  public int rnum() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      int rv = crrnum(index);
      if(rv == -1) throw new CuriaException(crecode());
      return rv;
    }
  }
  /**
   * Check whether the database handle is a writer or not.
   * @return true if the handle is a writer, false if not.
   * @throws CuriaException if an error occurs.
   */
  public boolean writable() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      return crwritable(index) == 0 ? false : true;
    }
  }
  /**
   * Check whether the database has a fatal error or not.
   * @return true if the database has a fatal error, false if not.
   * @throws CuriaException if an error occurs.
   */
  public boolean fatalerror() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      return crfatalerror(index) == 0 ? false : true;
    }
  }
  /**
   * Get the inode number of the database.
   * @return the inode number of the database directory.
   * @throws CuriaException if an error occurs.
   */
  public int inode() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      return crinode(index);
    }
  }
  /**
   * Get the last modified time of the database.
   * @return the last modified time of the database.
   * @throws CuriaException if an error occurs.
   */
  public long mtime() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      return crmtime(index);
    }
  }
  /**
   * Store a large object.
   * @param key a byte array of a key.
   * @param val a byte array of a value.
   * @param dmode behavior when the key overlaps, by the following values: `Curia.DOVER',
   * which means the specified value overwrites the existing one, `Curia.DKEEP', which means the
   * existing value is kept, `Curia.DCAT', which means the specified value is concatenated at
   * the end of the existing value.
   * @return always true.  However, if the silent flag is true and replace is cancelled, false is
   * returned instead of exception.
   * @throws CuriaException if an error occurs or replace is cancelled.
   */
  public boolean putlob(byte[] key, byte[] val, int dmode) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(crputlob(index, key, key.length, val, val.length, dmode) == 0){
        if(silent && crecode() == EKEEP) return false;
        throw new CuriaException(crecode());
      }
      return true;
    }
  }
  /**
   * Store a large object with overwrite.
   * The same as `putlob(key, val, Curia.DOVER)'.
   * @see #put(byte[], byte[], int)
   */
  public boolean putlob(byte[] key, byte[] val) throws CuriaException {
    return putlob(key, val, DOVER);
  }
  /**
   * Delete a large object.
   * @param key a byte array of a key.
   * @return always true.  However, if the silent flag is true and no record corresponds, false
   * is returned instead of exception.
   * @throws CuriaException if an error occurs or no large object corresponds.
   */
  public boolean outlob(byte[] key) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      if(croutlob(index, key, key.length) == 0){
        if(silent && crecode() == ENOITEM) return false;
        throw new CuriaException(crecode());
      }
      return true;
    }
  }
  /**
   * Retrieve a large object.
   * @param key a byte array of a key.
   * @param start the array index of the beginning of the value to be read.
   * @param max the max size to be read.  If it is negative, the size to read is unlimited.
   * @return a byte array of the value of the corresponding large object.  If the silent flag is
   * true and no record corresponds, `null' is returned instead of exception.
   * @throws CuriaException if an error occurs, no large object corresponds or the size of the
   * value of the corresponding is less than the index specified by the parameter `start'.
   */
  public byte[] getlob(byte[] key, int start, int max) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      byte[] val = crgetlob(index, key, key.length, start, max);
      if(val == null){
        if(silent && crecode() == ENOITEM) return null;
        throw new CuriaException(crecode());
      }
      return val;
    }
  }
  /**
   * Retrieve whole value of a large object.
   * The same as `get(key, 0, -1)'.
   * @see #get(byte[], int, int)
   */
  public byte[] getlob(byte[] key) throws CuriaException {
    return getlob(key, 0, -1);
  }
  /**
   * Get the size of the value of a large object.
   * @param key a byte array of a key.
   * @return the size of the value of the corresponding large object.
   * @throws CuriaException if an error occurs or no large object corresponds.
   * @note Because this method does not read the entity of a large object, it is faster
   * than `get'.
   */
  public int vsizlob(byte[] key) throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      int rv = crvsiz(index, key, key.length);
      if(rv == -1) throw new CuriaException(crecode());
      return rv;
    }
  }
  /**
   * Get the number of the large objects stored in the database.
   * @return the number of the large objects stored in the database.
   * @throws CuriaException if an error occurs.
   */
  public int rnumlob() throws CuriaException {
    if(index < 0) throw new CuriaException();
    synchronized(ADBM.class){
      int rv = crrnumlob(index);
      if(rv == -1) throw new CuriaException(crecode());
      return rv;
    }
  }
  /**
   * Store a record.
   * @param key a byte array of a key.
   * @param val a byte array of a value.
   * @param replace whether the existing value is to be overwritten or not.
   * @throws CuriaException if an error occurs or replace is cancelled.
   */
  public void store(byte[] key, byte[] val, boolean replace) throws CuriaException {
    if(!put(key, val, replace ? DOVER : DKEEP)) throw new CuriaException(EKEEP);
  }
  /**
   * Delete a record.
   * @param key a byte array of a key.
   * @throws CuriaException if an error occurs or no record corresponds.
   */
  public void delete(byte[] key) throws CuriaException {
    if(!out(key)) throw new CuriaException(ENOITEM);
  }
  /**
   * Fetch a record.
   * @param key a byte array of a key.
   * @return a byte array of the value of the corresponding record.
   * @throws CuriaException if an error occurs or no record corresponds.
   */
  public byte[] fetch(byte[] key) throws CuriaException {
    byte[] vbuf = get(key, 0, -1);
    if(vbuf == null) throw new CuriaException(ENOITEM);
    return vbuf;
  }
  /**
   * Get the first key.
   * @return a byte array of the key of the first record.
   * @throws CuriaException if an error occurs or no record corresponds.
   */
  public byte[] firstkey() throws CuriaException {
    iterinit();
    byte[] kbuf = iternext();
    if(kbuf == null) throw new CuriaException(ENOITEM);
    return kbuf;
  }
  /**
   * Get the next key.
   * @return a byte array of the key of the next record.
   * @throws CuriaException if an error occurs or no record corresponds.
   */
  public byte[] nextkey() throws CuriaException {
    byte[] kbuf = iternext();
    if(kbuf == null) throw new CuriaException(ENOITEM);
    return kbuf;
  }
  /**
   * Check whether a fatal error occured or not.
   * @return true if the database has a fatal error, false if not.
   * @throws CuriaException if an error occurs.
   */
  public boolean error() throws CuriaException {
    return fatalerror();
  }
  //----------------------------------------------------------------
  // native methods
  //----------------------------------------------------------------
  private static synchronized final native void crinit();
  private static synchronized final native String crversion();
  private static synchronized final native int crecode();
  private static synchronized final native String crerrmsg(int ecode);
  private static synchronized final native int cropen(String name, int omode, int bnum, int dnum);
  private static synchronized final native int crclose(int index);
  private static synchronized final native int crput(int index, byte[] key, int ksiz,
                                                     byte[] val, int vsiz, int dmode);
  private static synchronized final native int crout(int index, byte[] key, int ksiz);
  private static synchronized final native byte[] crget(int index, byte[] key, int ksiz,
                                                        int start, int max);
  private static synchronized final native int crvsiz(int index, byte[] key, int ksiz);
  private static synchronized final native int criterinit(int index);
  private static synchronized final native byte[] criternext(int index);
  private static synchronized final native int crsetalign(int index, int align);
  private static synchronized final native int crsetfbpsiz(int index, int size);
  private static synchronized final native int crsync(int index);
  private static synchronized final native int croptimize(int index, int bnum);
  private static synchronized final native String crname(int index);
  private static synchronized final native double crfsizd(int index);
  private static synchronized final native int crbnum(int index);
  private static synchronized final native int crbusenum(int index);
  private static synchronized final native int crrnum(int index);
  private static synchronized final native int crwritable(int index);
  private static synchronized final native int crfatalerror(int index);
  private static synchronized final native int crinode(int index);
  private static synchronized final native long crmtime(int index);
  private static synchronized final native int crputlob(int index, byte[] key, int ksiz,
                                                        byte[] val, int vsiz, int dmode);
  private static synchronized final native int croutlob(int index, byte[] key, int ksiz);
  private static synchronized final native byte[] crgetlob(int index, byte[] key, int ksiz,
                                                           int start, int max);
  private static synchronized final native int crvsizlob(int index, byte[] key, int ksiz);
  private static synchronized final native int crrnumlob(int index);
  private static synchronized final native int crremove(String name);
  private static synchronized final native byte[] crsnaffle(String name, byte[] key, int ksiz);
}



/* END OF FILE */