gora-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [gora] carlosrmng commented on a change in pull request #156: GORA 411 - Add exists(key) to DataStore interface
Date Wed, 01 May 2019 04:18:30 GMT
carlosrmng commented on a change in pull request #156: GORA 411 - Add exists(key) to DataStore
interface
URL: https://github.com/apache/gora/pull/156#discussion_r280002698
 
 

 ##########
 File path: gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStore.java
 ##########
 @@ -176,6 +176,27 @@ public boolean schemaExists() throws GoraException {
     }
   }
 
+  @Override
+  public boolean exists(K key) throws GoraException {
+    Object[] keyl = null;
+    if (igniteMapping.getPrimaryKey().size() == 1) {
+      keyl = new Object[]{key};
+    } else {
+      //Composite key pending
+    }
+    String selectQuery = IgniteSQLBuilder.createSelectQueryExists(igniteMapping);
+    try (PreparedStatement stmt = connection.prepareStatement(selectQuery)) {
+      IgniteSQLBuilder.fillSelectQuery(stmt, igniteMapping, keyl);
+      ResultSet rs = stmt.executeQuery();
+      rs.next();
+      int resp = rs.getInt(1);
 
 Review comment:
   It seems that John is using a count aggregation function for counting all records which
match the key. But, due that the key should be unique in the table it would be probably better
to implement a select query that return a constant and check whether the resultset is empty
as you suggest. Let's say.
   `select 1 from xxx where key = yyy`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message