diff --git a/gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStore.java b/gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStore.java index d852846f7..bc4e4f104 100644 --- a/gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStore.java +++ b/gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStore.java @@ -307,9 +307,13 @@ public void put(K key, T obj) throws GoraException { Schema schema = obj.getSchema(); List fields = schema.getFields(); Map data = new HashMap<>(); + List dataKeyList = new ArrayList<>(); + List dataValueList = new ArrayList<>(); if (igniteMapping.getPrimaryKey().size() == 1) { Column getKey = igniteMapping.getPrimaryKey().get(0); data.put(getKey, key); + dataKeyList.add(getKey); + dataValueList.add(key); } else { //Composite keys pending.. } @@ -320,11 +324,13 @@ public void put(K key, T obj) throws GoraException { Schema fieldSchema = field.schema(); Object serializedObj = serializeFieldValue(fieldSchema, fieldValue); data.put(mappedColumn, serializedObj); + dataKeyList.add(mappedColumn); + dataValueList.add(serializedObj); } } - String baseInsertStatement = IgniteSQLBuilder.createInsertQuery(igniteMapping, data); + String baseInsertStatement = IgniteSQLBuilder.createInsertQuery(igniteMapping, dataKeyList); try (PreparedStatement stmt = connection.prepareStatement(baseInsertStatement)) { - IgniteSQLBuilder.fillInsertQuery(stmt, data); + IgniteSQLBuilder.fillInsertQuery(stmt, dataValueList); stmt.executeUpdate(); } catch (SQLException ex) { throw new GoraException(ex); diff --git a/gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStoreMetadataAnalyzer.java b/gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStoreMetadataAnalyzer.java index ab7413eb4..d56a208d2 100644 --- a/gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStoreMetadataAnalyzer.java +++ b/gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteStoreMetadataAnalyzer.java @@ -23,6 +23,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Properties; @@ -64,6 +65,7 @@ public List getTablesNames() throws GoraException { } catch (SQLException ex) { throw new GoraException(ex); } + Collections.sort(tabs); return tabs; } diff --git a/gora-ignite/src/main/java/org/apache/gora/ignite/utils/IgniteSQLBuilder.java b/gora-ignite/src/main/java/org/apache/gora/ignite/utils/IgniteSQLBuilder.java index c9376b255..0c5dbcf96 100644 --- a/gora-ignite/src/main/java/org/apache/gora/ignite/utils/IgniteSQLBuilder.java +++ b/gora-ignite/src/main/java/org/apache/gora/ignite/utils/IgniteSQLBuilder.java @@ -111,15 +111,15 @@ public static String dropTable(String tableName) { * @param data A map containing the Column-Value pairs of the new record. * @return SQL insert statement */ - public static String createInsertQuery(IgniteMapping mapping, Map data) { + public static String createInsertQuery(IgniteMapping mapping, List dataKeyList) { DbSpec spec = new DbSpec(); DbSchema schema = spec.addDefaultSchema(); DbTable aTable = schema.addTable(mapping.getTableName()); InsertQuery insertQuery = new InsertQuery(aTable); - List> list = new ArrayList<>(data.entrySet()); - String[] columns = new String[list.size()]; - for (int i = 0; i < list.size(); i++) { - columns[i] = list.get(i).getKey().getName(); + // List> list = new ArrayList<>(data.entrySet()); + String[] columns = new String[dataKeyList.size()]; + for (int i = 0; i < dataKeyList.size(); i++) { + columns[i] = dataKeyList.get(i).getName(); } return insertQuery.addCustomPreparedColumns(columns).validate().toString() .replaceFirst("INSERT", "MERGE"); @@ -135,11 +135,11 @@ public static String createInsertQuery(IgniteMapping mapping, Map insertData) throws SQLException { - List> list = new ArrayList<>(insertData.entrySet()); - for (int i = 0; i < list.size(); i++) { + public static void fillInsertQuery(PreparedStatement statement, List insertData) throws SQLException { + // List> list = new ArrayList<>(insertData.entrySet()); + for (int i = 0; i < insertData.size(); i++) { int j = i + 1; - statement.setObject(j, list.get(i).getValue()); + statement.setObject(j, insertData.get(i)); } } diff --git a/gora-ignite/src/test/java/org/apache/gora/ignite/store/TestIgniteStore.java b/gora-ignite/src/test/java/org/apache/gora/ignite/store/TestIgniteStore.java index 3eeb13825..5950c5ef5 100644 --- a/gora-ignite/src/test/java/org/apache/gora/ignite/store/TestIgniteStore.java +++ b/gora-ignite/src/test/java/org/apache/gora/ignite/store/TestIgniteStore.java @@ -39,7 +39,7 @@ public class TestIgniteStore extends DataStoreTestBase { public void igniteStoreMetadataAnalyzerTest() throws Exception { DataStoreMetadataAnalyzer createAnalyzer = DataStoreMetadataFactory.createAnalyzer(DataStoreTestBase.testDriver.getConfiguration()); Assert.assertEquals("Ignite Store Metadata Type", "IGNITE", createAnalyzer.getType()); - Assert.assertTrue("Ignite Store Metadata Table Names", createAnalyzer.getTablesNames().equals(Lists.newArrayList("WEBPAGE", "EMPLOYEE"))); + Assert.assertTrue("Ignite Store Metadata Table Names", createAnalyzer.getTablesNames().equals(Lists.newArrayList("EMPLOYEE", "WEBPAGE"))); IgniteTableMetadata tableInfo = (IgniteTableMetadata) createAnalyzer.getTableInfo("EMPLOYEE"); Assert.assertEquals("Ignite Store Metadata Table Primary Key Column", "PKSSN", tableInfo.getPrimaryKey()); Assert.assertEquals("Ignite Store Metadata Table Primary Key Type", "VARCHAR", tableInfo.getPrimaryKeyType());