Skip to content

Commit

Permalink
TEIID-3563 fixing capability initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jul 22, 2015
1 parent 23d1b49 commit c5e2f85
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Expand Up @@ -219,6 +219,19 @@ protected boolean usesDatabaseVersion() {
@Override
public void initCapabilities(Connection connection)
throws TranslatorException {
try {
DatabaseMetaData metadata = connection.getMetaData();
supportsGeneratedKeys = metadata.supportsGetGeneratedKeys();
if (this.version == null) {
String fullVersion = metadata.getDatabaseProductVersion();
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Setting the database version to", fullVersion); //$NON-NLS-1$
setDatabaseVersion(fullVersion);
}
} catch (SQLException e) {
if (this.version == null) {
throw new TranslatorException(e);
}
}
}

@Override
Expand Down Expand Up @@ -1169,7 +1182,6 @@ protected void afterInitialConnectionObtained(Connection connection) {
sb.append(";DriverName=").append(dbmd.getDriverName()); //$NON-NLS-1$
sb.append(";DriverVersion=").append(dbmd.getDriverVersion()); //$NON-NLS-1$
sb.append(";IsolationLevel=").append(dbmd.getDefaultTransactionIsolation()); //$NON-NLS-1$
supportsGeneratedKeys = dbmd.supportsGetGeneratedKeys();
LogManager.logInfo(LogConstants.CTX_CONNECTOR, sb.toString());
} catch (SQLException e) {
LogManager.logInfo(LogConstants.CTX_CONNECTOR, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11002));
Expand All @@ -1184,20 +1196,10 @@ protected void afterInitialConnectionObtained(Connection connection) {
*/
public void obtainedConnection(Connection connection) {
if (initialConnection.compareAndSet(true, false)) {
try {
DatabaseMetaData metadata = connection.getMetaData();
String fullVersion = metadata.getDatabaseProductVersion();
setDatabaseVersion(fullVersion);
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Setting the database version to", fullVersion); //$NON-NLS-1$
} catch (SQLException e) {
LogManager.logInfo(LogConstants.CTX_CONNECTOR, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11002));
}
afterInitialConnectionObtained(connection);
}
}



/**
* Create the {@link SQLConversionVisitor} that will perform translation. Typical custom
* JDBC connectors will not need to create custom conversion visitors, rather implementors
Expand Down
Expand Up @@ -133,9 +133,6 @@ public void start() throws TranslatorException {
registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CONCAT, new AliasModifier("||")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower")); //$NON-NLS-1$
if (getVersion().compareTo(NINE_0) <= 0) {
registerFunctionModifier(SourceSystemFunctions.LEFT, new LeftOrRightFunctionModifier(getLanguageFactory()));
}
registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr")); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper")); //$NON-NLS-1$

Expand Down Expand Up @@ -234,6 +231,9 @@ public List<?> translate(Function function) {
public void initCapabilities(Connection connection)
throws TranslatorException {
super.initCapabilities(connection);
if (getVersion().compareTo(NINE_0) <= 0) {
registerFunctionModifier(SourceSystemFunctions.LEFT, new LeftOrRightFunctionModifier(getLanguageFactory()));
}
if (this.postGisVersion.compareTo(Version.DEFAULT_VERSION) != 0) {
return;
}
Expand Down
Expand Up @@ -24,8 +24,11 @@

import static org.junit.Assert.*;

import java.sql.Connection;

import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.core.util.SimpleMock;
import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.jdbc.TranslationHelper;
Expand All @@ -41,6 +44,8 @@ public class TestPostgreSQLTranslator {
TRANSLATOR.setUseBindVariables(false);
TRANSLATOR.setDatabaseVersion(Version.DEFAULT_VERSION);
TRANSLATOR.start();
TRANSLATOR.setPostGisVersion("1.0");
TRANSLATOR.initCapabilities(SimpleMock.createSimpleMock(Connection.class));
}

public String getTestVDB() {
Expand All @@ -53,6 +58,10 @@ private String getTestBQTVDB() {

public void helpTestVisitor(String vdb, String input, String expectedOutput) throws TranslatorException {
TranslationHelper.helpTestVisitor(vdb, input, expectedOutput, TRANSLATOR);
}

@Test public void testStartWithoutVersion() throws TranslatorException {
new PostgreSQLExecutionFactory().start();
}

@Test public void testConversion1() throws Exception {
Expand Down

0 comments on commit c5e2f85

Please sign in to comment.