Configure HikariCP in Slick 3 - slick

I have a project with that is using Slick 3.1.0 with jTDS as the JDBC driver. When I enable connection pooling, which is using HikariCP, I get the following exception:
java.sql.SQLException: JDBC4 Connection.isValid()
method not supported, connection test query must be configured
So for SQL Server the SQL query would be SELECT 1. My question is: When using Slick, how do I set properties for HikariCP? Is there some property to set in the config file? I tried the following to no effect:
jtds {
driver = "net.sourceforge.jtds.jdbc.Driver"
url = "jdbc:jtds:sqlserver://foobar.org:1433/somedatabase"
user = "theUser"
password = "theSecretPassword"
properties {
connectionTestQuery = "SELECT 1"
}
}

Found the solution to my own question. The HikariCP properties just go straight into the config file. For example, the solution to setting the connection test query was:
jtds {
driver = "net.sourceforge.jtds.jdbc.Driver"
url = "jdbc:jtds:sqlserver://foobar.org:1433/somedatabase"
user = "theUser"
password = "theSecretPassword"
connectionTestQuery = "SELECT 1"
}

Related

How do I dynamically add where conditions?

How do I make a dynamic query without SQL injection in n=Node.js SQL Server?
I used this query to prevent SQL injection.
const conn = await pool;
conn.query`select * from TEST where id = ${test}`;
But sometimes I have to add a WHERE Clause.
I tried this, but an error occurred.
let addwhere = `AND name = ${name}}`;
conn.query`select * from TEST where id = ${test} ${addwhere}`;
How do I dynamically add where conditions?

How to add session properties of presto in spark

Is there any way to set session parameters of presto in spark, while building a Dataframe out of it.
public Dataset<Row> readPrestoTbl(){
Dataset<Row> stgTblDF = sparksession
.read()
.jdbc(dcrIdentity.getProperty(env + "." + "presto_url")
+ "?SSL="
+ dcrIdentity.getProperty(env + "."
+ "presto_client_SSL"), demoLckQuery, getDBProperties());
}
private Properties getDBProperties() {
Properties dbProperties = new Properties();
dbProperties.put("user", prestoCredentials.getUsername());
dbProperties.put("password", prestoCredentials.getPassword());
dbProperties.put("Driver", "io.prestosql.jdbc.PrestoDriver");
dbProperties.put("task.max-worker-threads", "10");
return dbProperties;
}
The way I have set task.max-worker-threads this property is there any option to set session properties like, required_workers_count or query_max_run_time etc.
I also tried below options, but every time its says Unrecognized connection property 'sessionProperties'.
while adding in properties
dbProperties.put("sessionProperties","task.max-worker-threads:10");
while loading in spark
.option("sessionProperties", "task.max-worker-threads:10")
Trino (formerly PrestoSQL) JDBC driver supports sessionProperties property.
https://trino.io/docs/current/installation/jdbc.html?highlight=sessionproperties#parameter-reference
Also, this is a blog post about the rebranding.
https://trino.io/blog/2020/12/27/announcing-trino.html

Sequelize.js - build SQL query without executing it

