-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add adapter property to change table count limit #134
base: main
Are you sure you want to change the base?
Conversation
…-virtual-schema can access them
- add tests for new table limit
- new methods JDBCAdapter::validateProperties and ::validateAdapterProperties - added parameter validation tests
- add property documentation in README
src/main/java/com/exasol/adapter/jdbc/BaseTableMetadataReader.java
Outdated
Show resolved
Hide resolved
src/test/java/com/exasol/adapter/jdbc/BaseTableMetadataReaderTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/exasol/adapter/jdbc/BaseTableMetadataReaderTest.java
Outdated
Show resolved
Hide resolved
protected void validateAdapterProperties(AdapterProperties properties) throws PropertyValidationException { | ||
if (properties.containsKey(JDBC_MAXTABLES_PROPERTY)) { | ||
int result = 0; | ||
try { | ||
result = Integer.parseUnsignedInt(properties.get(JDBC_MAXTABLES_PROPERTY)); | ||
} catch (NumberFormatException e) { | ||
// pass | ||
} | ||
if( result == 0 ) { | ||
throw new PropertyValidationException(ExaError.messageBuilder("E-VSCJDBC-43") // | ||
.message("Invalid parameter value.") // | ||
.mitigation( | ||
"The adapter property {{max_tables_property}}" + " if present, must be a positive integer.") // | ||
.parameter("max_tables_property", JDBC_MAXTABLES_PROPERTY) // | ||
.toString()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected void validateAdapterProperties(AdapterProperties properties) throws PropertyValidationException { | |
if (properties.containsKey(JDBC_MAXTABLES_PROPERTY)) { | |
int result = 0; | |
try { | |
result = Integer.parseUnsignedInt(properties.get(JDBC_MAXTABLES_PROPERTY)); | |
} catch (NumberFormatException e) { | |
// pass | |
} | |
if( result == 0 ) { | |
throw new PropertyValidationException(ExaError.messageBuilder("E-VSCJDBC-43") // | |
.message("Invalid parameter value.") // | |
.mitigation( | |
"The adapter property {{max_tables_property}}" + " if present, must be a positive integer.") // | |
.parameter("max_tables_property", JDBC_MAXTABLES_PROPERTY) // | |
.toString()); | |
} | |
} | |
} | |
protected void validateAdapterProperties(final AdapterProperties properties) throws PropertyValidationException { | |
try { | |
validatePropertyValue(properties.get(JDBC_MAXTABLES_PROPERTY)); | |
} catch (final IllegalArgumentException exception) { | |
throw new PropertyValidationException(ExaError.messageBuilder("E-VSCJDBC-43") // | |
.message("Invalid parameter value.") // | |
.mitigation("The adapter property {{max_tables_property}}" // | |
+ " if present, must be a positive integer.") // | |
.parameter("max_tables_property", JDBC_MAXTABLES_PROPERTY) // | |
.toString()); | |
} | |
} | |
private void validatePropertyValue(final String string) { | |
if (string == null) { | |
return; | |
} | |
final int value = Integer.parseUnsignedInt(string); | |
if (value == 0) { | |
throw new IllegalArgumentException(); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.... the method was meant to be extendable with more property checks -- (property, value and error message) should all be in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was tempted to think the same - please feel free!
// Validate properties for both the base adapter and the sql dialect | ||
private void validateProperties(AdapterProperties properties) throws PropertyValidationException { | ||
validateAdapterProperties(properties); | ||
if( this.sqlDialectFactory != null ) { | ||
this.sqlDialectFactory.createSqlDialect(null, properties).validateProperties(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dialect properties will be validated in method readMetaData()
(two signatures).
But we could avoid code duplication in these methods:
// Validate properties for both the base adapter and the sql dialect | |
private void validateProperties(AdapterProperties properties) throws PropertyValidationException { | |
validateAdapterProperties(properties); | |
if( this.sqlDialectFactory != null ) { | |
this.sqlDialectFactory.createSqlDialect(null, properties).validateProperties(); | |
} | |
} | |
private SqlDialect createDialect(final AdapterProperties properties, final ExaMetadata exasolMetadata) | |
throws PropertyValidationException { | |
final ConnectionFactory connectionFactory = new RemoteConnectionFactory(exasolMetadata, properties); | |
final SqlDialect dialect = createDialect(connectionFactory, properties); | |
dialect.validateProperties(); | |
return dialect; | |
} |
@@ -40,6 +42,7 @@ public CreateVirtualSchemaResponse createVirtualSchema(final ExaMetadata exasolM | |||
final CreateVirtualSchemaRequest request) throws AdapterException { | |||
logCreateVirtualSchemaRequestReceived(request); | |||
final AdapterProperties properties = getPropertiesFromRequest(request); | |||
validateProperties(properties); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateProperties(properties); | |
validateAdapterProperties(properties); |
|
||
validateProperties(mergedProperties); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dialect properties will be validated in method readMetaData()
validateProperties(mergedProperties); | |
validateAdapterProperties(mergedProperties); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that reopens the problem that you can ALTER your virtual schema without any errors, and it will only explode on refresh or use...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is your concern, that isRefreshingVirtualSchemaRequired()
might return false and hence avoiding a call to readMetadata()
?
…java Co-authored-by: Christoph Kuhnke <github@kuhnke.net>
Kudos, SonarCloud Quality Gate passed! |
JDBCAdapter
to validate properties on create and setProperty events.private
membersprotected