KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > utilint > DatabaseUtil


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002-2006
5  * Oracle Corporation. All rights reserved.
6  *
7  * $Id: DatabaseUtil.java,v 1.1 2006/11/06 20:36:58 linda Exp $
8  */

9
10 package com.sleepycat.je.utilint;
11
12 import com.sleepycat.je.DatabaseEntry;
13
14 /**
15  * Utils for use in the db package.
16  */

17 public class DatabaseUtil {
18
19     /**
20      * Throw an exception if the parameter is null.
21      */

22     static public void checkForNullParam(Object JavaDoc param, String JavaDoc name) {
23         if (param == null) {
24             throw new NullPointerException JavaDoc(name + " cannot be null");
25         }
26     }
27
28     /**
29      * Throw an exception if the dbt is null or the data field is not set.
30      */

31     static public void checkForNullDbt(DatabaseEntry dbt,
32                 String JavaDoc name,
33                 boolean checkData) {
34         if (dbt == null) {
35             throw new NullPointerException JavaDoc
36         ("DatabaseEntry " + name + " cannot be null");
37         }
38
39         if (checkData) {
40             if (dbt.getData() == null) {
41                 throw new NullPointerException JavaDoc
42             ("Data field for DatabaseEntry " +
43              name + " cannot be null");
44             }
45         }
46     }
47
48     /**
49      * Throw an exception if the key dbt has the partial flag set. This method
50      * should be called for all put() operations.
51      */

52     static public void checkForPartialKey(DatabaseEntry dbt) {
53         if (dbt.getPartial()) {
54             throw new IllegalArgumentException JavaDoc
55         ("A partial key DatabaseEntry is not allowed");
56         }
57     }
58 }
59
Popular Tags