001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.jdbc.meta;
020:
021: import java.io.File;
022:
023: import org.apache.openjpa.jdbc.conf.JDBCSeqValue;
024: import org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq;
025: import org.apache.openjpa.jdbc.kernel.TableJDBCSeq;
026: import org.apache.openjpa.jdbc.kernel.ValueTableJDBCSeq;
027: import org.apache.openjpa.lib.conf.PluginValue;
028: import org.apache.openjpa.meta.SequenceMetaData;
029:
030: /**
031: * Specialization of sequence metadata for ORM.
032: *
033: * @author Abe White
034: */
035: public class SequenceMapping extends SequenceMetaData {
036:
037: /**
038: * {@link ValueTableJDBCSeq} alias.
039: */
040: public static final String IMPL_VALUE_TABLE = "value-table";
041:
042: /**
043: * {@link TableJDBCSeq} alias.
044: */
045: public static final String IMPL_TABLE = "table";
046:
047: /**
048: * {@link ClassTableJDBCSeq} alias.
049: */
050: public static final String IMPL_CLASS_TABLE = "class-table";
051:
052: // plugin property names for standard props
053: private static final String PROP_TABLE = "Table";
054: private static final String PROP_SEQUENCE_COL = "SequenceColumn";
055: private static final String PROP_PK_COL = "PrimaryKeyColumn";
056: private static final String PROP_PK_VALUE = "PrimaryKeyValue";
057:
058: private File _mapFile = null;
059: private String _table = null;
060: private String _sequenceColumn = null;
061: private String _primaryKeyColumn = null;
062: private String _primaryKeyValue = null;
063:
064: public SequenceMapping(String name, MappingRepository repos) {
065: super (name, repos);
066: }
067:
068: /**
069: * Allow sequence to have a mapping file separate from its metadata
070: * source file.
071: */
072: public File getMappingFile() {
073: return _mapFile;
074: }
075:
076: /**
077: * Allow sequence to have a mapping file separate from its metadata
078: * source file.
079: */
080: public void setMappingFile(File file) {
081: _mapFile = file;
082: }
083:
084: /**
085: * Name of sequence table, if any.
086: */
087: public String getTable() {
088: return _table;
089: }
090:
091: /**
092: * Name of sequence table, if any.
093: */
094: public void setTable(String table) {
095: _table = table;
096: }
097:
098: /**
099: * Name of sequence column, if any.
100: */
101: public String getSequenceColumn() {
102: return _sequenceColumn;
103: }
104:
105: /**
106: * Name of sequence column, if any.
107: */
108: public void setSequenceColumn(String sequenceColumn) {
109: _sequenceColumn = sequenceColumn;
110: }
111:
112: /**
113: * Name of primary key column, if any.
114: */
115: public String getPrimaryKeyColumn() {
116: return _primaryKeyColumn;
117: }
118:
119: /**
120: * Name of primary key column, if any.
121: */
122: public void setPrimaryKeyColumn(String primaryKeyColumn) {
123: _primaryKeyColumn = primaryKeyColumn;
124: }
125:
126: /**
127: * Primary key value, if not auto-determined.
128: */
129: public String getPrimaryKeyValue() {
130: return _primaryKeyValue;
131: }
132:
133: /**
134: * Primary key value, if not auto-determined.
135: */
136: public void setPrimaryKeyValue(String primaryKeyValue) {
137: _primaryKeyValue = primaryKeyValue;
138: }
139:
140: protected PluginValue newPluginValue(String property) {
141: return new JDBCSeqValue(property);
142: }
143:
144: protected void addStandardProperties(StringBuffer props) {
145: super.addStandardProperties(props);
146: appendProperty(props, PROP_TABLE, _table);
147: appendProperty(props, PROP_SEQUENCE_COL, _sequenceColumn);
148: appendProperty(props, PROP_PK_COL, _primaryKeyColumn);
149: appendProperty(props, PROP_PK_VALUE, _primaryKeyValue);
150: }
151: }
|