Skip to main content
summaryrefslogtreecommitdiffstats
blob: 319bec1303730343fb334f15bd91313149385b4e (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/

package org.eclipse.osee.framework.core.datastore.schema.data;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.eclipse.osee.framework.core.datastore.schema.data.AppliesToClause.OrderType;
import org.eclipse.osee.framework.jdk.core.persistence.Xmlizable;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * @author Roberto E. Escobar
 */
public class IndexElement implements Xmlizable {

   public enum IndexFields {
      id,
      mySqlIgnore,
      type,
      tablespace;
   }

   private String id;
   private String indexType;
   private final List<AppliesToClause> appliesToList;
   private boolean ignoreMySql = false;
   private String tablespace;

   public IndexElement(String id) {
      this.id = id;
      this.appliesToList = new ArrayList<AppliesToClause>();
      this.indexType = "";
      this.tablespace = "";
   }

   public void setId(String id) {
      this.id = id;
   }

   public String getId() {
      return id;
   }

   public void addAppliesTo(String name, OrderType type) {
      appliesToList.add(new AppliesToClause(name, type));
   }

   public List<AppliesToClause> getAppliesToList() {
      return appliesToList;
   }

   @Override
   public String toString() {
      StringBuilder toReturn = new StringBuilder();
      toReturn.append(" Index: " + id);
      toReturn.append(getAppliesToAsString());
      return toReturn.toString();
   }

   @Override
   public Element toXml(Document doc) {
      Element element = doc.createElement(TableElement.TableSections.Index.name());
      element.setAttribute(IndexFields.id.name(), id);
      for (AppliesToClause clause : appliesToList) {
         element.appendChild(clause.toXml(doc));
      }
      return element;
   }

   public String getAppliesToAsString() {
      StringBuilder toReturn = new StringBuilder();
      for (int index = 0; index < appliesToList.size(); index++) {
         toReturn.append("\n\t\tApplies to " + appliesToList.get(index));
      }
      return toReturn.toString();
   }

   @Override
   public boolean equals(Object otherObject) {
      if (otherObject instanceof IndexElement == false) {
         return false;
      }
      if (this == otherObject) {
         return true;
      }
      IndexElement that = (IndexElement) otherObject;
      return new EqualsBuilder().appendSuper(super.equals(otherObject)).append(this.appliesToList,
         that.getAppliesToList()).append(this.id, that.getId()).isEquals();
   }

   @Override
   public int hashCode() {
      return new HashCodeBuilder(113, 67).append(id).append(appliesToList).toHashCode();
   }

   public void setMySqlIgnore(boolean b) {
      this.ignoreMySql = b;
   }

   public void setIndexType(String indexType) {
      if (indexType != null) {
         this.indexType = indexType;
      }
   }

   public String getIndexType() {
      return indexType;
   }

   public boolean ignoreMySql() {
      return this.ignoreMySql;
   }

   public String getTablespace() {
      return Strings.isValid(tablespace) ? tablespace : "";
   }

   public void setTablespace(String tablespace) {
      this.tablespace = tablespace;
   }
}

Back to the top