Author: shawkins
Date: 2012-06-18 22:20:38 -0400 (Mon, 18 Jun 2012)
New Revision: 4186
Modified:
trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java
trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/MetadataProcessor.java
trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/runtime/src/main/java/org/teiid/deployers/EventDistributorImpl.java
trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java
Log:
TEIID-2078 minor metadata enhancements
Modified: trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java 2012-06-19 00:14:18 UTC (rev
4185)
+++ trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java 2012-06-19 02:20:38 UTC (rev
4186)
@@ -24,6 +24,8 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
public class ColumnSet<T extends AbstractMetadataRecord> extends
AbstractMetadataRecord {
@@ -31,20 +33,46 @@
private List<Column> columns;
private T parent;
+ private transient Map<String, Column> columnMap;
public List<Column> getColumns() {
return columns;
}
+ /**
+ * Get the {@link Column} via a case-insensitive lookup
+ * @param name
+ * @return the {@link Column} or null if it doesn't exist
+ */
+ public Column getColumnByName(String name) {
+ if (columns == null) {
+ return null;
+ }
+ Map<String, Column> map = columnMap;
+ if (map == null) {
+ map = new TreeMap<String, Column>();
+ for (Column c : columns) {
+ map.put(c.getName(), c);
+ }
+ columnMap = map;
+ }
+ return map.get(name);
+ }
+
public void addColumn(Column column) {
if (columns == null) {
columns = new ArrayList<Column>();
}
columns.add(column);
+ Map<String, Column> map = columnMap;
+ if (map != null) {
+ map.put(column.getName(), column);
+ }
}
public void setColumns(List<Column> columns) {
this.columns = columns;
+ columnMap = null;
}
@Override
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-06-19 00:14:18
UTC (rev 4185)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-06-19 02:20:38
UTC (rev 4186)
@@ -115,6 +115,9 @@
//TODO: for now this is not used
throw new TranslatorException(DataPlugin.Event.TEIID60008,
DataPlugin.Util.gs(DataPlugin.Event.TEIID60008, name));
}
+ if (table.getColumnByName(name) != null) {
+ throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60013,
table.getFullName() + AbstractMetadataRecord.NAME_DELIM_CHAR + name));
+ }
Column column = new Column();
column.setName(name);
table.addColumn(column);
@@ -302,17 +305,11 @@
private void assignColumns(List<String> columnNames, Table table,
ColumnSet<?> columns) throws TranslatorException {
for (String columnName : columnNames) {
- boolean match = false;
- for (Column column : table.getColumns()) {
- if (column.getName().equals(columnName)) {
- match = true;
- columns.getColumns().add(column);
- break;
- }
+ Column column = table.getColumnByName(columnName);
+ if (column == null) {
+ throw new TranslatorException(DataPlugin.Event.TEIID60011,
DataPlugin.Util.gs(DataPlugin.Event.TEIID60011, columnName));
}
- if (!match) {
- throw new TranslatorException(DataPlugin.Event.TEIID60011,
DataPlugin.Util.gs(DataPlugin.Event.TEIID60011, columnName));
- }
+ columns.getColumns().add(column);
}
}
Modified:
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java
===================================================================
---
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java 2012-06-19
00:14:18 UTC (rev 4185)
+++
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java 2012-06-19
02:20:38 UTC (rev 4186)
@@ -117,15 +117,7 @@
}
private boolean columnExists(String name, Table table) {
- if (table.getColumns() == null) {
- return false;
- }
- for (Column existingColumn: table.getColumns()) {
- if (existingColumn.getName().equals(name)) {
- return true;
- }
- }
- return false;
+ return table.getColumnByName(name) != null;
}
private Column addColumn(MetadataFactory mf, String name, String type, Table
entityTable) throws TranslatorException {
Modified:
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/MetadataProcessor.java
===================================================================
---
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/MetadataProcessor.java 2012-06-19
00:14:18 UTC (rev 4185)
+++
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/MetadataProcessor.java 2012-06-19
02:20:38 UTC (rev 4186)
@@ -99,8 +99,8 @@
Column col = null;
columns = child.getColumns();
- for (Iterator colIter = columns.iterator(); colIter.hasNext();) {
- Column column = (Column) colIter.next();
+ for (Iterator<Column> colIter = columns.iterator(); colIter.hasNext();) {
+ Column column = colIter.next();
if(column.getName().equals(relationship.getForeignKeyField())) {
col = column;
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java 2012-06-19
00:14:18 UTC (rev 4185)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java 2012-06-19
02:20:38 UTC (rev 4186)
@@ -247,13 +247,10 @@
private static Column addColumn(String name, Datatype type, Table table) throws
TranslatorException {
Column column = new Column();
column.setName(name);
- if (table.getColumns() != null) {
- for (Column c:table.getColumns()) {
- if (c.getName().equalsIgnoreCase(name)) {
- throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31087,
name, table.getFullName()));
- }
- }
+ if (table.getColumnByName(name) != null) {
+ throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31087, name,
table.getFullName()));
}
+ column.setUpdatable(table.supportsUpdate());
table.addColumn(column);
column.setPosition(table.getColumns().size()); //1 based indexing
if (type == null) {
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-06-19
00:14:18 UTC (rev 4185)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-06-19
02:20:38 UTC (rev 4186)
@@ -544,10 +544,9 @@
}
Column getColumn(String columnName, Table table) throws ParseException {
- for (Column col:table.getColumns()) {
- if (col.getName().equalsIgnoreCase(columnName)) {
- return col;
- }
+ Column c = table.getColumnByName(columnName);
+ if (c != null) {
+ return c;
}
throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_column",
columnName, table.getName())); //$NON-NLS-1$
}
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-06-19 00:14:18
UTC (rev 4185)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-06-19 02:20:38
UTC (rev 4186)
@@ -4267,6 +4267,11 @@
}
table.setSelectTransformation(query.toString());
}
+ if (!table.supportsUpdate() && table.getColumns() != null) {
+ for (Column c : table.getColumns()) {
+ c.setUpdatable(false);
+ }
+ }
}
}
@@ -4413,6 +4418,7 @@
{
try{
column = factory.addColumn(validateElementName(element), type.type, table);
+ column.setUpdatable(true);
if (type.length != null){
column.setLength(type.length);
}
@@ -4487,11 +4493,15 @@
}
{
key = id()
- ((value = stringVal())
+ (value = stringVal()
|
- (t = <INTEGERVAL>)
+ t = <INTEGERVAL>
|
- (t = <DECIMALVAL>))
+ t = <DECIMALVAL>
+ |
+ t = <TRUE>
+ |
+ t = <FALSE>)
{
if (t != null) {
value = t.image;
Modified: trunk/runtime/src/main/java/org/teiid/deployers/EventDistributorImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/EventDistributorImpl.java 2012-06-19
00:14:18 UTC (rev 4185)
+++ trunk/runtime/src/main/java/org/teiid/deployers/EventDistributorImpl.java 2012-06-19
02:20:38 UTC (rev 4186)
@@ -35,8 +35,8 @@
import org.teiid.metadata.Procedure;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.Table.TriggerEvent;
import org.teiid.metadata.TableStats;
+import org.teiid.metadata.Table.TriggerEvent;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.relational.RelationalPlanner;
import org.teiid.query.processor.DdlPlan;
@@ -96,12 +96,10 @@
if (t == null) {
return;
}
- for (Column c : t.getColumns()) {
- if (c.getName().equalsIgnoreCase(columnName)) {
- c.setColumnStats(stats);
- t.setLastModified(System.currentTimeMillis());
- break;
- }
+ Column c = t.getColumnByName(columnName);
+ if (c != null) {
+ c.setColumnStats(stats);
+ t.setLastModified(System.currentTimeMillis());
}
}
Modified: trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java 2012-06-19
00:14:18 UTC (rev 4185)
+++ trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java 2012-06-19
02:20:38 UTC (rev 4186)
@@ -171,7 +171,7 @@
mmd1.setName("virt");
mmd1.setModelType(Type.VIRTUAL);
mmd1.setSchemaSourceType("ddl");
- mmd1.setSchemaText("create view \"my-view\" (\"my-column\"
string OPTIONS (UPDATABLE 'true')) OPTIONS (UPDATABLE 'true') as select *
from \"my-table\"");
+ mmd1.setSchemaText("create view \"my-view\" OPTIONS (UPDATABLE
'true') as select * from \"my-table\"");
es.deployVDB("test", Arrays.asList(mmd, mmd1));