001: /**********************************************************************
002: Copyright (c) 2006 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: **********************************************************************/package org.jpox.metadata;
018:
019: import org.jpox.util.StringUtils;
020:
021: /**
022: * Representation of the MetaData of a TableGenerator (JPA).
023: *
024: * @since 1.1
025: * @version $Revision: 1.5 $
026: */
027: public class TableGeneratorMetaData extends MetaData {
028: /** Name under which this table generator is known. */
029: protected final String name;
030:
031: /** Name of the table to use for sequences */
032: protected String tableName;
033:
034: /** Name of the catalog to use for the table */
035: protected String catalogName;
036:
037: /** Name of the schema to use for the table */
038: protected String schemaName;
039:
040: /** Name of the primary-key column name */
041: protected String pkColumnName;
042:
043: /** Name of the value column name */
044: protected String valueColumnName;
045:
046: /** Name of the primary-key column value */
047: protected String pkColumnValue;
048:
049: /** Initial value in the table. */
050: protected long initialValue = 0;
051:
052: /** Allocation size for ids from the table. */
053: protected long allocationSize = 50;
054:
055: /**
056: * Constructor.
057: * @param parent The parent of this element
058: * @param name The generator name
059: * @param tableName The table name
060: * @param catalogName Catalog name for the table
061: * @param schemaName Schema name for the table
062: * @param pkColumnName Name of PK column in table
063: * @param valueColumnName Name of value column in table
064: * @param pkColumnValue Value of the pk in the table
065: * @param initialValue Initial value
066: * @param allocationSize Allocation size
067: */
068: public TableGeneratorMetaData(final MetaData parent,
069: final String name, final String tableName,
070: final String catalogName, final String schemaName,
071: final String pkColumnName, final String valueColumnName,
072: final String pkColumnValue, final String initialValue,
073: final String allocationSize) {
074: super (parent);
075:
076: if (StringUtils.isWhitespace(name)) {
077: throw new InvalidMetaDataException(LOCALISER, "044155");
078: }
079:
080: this .name = name;
081: this .tableName = (StringUtils.isWhitespace(tableName) ? null
082: : tableName);
083: this .catalogName = (StringUtils.isWhitespace(catalogName) ? null
084: : catalogName);
085: this .schemaName = (StringUtils.isWhitespace(schemaName) ? null
086: : schemaName);
087: this .pkColumnName = (StringUtils.isWhitespace(pkColumnName) ? null
088: : pkColumnName);
089: this .valueColumnName = (StringUtils
090: .isWhitespace(valueColumnName) ? null : valueColumnName);
091: this .pkColumnValue = (StringUtils.isWhitespace(pkColumnValue) ? null
092: : pkColumnValue);
093: if (!StringUtils.isWhitespace(initialValue)) {
094: this .initialValue = new Long(initialValue).longValue();
095: }
096: if (!StringUtils.isWhitespace(allocationSize)) {
097: this .allocationSize = new Long(allocationSize).longValue();
098: }
099: }
100:
101: /**
102: * Convenience accessor for the fully-qualified name of the sequence.
103: * @return Fully qualfiied name of the sequence (including the package name).
104: */
105: public String getFullyQualifiedName() {
106: PackageMetaData pmd = (PackageMetaData) getParent();
107: return pmd.getName() + "." + name;
108: }
109:
110: /**
111: * Accessor for the generator name.
112: * @return generator name
113: */
114: public String getName() {
115: return name;
116: }
117:
118: /**
119: * Accessor for the table name.
120: * @return table name
121: */
122: public String getTableName() {
123: return tableName;
124: }
125:
126: /**
127: * Accessor for the catalog name.
128: * @return catalog name
129: */
130: public String getCatalogName() {
131: return catalogName;
132: }
133:
134: /**
135: * Accessor for the schema name.
136: * @return schema name
137: */
138: public String getSchemaName() {
139: return schemaName;
140: }
141:
142: /**
143: * Accessor for the PK column name.
144: * @return PK column name
145: */
146: public String getPKColumnName() {
147: return pkColumnName;
148: }
149:
150: /**
151: * Accessor for the value column name.
152: * @return Value column name
153: */
154: public String getValueColumnName() {
155: return valueColumnName;
156: }
157:
158: /**
159: * Accessor for the PK column value.
160: * @return PK column value
161: */
162: public String getPKColumnValue() {
163: return pkColumnValue;
164: }
165:
166: /**
167: * Accessor for the initial value of the sequence.
168: * @return The initial value
169: */
170: public long getInitialValue() {
171: return initialValue;
172: }
173:
174: /**
175: * Accessor for the allocation size of the sequence.
176: * @return The allocation size
177: */
178: public long getAllocationSize() {
179: return allocationSize;
180: }
181:
182: /**
183: * Returns a string representation of the object.
184: * @param prefix prefix string
185: * @param indent indent string
186: * @return a string representation of the object.
187: */
188: public String toString(String prefix, String indent) {
189: StringBuffer sb = new StringBuffer();
190: sb.append(prefix).append(
191: "<table-generator name=\"" + name + "\"\n");
192:
193: // Add extensions
194: sb.append(super .toString(prefix + indent, indent));
195:
196: sb.append(prefix + "</table-generator>\n");
197: return sb.toString();
198: }
199: }
|