001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.backends.jeb;
028
029 import org.opends.server.types.EntryEncodeConfig;
030
031 import static org.opends.server.util.Validator.*;
032
033 /**
034 * Configuration class to indicate desired compression and cryptographic options
035 * for the data stored in the database.
036 */
037 public class DataConfig
038 {
039 /**
040 * Indicates whether data should be compressed before writing to the database.
041 */
042 private boolean compressed = false;
043
044 /**
045 * The configuration to use when encoding entries in the database.
046 */
047 private EntryEncodeConfig encodeConfig = new EntryEncodeConfig();
048
049 /**
050 * Constrct a new DataConfig object with the specified settings.
051 *
052 * @param compressed true if data should be compressed, false if not.
053 * @param compactEncoding true if data should be encoded in compact form,
054 * false if not.
055 * @param compressedSchema the compressed schema manager to use. It must not
056 * be {@code null} if compactEncoding is {@code true}.
057 */
058 public DataConfig(boolean compressed, boolean compactEncoding,
059 JECompressedSchema compressedSchema)
060 {
061 this.compressed = compressed;
062
063 if (compressedSchema == null)
064 {
065 ensureTrue(! compactEncoding);
066 this.encodeConfig = new EntryEncodeConfig(false, compactEncoding, false);
067 }
068 else
069 {
070 this.encodeConfig =
071 new EntryEncodeConfig(false, compactEncoding, compactEncoding,
072 compressedSchema);
073 }
074 }
075
076 /**
077 * Determine whether data should be compressed before writing to the database.
078 * @return true if data should be compressed, false if not.
079 */
080 public boolean isCompressed()
081 {
082 return compressed;
083 }
084
085 /**
086 * Determine whether entries should be encoded with the compact form before
087 * writing to the database.
088 * @return true if data should be encoded in the compact form.
089 */
090 public boolean isCompactEncoding()
091 {
092 return encodeConfig.compressAttributeDescriptions();
093 }
094
095
096
097 /**
098 * Configure whether data should be compressed before writing to the database.
099 * @param compressed true if data should be compressed, false if not.
100 */
101 public void setCompressed(boolean compressed)
102 {
103 this.compressed = compressed;
104 }
105
106 /**
107 * Configure whether data should be encoded with the compact form before
108 * writing to the database.
109 * @param compactEncoding true if data should be encoded in compact form,
110 * false if not.
111 * @param compressedSchema The compressed schema manager to use. It must not
112 * be {@code null} if compactEncoding is {@code true}.
113 */
114 public void setCompactEncoding(boolean compactEncoding,
115 JECompressedSchema compressedSchema)
116 {
117 if (compressedSchema == null)
118 {
119 ensureTrue(! compactEncoding);
120 this.encodeConfig = new EntryEncodeConfig(false, compactEncoding,
121 compactEncoding);
122 }
123 else
124 {
125 this.encodeConfig = new EntryEncodeConfig(false, compactEncoding,
126 compactEncoding,
127 compressedSchema);
128 }
129 }
130
131 /**
132 * Get the EntryEncodeConfig object in use by this configuration.
133 * @return the EntryEncodeConfig object in use by this configuration.
134 */
135 public EntryEncodeConfig getEntryEncodeConfig()
136 {
137 return this.encodeConfig;
138 }
139
140 /**
141 * Get a string representation of this object.
142 * @return A string representation of this object.
143 */
144 public String toString()
145 {
146 StringBuilder builder = new StringBuilder();
147 builder.append("DataConfig(compressed=");
148 builder.append(compressed);
149 builder.append(", ");
150 encodeConfig.toString(builder);
151 builder.append(")");
152 return builder.toString();
153 }
154 }