blob: d903ee6bdb52bf64fe606b439ebe6ef6a7de2fe3 (
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
|
/*******************************************************************************
* 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.branch.management.exchange.handler;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.osee.framework.database.core.SQL3DataType;
/**
* @author Roberto E. Escobar
*/
public class MetaData {
private final Map<String, SQL3DataType> dataConversionMap;
private final String tableTarget;
private String query;
MetaData(String tableName) {
this.dataConversionMap = new LinkedHashMap<String, SQL3DataType>();
this.tableTarget = tableName;
this.query = null;
}
private String buildQuery() {
String toReturn = null;
Collection<String> columnNames = getColumnNames();
if (columnNames.isEmpty() != true) {
String columns = columnNames.toString();
columns = columns.substring(1, columns.length() - 1);
StringBuffer params = new StringBuffer();
for (int index = 0; index < columnNames.size(); index++) {
params.append("?");
if (index + 1 < columnNames.size()) {
params.append(", ");
}
}
toReturn = String.format("INSERT INTO %s (%s) VALUES (%s)", tableTarget, columns, params);
}
return toReturn;
}
void addColumn(String columnName, SQL3DataType sql3DataType) {
this.dataConversionMap.put(columnName, sql3DataType);
}
public int getColumnSize() {
return dataConversionMap.size();
}
public String getTableName() {
return tableTarget;
}
public Collection<String> getColumnNames() {
return this.dataConversionMap.keySet();
}
public String getQuery() {
if (query == null) {
query = buildQuery();
}
return query;
}
public SQL3DataType toDataType(String fieldName) {
return this.dataConversionMap.get(fieldName);
}
public Class<?> toClass(String fieldName) {
SQL3DataType dataType = this.dataConversionMap.get(fieldName);
return dataType != null ? dataType.getJavaEquivalentClass() : null;
}
@Override
public String toString() {
return getTableName();
}
}
|