001: /**
002: * Copyright (C) 2001-2005 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.metadata;
018:
019: /**
020: *
021: *
022: * @author S.Chassande-Barrioz
023: */
024: public class SpeedoColumn extends SpeedoElement {
025: public String name;
026: public String targetColumn;
027: public String targetField;
028: public String jdbcType;
029: public String sqlType;
030: public int length;
031: public int scale;
032: public boolean allowNull;
033: public String defaultValue;
034: public SpeedoTable table;
035: public boolean insertable;
036: public boolean updatable;
037:
038: public SpeedoColumn() {
039: super ();
040: }
041:
042: public SpeedoColumn(String n) {
043: this ();
044: this .name = n;
045: }
046:
047: public SpeedoColumn(String n, SpeedoTable t) {
048: this (n);
049: this .table = t;
050: }
051:
052: public Object clone() {
053: SpeedoColumn scol = new SpeedoColumn();
054: scol.name = name;
055: scol.targetColumn = targetColumn;
056: scol.targetField = targetField;
057: scol.jdbcType = jdbcType;
058: scol.sqlType = sqlType;
059: scol.length = length;
060: scol.scale = scale;
061: scol.allowNull = allowNull;
062: scol.defaultValue = defaultValue;
063: scol.table = table;
064: scol.insertable = insertable;
065: scol.updatable = updatable;
066: return scol;
067: }
068:
069: public void merge(SpeedoColumn c) {
070: if (name == null && c.name != null) {
071: name = c.name;
072: }
073: if (targetColumn == null && c.targetColumn != null) {
074: targetColumn = c.targetColumn;
075: }
076: if (targetField == null && c.targetField != null) {
077: targetField = c.targetField;
078: }
079: if (jdbcType == null && c.jdbcType != null) {
080: jdbcType = c.jdbcType;
081: }
082: if (sqlType == null && c.sqlType != null) {
083: sqlType = c.sqlType;
084: }
085: if (length == -1 && c.length != -1) {
086: length = c.length;
087: }
088: if (scale == -1 && c.scale != -1) {
089: scale = c.scale;
090: }
091: allowNull = allowNull && c.allowNull;
092: if (defaultValue == null && c.defaultValue != null) {
093: defaultValue = c.defaultValue;
094: }
095: if (table == null && c.table != null) {
096: table = c.table;
097: }
098: }
099:
100: public String toString() {
101: StringBuffer sb = new StringBuffer();
102: sb.append("SpeedoColumn: name=").append(name);
103: if (targetColumn != null) {
104: sb.append(", targetColumn=").append(targetColumn);
105: }
106: if (targetField != null) {
107: sb.append(", targetField=").append(targetField);
108: }
109: if (jdbcType != null) {
110: sb.append(", jdbcType=").append(jdbcType);
111: }
112: if (sqlType != null) {
113: sb.append(", sqlType=").append(sqlType);
114: }
115: if (defaultValue != null) {
116: sb.append(", defaultValue=").append(defaultValue);
117: }
118: if (table != null) {
119: sb.append(", table=").append(table.name);
120: }
121: if (length > 0) {
122: sb.append(", length=").append(length);
123: }
124: if (scale > 0) {
125: sb.append(", scale=").append(scale);
126: }
127: if (!allowNull) {
128: sb.append(", allowNull=").append(allowNull);
129: }
130: if (!insertable) {
131: sb.append(", insertable=").append(insertable);
132: }
133: if (!updatable) {
134: sb.append(", updatable=").append(updatable);
135: }
136: return sb.toString();
137: }
138: }
|