Is there a way to get Sequelize to build a query with the replacements (so I'll be able to use their SQL injection cleanup) and just get the raw SQL query, without executing it?
You can just call the QueryGenerator with the type of query you want to generate.
For example a selectQuery:
const sql = MyModel.QueryGenerator.selectQuery(
MyModel.getTableName(), {
where: {
someAttribute: "value"
},
attributes: ["other", "attributes"]
},
MyModel);
There's also insertQuery, updateQuery, deleteQuery too.
It looks like this feature isn't implemented yet, but there are some users trying to push the issue forward.
See github issue.
it's undocumented, but I use next way (Sequelize ver. 5.2.13):
let tableName = myModel.getTableName(options);
let qi = myModel.QueryInterface;
options.type = 'SELECT';
options.model = myModel;
var sql = qi.QueryGenerator.selectQuery(tableName, options, myModel);

Insert data into cassandra using datastax driver

We are trying to insert data from CSV file into Cassandra using the DataStax driver for Java. What are the available methods to do so?
We are currently using running cqlsh to load from a CSV file.
The question is quite vague. Usually, you should be able to provide code, and give an example of something that isn't working quite right for you.
That being said, I just taught a class (this week) on this subject for our developers at work. So I can give you some quick examples.
First of all, you should have a separate class built to handle your Cassandra connection objects. I usually build it with a couple of constructors so that it can be called in a couple different ways. But each essentially calls a connect method, which looks something like this:
public void connect(String[] nodes, String user, String pwd, String dc) {
QueryOptions qo = new QueryOptions();
qo.setConsistencyLevel(ConsistencyLevel.LOCAL_ONE);
cluster = Cluster.builder()
.addContactPoints(nodes)
.withCredentials(user,pwd)
.withQueryOptions(qo)
.withLoadBalancingPolicy(
new TokenAwarePolicy(
DCAwareRoundRobinPolicy.builder()
.withLocalDc(dc)
.build()
)
)
.build();
session = cluster.connect();
With that in place, I also write a few simple methods to expose some functionality of the of the session object:
public ResultSet query(String strCQL) {
return session.execute(strCQL);
}
public PreparedStatement prepare(String strCQL) {
return session.prepare(strCQL);
}
public ResultSet query(BoundStatement bStatement) {
return session.execute(bStatement);
}
With those in-place, I can then call these methods from within a service layer. A simple INSERT (with preparing a statement and binding values to it) looks like this:
String[] nodes = {"10.6.8.2","10.6.6.4"};
CassandraConnection conn = new CassandraConnection(nodes, "aploetz", "flynnLives", "West-DC");
String userID = "Aaron";
String value = "whatever";
String strINSERT = "INSERT INTO stackoverflow.timestamptest "
+ "(userid, activetime, value) "
+ "VALUES (?,dateof(now()),?)";
PreparedStatement pIStatement = conn.prepare(strINSERT);
BoundStatement bIStatement = new BoundStatement(pIStatement);
bIStatement.bind(userID, value);
conn.query(bIStatement);
In addition, the DataStax Java Driver has a folder called "examples" in their Git repo. Here's a link to the "basic" examples, which I recommend reading further.

Displaying Managed Property in Search Results - FAST Search for Sharepoint 2010

We are working with Fast Search for Sharepoint 2010 and had some backend setup done with creating some managed properties e.g. BestBetDescription, keywords etc.
From the front-end part we are creating an application what will fetch all these properties and display in a grid.
However while querying the backend we are NOT getting these managed properties (BestBetDescription) along with other properties such as Title, URL etc.
Following is my source code:
settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("FAST Query SSA");
keywordQuery = new KeywordQuery(searchProxy);
keywordQuery.EnableFQL = true;
keywordQuery.QueryText = p;
keywordQuery.ResultsProvider = SearchProvider.FASTSearch;
keywordQuery.ResultTypes = ResultType.RelevantResults;
ResultTableCollection resultsTableCollection = keywordQuery.Execute();
ResultTable searchResultsTable = resultsTableCollection[ResultType.RelevantResults];
DataTable resultsDataTable = new DataTable();
resultsDataTable.TableName = "Results";
resultsDataTable.Load(searchResultsTable, LoadOption.OverwriteChanges);
return resultsDataTable;
The results are returned and I cannot see the Managed properties which we create in the resultDataTable.
Is there any property I missed or is this a backend issue ?
Thanks.
Hi if you are creating your custom Metadata Property then u should use this option to be selected
please check below link
http://screencast.com/t/SQdlarjhx4F
You can find this option in :
central admin:- services :- fast search :- Metadata Property :- your property
I was missing a property KeywordQuery.SelectProperties
So the code looks something like this
String[] arrSearchProperties = new String[] { "Title", "body", "url" };
KeywordQuery.SelectProperties(arrSearchProperties);
This will fetch you all the Managed Properties defined by you.

Resources