Skip to main content
summaryrefslogtreecommitdiffstats
blob: 934f328c61ca7b177d17f4447d9271d32f3cb865 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * Copyright (c) 2013, 2015 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.net4j.internal.db.ddl;

import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.db.ddl.SchemaElementNotFoundException;
import org.eclipse.net4j.spi.db.ddl.InternalDBTable;

/**
 * @author Eike Stepper
 */
public final class DelegatingDBTable extends DelegatingDBSchemaElement implements InternalDBTable
{
  DelegatingDBTable(InternalDBTable delegate)
  {
    super(delegate);
  }

  @Override
  public InternalDBTable getDelegate()
  {
    return (InternalDBTable)super.getDelegate();
  }

  @Override
  public void setDelegate(IDBSchemaElement delegate)
  {
    IDBField[] wrapperFields = getFields();
    IDBIndex[] wrapperIndices = getIndices();

    IDBTable delegateTable = (IDBTable)delegate;
    super.setDelegate(delegateTable);

    for (IDBField wrapperField : wrapperFields)
    {
      IDBField delegateField = delegateTable.getField(wrapperField.getName());
      ((DelegatingDBSchemaElement)wrapperField).setDelegate(delegateField);
    }

    for (IDBIndex wrapperIndex : wrapperIndices)
    {
      IDBIndex delegateIndex = delegateTable.getIndex(wrapperIndex.getName());
      ((DelegatingDBSchemaElement)wrapperIndex).setDelegate(delegateIndex);
    }
  }

  public IDBTable getWrapper()
  {
    return this;
  }

  @Override
  public IDBSchema getParent()
  {
    return wrap(getDelegate().getParent());
  }

  public IDBField addField(String name, DBType type)
  {
    return wrap(getDelegate().addField(name, type));
  }

  public IDBField addField(String name, DBType type, boolean notNull)
  {
    return wrap(getDelegate().addField(name, type, notNull));
  }

  public void removeField(IDBField fieldToRemove)
  {
    getDelegate().removeField(unwrap(fieldToRemove));
  }

  public IDBField addField(String name, DBType type, int precision)
  {
    return wrap(getDelegate().addField(name, type, precision));
  }

  public void removeIndex(IDBIndex indexToRemove)
  {
    getDelegate().removeIndex(unwrap(indexToRemove));
  }

  public IDBField addField(String name, DBType type, int precision, boolean notNull)
  {
    return wrap(getDelegate().addField(name, type, precision, notNull));
  }

  public IDBField addField(String name, DBType type, int precision, int scale)
  {
    return wrap(getDelegate().addField(name, type, precision, scale));
  }

  public IDBField addField(String name, DBType type, int precision, int scale, boolean notNull)
  {
    return wrap(getDelegate().addField(name, type, precision, scale, notNull));
  }

  public IDBField getFieldSafe(String name) throws SchemaElementNotFoundException
  {
    return wrap(getDelegate().getFieldSafe(name));
  }

  public IDBField getField(String name)
  {
    return wrap(getDelegate().getField(name));
  }

  public IDBField getField(int position)
  {
    return wrap(getDelegate().getField(position));
  }

  public int getFieldCount()
  {
    return getDelegate().getFieldCount();
  }

  public IDBField[] getFields()
  {
    return wrap(getDelegate().getFields(), IDBField.class);
  }

  public IDBField[] getFields(String... fieldNames) throws SchemaElementNotFoundException
  {
    return wrap(getDelegate().getFields(fieldNames), IDBField.class);
  }

  public boolean hasIndexFor(IDBField... fields)
  {
    return getDelegate().hasIndexFor(unwrap(fields, IDBField.class));
  }

  public IDBIndex addIndex(String name, Type type, IDBField... fields)
  {
    return wrap(getDelegate().addIndex(name, type, unwrap(fields, IDBField.class)));
  }

  public IDBIndex addIndex(String name, Type type, String... fieldNames) throws SchemaElementNotFoundException
  {
    return wrap(getDelegate().addIndex(name, type, fieldNames));
  }

  public IDBIndex addIndexEmpty(String name, Type type)
  {
    return wrap(getDelegate().addIndexEmpty(name, type));
  }

  public IDBIndex addIndex(Type type, IDBField... fields)
  {
    return wrap(getDelegate().addIndex(type, unwrap(fields, IDBField.class)));
  }

  public IDBIndex addIndex(Type type, String... fieldNames) throws SchemaElementNotFoundException
  {
    return wrap(getDelegate().addIndex(type, fieldNames));
  }

  public IDBIndex addIndexEmpty(Type type)
  {
    return wrap(getDelegate().addIndexEmpty(type));
  }

  public IDBIndex getIndexSafe(String name) throws SchemaElementNotFoundException
  {
    return wrap(getDelegate().getIndexSafe(name));
  }

  public IDBIndex getIndex(String name)
  {
    return wrap(getDelegate().getIndex(name));
  }

  public IDBIndex getIndex(int position)
  {
    return wrap(getDelegate().getIndex(position));
  }

  public int getIndexCount()
  {
    return getDelegate().getIndexCount();
  }

  public IDBIndex[] getIndices()
  {
    return wrap(getDelegate().getIndices(), IDBIndex.class);
  }

  public IDBIndex getPrimaryKeyIndex()
  {
    return wrap(getDelegate().getPrimaryKeyIndex());
  }

  public String sqlInsert()
  {
    return getDelegate().sqlInsert();
  }

  public boolean isInsertSequential()
  {
    return getDelegate().isInsertSequential();
  }

  public void setInsertSequential(boolean on)
  {
    getDelegate().setInsertSequential(on);
  }
}

Back to the top