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
|
/*******************************************************************************
* 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.sql;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.datastore.internal.Activator;
import org.eclipse.osee.framework.core.datastore.schema.data.ColumnMetadata;
import org.eclipse.osee.framework.core.datastore.schema.data.TableElement;
import org.eclipse.osee.framework.core.datastore.schema.data.TableElement.ColumnFields;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.logging.OseeLog;
/**
* @author Roberto E. Escobar
*/
public class SqlManagerImpl extends SqlManager {
public SqlManagerImpl(SqlDataType sqlDataType) {
super(sqlDataType);
}
private String handleColumnCreationSection(Map<String, ColumnMetadata> columns) {
List<String> lines = new ArrayList<String>();
Set<String> keys = columns.keySet();
for (String key : keys) {
Map<ColumnFields, String> column = columns.get(key).getColumnFields();
lines.add(columnDataToSQL(column));
}
String toExecute = org.eclipse.osee.framework.jdk.core.util.Collections.toString(",\n", lines);
return toExecute;
}
@Override
public void createTable(TableElement tableDef) throws OseeCoreException {
StringBuilder toExecute = new StringBuilder();
toExecute.append(SqlManager.CREATE_STRING + " TABLE " + formatQuotedString(tableDef.getFullyQualifiedTableName(),
"\\.") + " ( \n");
toExecute.append(handleColumnCreationSection(tableDef.getColumns()));
toExecute.append(handleConstraintCreationSection(tableDef.getConstraints(), tableDef.getFullyQualifiedTableName()));
toExecute.append(handleConstraintCreationSection(tableDef.getForeignKeyConstraints(),
tableDef.getFullyQualifiedTableName()));
toExecute.append(" \n)\n");
OseeLog.log(Activator.class, Level.FINE, "Creating Table: [ " + tableDef.getFullyQualifiedTableName() + "]");
ConnectionHandler.runPreparedUpdate(toExecute.toString());
}
@Override
public void dropTable(TableElement tableDef) throws OseeCoreException {
StringBuilder toExecute = new StringBuilder();
toExecute.append(SqlManager.DROP_STRING + " TABLE " + formatQuotedString(tableDef.getFullyQualifiedTableName(),
"\\."));
OseeLog.log(Activator.class, Level.FINE, "Dropping Table: [ " + tableDef.getFullyQualifiedTableName() + "]");
ConnectionHandler.runPreparedUpdate(toExecute.toString());
}
}
|