Author: shawkins
Date: 2011-03-24 00:31:11 -0400 (Thu, 24 Mar 2011)
New Revision: 3032
Added:
trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java
Modified:
trunk/api/src/main/java/org/teiid/metadata/Schema.java
trunk/api/src/main/resources/org/teiid/connector/i18n.properties
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
trunk/connectors/translator-jdbc/src/main/resources/org/teiid/translator/jdbc/i18n.properties
trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDymamicImportedMetaData.java
Log:
TEIID-1490 adding better handling of a duplicate name failure at import time
Added: trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java
(rev 0)
+++ trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java 2011-03-24
04:31:11 UTC (rev 3032)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.metadata;
+
+public class DuplicateRecordException extends AssertionError {
+
+ private static final long serialVersionUID = -1319489333975416115L;
+
+ public DuplicateRecordException(String msg) {
+ super(msg);
+ }
+
+}
Property changes on:
trunk/api/src/main/java/org/teiid/metadata/DuplicateRecordException.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/api/src/main/java/org/teiid/metadata/Schema.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/Schema.java 2011-03-24 03:37:10 UTC (rev
3031)
+++ trunk/api/src/main/java/org/teiid/metadata/Schema.java 2011-03-24 04:31:11 UTC (rev
3032)
@@ -25,6 +25,8 @@
import java.util.LinkedHashMap;
import java.util.Map;
+import org.teiid.connector.DataPlugin;
+
public class Schema extends AbstractMetadataRecord {
private static final long serialVersionUID = -5113742472848113008L;
@@ -40,21 +42,21 @@
public void addTable(Table table) {
table.setParent(this);
if (this.tables.put(table.getCanonicalName(), table) != null) {
- throw new AssertionError("Duplicate Table " + table.getName());
//$NON-NLS-1$
+ throw new
DuplicateRecordException(DataPlugin.Util.getString("Schema.duplicate_table",
table.getName())); //$NON-NLS-1$
}
}
public void addProcedure(Procedure procedure) {
procedure.setParent(this);
if (this.procedures.put(procedure.getCanonicalName(), procedure) != null) {
- throw new AssertionError("Duplicate Procedure " + procedure.getName());
//$NON-NLS-1$
+ throw new
DuplicateRecordException(DataPlugin.Util.getString("Schema.duplicate_procedure",
procedure.getName())); //$NON-NLS-1$
}
}
public void addFunction(FunctionMethod function) {
function.setParent(this);
if (this.functions.put(function.getCanonicalName(), function) != null) {
- throw new AssertionError("Duplicate function " + function.getName());
//$NON-NLS-1$
+ throw new
DuplicateRecordException(DataPlugin.Util.getString("Schema.duplicate_function",
function.getName())); //$NON-NLS-1$
}
}
Modified: trunk/api/src/main/resources/org/teiid/connector/i18n.properties
===================================================================
--- trunk/api/src/main/resources/org/teiid/connector/i18n.properties 2011-03-24 03:37:10
UTC (rev 3031)
+++ trunk/api/src/main/resources/org/teiid/connector/i18n.properties 2011-03-24 04:31:11
UTC (rev 3032)
@@ -32,3 +32,6 @@
MetadataFactory.no_column_found=No column found with name {0}
MetadataFactory.invalid_name=Invalid column name ''{0}'', cannot contain
the . character.
+Schema.duplicate_table=Duplicate table {0}
+Schema.duplicate_procedure=Duplicate procedure {0}
+Schema.duplicate_function=Duplicate function {0}
\ No newline at end of file
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 2011-03-24
03:37:10 UTC (rev 3031)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2011-03-24
04:31:11 UTC (rev 3032)
@@ -39,6 +39,7 @@
import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.BaseColumn;
import org.teiid.metadata.Column;
+import org.teiid.metadata.DuplicateRecordException;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.Procedure;
import org.teiid.metadata.Table;
@@ -108,22 +109,26 @@
}
}
- Map<String, TableInfo> tableMap = getTables(metadataFactory, metadata);
-
- if (importKeys) {
- getPrimaryKeys(metadataFactory, metadata, tableMap);
+ try {
+ Map<String, TableInfo> tableMap = getTables(metadataFactory, metadata);
- getForeignKeys(metadataFactory, metadata, tableMap);
+ if (importKeys) {
+ getPrimaryKeys(metadataFactory, metadata, tableMap);
+
+ getForeignKeys(metadataFactory, metadata, tableMap);
+ }
+
+ if (importIndexes) {
+ getIndexes(metadataFactory, metadata, tableMap);
+ }
+
+ if (importProcedures) {
+ getProcedures(metadataFactory, metadata);
+ }
+ } catch (DuplicateRecordException e) {
+ throw new TranslatorException(e,
JDBCPlugin.Util.getString("JDBCMetadataProcessor.not_unique")); //$NON-NLS-1$
}
- if (importIndexes) {
- getIndexes(metadataFactory, metadata, tableMap);
- }
-
- if (importProcedures) {
- getProcedures(metadataFactory, metadata);
- }
-
}
private void getProcedures(MetadataFactory metadataFactory,
Modified:
trunk/connectors/translator-jdbc/src/main/resources/org/teiid/translator/jdbc/i18n.properties
===================================================================
---
trunk/connectors/translator-jdbc/src/main/resources/org/teiid/translator/jdbc/i18n.properties 2011-03-24
03:37:10 UTC (rev 3031)
+++
trunk/connectors/translator-jdbc/src/main/resources/org/teiid/translator/jdbc/i18n.properties 2011-03-24
04:31:11 UTC (rev 3032)
@@ -29,3 +29,4 @@
ConnectionListener.failed_to_report_jdbc_connection_details=Failed to report the JDBC
driver and connection information
+JDBCMetadataProcessor.not_unique=Teiid runtime names, which are case insensitive, for the
imported metadata are not unique. If not already set, use the setting
importer.useFullSchemaName to create Teiid names that include the source schema.
\ No newline at end of file
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2011-03-24
03:37:10 UTC (rev 3031)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2011-03-24
04:31:11 UTC (rev 3032)
@@ -22,6 +22,7 @@
package org.teiid.jdbc;
import java.io.File;
+import java.util.LinkedHashMap;
import java.util.Properties;
import org.jboss.deployers.spi.DeploymentException;
@@ -48,6 +49,7 @@
import org.teiid.metadata.index.IndexMetadataFactory;
import org.teiid.metadata.index.VDBMetadataFactory;
import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.SourceCapabilities;
import org.teiid.services.SessionServiceImpl;
@@ -100,8 +102,14 @@
IndexMetadataFactory imf = VDBMetadataFactory.loadMetadata(new
File(vdbPath).toURI().toURL());
MetadataStore metadata = imf.getMetadataStore(repo.getSystemStore().getDatatypes());
+ LinkedHashMap<String, Resource> entries = imf.getEntriesPlusVisibilities();
- VDBMetaData vdbMetaData = new VDBMetaData();
+ deployVDB(vdbName, metadata, entries);
+ }
+
+ public void deployVDB(String vdbName, MetadataStore metadata,
+ LinkedHashMap<String, Resource> entries) {
+ VDBMetaData vdbMetaData = new VDBMetaData();
vdbMetaData.setName(vdbName);
vdbMetaData.setStatus(VDB.Status.ACTIVE);
@@ -120,10 +128,10 @@
try {
MetadataStoreGroup stores = new MetadataStoreGroup();
stores.addStore(metadata);
- this.repo.addVDB(vdbMetaData, stores, imf.getEntriesPlusVisibilities(), null, cmr);
+ this.repo.addVDB(vdbMetaData, stores, entries, null, cmr);
} catch (DeploymentException e) {
throw new RuntimeException(e);
- }
+ }
}
public void removeVDB(String vdbName) {
Modified:
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDymamicImportedMetaData.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDymamicImportedMetaData.java 2011-03-24
03:37:10 UTC (rev 3031)
+++
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDymamicImportedMetaData.java 2011-03-24
04:31:11 UTC (rev 3032)
@@ -25,15 +25,19 @@
import static org.junit.Assert.*;
import java.sql.Connection;
+import java.util.LinkedHashMap;
import java.util.Properties;
-import org.junit.Before;
import org.junit.Test;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.deployers.VDBRepository;
import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Procedure;
+import org.teiid.metadata.Table;
import org.teiid.metadata.index.VDBMetadataFactory;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.jdbc.teiid.TeiidExecutionFactory;
@@ -43,32 +47,60 @@
@SuppressWarnings("nls")
public class TestDymamicImportedMetaData {
- Connection conn;
-
- ////////////////////Query Related Methods///////////////////////////
-
- @Before public void setUp() throws Exception {
- FakeServer server = new FakeServer();
- server.deployVDB("test", UnitTestUtil.getTestDataPath() +
"/TestCase3473/test.vdb");
- conn = server.createConnection("jdbc:teiid:test"); //$NON-NLS-1$
- }
-
- private MetadataFactory getMetadata(Properties importProperties)
+ private MetadataFactory getMetadata(Properties importProperties, Connection conn)
throws TranslatorException {
- VDBRepository vdbRepository = new VDBRepository();
- vdbRepository.setSystemStore(VDBMetadataFactory.getSystem());
+ MetadataFactory mf = createMetadataFactory("test", importProperties);
TeiidExecutionFactory tef = new TeiidExecutionFactory();
- MetadataFactory mf = new MetadataFactory("test",
vdbRepository.getBuiltinDatatypes(), importProperties);
tef.getMetadata(mf, conn);
return mf;
}
+
+ private MetadataFactory createMetadataFactory(String schema, Properties
importProperties) {
+ VDBRepository vdbRepository = new VDBRepository();
+ vdbRepository.setSystemStore(VDBMetadataFactory.getSystem());
+ return new MetadataFactory(schema, vdbRepository.getBuiltinDatatypes(),
importProperties);
+ }
@Test public void testProcImport() throws Exception {
+ FakeServer server = new FakeServer();
+ server.deployVDB("test", UnitTestUtil.getTestDataPath() +
"/TestCase3473/test.vdb");
+ Connection conn = server.createConnection("jdbc:teiid:test");
//$NON-NLS-1$
+
Properties importProperties = new Properties();
importProperties.setProperty("importer.importProcedures",
Boolean.TRUE.toString());
- MetadataFactory mf = getMetadata(importProperties);
+ MetadataFactory mf = getMetadata(importProperties, conn);
Procedure p =
mf.getMetadataStore().getSchemas().get("TEST").getProcedures().get("GETXMLSCHEMAS");
assertEquals(1, p.getResultSet().getColumns().size());
}
+
+ @Test public void testDuplicatException() throws Exception {
+ FakeServer server = new FakeServer();
+ MetadataFactory mf = createMetadataFactory("x", new Properties());
+ MetadataFactory mf1 = createMetadataFactory("y", new Properties());
+
+ Table dup = mf.addTable("dup");
+ Table dup1 = mf1.addTable("dup");
+
+ mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
+ mf1.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup1);
+
+ MetadataStore ms = mf.getMetadataStore();
+ ms.addSchema(mf1.getMetadataStore().getSchemas().values().iterator().next());
+
+ server.deployVDB("test", ms, new LinkedHashMap<String,
Resource>());
+ Connection conn = server.createConnection("jdbc:teiid:test");
//$NON-NLS-1$
+
+ Properties importProperties = new Properties();
+ try {
+ getMetadata(importProperties, conn);
+ } catch (TranslatorException e) {
+
+ }
+
+ importProperties.setProperty("importer.useFullSchemaName",
Boolean.TRUE.toString());
+ getMetadata(importProperties, conn);
+
assertNotNull(mf.getMetadataStore().getSchemas().get("X").getTables().get("DUP"));
+ }
+
}