Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c8b012cbef6da6e35893c7bb100e5d7bf7f1707d (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
/*
 * Copyright (c) 2013, 2016 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.delta;

import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBSchemaElement;
import org.eclipse.net4j.db.ddl.delta.IDBDelta;
import org.eclipse.net4j.db.ddl.delta.IDBDeltaVisitor;
import org.eclipse.net4j.db.ddl.delta.IDBPropertyDelta;

import java.io.IOException;
import java.io.Writer;
import java.text.MessageFormat;
import java.util.List;

/**
 * @author Eike Stepper
 */
public final class DBPropertyDelta<T> extends DBDelta implements IDBPropertyDelta<T>
{
  private static final long serialVersionUID = 1L;

  private Type type;

  private T value;

  private T oldValue;

  public DBPropertyDelta(DBDelta parent, String name, Type type, T value, T oldValue)
  {
    super(parent, name, DBDelta.getChangeKind(value, oldValue));
    this.type = type;
    this.value = value;
    this.oldValue = oldValue;
  }

  /**
   * Constructor for deserialization.
   */
  protected DBPropertyDelta()
  {
  }

  public DeltaType getDeltaType()
  {
    return DeltaType.PROPERTY;
  }

  public IDBSchemaElement getSchemaElement(IDBSchema schema)
  {
    return null;
  }

  public Type getType()
  {
    return type;
  }

  public T getValue()
  {
    return value;
  }

  public T getOldValue()
  {
    return oldValue;
  }

  @Override
  public String toString()
  {
    return MessageFormat.format("DBPropertyDelta[name={0}, kind={1}, type={2}, value={3}, oldValue={4}]", getName(), getChangeKind(), getType(), getValue(),
        getOldValue());
  }

  @Override
  protected void doAccept(IDBDeltaVisitor visitor)
  {
    visitor.visit(this);
  }

  @Override
  protected void collectElements(List<IDBDelta> elements)
  {
    // Do nothing
  }

  @Override
  protected void dumpAdditionalProperties(Writer writer) throws IOException
  {
    writer.append(", type=");
    writer.append(getType().toString());
    writer.append(", value=");
    writer.append(toString(getValue()));
    writer.append(", oldValue=");
    writer.append(toString(getOldValue()));
  }

  private static CharSequence toString(Object object)
  {
    if (object == null)
    {
      return "null";
    }

    return object.toString();
  }
}

Back to the top