teiid SVN: r4401 - in trunk: build/kits/jboss-as7/docs/teiid and 8 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-05 22:46:11 -0400 (Wed, 05 Sep 2012)
New Revision: 4401
Modified:
trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java
trunk/api/src/main/java/org/teiid/metadata/Table.java
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java
trunk/connectors/translator-jpa/src/test/java/org/teiid/translator/jpa/TestJSelectJPQLVisitor.java
trunk/connectors/translator-jpa/src/test/resources/sakila.ddl
trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java
trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java
trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
Log:
TEIID-2187 fixing constraint parsing
Modified: trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -50,7 +50,7 @@
}
Map<String, Column> map = columnMap;
if (map == null) {
- map = new TreeMap<String, Column>();
+ map = new TreeMap<String, Column>(String.CASE_INSENSITIVE_ORDER);
for (Column c : columns) {
map.put(c.getName(), c);
}
@@ -84,12 +84,4 @@
this.parent = parent;
}
- public Column getColumn(String name) {
- for (Column c:columns) {
- if (c.getCanonicalName().equals(name.toUpperCase())) {
- return c;
- }
- }
- return null;
- }
}
\ No newline at end of file
Modified: trunk/api/src/main/java/org/teiid/metadata/Table.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/Table.java 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/api/src/main/java/org/teiid/metadata/Table.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -22,6 +22,7 @@
package org.teiid.metadata;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
@@ -57,10 +58,10 @@
private boolean isSystem;
private boolean isMaterialized;
private boolean supportsUpdate;
- private List<ForeignKey> foriegnKeys = new LinkedList<ForeignKey>();
- private List<KeyRecord> indexes = new LinkedList<KeyRecord>();
- private List<KeyRecord> uniqueKeys = new LinkedList<KeyRecord>();
- private List<KeyRecord> accessPatterns = new LinkedList<KeyRecord>();
+ private List<ForeignKey> foriegnKeys = new ArrayList<ForeignKey>(2);
+ private List<KeyRecord> indexes = new ArrayList<KeyRecord>(2);
+ private List<KeyRecord> uniqueKeys = new ArrayList<KeyRecord>(2);
+ private List<KeyRecord> accessPatterns = new ArrayList<KeyRecord>(2);
private KeyRecord primaryKey;
//view information
@@ -209,15 +210,6 @@
this.foriegnKeys = foriegnKeys;
}
- public ForeignKey getForeignKey(String name) {
- for (ForeignKey fk:this.foriegnKeys) {
- if (fk.getName().equals(name)) {
- return fk;
- }
- }
- return null;
- }
-
public List<KeyRecord> getIndexes() {
return this.indexes;
}
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-09-06 02:46:11 UTC (rev 4401)
@@ -47,7 +47,8 @@
<li>TEIID-2166 array_get will return null if the index is out of bounds rather than raising an error.
<li>TEIID-2175 for 8.0 and 8.1 clients the server will check if serialized date/time values fall outside of 32-bit value ranges (year 1900 - 9999 for dates and times between years 1901 and 2038) and throw an exception. The previous behavior was
to truncate. The exception and the use of 32 bit serialization can be avoided by setting the system property org.teiid.longDatesTimes to true.
- <li>TEIID-2184 to be consistent with the rest of Teiid's logic the system functions dayName and monthName will return values from the default locale, rather than only the English names. Use the system property org.teiid.enDateNames true to revert to the pre-8.2 behavior.
+ <li>TEIID-2184 to be consistent with the rest of Teiid's logic the system functions dayName and monthName will return values from the default locale, rather than only the English names. Use the system property org.teiid.enDateNames true to revert to the pre-8.2 behavior.
+ <li>TEIID-2187 the CONSTRAINT keyword is not correctly used in table DDL. It should be replaced with a comma from scripts to be compatible with 8.2. If desired, 8.2 now supports the CONSTRAINT keyword to provide a name for each constraint.
</ul>
<h4>from 8.0</h4>
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-09-05 18:24:43 UTC (rev 4400)
+++ trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -126,13 +126,13 @@
c.setUpdatable(true);
return c;
}
- return entityTable.getColumn(name);
+ return entityTable.getColumnByName(name);
}
private void addForiegnKey(MetadataFactory mf, String name, List<String> columnNames, String referenceTable, Table table) throws TranslatorException {
ForeignKey fk = mf.addForiegnKey("FK_"+name, columnNames, referenceTable, table);
for (String column:columnNames) {
- Column c = table.getColumn(column);
+ Column c = table.getColumnByName(column);
c.setProperty(KEY_ASSOSIATED_WITH_FOREIGN_TABLE, mf.getName()+Tokens.DOT+referenceTable);
}
fk.setNameInSource(name);
Modified: trunk/connectors/translator-jpa/src/test/java/org/teiid/translator/jpa/TestJSelectJPQLVisitor.java
===================================================================
--- trunk/connectors/translator-jpa/src/test/java/org/teiid/translator/jpa/TestJSelectJPQLVisitor.java 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/connectors/translator-jpa/src/test/java/org/teiid/translator/jpa/TestJSelectJPQLVisitor.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -21,11 +21,12 @@
*/
package org.teiid.translator.jpa;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.teiid.cdk.api.TranslationUtility;
+import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.language.Select;
import org.teiid.query.metadata.TransformationMetadata;
@@ -41,7 +42,7 @@
jpaTranslator = new JPA2ExecutionFactory();
jpaTranslator.start();
- TransformationMetadata metadata = RealMetadataFactory.fromDDL(UnitTestUtil.getTestDataFile("sakila.ddl"), "sakila", "sakila");
+ TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("sakila.ddl")), "sakila", "sakila");
utility = new TranslationUtility(metadata);
}
Modified: trunk/connectors/translator-jpa/src/test/resources/sakila.ddl
===================================================================
--- trunk/connectors/translator-jpa/src/test/resources/sakila.ddl 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/connectors/translator-jpa/src/test/resources/sakila.ddl 2012-09-06 02:46:11 UTC (rev 4401)
@@ -1,16 +1,16 @@
CREATE FOREIGN TABLE country (
country_id integer NOT NULL AUTO_INCREMENT,
country varchar(50) NOT NULL,
- last_update timestamp NOT NULL
- CONSTRAINT PRIMARY KEY (country_id)
+ last_update timestamp NOT NULL,
+ PRIMARY KEY (country_id)
);
CREATE FOREIGN TABLE city (
city_id integer NOT NULL AUTO_INCREMENT,
city varchar(50) NOT NULL,
country_id integer NOT NULL OPTIONS (assosiated_with_table 'sakila.country'),
- last_update timestamp NOT NULL
- CONSTRAINT PRIMARY KEY (city_id),
+ last_update timestamp NOT NULL,
+ PRIMARY KEY (city_id),
FOREIGN KEY (country_id) REFERENCES country (country_id) OPTIONS(NAMEINSOURCE 'country')
);
@@ -22,8 +22,8 @@
city_id integer NOT NULL OPTIONS (assosiated_with_table 'sakila.city'),
postal_code varchar(10),
phone varchar(20) NOT NULL,
- last_update timestamp NOT NULL
- CONSTRAINT PRIMARY KEY (address_id),
+ last_update timestamp NOT NULL,
+ PRIMARY KEY (address_id),
FOREIGN KEY (city_id) REFERENCES city (city_id) OPTIONS(NAMEINSOURCE 'city')
);
@@ -37,8 +37,8 @@
active boolean NOT NULL,
username varchar(16) NOT NULL,
password varchar(40),
- last_update timestamp
- CONSTRAINT PRIMARY KEY (staff_id),
+ last_update timestamp,
+ PRIMARY KEY (staff_id),
FOREIGN KEY (store_id) REFERENCES store (store_id) OPTIONS(NAMEINSOURCE 'store'),
FOREIGN KEY (address_id) REFERENCES address (address_id) OPTIONS(NAMEINSOURCE 'address')
);
@@ -47,8 +47,8 @@
store_id byte NOT NULL AUTO_INCREMENT,
manager_staff_id byte NOT NULL OPTIONS (assosiated_with_table 'sakila.staff'),
address_id integer NOT NULL OPTIONS (assosiated_with_table 'sakila.store'),
- last_update timestamp NOT NULL
- CONSTRAINT PRIMARY KEY (store_id),
+ last_update timestamp NOT NULL,
+ PRIMARY KEY (store_id),
FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) OPTIONS(NAMEINSOURCE 'staff'),
FOREIGN KEY (address_id) REFERENCES address (address_id) OPTIONS(NAMEINSOURCE 'address')
);
@@ -62,8 +62,8 @@
address_id integer NOT NULL OPTIONS (assosiated_with_table 'sakila.address'),
active boolean NOT NULL,
create_date timestamp NOT NULL,
- last_update timestamp
- constraint PRIMARY KEY (customer_id),
+ last_update timestamp,
+ PRIMARY KEY (customer_id),
FOREIGN KEY (address_id) REFERENCES address (address_id) OPTIONS(NAMEINSOURCE 'address'),
FOREIGN KEY (store_id) REFERENCES store (store_id) OPTIONS(NAMEINSOURCE 'store')
);
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -156,14 +156,7 @@
}
visit(c, table);
}
-
- // constraints
- String contraints = buildContraints(table);
- if (!contraints.isEmpty()) {
- buffer.append(NEWLINE).append(TAB);
- buffer.append(CONSTRAINT);
- buffer.append(contraints);
- }
+ buildContraints(table);
buffer.append(NEWLINE);
buffer.append(RPAREN);
}
@@ -237,80 +230,50 @@
}
}
- private String buildContraints(Table table) {
- StringBuilder options = new StringBuilder();
+ private void buildContraints(Table table) {
+ addConstraints(table.getAccessPatterns(), "AP", ACCESSPATTERN); //$NON-NLS-1$
- boolean first = true;
- for (KeyRecord key:table.getAccessPatterns()) {
- if (first) {
- first = false;
- }
- else {
- options.append(COMMA);
- }
- options.append(SPACE).append(ACCESSPATTERN);
- addColumns(options, key.getColumns(), false);
- }
-
-
KeyRecord pk = table.getPrimaryKey();
- if (pk != null && pk.getColumns().size() > 1) {
- if (first) {
- first = false;
- }
- else {
- options.append(COMMA);
- }
- options.append(SPACE).append(PRIMARY_KEY);
- addColumns(options, pk.getColumns(), false);
+ if (pk != null) {
+ addConstraint("PK", PRIMARY_KEY, pk); //$NON-NLS-1$
}
-
- for (KeyRecord key:table.getUniqueKeys()) {
- if (key != null && key.getColumns().size() > 1) {
- if (first) {
- first = false;
- }
- else {
- options.append(COMMA);
- }
- options.append(SPACE).append(UNIQUE);
- addColumns(options, key.getColumns(), false);
- }
- }
-
- for (KeyRecord key:table.getIndexes()) {
- if (key != null && key.getColumns().size() > 1) {
- if (first) {
- first = false;
- }
- else {
- options.append(COMMA);
- }
- options.append(SPACE).append(INDEX);
- addColumns(options, key.getColumns(), false);
- }
- }
- for (ForeignKey key:table.getForeignKeys()) {
- if (first) {
- first = false;
- }
- else {
- options.append(COMMA);
- }
- options.append(SPACE).append(FOREIGN_KEY);
- addColumns(options, key.getColumns(), false);
- options.append(SPACE).append(REFERENCES);
+ addConstraints(table.getUniqueKeys(), UNIQUE, UNIQUE);
+ addConstraints(table.getIndexes(), INDEX, INDEX);
+
+ for (int i = 0; i < table.getForeignKeys().size(); i++) {
+ ForeignKey key = table.getForeignKeys().get(i);
+ addConstraint("FK" + i, FOREIGN_KEY, key); //$NON-NLS-1$
+ buffer.append(SPACE).append(REFERENCES);
if (key.getReferenceTableName() != null) {
- options.append(SPACE).append(key.getReferenceTableName());
+ buffer.append(SPACE).append(key.getReferenceTableName());
}
- options.append(SPACE);
- addNames(options, key.getReferenceColumns());
+ buffer.append(SPACE);
+ addNames(buffer, key.getReferenceColumns());
}
-
- return options.toString();
}
+ private void addConstraints(List<KeyRecord> constraints, String defaultName, String type) {
+ for (int i = 0; i < constraints.size(); i++) {
+ KeyRecord constraint = constraints.get(i);
+ addConstraint(defaultName + i, type, constraint);
+ }
+ }
+
+ private void addConstraint(String defaultName, String type,
+ KeyRecord constraint) {
+ if (constraint.getType() != KeyRecord.Type.AccessPattern && constraint.getColumns().size() <= 1) {
+ return;
+ }
+ buffer.append(COMMA).append(NEWLINE).append(TAB);
+ boolean nameMatches = defaultName.equals(constraint.getName());
+ if (!nameMatches) {
+ buffer.append(CONSTRAINT).append(SPACE).append(SQLStringVisitor.escapeSinglePart(constraint.getName())).append(SPACE);
+ }
+ buffer.append(type);
+ addColumns(buffer, constraint.getColumns(), false);
+ }
+
private void addColumns(StringBuilder builder, List<Column> columns, boolean includeType) {
builder.append(LPAREN);
boolean first = true;
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-09-06 02:46:11 UTC (rev 4401)
@@ -4689,6 +4689,7 @@
boolean view = false;
Command query = null;
Token comment = null;
+ String name = null;
}
{
<CREATE> (<FOREIGN> <TABLE> | [<VIRTUAL>] <VIEW> {view = true;})
@@ -4703,14 +4704,10 @@
}
[<LPAREN>
createColumn(factory, table)
- (LOOKAHEAD(2) <COMMA>
+ (LOOKAHEAD(3) <COMMA>
createColumn(factory, table)
)*
- [<CONSTRAINT> (primaryKeys(factory, table) | constraints(factory, table) | foreignKeys(factory, table))
- (<COMMA>
- (primaryKeys(factory, table) | constraints(factory, table)|foreignKeys(factory, table))
- )*
- ]
+ (<COMMA>{name=null;} [<CONSTRAINT> name = id()] (primaryKeys(factory, table, name) | constraints(factory, table, name) | foreignKeys(factory, table, name)))*
<RPAREN>]
[optionsClause(table, factory)
{
@@ -4740,7 +4737,7 @@
description=Defines the foreign key referential constraint.
example={code:sql}FOREIGN KEY (a, b) REFERENCES tbl (x, y){code}
*/
-void foreignKeys(MetadataFactory factory, Table table) :
+void foreignKeys(MetadataFactory factory, Table table, String name) :
{
List<String> columnNames = null;
String viewName = null;
@@ -4763,7 +4760,7 @@
[pkColumnNames = getColumnNames()]
{
try{
- key = factory.addForiegnKey("FK"+table.getForeignKeys().size(), columnNames, pkColumnNames, viewName, table);
+ key = factory.addForiegnKey(name != null?name:("FK"+table.getForeignKeys().size()), columnNames, pkColumnNames, viewName, table);
} catch (TranslatorException e){
throw new ParseException(e.getMessage());
}
@@ -4780,7 +4777,7 @@
description=Defines the primary key.
example={code:sql}PRIMARY KEY (a, b){code}
*/
-void primaryKeys(MetadataFactory factory, Table table) :
+void primaryKeys(MetadataFactory factory, Table table, String name) :
{
List<String> columnNames = null;
Column column = null;
@@ -4797,7 +4794,7 @@
throw new ParseException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
}
try{
- key = factory.addPrimaryKey("PK", columnNames, table);
+ key = factory.addPrimaryKey(name!=null?name:"PK", columnNames, table);
} catch(TranslatorException e){
throw new ParseException(e.getMessage());
}
@@ -4814,7 +4811,7 @@
description=Defines ACCESSPATTERN and UNIQUE constraints and INDEXes.
example={code:sql}UNIQUE (a){code}
*/
-void constraints(MetadataFactory factory, Table table) :
+void constraints(MetadataFactory factory, Table table, String name) :
{
KeyRecord keyrecord = null;
Column column = null;
@@ -4824,21 +4821,19 @@
}
{
( type = <UNIQUE> | type = <INDEX> | type = <ACCESSPATTERN>)
- {
+ {
columnNames = getColumnNames();
for (String col: columnNames) {
column = getColumn(col, table);
}
try{
if (type.image.equalsIgnoreCase("INDEX")) {
- key = factory.addIndex("INDEX"+table.getIndexes().size(), true, columnNames, table);
+ key = factory.addIndex(name != null?name:("INDEX"+table.getIndexes().size()), true, columnNames, table);
+ } else if (type.image.equalsIgnoreCase("UNIQUE")) {
+ key = factory.addIndex(name != null?name:("UNIQUE"+table.getUniqueKeys().size()), false, columnNames, table);
+ } else if (type.image.equalsIgnoreCase("ACCESSPATTERN")) {
+ key = factory.addAccessPattern(name != null?name:("AP"+table.getAccessPatterns().size()), columnNames, table);
}
- if (type.image.equalsIgnoreCase("UNIQUE")) {
- key = factory.addIndex("UNIQUE"+table.getUniqueKeys().size(), false, columnNames, table);
- }
- if (type.image.equalsIgnoreCase("ACCESSPATTERN")) {
- key = factory.addAccessPattern("AP"+table.getAccessPatterns().size(), columnNames, table);
- }
}catch(TranslatorException e){
throw new ParseException(e.getMessage());
}
@@ -4928,18 +4923,14 @@
{
try{
if (index){
- factory.addIndex(element, true, columnName, table);
- }
-
- if (unique){
- factory.addIndex(element, false, columnName, table);
- }
-
- if (pk) {
+ factory.addIndex("INDEX"+table.getIndexes().size(), true, columnName, table);
+ } else if (unique){
+ factory.addIndex("UNIQUE"+table.getIndexes().size(), false, columnName, table);
+ } else if (pk) {
if (table.getPrimaryKey() != null) {
throw new ParseException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
}
- factory.addPrimaryKey(element, columnName, table);
+ factory.addPrimaryKey("PK", columnName, table);
}
}catch(TranslatorException e){
throw new ParseException(e.getMessage());
Modified: trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -78,10 +78,10 @@
e6.setDefaultValue("hello");
mf.addPrimaryKey("PK", Arrays.asList("e1"), table);
- mf.addIndex("UK", false, Arrays.asList("e2"), table);
- mf.addIndex("UK2", false, Arrays.asList("e3"), table);
- mf.addIndex("IDX", true, Arrays.asList("e5"), table);
- mf.addIndex("IDX2", true, Arrays.asList("e6"), table);
+ mf.addIndex("UNIQUE0", false, Arrays.asList("e2"), table);
+ mf.addIndex("UNIQUE1", false, Arrays.asList("e3"), table);
+ mf.addIndex("INDEX0", true, Arrays.asList("e5"), table);
+ mf.addIndex("INDEX1", true, Arrays.asList("e6"), table);
Map<String, String> options = new HashMap<String, String>();
options.put("CARDINALITY", "12");
@@ -97,45 +97,45 @@
@Test
public void testMultiKeyPK() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date CONSTRAINT PRIMARY KEY (e1, e2))";
+ String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, PRIMARY KEY (e1, e2))";
String expected = "CREATE FOREIGN TABLE G1 (\n" +
" e1 integer,\n" +
" e2 string,\n" +
- " e3 date\n" +
- " CONSTRAINT PRIMARY KEY(e1, e2)\n" +
+ " e3 date,\n" +
+ " PRIMARY KEY(e1, e2)\n" +
");";
helpTest(ddl, expected);
}
@Test
public void testConstraints2() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date CONSTRAINT " +
+ String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, " +
"ACCESSPATTERN(e1), UNIQUE(e1), ACCESSPATTERN(e2, e3))";
String expected = "CREATE FOREIGN TABLE G1 (\n" +
" e1 integer UNIQUE,\n" +
" e2 string,\n" +
- " e3 date\n" +
- " CONSTRAINT ACCESSPATTERN(e1), ACCESSPATTERN(e2, e3)\n" +
+ " e3 date,\n" +
+ " ACCESSPATTERN(e1),\n ACCESSPATTERN(e2, e3)\n" +
");";
helpTest(ddl, expected);
}
@Test
public void testFK() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1(\"g1-e1\" integer, g1e2 varchar CONSTRAINT PRIMARY KEY(\"g1-e1\", g1e2));\n" +
- "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT " +
+ String ddl = "CREATE FOREIGN TABLE G1(\"g1-e1\" integer, g1e2 varchar, PRIMARY KEY(\"g1-e1\", g1e2));\n" +
+ "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, " +
"FOREIGN KEY (g2e1, g2e2) REFERENCES G1 (g1e1, g1e2))";
String expected = "CREATE FOREIGN TABLE G1 (\n" +
" \"g1-e1\" integer,\n" +
- " g1e2 string\n" +
- " CONSTRAINT PRIMARY KEY(\"g1-e1\", g1e2)\n" +
+ " g1e2 string,\n" +
+ " PRIMARY KEY(\"g1-e1\", g1e2)\n" +
");\n" +
"\n" +
"CREATE FOREIGN TABLE G2 (\n" +
" g2e1 integer,\n" +
- " g2e2 string\n" +
- " CONSTRAINT FOREIGN KEY(g2e1, g2e2) REFERENCES G1 (g1e1, g1e2)\n" +
+ " g2e2 string,\n" +
+ " FOREIGN KEY(g2e1, g2e2) REFERENCES G1 (g1e1, g1e2)\n" +
");";
helpTest(ddl, expected);
@@ -143,19 +143,19 @@
@Test
public void testOptionalFK() throws Exception {
- String ddl = "CREATE FOREIGN TABLE \"G1+\"(g1e1 integer, g1e2 varchar CONSTRAINT PRIMARY KEY(g1e1, g1e2));\n" +
- "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT PRIMARY KEY(g2e1, g2e2)," +
+ String ddl = "CREATE FOREIGN TABLE \"G1+\"(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));\n" +
+ "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2)," +
"FOREIGN KEY (g2e1, g2e2) REFERENCES G1)";
String expected = "CREATE FOREIGN TABLE \"G1+\" (\n" +
" g1e1 integer,\n" +
- " g1e2 string\n" +
- " CONSTRAINT PRIMARY KEY(g1e1, g1e2)\n" +
+ " g1e2 string,\n" +
+ " PRIMARY KEY(g1e1, g1e2)\n" +
");\n" +
"\n" +
"CREATE FOREIGN TABLE G2 (\n" +
" g2e1 integer,\n" +
- " g2e2 string\n" +
- " CONSTRAINT PRIMARY KEY(g2e1, g2e2), FOREIGN KEY(g2e1, g2e2) REFERENCES G1 \n" +
+ " g2e2 string,\n" +
+ " PRIMARY KEY(g2e1, g2e2),\n FOREIGN KEY(g2e1, g2e2) REFERENCES G1 \n" +
");";
helpTest(ddl, expected);
}
Modified: trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -178,8 +178,8 @@
@Test
public void testCrossReferenceFK() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar CONSTRAINT PRIMARY KEY(g1e1, g1e2));";
- String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT PRIMARY KEY(g2e1, g2e2), FOREIGN KEY (g2e1, g2e2) REFERENCES pm1.G1(g1e1, g1e2))";
+ String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));";
+ String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2), FOREIGN KEY (g2e1, g2e2) REFERENCES pm1.G1(g1e1, g1e2))";
buildModel("pm1", true, this.vdb, this.store, ddl);
buildModel("pm2", true, this.vdb, this.store, ddl2);
@@ -197,8 +197,8 @@
@Test
public void testCrossReferenceFKFromUniqueKey() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar CONSTRAINT UNIQUE(g1e2));";
- String ddl2 = "CREATE FOREIGN TABLE G2(g2e1 integer, g2e2 varchar CONSTRAINT FOREIGN KEY (g2e2) REFERENCES pm1.G1(g1e2))";
+ String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, UNIQUE(g1e2));";
+ String ddl2 = "CREATE FOREIGN TABLE G2(g2e1 integer, g2e2 varchar, FOREIGN KEY (g2e2) REFERENCES pm1.G1(g1e2))";
buildModel("pm1", true, this.vdb, this.store, ddl);
buildModel("pm2", true, this.vdb, this.store, ddl2);
@@ -216,8 +216,8 @@
@Test
public void testCrossReferenceResoveOptionalFK() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar CONSTRAINT PRIMARY KEY(g1e1, g1e2));";
- String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT FOREIGN KEY (g2e1, g2e2) REFERENCES pm1.G1)";
+ String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));";
+ String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, FOREIGN KEY (g2e1, g2e2) REFERENCES pm1.G1)";
buildModel("pm1", true, this.vdb, this.store, ddl);
buildModel("pm2", true, this.vdb, this.store, ddl2);
@@ -236,8 +236,8 @@
@Test
public void testCrossReferenceFKNoPKonRefTable() throws Exception {
// note here the unique here does not matter for non-existent reference columns, only primary key counted.
- String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar CONSTRAINT UNIQUE(g1e1, g1e2));";
- String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT PRIMARY KEY(g2e1, g2e2), FOREIGN KEY (g2e1, g2e2) REFERENCES pm1.G1)";
+ String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, UNIQUE(g1e1, g1e2));";
+ String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2), FOREIGN KEY (g2e1, g2e2) REFERENCES pm1.G1)";
buildModel("pm1", true, this.vdb, this.store, ddl);
buildModel("pm2", true, this.vdb, this.store, ddl2);
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -22,8 +22,6 @@
*/
import static org.junit.Assert.*;
-import java.io.File;
-import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -31,7 +29,6 @@
import org.junit.Test;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
-import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.metadata.*;
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.query.metadata.MetadataValidator;
@@ -146,7 +143,7 @@
@Test
public void testMultiKeyPK() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date CONSTRAINT PRIMARY KEY (e1, e2))";
+ String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, PRIMARY KEY (e1, e2))";
Schema s = helpParse(ddl, "model").getSchema();
Map<String, Table> tableMap = s.getTables();
@@ -159,7 +156,7 @@
@Test
public void testOptionsKey() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date CONSTRAINT UNIQUE (e1) OPTIONS (CUSTOM_PROP 'VALUE'))";
+ String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, UNIQUE (e1) OPTIONS (CUSTOM_PROP 'VALUE'))";
Schema s = helpParse(ddl, "model").getSchema();
Map<String, Table> tableMap = s.getTables();
@@ -171,8 +168,8 @@
@Test
public void testConstraints() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date " +
- " CONSTRAINT PRIMARY KEY (e1, e2), INDEX(e2, e3), ACCESSPATTERN(e1), UNIQUE(e1)," +
+ String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, " +
+ " PRIMARY KEY (e1, e2), INDEX(e2, e3), ACCESSPATTERN(e1), UNIQUE(e1)," +
" ACCESSPATTERN(e2, e3))";
Schema s = helpParse(ddl, "model").getSchema();
@@ -191,7 +188,7 @@
@Test
public void testConstraints2() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date CONSTRAINT " +
+ String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, " +
"ACCESSPATTERN(e1), UNIQUE(e1), ACCESSPATTERN(e2, e3))";
Schema s = helpParse(ddl, "model").getSchema();
@@ -218,8 +215,8 @@
@Test
public void testFK() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar CONSTRAINT PRIMARY KEY(g1e1, g1e2));\n" +
- "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT " +
+ String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));\n" +
+ "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, " +
"FOREIGN KEY (g2e1, g2e2) REFERENCES G1 (g1e1, g1e2))";
Schema s = helpParse(ddl, "model").getSchema();
@@ -237,8 +234,8 @@
@Test
public void testOptionalFK() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar CONSTRAINT PRIMARY KEY(g1e1, g1e2));\n" +
- "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT PRIMARY KEY(g2e1, g2e2)," +
+ String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));\n" +
+ "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2)," +
"FOREIGN KEY (g2e1, g2e2) REFERENCES G1)";
MetadataFactory s = helpParse(ddl, "model");
@@ -269,7 +266,7 @@
@Test
public void testOptionalFKFail() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar);\n" +
- "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT PRIMARY KEY(g2e1, g2e2)," +
+ "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2)," +
"FOREIGN KEY (g2e1, g2e2) REFERENCES G1)";
MetadataFactory s = helpParse(ddl, "model");
@@ -297,9 +294,9 @@
@Test
public void testFKAccrossSchemas() throws Exception {
- String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar CONSTRAINT PRIMARY KEY(g1e1, g1e2));\n";
+ String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));\n";
- String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar CONSTRAINT PRIMARY KEY(g2e1, g2e2)," +
+ String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2)," +
"FOREIGN KEY (g2e1, g2e2) REFERENCES model.G1)";
MetadataFactory f1 = helpParse(ddl, "model");
@@ -648,12 +645,6 @@
return mf;
}
- public MetadataFactory buildMetadataFactory(File ddlFile, String model) throws IOException, ParseException {
- MetadataFactory mf = new MetadataFactory(null, 1, model, getDataTypes(), new Properties(), null);
- parser.parseDDL(mf, ObjectConverterUtil.convertFileToString(ddlFile));
- return mf;
- }
-
public static Map<String, Datatype> getDataTypes() {
return SystemMetadata.getInstance().getRuntimeTypeMap();
}
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2012-09-05 18:24:43 UTC (rev 4400)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2012-09-06 02:46:11 UTC (rev 4401)
@@ -22,7 +22,6 @@
package org.teiid.query.unittest;
-import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -61,11 +60,13 @@
import org.teiid.query.mapping.xml.MappingVisitor;
import org.teiid.query.mapping.xml.Navigator;
import org.teiid.query.metadata.CompositeMetadataStore;
+import org.teiid.query.metadata.MetadataValidator;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.FakeFunctionMetadataSource;
import org.teiid.query.parser.TestDDLParser;
import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.validator.ValidatorReport;
@SuppressWarnings("nls")
public class RealMetadataFactory {
@@ -342,7 +343,10 @@
udfs.add(new FunctionTree(schema.getName(), new UDFSource(schema.getFunctions().values()), true));
}
}
- return new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs);
+ TransformationMetadata metadata = new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs);
+ vdbMetaData.addAttchment(TransformationMetadata.class, metadata);
+ vdbMetaData.addAttchment(QueryMetadataInterface.class, metadata);
+ return metadata;
}
/**
@@ -2666,8 +2670,13 @@
return createTransformationMetadata(metadataStore, "example4");
}
- public static TransformationMetadata fromDDL(File ddlFile, String vdbName, String modelName) throws Exception {
- MetadataFactory mf = new TestDDLParser().buildMetadataFactory(ddlFile, modelName);
- return createTransformationMetadata(mf.asMetadataStore(), vdbName);
+ public static TransformationMetadata fromDDL(String ddl, String vdbName, String modelName) throws Exception {
+ MetadataFactory mf = TestDDLParser.helpParse(ddl, modelName);
+ TransformationMetadata tm = createTransformationMetadata(mf.asMetadataStore(), vdbName);
+ ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
+ if (report.hasItems()) {
+ throw new RuntimeException(report.getFailureMessage());
+ }
+ return tm;
}
}
12 years, 3 months
teiid SVN: r4400 - in trunk/jboss-integration/src/main/java/org/teiid/jboss: rest and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-09-05 14:24:43 -0400 (Wed, 05 Sep 2012)
New Revision: 4400
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java
Log:
TEIID-2158: making scope limited to single vdb, thus avoiding the duplicate resource managements.
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-09-05 17:59:08 UTC (rev 4399)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-09-05 18:24:43 UTC (rev 4400)
@@ -173,7 +173,7 @@
getVDBRepository().addListener(this.vdbListener);
- this.restEasyListener = new ResteasyEnabler(controllerValue.getValue(), executorInjector.getValue());
+ this.restEasyListener = new ResteasyEnabler(this.vdb.getName(), this.vdb.getVersion(), controllerValue.getValue(), executorInjector.getValue());
getVDBRepository().addListener(this.restEasyListener);
MetadataStore store = new MetadataStore();
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java 2012-09-05 17:59:08 UTC (rev 4399)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java 2012-09-05 18:24:43 UTC (rev 4400)
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.as.controller.ModelController;
import org.teiid.adminapi.Admin;
@@ -47,63 +48,78 @@
static final String REST_NAMESPACE = "{http://teiid.org/rest}"; //$NON-NLS-1$
private Admin admin;
private Executor executor;
+ private String vdbName;
+ private int vdbVersion;
+ private AtomicBoolean deployed = new AtomicBoolean(false);
- public ResteasyEnabler(ModelController deployer, Executor executor) {
+ public ResteasyEnabler(String vdbName, int version, ModelController deployer, Executor executor) {
this.admin = AdminFactory.getInstance().createAdmin(deployer.createClient(executor));
this.executor = executor;
+ this.vdbName = vdbName;
+ this.vdbVersion = version;
}
@Override
- public void added(String name, int version, CompositeVDB vdb) {
+ public synchronized void added(String name, int version, CompositeVDB vdb) {
}
@Override
- public void finishedDeployment(String name, int version, CompositeVDB cvdb) {
- final VDBMetaData vdb = cvdb.getVDB();
-
- String generate = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"auto-generate"); //$NON-NLS-1$
+ public synchronized void finishedDeployment(String name, int version, CompositeVDB cvdb) {
+ if (this.vdbName.equals(name) && this.vdbVersion == version) {
- final String warName = buildName(vdb);
- if (generate != null && Boolean.parseBoolean(generate)
- && hasRestMetadata(vdb)
- && !((AdminImpl) this.admin).getDeployments().contains(warName)) {
- // this must be executing the async thread to avoid any lock-up from management operations
- this.executor.execute(new Runnable() {
- @Override
- public void run() {
- try {
- RestASMBasedWebArchiveBuilder builder = new RestASMBasedWebArchiveBuilder();
- byte[] warContents = builder.createRestArchive(vdb);
- admin.deploy(warName, new ByteArrayInputStream(warContents));
- } catch (FileNotFoundException e) {
- LogManager.logWarning(LogConstants.CTX_RUNTIME, e);
- } catch (IOException e) {
- LogManager.logWarning(LogConstants.CTX_RUNTIME, e);
- } catch (AdminException e) {
- LogManager.logWarning(LogConstants.CTX_RUNTIME, e);
+ final VDBMetaData vdb = cvdb.getVDB();
+
+ String generate = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"auto-generate"); //$NON-NLS-1$
+
+ final String warName = buildName(vdb);
+ if (generate != null && Boolean.parseBoolean(generate)
+ && hasRestMetadata(vdb)
+ && !this.deployed.get()
+ && !((AdminImpl) this.admin).getDeployments().contains(warName)) {
+
+ this.deployed.set(true);
+
+ // this must be executing the async thread to avoid any lock-up from management operations
+ this.executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ RestASMBasedWebArchiveBuilder builder = new RestASMBasedWebArchiveBuilder();
+ byte[] warContents = builder.createRestArchive(vdb);
+ admin.deploy(warName, new ByteArrayInputStream(warContents));
+ } catch (FileNotFoundException e) {
+ LogManager.logWarning(LogConstants.CTX_RUNTIME, e);
+ } catch (IOException e) {
+ LogManager.logWarning(LogConstants.CTX_RUNTIME, e);
+ } catch (AdminException e) {
+ LogManager.logWarning(LogConstants.CTX_RUNTIME, e);
+ }
}
- }
- });
+ });
+ }
}
}
@Override
- public void removed(String name, int version, CompositeVDB cvdb) {
- VDBMetaData vdb = cvdb.getVDB();
- String generate = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"auto-generate"); //$NON-NLS-1$
- final String warName = buildName(vdb);
- if (generate != null && Boolean.parseBoolean(generate)
- && ((AdminImpl) this.admin).getDeployments().contains(warName)) {
- this.executor.execute(new Runnable() {
- @Override
- public void run() {
- try {
- admin.undeploy(warName);
- } catch (AdminException e) {
- LogManager.logWarning(LogConstants.CTX_RUNTIME, e);
- }
- }
- });
+ public synchronized void removed(String name, int version, CompositeVDB cvdb) {
+ if (this.vdbName.equals(name) && this.vdbVersion == version) {
+ VDBMetaData vdb = cvdb.getVDB();
+
+ // we only want un-deploy what is auto-generated previously
+ final String warName = buildName(vdb);
+ if (this.deployed.get()) {
+ this.deployed.set(false);
+ this.executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ admin.undeploy(warName);
+ } catch (AdminException e) {
+ LogManager.logWarning(LogConstants.CTX_RUNTIME, e);
+ }
+ }
+ });
+ }
}
}
12 years, 3 months
teiid SVN: r4399 - in trunk/engine/src: test/java/org/teiid/common/buffer and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-05 13:59:08 -0400 (Wed, 05 Sep 2012)
New Revision: 4399
Modified:
trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
Log:
TEIID-2186 correcting the valid check
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java 2012-09-04 14:10:43 UTC (rev 4398)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java 2012-09-05 17:59:08 UTC (rev 4399)
@@ -53,6 +53,8 @@
private boolean inPartial;
+ private List<Object> cachedBound;
+
private ArrayList<SearchResult> places = new ArrayList<SearchResult>();
/**
@@ -111,7 +113,7 @@
if (!direction) {
values = upper.values;
}
- if (lowerBound != null) {
+ if (lowerBound != null && page == bound) {
valid = index<=boundIndex;
}
} else {
@@ -172,7 +174,12 @@
return null;
}
if (newValue.size() < tree.getKeyLength()) {
- init(new ArrayList<Object>(newValue), newValue, true);
+ if (cachedBound == null) {
+ cachedBound = new ArrayList<Object>(tree.getKeyLength());
+ }
+ cachedBound.clear();
+ cachedBound.addAll(newValue);
+ init(cachedBound, newValue, true);
inPartial = true;
continue;
}
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2012-09-04 14:10:43 UTC (rev 4398)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2012-09-05 17:59:08 UTC (rev 4399)
@@ -25,6 +25,7 @@
import static org.junit.Assert.*;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.junit.Test;
@@ -32,6 +33,8 @@
import org.teiid.common.buffer.impl.BufferFrontedFileStoreCache;
import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.processor.CollectionTupleSource;
import org.teiid.query.sql.symbol.ElementSymbol;
@SuppressWarnings({"nls", "unchecked"})
@@ -130,4 +133,28 @@
}
+ @Test public void testSearch() throws TeiidComponentException, TeiidProcessingException {
+ BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
+ bm.setProcessorBatchSize(1);
+
+ ElementSymbol e1 = new ElementSymbol("x");
+ e1.setType(Integer.class);
+ ElementSymbol e2 = new ElementSymbol("x");
+ e1.setType(Integer.class);
+ List elements = Arrays.asList(e1, e2);
+ STree map = bm.createSTree(elements, "1", 2);
+
+ int size = 1<<16;
+ for (int i = 0; i < size; i++) {
+ assertNull(map.insert(Arrays.asList(i, i), InsertMode.NEW, -1));
+ assertEquals(i + 1, map.getRowCount());
+ }
+ map.compact();
+ for (int i = 0; i < size; i++) {
+ TupleBrowser tb = new TupleBrowser(map, new CollectionTupleSource(Collections.singletonList(Arrays.asList(i)).iterator()), true);
+ assertNotNull(tb.nextTuple());
+ assertNull(tb.nextTuple());
+ }
+ }
+
}
12 years, 3 months
teiid SVN: r4398 - in trunk: common-core/src/test/java/org/teiid/core/types/basic and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-04 10:10:43 -0400 (Tue, 04 Sep 2012)
New Revision: 4398
Modified:
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java
trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
Log:
TEIID-2184 fixing unit tests and month/dayname to not be specific to the en/us locale
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-09-04 12:30:31 UTC (rev 4397)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-09-04 14:10:43 UTC (rev 4398)
@@ -46,7 +46,8 @@
<ul>
<li>TEIID-2166 array_get will return null if the index is out of bounds rather than raising an error.
<li>TEIID-2175 for 8.0 and 8.1 clients the server will check if serialized date/time values fall outside of 32-bit value ranges (year 1900 - 9999 for dates and times between years 1901 and 2038) and throw an exception. The previous behavior was
- to truncate. The exception and the use of 32 bit serialization can be avoided by setting the system property org.teiid.longDatesTimes to true.
+ to truncate. The exception and the use of 32 bit serialization can be avoided by setting the system property org.teiid.longDatesTimes to true.
+ <li>TEIID-2184 to be consistent with the rest of Teiid's logic the system functions dayName and monthName will return values from the default locale, rather than only the English names. Use the system property org.teiid.enDateNames true to revert to the pre-8.2 behavior.
</ul>
<h4>from 8.0</h4>
Modified: trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java 2012-09-04 12:30:31 UTC (rev 4397)
+++ trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java 2012-09-04 14:10:43 UTC (rev 4398)
@@ -31,6 +31,7 @@
import java.sql.Timestamp;
import org.junit.Test;
+import org.teiid.core.CorePlugin;
import org.teiid.core.types.ClobImpl;
import org.teiid.core.types.ClobType;
import org.teiid.core.types.DataTypeManager;
@@ -249,7 +250,8 @@
}
@Test public void testRangeCheck1() throws Exception {
- helpTransformException(new Double("1E11"), DataTypeManager.DefaultDataClasses.INTEGER, "TEIID10058 The Double value '100,000,000,000' is outside the of range for Integer"); //$NON-NLS-1$ //$NON-NLS-2$
+ Double value = new Double("1E11");//$NON-NLS-1$
+ helpTransformException(value, DataTypeManager.DefaultDataClasses.INTEGER, CorePlugin.Util.gs(CorePlugin.Event.TEIID10058, value, Double.class.getSimpleName(), Integer.class.getSimpleName())); //$NON-NLS-1$ //$NON-NLS-2$
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2012-09-04 12:30:31 UTC (rev 4397)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2012-09-04 14:10:43 UTC (rev 4398)
@@ -36,11 +36,14 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
+import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
+import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
import java.util.UUID;
@@ -55,6 +58,7 @@
import org.teiid.core.types.TransformationException;
import org.teiid.core.types.InputStreamFactory.BlobInputStreamFactory;
import org.teiid.core.types.InputStreamFactory.ClobInputStreamFactory;
+import org.teiid.core.util.PropertiesUtils;
import org.teiid.core.util.TimestampWithTimezone;
import org.teiid.language.SQLConstants;
import org.teiid.language.SQLConstants.NonReserved;
@@ -374,13 +378,34 @@
// ================== Function = dayname =====================
- static final String[] dayNames = new String[] {
- "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
-
+ static String[] dayNames;
+ static String[] monthNames;
+
public static Object dayName(Date x) {
- return dayNames[getField(x, Calendar.DAY_OF_WEEK) - 1];
+ return getDayNames()[getField(x, Calendar.DAY_OF_WEEK) - 1];
}
+
+ private static Locale getSymbolLocale() {
+ return PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.enDateNames", false)?Locale.ENGLISH:Locale.getDefault(); //$NON-NLS-1$
+ }
+ static String[] getMonthNames() {
+ if (monthNames == null) {
+ DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(getSymbolLocale());
+ String[] months = dateFormatSymbols.getMonths();
+ monthNames = Arrays.copyOf(months, 12);
+ }
+ return monthNames;
+ }
+
+ static String[] getDayNames() {
+ if (dayNames == null) {
+ DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(getSymbolLocale());
+ dayNames = Arrays.copyOfRange(dateFormatSymbols.getWeekdays(), 1, 8);
+ }
+ return dayNames;
+ }
+
// ================== Function = dayofmonth =====================
public static Object dayOfMonth(Date x) {
@@ -423,12 +448,8 @@
// ================== Function = monthname =====================
- static final String[] monthNames = new String[] {
- "January", "February", "March", "April", "May", "June", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- "July", "August", "September", "October", "November", "December" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-
public static Object monthName(Date x) {
- return monthNames[getField(x, Calendar.MONTH)];
+ return getMonthNames()[getField(x, Calendar.MONTH)];
}
// ================== Function = second =====================
@@ -1068,7 +1089,7 @@
SimpleDateFormat sdf = CommandContext.getDateFormat(context, format);
return sdf.format(date);
} catch (IllegalArgumentException iae) {
- throw new FunctionExecutionException(QueryPlugin.Event.TEIID30409, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30409,iae.getMessage()));
+ throw new FunctionExecutionException(QueryPlugin.Event.TEIID30409, iae, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30409,iae.getMessage()));
}
}
@@ -1079,7 +1100,7 @@
try {
return df.parse(date);
} catch (ParseException e) {
- throw new FunctionExecutionException(QueryPlugin.Event.TEIID30410, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30410, date, format));
+ throw new FunctionExecutionException(QueryPlugin.Event.TEIID30410, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30410, date, format));
}
}
@@ -1095,7 +1116,7 @@
DecimalFormat df = CommandContext.getDecimalFormat(context, format);
return df.format(number);
} catch (IllegalArgumentException iae) {
- throw new FunctionExecutionException(QueryPlugin.Event.TEIID30411, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30411, iae.getMessage()));
+ throw new FunctionExecutionException(QueryPlugin.Event.TEIID30411, iae, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30411, iae.getMessage()));
}
}
Modified: trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java 2012-09-04 12:30:31 UTC (rev 4397)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java 2012-09-04 14:10:43 UTC (rev 4398)
@@ -33,6 +33,7 @@
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
@@ -80,12 +81,18 @@
private static final Class<Timestamp> T_TIMESTAMP = DataTypeManager.DefaultDataClasses.TIMESTAMP;
private FunctionLibrary library = new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions());
+ private Locale locale;
- @Before public void setUp() {
+ @Before public void setUp() {
+ locale = Locale.getDefault();
+ Locale.setDefault(Locale.US);
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$
}
@After public void tearDown() {
+ Locale.setDefault(locale);
+ FunctionMethods.dayNames = null;
+ FunctionMethods.monthNames = null;
TimestampWithTimezone.resetCalendar(null);
}
@@ -1270,9 +1277,10 @@
}
@Test public void testInvokeDayName() {
- for (int i = 0; i < FunctionMethods.dayNames.length; i++) {
+ String[] dayNames = FunctionMethods.getDayNames();
+ for (int i = 0; i < dayNames.length; i++) {
Date time = TimestampUtil.createDate(100, 0, i + 2);
- helpInvokeMethod("dayName", new Object[] { time }, FunctionMethods.dayNames[i]); //$NON-NLS-1$
+ helpInvokeMethod("dayName", new Object[] { time }, dayNames[i]); //$NON-NLS-1$
}
}
@@ -1297,9 +1305,10 @@
}
@Test public void testInvokeMonthName() {
- for (int i = 0; i < FunctionMethods.monthNames.length; i++) {
+ String[] monthNames = FunctionMethods.getMonthNames();
+ for (int i = 0; i < monthNames.length; i++) {
Date time = TimestampUtil.createDate(100, i, 1);
- helpInvokeMethod("monthName", new Object[] { time }, FunctionMethods.monthNames[i]); //$NON-NLS-1$
+ helpInvokeMethod("monthName", new Object[] { time }, monthNames[i]); //$NON-NLS-1$
}
}
12 years, 3 months
teiid SVN: r4397 - trunk/test-integration/common/src/test/resources/TestODBCSocketTransport.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-04 08:30:31 -0400 (Tue, 04 Sep 2012)
New Revision: 4397
Added:
trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testArrayTypes.expected
trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testInt2Vector.expected
trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPgProc.expected
Log:
TEIID-2166 adding test updates missed by eclipse
Added: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testArrayTypes.expected
===================================================================
--- trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testArrayTypes.expected (rev 0)
+++ trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testArrayTypes.expected 2012-09-04 12:30:31 UTC (rev 4397)
@@ -0,0 +1,27 @@
+int2vector
+indkey
+1
+1
+1
+1
+3
+1
+2
+2
+1
+1
+3
+2
+1
+3
+4
+5
+1
+2
+1
+1
+1
+1
+Row Count : 22
+getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
+indkey 1111 java.lang.Object indkey int2vector 2147483647 2147483647 0 false true false false 1 false true false true
Added: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testInt2Vector.expected
===================================================================
--- trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testInt2Vector.expected (rev 0)
+++ trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testInt2Vector.expected 2012-09-04 12:30:31 UTC (rev 4397)
@@ -0,0 +1,27 @@
+int2vector
+indkey
+1
+1
+1
+1
+3
+1
+2
+2
+1
+1
+3
+2
+1
+3
+4
+5
+1
+2
+1
+1
+1
+1
+Row Count : 22
+getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
+indkey 1111 java.lang.Object indkey int2vector 2147483647 2147483647 0 false true false false 1 false true false true
Added: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPgProc.expected
===================================================================
--- trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPgProc.expected (rev 0)
+++ trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testPgProc.expected 2012-09-04 12:30:31 UTC (rev 4397)
@@ -0,0 +1,21 @@
+int4 varchar bool int4 int2 oidvector _text _char _oid int4
+oid proname proretset prorettype pronargs proargtypes proargnames proargmodes proallargtypes pronamespace
+2 isLoggable false 16 2 1043 1043 {"level","context"} <null> <null> 3
+3 logMsg false 16 3 1043 1043 2$ {"level","context","msg"} <null> {1043,1043,228$ 3
+4 refreshMatView false 23 2 1043 16 {"ViewName","Invalidate"} <null> {1043,16} 3
+5 refreshMatViewRow false 23 2 1043 2283 {"ViewName","Key"} <null> {1043,2283} 3
+6 setColumnStats false 2278 6 1043 1043 2$ {"tableName","columnName","distinctCount","nullCount","max","min"$ <null> {1043,1043,23,$ 3
+7 setProperty false 14939 3 1043 1043 1$ {"UID","Name","Value"} <null> {1043,1043,149$ 3
+8 setTableStats false 2278 2 1043 23 {"tableName","cardinality"} <null> {1043,23} 3
+Row Count : 7
+getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
+oid 4 java.lang.Integer oid int4 11 10 0 false false false false 1 false true true true
+proname 12 java.lang.String proname varchar 4000 4000 0 false true false false 1 false true false true
+proretset -7 java.lang.Boolean proretset bool 1 1 0 false false false false 1 false true false true
+prorettype 4 java.lang.Integer prorettype int4 11 10 0 false false false false 1 false true true true
+pronargs 5 java.lang.Integer pronargs int2 6 5 0 false false false false 1 false true true true
+proargtypes 1111 java.lang.Object proargtypes oidvector 10 10 0 false false false false 1 false true false true
+proargnames 2003 java.sql.Array proargnames _text 2147483647 2147483647 0 false true false false 1 false true false true
+proargmodes 2003 java.sql.Array proargmodes _char 1 1 0 false true false false 1 false true false true
+proallargtypes 2003 java.sql.Array proallargtypes _oid 10 10 0 false false false false 1 false true false true
+pronamespace 4 java.lang.Integer pronamespace int4 11 10 0 false false false false 1 false true true true
12 years, 3 months
teiid SVN: r4396 - in trunk: client/src/main/java/org/teiid and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-04 08:26:59 -0400 (Tue, 04 Sep 2012)
New Revision: 4396
Removed:
trunk/client/src/main/java/org/teiid/adminapi/
Modified:
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/client/src/main/java/org/teiid/client/BatchSerializer.java
trunk/client/src/main/java/org/teiid/jdbc/JDBCPlugin.java
trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
trunk/client/src/test/java/org/teiid/client/TestBatchSerializer.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
Log:
TEIID-2175 changing the date/time serialization
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-09-04 11:53:12 UTC (rev 4395)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-09-04 12:26:59 UTC (rev 4396)
@@ -42,9 +42,11 @@
<li>decodeinteger/decodestring have been deprecated. A CASE expression should be used instead.
</ul>
-<h4>from 8.0</h4>
+<h4>from 8.1</h4>
<ul>
<li>TEIID-2166 array_get will return null if the index is out of bounds rather than raising an error.
+ <li>TEIID-2175 for 8.0 and 8.1 clients the server will check if serialized date/time values fall outside of 32-bit value ranges (year 1900 - 9999 for dates and times between years 1901 and 2038) and throw an exception. The previous behavior was
+ to truncate. The exception and the use of 32 bit serialization can be avoided by setting the system property org.teiid.longDatesTimes to true.
</ul>
<h4>from 8.0</h4>
Modified: trunk/client/src/main/java/org/teiid/client/BatchSerializer.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/BatchSerializer.java 2012-09-04 11:53:12 UTC (rev 4395)
+++ trunk/client/src/main/java/org/teiid/client/BatchSerializer.java 2012-09-04 12:26:59 UTC (rev 4396)
@@ -54,10 +54,20 @@
/**
* @since 4.2
+ *
+ * <ul>
+ * <li>version 0: starts with 7.1 and uses simple serialization too broadly
+ * <li>version 1: starts with 8.0 uses better string, blob, clob, xml, etc.
+ * add varbinary support.
+ * however was possibly silently truncating date/time values that were
+ * outside of jdbc allowed values
+ * <li>version 2: starts with 8.2 and adds better array serialization and
+ * uses a safer date/time serialization
+ * </ul>
*/
public class BatchSerializer {
- private static final byte CURRENT_VERSION = (byte)2;
+ static final byte CURRENT_VERSION = (byte)2;
private BatchSerializer() {} // Uninstantiable
@@ -70,13 +80,13 @@
serializers.put(DataTypeManager.DefaultDataTypes.BOOLEAN, new ColumnSerializer[] {new BooleanColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.BYTE, new ColumnSerializer[] {new ByteColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.CHAR, new ColumnSerializer[] {new CharColumnSerializer()});
- serializers.put(DataTypeManager.DefaultDataTypes.DATE, new ColumnSerializer[] {new DateColumnSerializer(), new DateColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.DATE, new ColumnSerializer[] {new DateColumnSerializer(), new DateColumnSerializer1(), new DateColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.DOUBLE, new ColumnSerializer[] {new DoubleColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.FLOAT, new ColumnSerializer[] {new FloatColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.INTEGER, new ColumnSerializer[] {new IntColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.LONG, new ColumnSerializer[] {new LongColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.SHORT, new ColumnSerializer[] {new ShortColumnSerializer()});
- serializers.put(DataTypeManager.DefaultDataTypes.TIME, new ColumnSerializer[] {new TimeColumnSerializer(), new TimeColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.TIME, new ColumnSerializer[] {new TimeColumnSerializer(), new TimeColumnSerializer1(), new TimeColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.TIMESTAMP, new ColumnSerializer[] {new TimestampColumnSerializer()});
serializers.put(DataTypeManager.DefaultDataTypes.STRING, new ColumnSerializer[] {defaultSerializer, new StringColumnSerializer1()});
serializers.put(DataTypeManager.DefaultDataTypes.CLOB, new ColumnSerializer[] {defaultSerializer, new ClobColumnSerializer1()});
@@ -617,18 +627,30 @@
}
static int DATE_NORMALIZER = 0;
+ public final static long MIN_DATE_32;
+ public final static long MAX_DATE_32;
+ public final static long MIN_TIME_32;
+ public final static long MAX_TIME_32;
static {
Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$
c.set(1900, 0, 1, 0, 0, 0);
c.set(Calendar.MILLISECOND, 0);
- DATE_NORMALIZER = -(int)(c.getTime().getTime()/60000); //support a 32 bit range starting at this value
+ MIN_DATE_32 = c.getTimeInMillis();
+ MAX_DATE_32 = MIN_DATE_32 + ((1l<<32)-1)*60000;
+ DATE_NORMALIZER = -(int)(MIN_DATE_32/60000); //support a 32 bit range starting at this value
+ MAX_TIME_32 = Integer.MAX_VALUE*1000l;
+ MIN_TIME_32 = Integer.MIN_VALUE*1000l;
}
private static class DateColumnSerializer1 extends ColumnSerializer {
protected void writeObject(ObjectOutput out, Object obj) throws IOException {
- out.writeInt((int)(((java.sql.Date)obj).getTime()/60000) + DATE_NORMALIZER);
+ long time = ((java.sql.Date)obj).getTime();
+ if (time < MIN_DATE_32 || time > MAX_DATE_32) {
+ throw new IOException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20029, obj.getClass().getName()));
+ }
+ out.writeInt((int)(time/60000) + DATE_NORMALIZER);
}
protected Object readObject(ObjectInput in) throws IOException {
return new java.sql.Date(((in.readInt()&0xffffffffL) - DATE_NORMALIZER)*60000);
@@ -637,7 +659,11 @@
private static class TimeColumnSerializer1 extends ColumnSerializer {
protected void writeObject(ObjectOutput out, Object obj) throws IOException {
- out.writeInt((int)(((Time)obj).getTime()/1000));
+ long time = ((Time)obj).getTime();
+ if (time < MIN_TIME_32 || time > MAX_TIME_32) {
+ throw new IOException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20029, obj.getClass().getName()));
+ }
+ out.writeInt((int)(time/1000));
}
protected Object readObject(ObjectInput in) throws IOException {
return new Time((in.readInt()&0xffffffffL)*1000);
Modified: trunk/client/src/main/java/org/teiid/jdbc/JDBCPlugin.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/JDBCPlugin.java 2012-09-04 11:53:12 UTC (rev 4395)
+++ trunk/client/src/main/java/org/teiid/jdbc/JDBCPlugin.java 2012-09-04 12:26:59 UTC (rev 4396)
@@ -57,6 +57,7 @@
TEIID20021,
TEIID20023,
TEIID20027,
- TEIID20028
+ TEIID20028,
+ TEIID20029
}
}
Modified: trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
===================================================================
--- trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties 2012-09-04 11:53:12 UTC (rev 4395)
+++ trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties 2012-09-04 12:26:59 UTC (rev 4396)
@@ -172,4 +172,5 @@
TEIID20028=data length too big: {0} > max of {1}. You may need to adjust the maxObjectSize client setting.
unexpected_element=Unexpected Element {0} encountered, expecting one of {1}
ambigious_gss_selection=Either configure "java.security.krb5.conf" property or combination of "java.security.krb5.realm" and "java.security.krb5.kdc" properties. Not both.
-no_gss_selection=No KRB5 configuration found. Either configure "java.security.krb5.conf" property or combination of "java.security.krb5.realm" and "java.security.krb5.kdc" properties.
\ No newline at end of file
+no_gss_selection=No KRB5 configuration found. Either configure "java.security.krb5.conf" property or combination of "java.security.krb5.realm" and "java.security.krb5.kdc" properties.
+TEIID20029={0} value outside of 32-bit value range. Please set the system property org.teiid.longDatesTimes to true to avoid this error.
\ No newline at end of file
Modified: trunk/client/src/test/java/org/teiid/client/TestBatchSerializer.java
===================================================================
--- trunk/client/src/test/java/org/teiid/client/TestBatchSerializer.java 2012-09-04 11:53:12 UTC (rev 4395)
+++ trunk/client/src/test/java/org/teiid/client/TestBatchSerializer.java 2012-09-04 12:26:59 UTC (rev 4396)
@@ -38,6 +38,7 @@
import org.teiid.core.types.BinaryType;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.TimestampWithTimezone;
+import org.teiid.query.unittest.TimestampUtil;
/**
@@ -45,11 +46,12 @@
*/
public class TestBatchSerializer {
- private static void helpTestSerialization(String[] types, List<?>[] batch) throws IOException, ClassNotFoundException {
+ private static void helpTestSerialization(String[] types, List<?>[] batch, byte version) throws IOException, ClassNotFoundException {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteStream);
List<List<?>> batchList = Arrays.asList(batch);
- BatchSerializer.writeBatch(out, types, batchList);
+
+ BatchSerializer.writeBatch(out, types, batchList, version);
out.flush();
byte[] bytes = byteStream.toByteArray();
@@ -119,28 +121,33 @@
@Test public void testSerializeBasicTypes() throws Exception {
// The number 8 is important here because boolean isNull information is packed into bytes,
// so we want to make sure the boundary cases are handled correctly
- helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(1)); // Less than 8 rows
- helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(8)); // Exactly 8 rows
- helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(17)); // More than 8 rows, but not a multiple of 8
- helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(120)); // A multiple of 8 rows
- helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(833)); // A bunch of rows. This should also test large strings
- helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(4096)); // A bunch of rows. This should also test large strings
+ helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(1), BatchSerializer.CURRENT_VERSION); // Less than 8 rows
+ helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(8), BatchSerializer.CURRENT_VERSION); // Exactly 8 rows
+ helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(17), BatchSerializer.CURRENT_VERSION); // More than 8 rows, but not a multiple of 8
+ helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(120), BatchSerializer.CURRENT_VERSION); // A multiple of 8 rows
+ helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(833), BatchSerializer.CURRENT_VERSION); // A bunch of rows. This should also test large strings
+ helpTestSerialization(sampleBatchTypes, sampleBatchWithNulls(4096), BatchSerializer.CURRENT_VERSION); // A bunch of rows. This should also test large strings
}
@Test public void testSerializeLargeStrings() throws Exception {
List<?> row = Arrays.asList(new Object[] {sampleString(66666)});
- helpTestSerialization(new String[] {DataTypeManager.DefaultDataTypes.STRING}, new List[] {row});
+ helpTestSerialization(new String[] {DataTypeManager.DefaultDataTypes.STRING}, new List[] {row}, BatchSerializer.CURRENT_VERSION);
}
@Test public void testSerializeNoData() throws Exception {
- helpTestSerialization(sampleBatchTypes, new List[0]);
+ helpTestSerialization(sampleBatchTypes, new List[0], BatchSerializer.CURRENT_VERSION);
}
@Test public void testSerializeDatatypeMismatch() throws Exception {
try {
- helpTestSerialization(new String[] {DataTypeManager.DefaultDataTypes.DOUBLE}, new List[] {Arrays.asList(new Object[] {"Hello!"})}); //$NON-NLS-1$
+ helpTestSerialization(new String[] {DataTypeManager.DefaultDataTypes.DOUBLE}, new List[] {Arrays.asList(new Object[] {"Hello!"})}, BatchSerializer.CURRENT_VERSION); //$NON-NLS-1$
} catch (RuntimeException e) {
assertEquals("TEIID20001 The modeled datatype double for column 0 doesn't match the runtime type \"java.lang.String\". Please ensure that the column's modeled datatype matches the expected data.", e.getMessage()); //$NON-NLS-1$
}
}
+
+ @Test(expected=IOException.class) public void testOutOfRangeDate() throws Exception {
+ helpTestSerialization(new String[] {DataTypeManager.DefaultDataTypes.DATE}, new List[] {Arrays.asList(TimestampUtil.createDate(-2, 0, 1))}, (byte)1);
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2012-09-04 11:53:12 UTC (rev 4395)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2012-09-04 12:26:59 UTC (rev 4396)
@@ -42,6 +42,7 @@
import org.teiid.adminapi.impl.SessionMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.client.security.SessionToken;
+import org.teiid.core.util.PropertiesUtils;
import org.teiid.dqp.message.RequestID;
import org.teiid.security.SecurityHelper;
@@ -50,14 +51,13 @@
private static final long serialVersionUID = -6389893410233192977L;
+ private static final boolean longDatesTimes = PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.longDatesTimes", false); //$NON-NLS-1$
+
public enum Version {
SEVEN_1("7.1", (byte)0), //$NON-NLS-1$
- SEVEN_2("7.2", (byte)0), //$NON-NLS-1$
SEVEN_3("7.3", (byte)0), //$NON-NLS-1$
SEVEN_4("7.4", (byte)0), //$NON-NLS-1$
- SEVEN_5("7.5", (byte)0), //$NON-NLS-1$
- SEVEN_6("7.6", (byte)0), //$NON-NLS-1$
- EIGHT_0("8.0", (byte)1), //$NON-NLS-1$
+ EIGHT_0("8.0", (byte)(longDatesTimes?0:1)), //$NON-NLS-1$
EIGHT_2("8.2", (byte)2); //$NON-NLS-1$
private String string;
12 years, 3 months
teiid SVN: r4395 - in trunk/api/src/main: java/org/teiid/metadata and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-04 07:53:12 -0400 (Tue, 04 Sep 2012)
New Revision: 4395
Modified:
trunk/api/src/main/java/org/teiid/connector/DataPlugin.java
trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
trunk/api/src/main/resources/org/teiid/connector/i18n.properties
Log:
TEIID-2183 fixing duplicate column message
Modified: trunk/api/src/main/java/org/teiid/connector/DataPlugin.java
===================================================================
--- trunk/api/src/main/java/org/teiid/connector/DataPlugin.java 2012-09-03 11:25:19 UTC (rev 4394)
+++ trunk/api/src/main/java/org/teiid/connector/DataPlugin.java 2012-09-04 11:53:12 UTC (rev 4395)
@@ -45,6 +45,7 @@
TEIID60012,
TEIID60013,
TEIID60014,
- TEIID60015
+ TEIID60015,
+ TEIID60016
}
}
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-09-03 11:25:19 UTC (rev 4394)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-09-04 11:53:12 UTC (rev 4395)
@@ -144,7 +144,7 @@
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));
+ throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60016, table.getFullName() + AbstractMetadataRecord.NAME_DELIM_CHAR + name));
}
Column column = new Column();
column.setName(name);
Modified: trunk/api/src/main/resources/org/teiid/connector/i18n.properties
===================================================================
--- trunk/api/src/main/resources/org/teiid/connector/i18n.properties 2012-09-03 11:25:19 UTC (rev 4394)
+++ trunk/api/src/main/resources/org/teiid/connector/i18n.properties 2012-09-04 11:53:12 UTC (rev 4395)
@@ -25,8 +25,8 @@
TEIID60013=Duplicate Table {0}
TEIID60014=Duplicate Procedure {0}
TEIID60015=Duplicate Function {0}
+TEIID60016=Duplicate Column {0}
-
TEIID60009=Unknown datatype {0}
TEIID60011=No column found with name {0}
TEIID60008=Invalid column name ''{0}'', cannot contain the . character.
12 years, 3 months
teiid SVN: r4394 - in trunk: client/src/test/java/org/teiid/jdbc and 8 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-03 07:25:19 -0400 (Mon, 03 Sep 2012)
New Revision: 4394
Modified:
trunk/client/src/main/java/org/teiid/client/BatchSerializer.java
trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java
trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java
trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java
trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestArray.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/Element.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java
Log:
TEIID-247 adding better array serialization
Modified: trunk/client/src/main/java/org/teiid/client/BatchSerializer.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/BatchSerializer.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/client/src/main/java/org/teiid/client/BatchSerializer.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -29,6 +29,8 @@
import java.io.ObjectStreamConstants;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.sql.Array;
+import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
@@ -40,6 +42,7 @@
import java.util.TimeZone;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.BinaryType;
import org.teiid.core.types.BlobType;
import org.teiid.core.types.ClobType;
@@ -54,43 +57,117 @@
*/
public class BatchSerializer {
- private BatchSerializer() {} // Uninstantiable
+ private static final byte CURRENT_VERSION = (byte)2;
+
+ private BatchSerializer() {} // Uninstantiable
private static ColumnSerializer defaultSerializer = new ColumnSerializer();
- private static final Map<String, ColumnSerializer> serializers = new HashMap<String, ColumnSerializer>(128);
+ private static final Map<String, ColumnSerializer[]> serializers = new HashMap<String, ColumnSerializer[]>(128);
static {
- serializers.put(DataTypeManager.DefaultDataTypes.BIG_DECIMAL, new BigDecimalColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.BIG_INTEGER, new BigIntegerColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.BOOLEAN, new BooleanColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.BYTE, new ByteColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.CHAR, new CharColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.DATE, new DateColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.DOUBLE, new DoubleColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.FLOAT, new FloatColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.INTEGER, new IntColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.LONG, new LongColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.SHORT, new ShortColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.TIME, new TimeColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.TIMESTAMP, new TimestampColumnSerializer());
- serializers.put(DataTypeManager.DefaultDataTypes.VARBINARY, new BinaryColumnSerializer());
+ serializers.put(DataTypeManager.DefaultDataTypes.BIG_DECIMAL, new ColumnSerializer[] {new BigDecimalColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.BIG_INTEGER, new ColumnSerializer[] {new BigIntegerColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.BOOLEAN, new ColumnSerializer[] {new BooleanColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.BYTE, new ColumnSerializer[] {new ByteColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.CHAR, new ColumnSerializer[] {new CharColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.DATE, new ColumnSerializer[] {new DateColumnSerializer(), new DateColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.DOUBLE, new ColumnSerializer[] {new DoubleColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.FLOAT, new ColumnSerializer[] {new FloatColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.INTEGER, new ColumnSerializer[] {new IntColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.LONG, new ColumnSerializer[] {new LongColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.SHORT, new ColumnSerializer[] {new ShortColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.TIME, new ColumnSerializer[] {new TimeColumnSerializer(), new TimeColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.TIMESTAMP, new ColumnSerializer[] {new TimestampColumnSerializer()});
+ serializers.put(DataTypeManager.DefaultDataTypes.STRING, new ColumnSerializer[] {defaultSerializer, new StringColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.CLOB, new ColumnSerializer[] {defaultSerializer, new ClobColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.BLOB, new ColumnSerializer[] {defaultSerializer, new BlobColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.XML, new ColumnSerializer[] {defaultSerializer, new XmlColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.NULL, new ColumnSerializer[] {defaultSerializer, new NullColumnSerializer1()});
+ serializers.put(DataTypeManager.DefaultDataTypes.OBJECT, new ColumnSerializer[] {defaultSerializer, new ObjectColumnSerializer(DataTypeManager.DefaultTypeCodes.VARBINARY, (byte)1)});
+ serializers.put(DataTypeManager.DefaultDataTypes.VARBINARY, new ColumnSerializer[] {new BinaryColumnSerializer(), new BinaryColumnSerializer1()});
}
- private static final Map<String, ColumnSerializer> version1serializers = new HashMap<String, ColumnSerializer>(128);
- static {
- version1serializers.put(DataTypeManager.DefaultDataTypes.DATE, new DateColumnSerializer1());
- version1serializers.put(DataTypeManager.DefaultDataTypes.TIME, new TimeColumnSerializer1());
- version1serializers.put(DataTypeManager.DefaultDataTypes.STRING, new StringColumnSerializer1());
- version1serializers.put(DataTypeManager.DefaultDataTypes.CLOB, new ClobColumnSerializer1());
- version1serializers.put(DataTypeManager.DefaultDataTypes.BLOB, new BlobColumnSerializer1());
- version1serializers.put(DataTypeManager.DefaultDataTypes.XML, new XmlColumnSerializer1());
- version1serializers.put(DataTypeManager.DefaultDataTypes.NULL, new NullColumnSerializer1());
- version1serializers.put(DataTypeManager.DefaultDataTypes.OBJECT, new ObjectColumnSerializer1(DataTypeManager.DefaultTypeCodes.VARBINARY));
- version1serializers.put(DataTypeManager.DefaultDataTypes.VARBINARY, new BinaryColumnSerializer1());
- }
+ private static ColumnSerializer arrayColumnSerializer = new ColumnSerializer() {
+
+ @Override
+ protected void writeObject(ObjectOutput out, Object obj)
+ throws IOException {
+ try {
+ super.writeObject(out, ((java.sql.Array)obj).getArray());
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ protected Object readObject(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ return new ArrayImpl((Object[]) in.readObject());
+ }
+
+ };
- static class BinaryColumnSerializer1 extends ColumnSerializer {
+ private static final ColumnSerializer arrayColumnSerialier2 = new ArrayColumnSerializer2(new ObjectColumnSerializer(DataTypeManager.DefaultTypeCodes.VARBINARY, (byte)2));
+
+ private static final class ArrayColumnSerializer2 extends ColumnSerializer {
+
+ ObjectColumnSerializer ser;
+
+ public ArrayColumnSerializer2(ObjectColumnSerializer ser) {
+ this.ser = ser;
+ }
+
@Override
+ protected void writeObject(ObjectOutput out, Object obj)
+ throws IOException {
+ Object[] values = null;
+ try {
+ values = (Object[]) ((Array)obj).getArray();
+ } catch (SQLException e) {
+ out.writeInt(-1);
+ return;
+ }
+ out.writeInt(values.length);
+ int code = DataTypeManager.getTypeCode(values.getClass().getComponentType());
+ out.writeByte((byte)code);
+ for (int i = 0; i < values.length;) {
+ writeIsNullData(out, i, values);
+ int end = Math.min(values.length, i+8);
+ for (; i < end; i++) {
+ if (values[i] != null) {
+ ser.writeObject(out, values[i], code);
+ }
+ }
+ }
+ out.writeBoolean((obj instanceof ArrayImpl && ((ArrayImpl)obj).isZeroBased()));
+ }
+
+ @Override
+ protected Object readObject(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ int length = in.readInt();
+ if (length == -1) {
+ return new ArrayImpl(null);
+ }
+ int code = in.readByte();
+ Object[] vals = (Object[])java.lang.reflect.Array.newInstance(DataTypeManager.getClass(code), length);
+ for (int i = 0; i < length;) {
+ byte b = in.readByte();
+ int end = Math.min(length, i+8);
+ for (; i < end; i++) {
+ if (!isNullObject(i, b)) {
+ vals[i] = ser.readObject(in, code);
+ }
+ }
+ }
+ ArrayImpl result = new ArrayImpl(vals);
+ result.setZeroBased(in.readBoolean());
+ return result;
+ }
+ }
+
+ static class BinaryColumnSerializer1 extends ColumnSerializer {
+ @Override
protected void writeObject(ObjectOutput out, Object obj)
throws IOException {
byte[] bytes = ((BinaryType)obj).getBytes();
@@ -125,12 +202,14 @@
}
}
- public static final class ObjectColumnSerializer1 extends ColumnSerializer {
+ public static final class ObjectColumnSerializer extends ColumnSerializer {
int highestKnownCode;
+ byte version;
- public ObjectColumnSerializer1(int highestKnownCode) {
+ public ObjectColumnSerializer(int highestKnownCode, byte version) {
this.highestKnownCode = highestKnownCode;
+ this.version = version;
}
@Override
@@ -138,14 +217,19 @@
throws IOException {
int code = DataTypeManager.getTypeCode(obj.getClass());
out.writeByte((byte)code);
- if (code == DataTypeManager.DefaultTypeCodes.BOOLEAN) {
+ writeObject(out, obj, code);
+ }
+
+ protected void writeObject(ObjectOutput out, Object obj, int code)
+ throws IOException {
+ if (code == DataTypeManager.DefaultTypeCodes.BOOLEAN) {
if (Boolean.TRUE.equals(obj)) {
out.write((byte)1);
} else {
out.write((byte)0);
}
} else if (code <= highestKnownCode && code != DataTypeManager.DefaultTypeCodes.OBJECT) {
- ColumnSerializer s = getSerializer(DataTypeManager.getDataTypeName(obj.getClass()), (byte)1);
+ ColumnSerializer s = getSerializer(DataTypeManager.getDataTypeName(obj.getClass()), version);
s.writeObject(out, obj);
} else {
super.writeObject(out, obj);
@@ -156,14 +240,19 @@
protected Object readObject(ObjectInput in) throws IOException,
ClassNotFoundException {
int code = in.readByte();
- if (code == DataTypeManager.DefaultTypeCodes.BOOLEAN) {
+ return readObject(in, code);
+ }
+
+ private Object readObject(ObjectInput in, int code) throws IOException,
+ ClassNotFoundException {
+ if (code == DataTypeManager.DefaultTypeCodes.BOOLEAN) {
if (in.readByte() == (byte)0) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
if (code != DataTypeManager.DefaultTypeCodes.OBJECT) {
- ColumnSerializer s = getSerializer(DataTypeManager.getDataTypeName(DataTypeManager.getClass(code)), (byte)1);
+ ColumnSerializer s = getSerializer(DataTypeManager.getDataTypeName(DataTypeManager.getClass(code)), version);
return s.readObject(in);
}
return super.readObject(in);
@@ -234,11 +323,11 @@
private static class XmlColumnSerializer1 extends ColumnSerializer {
protected void writeObject(ObjectOutput out, Object obj) throws IOException {
- ((XMLType)obj).writeExternal(out, (byte)1);
+ ((XMLType)obj).writeExternal(out, CURRENT_VERSION);
}
protected Object readObject(ObjectInput in) throws IOException, ClassNotFoundException {
XMLType xt = new XMLType();
- xt.readExternal(in, (byte)1);
+ xt.readExternal(in, CURRENT_VERSION);
return xt;
}
}
@@ -273,6 +362,15 @@
out.write(currentByte);
}
}
+
+ static void writeIsNullData(ObjectOutput out, int offset, Object[] batch) throws IOException {
+ int currentByte = 0;
+ for (int mask = 0x80; offset < batch.length; offset++, mask >>= 1) {
+ if (batch[offset] == null) currentByte |= mask;
+ }
+ out.write(currentByte);
+ }
+
/**
* Reads the isNull data into a byte array
* @param in
@@ -293,10 +391,14 @@
* @return
* @since 4.2
*/
- static boolean isNullObject(byte[] isNull, int row) {
+ static final boolean isNullObject(byte[] isNull, int row) {
// byte number mask bits to shift mask
return (isNull [ row / 8 ] & (0x01 << (7 - (row % 8)))) != 0;
}
+
+ private static final boolean isNullObject(int row, byte b) {
+ return (b & (0x01 << (7 - (row % 8)))) != 0;
+ }
/**
* An abstract serializer for native types
@@ -556,21 +658,22 @@
}
private static ColumnSerializer getSerializer(String type, byte version) {
- ColumnSerializer cs = null;
- if (version == 1) {
- cs = version1serializers.get((type == null) ? DataTypeManager.DefaultDataTypes.OBJECT : type);
+ ColumnSerializer[] sers = serializers.get(type);
+ if (sers == null) {
+ if (DataTypeManager.isArrayType(type)) {
+ if (version < 2) {
+ return arrayColumnSerializer;
+ }
+ //TODO: make this scalable with version
+ return arrayColumnSerialier2;
+ }
+ return defaultSerializer;
}
- if (cs == null) {
- cs = serializers.get((type == null) ? DataTypeManager.DefaultDataTypes.OBJECT : type);
- }
- if (cs == null) {
- return defaultSerializer;
- }
- return cs;
+ return sers[Math.min(version, sers.length - 1)];
}
public static void writeBatch(ObjectOutput out, String[] types, List<? extends List<?>> batch) throws IOException {
- writeBatch(out, types, batch, (byte)1);
+ writeBatch(out, types, batch, CURRENT_VERSION);
}
public static void writeBatch(ObjectOutput out, String[] types, List<? extends List<?>> batch, byte version) throws IOException {
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -154,11 +154,9 @@
@Test public void testCreateThrowable3() {
TeiidSQLException e = testCreateThrowable(
new TeiidException(
- new TeiidRuntimeException(
new SocketTimeoutException(
"A test MM Invalid Session Exception"), //$NON-NLS-1$
"Test MetaMatrixRuntimeException with a InvalidSessionException in it"), //$NON-NLS-1$
- "Test MM Core Exception with an MM Runtime Exception in it and an InvalidSessionException nested within"), //$NON-NLS-1$
SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
//test to ensure that wrapping mmsqlexceptions works
Modified: trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -65,7 +65,7 @@
super(message);
}
- public TeiidRuntimeException(final String code, final String message) {
+ TeiidRuntimeException(final String code, final String message) {
super(message);
// The following setCode call should be executed after setting the message
setCode(code);
@@ -83,37 +83,15 @@
setCode(code.toString());
}
- public TeiidRuntimeException(BundleUtil.Event code) {
- super();
- setCode(code.toString());
- }
-
- public TeiidRuntimeException(final String[] message) {
- super(message[1]);
- // The following setCode call should be executed after setting the message
- setCode(message[0]);
- }
-
/**
* Construct an instance with a linked exception specified. If the exception is a {@link TeiidException} or a
- * MetaMatrixRuntimeException, then the code will be set to the exception's code.
+ * TeoodRuntimeException, then the code will be set to the exception's code.
* @param e An exception to chain to this exception
*/
public TeiidRuntimeException(final Throwable e) {
- this(e, ( e instanceof java.lang.reflect.InvocationTargetException )
- ? ((java.lang.reflect.InvocationTargetException)e).getTargetException().getMessage()
- : (e == null ? null : e.getMessage()));
- }
-
- /**
- * Construct an instance with the linked exception and error message specified. If the message is actually a key, the error
- * message will be retrieved from a resource bundle the key, and code will be set to that key. Otherwise, if the specified
- * exception is a {@link TeiidException} or a MetaMatrixRuntimeException, the code will be set to the exception's code.
- * @param e The exception to chain to this exception
- * @param message The error message or a resource bundle key
- */
- public TeiidRuntimeException(final Throwable e, final String message) {
- super(message, e);
+ super(( e instanceof java.lang.reflect.InvocationTargetException )
+ ? ((java.lang.reflect.InvocationTargetException)e).getTargetException().getMessage()
+ : (e == null ? null : e.getMessage()), e);
setCode(TeiidException.getCode(e));
}
Modified: trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/common-core/src/main/java/org/teiid/core/types/ArrayImpl.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -22,7 +22,10 @@
package org.teiid.core.types;
-import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -32,12 +35,14 @@
import java.util.Map;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.ExternalizeUtil;
import org.teiid.core.util.HashCodeUtil;
/**
* Provides a serializable {@link Array} implementation with minimal JDBC functionality.
*/
-public final class ArrayImpl implements Comparable<ArrayImpl>, Serializable, Array {
+public final class ArrayImpl implements Comparable<ArrayImpl>, Externalizable, Array {
+ private static final String INVALID = ""; //$NON-NLS-1$
private static final long serialVersionUID = 517794153664734815L;
/**
* a regrettable hack for pg compatibility since we want to avoid adding a vector type
@@ -53,6 +58,16 @@
this.values = values;
}
+ public ArrayImpl() {
+
+ }
+
+ private void checkValues() throws SQLException {
+ if (values == null) {
+ throw new SQLException("Already freed or invalid"); //$NON-NLS-1$
+ }
+ }
+
@Override
public int compareTo(ArrayImpl o) {
return compareTo(o, false, null);
@@ -62,6 +77,12 @@
if (zeroBased != o.zeroBased) {
throw new TeiidRuntimeException("Incompatible types"); //$NON-NLS-1$
}
+ try {
+ checkValues();
+ o.checkValues();
+ } catch (SQLException e) {
+ throw new TeiidRuntimeException(e);
+ }
int len1 = values.length;
int len2 = o.values.length;
int lim = Math.min(len1, len2);
@@ -113,6 +134,9 @@
}
public Object[] getValues() {
+ if (values == null) {
+ throw new TeiidRuntimeException("Already freed or invalid"); //$NON-NLS-1$
+ }
return values;
}
@@ -131,11 +155,12 @@
@Override
public void free() throws SQLException {
-
+ this.values = null;
}
@Override
public Object getArray() throws SQLException {
+ checkValues();
return values;
}
@@ -154,6 +179,7 @@
if (iIndex >= values.length || iIndex < 0) {
throw new ArrayIndexOutOfBoundsException(iIndex);
}
+ checkValues();
return Arrays.copyOfRange(values, iIndex, Math.min(iIndex + count, values.length));
}
@@ -165,11 +191,13 @@
@Override
public int getBaseType() throws SQLException {
+ checkValues();
return JDBCSQLTypeInfo.getSQLType(DataTypeManager.getDataTypeName(values.getClass().getComponentType()));
}
@Override
public String getBaseTypeName() throws SQLException {
+ checkValues();
return DataTypeManager.getDataTypeName(values.getClass().getComponentType());
}
@@ -195,4 +223,26 @@
throw new SQLFeatureNotSupportedException();
}
+ @Override
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ String componentType = in.readUTF();
+ if (INVALID.equalsIgnoreCase(componentType)) {
+ return;
+ }
+ ExternalizeUtil.readArray(in, DataTypeManager.getDataTypeClass(componentType));
+ zeroBased = in.readBoolean();
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ if (values == null) {
+ out.writeUTF(INVALID);
+ return;
+ }
+ out.writeUTF(DataTypeManager.getDataTypeName(this.values.getClass().getComponentType()));
+ ExternalizeUtil.writeArray(out, values);
+ out.writeBoolean(zeroBased);
+ }
+
}
Modified: trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -84,15 +84,6 @@
}
- public void testMetaMatrixRuntimeExceptionWithExceptionAndMessage() {
- final String code = "1234"; //$NON-NLS-1$
- final TeiidRuntimeException child = new TeiidRuntimeException(code, "Child"); //$NON-NLS-1$
- final TeiidRuntimeException err = new TeiidRuntimeException(child, "Test"); //$NON-NLS-1$
- assertSame(child, err.getCause());
- assertEquals(code, err.getCode());
- assertEquals("1234 Test", err.getMessage()); //$NON-NLS-1$
-
- }
public static enum Event implements BundleUtil.Event {
Code,
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -57,7 +57,8 @@
SEVEN_4("7.4", (byte)0), //$NON-NLS-1$
SEVEN_5("7.5", (byte)0), //$NON-NLS-1$
SEVEN_6("7.6", (byte)0), //$NON-NLS-1$
- EIGHT_0("8.0", (byte)1); //$NON-NLS-1$
+ EIGHT_0("8.0", (byte)1), //$NON-NLS-1$
+ EIGHT_2("8.2", (byte)2); //$NON-NLS-1$
private String string;
private byte clientSerializationVersion;
Modified: trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -245,7 +245,6 @@
TEIID30234,
TEIID30235,
TEIID30236,
- TEIID30237,
TEIID30238,
TEIID30239,
TEIID30240,
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -366,7 +366,7 @@
clone.activeReaders = new AtomicInteger();
return clone;
} catch (CloneNotSupportedException e) {
- throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30237);
+ throw new TeiidRuntimeException(e);
} finally {
lock.readLock().unlock();
}
Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestArray.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestArray.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestArray.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -28,8 +28,8 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.sql.SQLException;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import org.junit.Test;
@@ -69,17 +69,25 @@
assertNotSame(a1.getExpressions().get(0), array.getExpressions().get(0));
}
+ @SuppressWarnings("unchecked")
@Test public void testArrayValueSerialization() throws Exception {
- ArrayImpl a1 = new ArrayImpl(new Integer[] {1, 2, 3});
+ ArrayImpl a1 = new ArrayImpl(new Integer[] {1, null, 3});
+ ArrayImpl a2 = new ArrayImpl(null);
String[] types = TupleBuffer.getTypeNames(Arrays.asList(new Array(Integer.class, null)));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
- BatchSerializer.writeBatch(oos, types, Collections.singletonList(Arrays.asList((a1))));
+ BatchSerializer.writeBatch(oos, types, Arrays.asList(Arrays.asList(a1), Arrays.asList(a2)));
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
List<List<Object>> batch = BatchSerializer.readBatch(ois, types);
assertEquals(a1, batch.get(0).get(0));
+ try {
+ ((java.sql.Array)batch.get(1).get(0)).getArray();
+ fail();
+ } catch (SQLException e) {
+
+ }
}
@Test public void testZeroBasedArray() throws Exception {
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/Element.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/Element.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/Element.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -31,7 +31,6 @@
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
-import org.teiid.core.TeiidRuntimeException;
import org.teiid.net.socket.SocketUtil;
import org.teiid.transport.SSLConfiguration;
@@ -206,7 +205,7 @@
node.get(type, name, DEFAULT).set(this.defaultValue);
}
else {
- throw new TeiidRuntimeException(IntegrationPlugin.Event.TEIID50045);
+ throw new AssertionError(this.modelType);
}
}
}
@@ -230,7 +229,7 @@
model.get(getModelName()).set(operation.get(getModelName()).asBoolean());
}
else {
- throw new TeiidRuntimeException(IntegrationPlugin.Event.TEIID50046);
+ throw new AssertionError(this.modelType);
}
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/IntegrationPlugin.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -75,8 +75,6 @@
TEIID50042, // error state
TEIID50043,
TEIID50044, // vdb save failed
- TEIID50045,
- TEIID50046,
TEIID50047,
TEIID50048,
TEIID50049,
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java 2012-09-01 11:34:08 UTC (rev 4393)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java 2012-09-03 11:25:19 UTC (rev 4394)
@@ -73,7 +73,7 @@
@Override
public boolean sameSubject(String securityDomain, Object context, Subject subject) {
if (context == null) {
- throw new TeiidRuntimeException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50090));
+ throw new TeiidRuntimeException(IntegrationPlugin.Event.TEIID50090, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50090));
}
SecurityContext previousContext = (SecurityContext)context;
Subject previousUser = previousContext.getSubjectInfo().getAuthenticatedSubject();
12 years, 3 months
teiid SVN: r4393 - trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-01 07:34:08 -0400 (Sat, 01 Sep 2012)
New Revision: 4393
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
Log:
TEIID-2180 limiting the scope of when a full single shot scan of columns is performed
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2012-09-01 11:27:36 UTC (rev 4392)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2012-09-01 11:34:08 UTC (rev 4393)
@@ -263,7 +263,7 @@
if ((excludeTables == null && schemaPattern == null && tableNamePattern == null) //getting everything
|| (singleSchema && tableNamePattern == null &&
(excludeTables == null //getting all from a single schema
- || tableMap.size() > Math.sqrt(tableMap.size() + excludedTables)))) { //not excluding enough from a single schema
+ || tableMap.size()/2 > Math.sqrt(tableMap.size()/2 + excludedTables)))) { //not excluding enough from a single schema
ResultSet columns = metadata.getColumns(catalog, schemaPattern, tableNamePattern, null);
processColumns(metadataFactory, tableMap, columns);
} else {
12 years, 4 months
teiid SVN: r4392 - trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-09-01 07:27:36 -0400 (Sat, 01 Sep 2012)
New Revision: 4392
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
Log:
TEIID-2180 limiting the scope of when a full single shot scan of columns is performed
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2012-09-01 02:29:04 UTC (rev 4391)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2012-09-01 11:27:36 UTC (rev 4392)
@@ -100,6 +100,8 @@
private Pattern excludeTables;
private Pattern excludeProcedures;
+ private int excludedTables;
+
public void getConnectorMetadata(Connection conn, MetadataFactory metadataFactory)
throws SQLException, TranslatorException {
DatabaseMetaData metadata = conn.getMetaData();
@@ -235,6 +237,7 @@
String tableName = tables.getString(3);
String fullName = getFullyQualifiedName(tableCatalog, tableSchema, tableName);
if (excludeTables != null && excludeTables.matcher(fullName).matches()) {
+ excludedTables++;
continue;
}
Table table = metadataFactory.addTable(useFullSchemaName?fullName:tableName);
@@ -256,7 +259,24 @@
DatabaseMetaData metadata, Map<String, TableInfo> tableMap)
throws SQLException, TranslatorException {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "JDBCMetadataProcessor - Importing columns"); //$NON-NLS-1$
- ResultSet columns = metadata.getColumns(catalog, schemaPattern, tableNamePattern, null);
+ boolean singleSchema = schemaPattern != null && !schemaPattern.contains("_") && !schemaPattern.contains("%"); //$NON-NLS-1$ //$NON-NLS-2$
+ if ((excludeTables == null && schemaPattern == null && tableNamePattern == null) //getting everything
+ || (singleSchema && tableNamePattern == null &&
+ (excludeTables == null //getting all from a single schema
+ || tableMap.size() > Math.sqrt(tableMap.size() + excludedTables)))) { //not excluding enough from a single schema
+ ResultSet columns = metadata.getColumns(catalog, schemaPattern, tableNamePattern, null);
+ processColumns(metadataFactory, tableMap, columns);
+ } else {
+ for (TableInfo ti : new LinkedHashSet<TableInfo>(tableMap.values())) {
+ ResultSet columns = metadata.getColumns(catalog, ti.schema, ti.name, null);
+ processColumns(metadataFactory, tableMap, columns);
+ }
+ }
+ }
+
+ private void processColumns(MetadataFactory metadataFactory,
+ Map<String, TableInfo> tableMap, ResultSet columns)
+ throws SQLException, TranslatorException {
int rsColumns = columns.getMetaData().getColumnCount();
while (columns.next()) {
String tableCatalog = columns.getString(1);
12 years, 4 months