You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2020/09/25 10:29:12 UTC
[ignite] branch master updated: IGNITE-13484: Fixed ODBC example
for several nodes. Added affinity key.
This is an automated email from the ASF dual-hosted git repository.
isapego pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 3abf762 IGNITE-13484: Fixed ODBC example for several nodes. Added affinity key.
3abf762 is described below
commit 3abf76225475a0d77e55086ec9c82c120b1e9d42
Author: Igor Sapego <is...@apache.org>
AuthorDate: Fri Sep 25 13:28:17 2020 +0300
IGNITE-13484: Fixed ODBC example for several nodes. Added affinity key.
This closes #8278
---
.../examples/odbc-example/config/example-odbc.xml | 19 ++++-
.../cpp/examples/odbc-example/src/odbc_example.cpp | 98 ++++++++++++++--------
2 files changed, 78 insertions(+), 39 deletions(-)
diff --git a/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml b/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml
index 4780f38..d170d6b 100644
--- a/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml
+++ b/modules/platforms/cpp/examples/odbc-example/config/example-odbc.xml
@@ -26,6 +26,16 @@
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+
+ <property name="cacheKeyConfiguration">
+ <list>
+ <bean class="org.apache.ignite.cache.CacheKeyConfiguration">
+ <property name="typeName" value="PersonKey"/>
+ <property name="affinityKeyFieldName" value="orgIdAff" />
+ </bean>
+ </list>
+ </property>
+
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
@@ -37,11 +47,13 @@
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
- <property name="keyType" value="java.lang.Long"/>
+ <property name="keyType" value="PersonKey"/>
<property name="valueType" value="Person"/>
<property name="fields">
<map>
+ <entry key="id" value="java.lang.Long"/>
+ <entry key="orgIdAff" value="java.lang.Long"/>
<entry key="orgId" value="java.lang.Long"/>
<entry key="firstName" value="java.lang.String"/>
<entry key="lastName" value="java.lang.String"/>
@@ -51,7 +63,10 @@
</property>
<property name="keyFields">
- <list></list>
+ <list>
+ <value>id</value>
+ <value>orgIdAff</value>
+ </list>
</property>
<property name="indexes">
diff --git a/modules/platforms/cpp/examples/odbc-example/src/odbc_example.cpp b/modules/platforms/cpp/examples/odbc-example/src/odbc_example.cpp
index 76b5c18..3c70630 100644
--- a/modules/platforms/cpp/examples/odbc-example/src/odbc_example.cpp
+++ b/modules/platforms/cpp/examples/odbc-example/src/odbc_example.cpp
@@ -185,8 +185,8 @@ void PopulatePerson(SQLHDBC dbc)
try
{
SQLCHAR query[] =
- "INSERT INTO Person (_key, orgId, firstName, lastName, resume, salary) "
- "VALUES (?, ?, ?, ?, ?, ?)";
+ "INSERT INTO Person (id, orgIdAff, orgId, firstName, lastName, resume, salary) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?)";
ret = SQLPrepare(stmt, query, static_cast<SQLSMALLINT>(sizeof(query)));
@@ -195,7 +195,9 @@ void PopulatePerson(SQLHDBC dbc)
// Binding columns.
- int64_t key = 0;
+ int64_t keyId = 0;
+ int64_t keyOrgIdAff = 0;
+
int64_t orgId = 0;
char firstName[1024] = { 0 };
SQLLEN firstNameLen = SQL_NTS;
@@ -205,43 +207,49 @@ void PopulatePerson(SQLHDBC dbc)
SQLLEN resumeLen = SQL_NTS;
double salary = 0.0;
- ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &key, 0, 0);
+ ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &keyId, 0, 0);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
- ret = SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &orgId, 0, 0);
+ ret = SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &keyOrgIdAff, 0, 0);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
- ret = SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
- sizeof(firstName), sizeof(firstName), firstName, 0, &firstNameLen);
+ ret = SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &orgId, 0, 0);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
ret = SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
- sizeof(lastName), sizeof(lastName), lastName, 0, &lastNameLen);
+ sizeof(firstName), sizeof(firstName), firstName, 0, &firstNameLen);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
ret = SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
+ sizeof(lastName), sizeof(lastName), lastName, 0, &lastNameLen);
+
+ if (!SQL_SUCCEEDED(ret))
+ ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
+
+ ret = SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
sizeof(resume), sizeof(resume), resume, 0, &resumeLen);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
- ret = SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &salary, 0, 0);
+ ret = SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &salary, 0, 0);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
// Filling cache.
+ keyId = 1;
+ keyOrgIdAff = 1;
- key = 1;
- orgId = 1;
+ orgId = keyOrgIdAff;
strncpy(firstName, "John", sizeof(firstName));
strncpy(lastName, "Doe", sizeof(lastName));
strncpy(resume, "Master Degree.", sizeof(resume));
@@ -257,8 +265,10 @@ void PopulatePerson(SQLHDBC dbc)
if (ret != SQL_NO_DATA)
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "No more data expected");
- ++key;
- orgId = 1;
+ ++keyId;
+ keyOrgIdAff = 1;
+
+ orgId = keyOrgIdAff;
strncpy(firstName, "Jane", sizeof(firstName));
strncpy(lastName, "Doe", sizeof(lastName));
strncpy(resume, "Bachelor Degree.", sizeof(resume));
@@ -275,8 +285,10 @@ void PopulatePerson(SQLHDBC dbc)
if (ret != SQL_NO_DATA)
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "No more data expected");
- ++key;
- orgId = 2;
+ ++keyId;
+ keyOrgIdAff = 2;
+
+ orgId = keyOrgIdAff;
strncpy(firstName, "John", sizeof(firstName));
strncpy(lastName, "Smith", sizeof(lastName));
strncpy(resume, "Bachelor Degree.", sizeof(resume));
@@ -292,8 +304,10 @@ void PopulatePerson(SQLHDBC dbc)
if (ret != SQL_NO_DATA)
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "No more data expected");
- ++key;
- orgId = 2;
+ ++keyId;
+ keyOrgIdAff = 2;
+
+ orgId = keyOrgIdAff;
strncpy(firstName, "Jane", sizeof(firstName));
strncpy(lastName, "Smith", sizeof(lastName));
strncpy(resume, "Master Degree.", sizeof(resume));
@@ -309,8 +323,10 @@ void PopulatePerson(SQLHDBC dbc)
if (ret != SQL_NO_DATA)
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "No more data expected");
- ++key;
- orgId = 2;
+ ++keyId;
+ keyOrgIdAff = 2;
+
+ orgId = keyOrgIdAff;
strncpy(firstName, "John", sizeof(firstName));
strncpy(lastName, "Roe", sizeof(lastName));
strncpy(resume, "Bachelor Degree.", sizeof(resume));
@@ -326,8 +342,10 @@ void PopulatePerson(SQLHDBC dbc)
if (ret != SQL_NO_DATA)
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "No more data expected");
- ++key;
- orgId = 2;
+ ++keyId;
+ keyOrgIdAff = 2;
+
+ orgId = keyOrgIdAff;
strncpy(firstName, "Jane", sizeof(firstName));
strncpy(lastName, "Roe", sizeof(lastName));
strncpy(resume, "Bachelor Degree.", sizeof(resume));
@@ -343,8 +361,10 @@ void PopulatePerson(SQLHDBC dbc)
if (ret != SQL_NO_DATA)
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "No more data expected");
- ++key;
- orgId = 1;
+ ++keyId;
+ keyOrgIdAff = 1;
+
+ orgId = keyOrgIdAff;
strncpy(firstName, "Richard", sizeof(firstName));
strncpy(lastName, "Miles", sizeof(lastName));
strncpy(resume, "Master Degree.", sizeof(resume));
@@ -360,8 +380,10 @@ void PopulatePerson(SQLHDBC dbc)
if (ret != SQL_NO_DATA)
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "No more data expected");
- ++key;
- orgId = 2;
+ ++keyId;
+ keyOrgIdAff = 2;
+
+ orgId = keyOrgIdAff;
strncpy(firstName, "Mary", sizeof(firstName));
strncpy(lastName, "Major", sizeof(lastName));
strncpy(resume, "Bachelor Degree.", sizeof(resume));
@@ -435,10 +457,10 @@ void PopulateOrganization(SQLHDBC dbc)
* Adjust salary for specified employee.
*
* @param dbc Database connection.
- * @param key Person key.
+ * @param id Person id.
* @param salary New salary.
*/
-void AdjustSalary(SQLHDBC dbc, int64_t key, double salary)
+void AdjustSalary(SQLHDBC dbc, int64_t id, double salary)
{
SQLHSTMT stmt;
@@ -450,14 +472,14 @@ void AdjustSalary(SQLHDBC dbc, int64_t key, double salary)
try
{
- SQLCHAR query[] = "UPDATE Person SET salary=? WHERE _key=?";
+ SQLCHAR query[] = "UPDATE Person SET salary=? WHERE id=?";
ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &salary, 0, 0);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
- ret = SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &key, 0, 0);
+ ret = SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &id, 0, 0);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
@@ -484,9 +506,9 @@ void AdjustSalary(SQLHDBC dbc, int64_t key, double salary)
* Remove specified person.
*
* @param dbc Database connection.
- * @param key Person key.
+ * @param id Person id.
*/
-void DeletePerson(SQLHDBC dbc, int64_t key)
+void DeletePerson(SQLHDBC dbc, int64_t id)
{
SQLHSTMT stmt;
@@ -498,9 +520,9 @@ void DeletePerson(SQLHDBC dbc, int64_t key)
try
{
- SQLCHAR query[] = "DELETE FROM Person WHERE _key=?";
+ SQLCHAR query[] = "DELETE FROM Person WHERE id=?";
- ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &key, 0, 0);
+ ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT, 0, 0, &id, 0, 0);
if (!SQL_SUCCEEDED(ret))
ThrowOdbcError(SQL_HANDLE_STMT, stmt, "Failed to bind parameter");
@@ -533,18 +555,20 @@ void QueryData(SQLHDBC dbc)
std::cout << std::endl;
std::cout << ">>> Getting list of persons:" << std::endl;
- GetDataWithOdbc(dbc, "SELECT firstName, lastName, resume, salary FROM Person");
+ GetDataWithOdbc(dbc, "SELECT firstName, lastName, resume, salary FROM Person ORDER BY id");
std::cout << std::endl;
std::cout << ">>> Getting average salary by degree:" << std::endl;
- GetDataWithOdbc(dbc, "SELECT resume, AVG(salary) FROM Person GROUP BY resume");
+ GetDataWithOdbc(dbc, "SELECT resume, AVG(salary) FROM Person GROUP BY resume ORDER BY resume");
std::cout << std::endl;
std::cout << ">>> Getting people with organizations:" << std::endl;
- GetDataWithOdbc(dbc, "SELECT firstName, lastName, Organization.name FROM Person "
- "INNER JOIN \"Organization\".Organization ON Person.orgId = Organization._KEY");
+ GetDataWithOdbc(dbc,
+ "SELECT firstName, lastName, Organization.name FROM Person "
+ "INNER JOIN \"Organization\".Organization ON Person.orgId = Organization._KEY "
+ "ORDER BY Person.id");
}
/**