-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[GEOT-7230] Implement a HINT parameter as part of the HANA plug-in #4064
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,9 @@ | |
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import org.geotools.data.DataAccessFactory.Param; | ||
import org.geotools.data.Parameter; | ||
import org.geotools.jdbc.JDBCDataStore; | ||
import org.geotools.jdbc.JDBCDataStoreFactory; | ||
|
@@ -32,19 +34,38 @@ | |
*/ | ||
public class HanaDataStoreFactory extends JDBCDataStoreFactory { | ||
|
||
private static final String DATABASE_ID = "hana"; | ||
|
||
public static final Param DBTYPE = | ||
new Param( | ||
"dbtype", | ||
String.class, | ||
"Type", | ||
true, | ||
"hana", | ||
DATABASE_ID, | ||
Collections.singletonMap(Parameter.LEVEL, "program")); | ||
|
||
public static final Param PORT = new Param("port", Integer.class, "Port", false); | ||
public static final Param PORT = | ||
new Param( | ||
"port", | ||
Integer.class, | ||
"Port to connect to. If omitted, you have to specify an instance.", | ||
false); | ||
|
||
public static final Param INSTANCE = | ||
new Param("instance", Integer.class, "Instance Number", false); | ||
new Param( | ||
"instance", | ||
Integer.class, | ||
"Instance Number. Leave empty if you have specified a port.", | ||
false); | ||
|
||
public static final Param DATABASE = | ||
new Param( | ||
"database", | ||
String.class, | ||
"Database. Leave empty if you have specified a port or if you want to connect in single database mode. " | ||
+ "Use SYSTEMDB for the system database. ", | ||
false); | ||
|
||
public static final Param USE_SSL = new Param("use ssl", Boolean.class, "Use SSL", false); | ||
|
||
|
@@ -61,6 +82,15 @@ public class HanaDataStoreFactory extends JDBCDataStoreFactory { | |
Boolean.FALSE, | ||
Collections.singletonMap(Param.LEVEL, "advanced")); | ||
|
||
public static final Param SELECT_HINTS = | ||
new Param( | ||
"SELECT Hints", | ||
String.class, | ||
"Comma-separated list of hints that will be applied to SELECT queries, e.g. ESTIMATION_SAPLES(0), NO_HASH_JOIN", | ||
false, | ||
null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the documentation it says the fifth parameter is for example input. Should be put ESTIMATION_SAMPLES(0) and NO_HASH_JOIN in there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially did this, but then realized that the GeoServer connection dialog uses the sample to pre-populate the textbox. Hence, I reverted it to null. |
||
Collections.singletonMap(Parameter.IS_LARGE_TEXT, Boolean.TRUE)); | ||
|
||
private static final String DESCRIPTION = "SAP HANA"; | ||
|
||
private static final String DRIVER_CLASS_NAME = "com.sap.db.jdbc.Driver"; | ||
|
@@ -72,7 +102,7 @@ public String getDescription() { | |
|
||
@Override | ||
protected String getDatabaseID() { | ||
return (String) DBTYPE.sample; | ||
return DATABASE_ID; | ||
} | ||
|
||
@Override | ||
|
@@ -92,13 +122,32 @@ protected String getValidationQuery() { | |
|
||
@Override | ||
protected void setupParameters(Map<String, Object> parameters) { | ||
super.setupParameters(parameters); | ||
|
||
parameters.put(DBTYPE.key, DBTYPE); | ||
parameters.put(PORT.key, PORT); | ||
parameters.put(INSTANCE.key, INSTANCE); | ||
parameters.put(USE_SSL.key, USE_SSL); | ||
parameters.put(ENCODE_FUNCTIONS.key, ENCODE_FUNCTIONS); | ||
LinkedHashMap<String, Object> parentParams = new LinkedHashMap<>(); | ||
super.setupParameters(parentParams); | ||
|
||
// Replace dbtype because the program level annotation is missing | ||
parentParams.put(DBTYPE.key, DBTYPE); | ||
|
||
// Replace port parameter as it is not required for HANA | ||
parentParams.put(PORT.key, PORT); | ||
|
||
// Replace database parameter to add additional documentation | ||
parentParams.put(DATABASE.key, DATABASE); | ||
|
||
// Insert additional parameters at the proper place | ||
for (Map.Entry<String, Object> param : parentParams.entrySet()) { | ||
parameters.put(param.getKey(), param.getValue()); | ||
if (PORT.key.equals(param.getKey())) { | ||
parameters.put(INSTANCE.key, INSTANCE); | ||
} | ||
if (DATABASE.key.equals(param.getKey())) { | ||
parameters.put(USE_SSL.key, USE_SSL); | ||
} | ||
if (EXPOSE_PK.key.equals(param.getKey())) { | ||
parameters.put(ENCODE_FUNCTIONS.key, ENCODE_FUNCTIONS); | ||
parameters.put(SELECT_HINTS.key, SELECT_HINTS); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -133,6 +182,8 @@ protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, Map<Str | |
HanaDialect dialect = (HanaDialect) dataStore.getSQLDialect(); | ||
Boolean encodeFunctions = (Boolean) ENCODE_FUNCTIONS.lookUp(params); | ||
dialect.setFunctionEncodingEnabled((encodeFunctions != null) && encodeFunctions); | ||
String selectHints = (String) SELECT_HINTS.lookUp(params); | ||
dialect.setSelectHints(selectHints); | ||
return dataStore; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.geotools.data.hana; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Map; | ||
import org.geotools.jdbc.JDBCTestSetup; | ||
import org.geotools.jdbc.JDBCTestSupport; | ||
import org.geotools.jdbc.SQLDialect; | ||
import org.junit.Test; | ||
|
||
public class HanaSelectHintOnlineTest extends JDBCTestSupport { | ||
|
||
@Override | ||
protected JDBCTestSetup createTestSetup() { | ||
return new HanaTestSetupPSPooling(); | ||
} | ||
|
||
@Override | ||
protected Map<String, Object> createDataStoreFactoryParams() throws Exception { | ||
Map<String, Object> params = super.createDataStoreFactoryParams(); | ||
params.put("SELECT Hints", "MYHINT1, MYHINT2"); | ||
return params; | ||
} | ||
|
||
@Test | ||
public void testSelectHint() throws Exception { | ||
SQLDialect dialect = dataStore.getSQLDialect(); | ||
StringBuffer sql = new StringBuffer(); | ||
dialect.handleSelectHints(sql, null, null); | ||
assertEquals(" WITH HINT( MYHINT1, MYHINT2 )", sql.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.
Is there an M missing in ESTIMATION_SAPLES(0)?
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.
Yes, fixed it.