01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: DatabaseUtil.java,v 1.1.2.2 2008/01/07 15:14:18 cwl Exp $
07: */
08:
09: package com.sleepycat.je.utilint;
10:
11: import com.sleepycat.je.DatabaseEntry;
12:
13: /**
14: * Utils for use in the db package.
15: */
16: public class DatabaseUtil {
17:
18: /**
19: * Throw an exception if the parameter is null.
20: */
21: static public void checkForNullParam(Object param, String name) {
22: if (param == null) {
23: throw new NullPointerException(name + " cannot be null");
24: }
25: }
26:
27: /**
28: * Throw an exception if the dbt is null or the data field is not set.
29: */
30: static public void checkForNullDbt(DatabaseEntry dbt, String name,
31: boolean checkData) {
32: if (dbt == null) {
33: throw new NullPointerException("DatabaseEntry " + name
34: + " cannot be null");
35: }
36:
37: if (checkData) {
38: if (dbt.getData() == null) {
39: throw new NullPointerException(
40: "Data field for DatabaseEntry " + name
41: + " cannot be null");
42: }
43: }
44: }
45:
46: /**
47: * Throw an exception if the key dbt has the partial flag set. This method
48: * should be called for all put() operations.
49: */
50: static public void checkForPartialKey(DatabaseEntry dbt) {
51: if (dbt.getPartial()) {
52: throw new IllegalArgumentException(
53: "A partial key DatabaseEntry is not allowed");
54: }
55: }
56: }
|