Repository: incubator-ignite Updated Branches: refs/heads/ignite-32 802f2c527 -> 9b132b7f5
# IGNITE-32: Fixed notes after review. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/9b132b7f Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/9b132b7f Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/9b132b7f Branch: refs/heads/ignite-32 Commit: 9b132b7f561b8ca981b98a2ab7fe239cbe0d6bae Parents: 802f2c5 Author: AKuznetsov <akuznet...@gridgain.com> Authored: Wed Feb 4 11:29:34 2015 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Wed Feb 4 11:29:34 2015 +0700 ---------------------------------------------------------------------- .../ignite/cache/CacheTypeFieldMetadata.java | 8 +- .../apache/ignite/cache/CacheTypeMetadata.java | 174 ++++++++++++++++ .../ignite/cache/store/jdbc/JdbcCacheStore.java | 180 ++++++++++------ .../cache/store/jdbc/JdbcPojoCacheStore.java | 4 +- .../core/src/test/config/store/jdbc/Ignite.xml | 32 +-- .../store/jdbc/PojoJdbcCacheStoreTest.java | 1 - .../ignite/schema/generator/XmlGenerator.java | 67 +++++- .../ignite/schema/model/PojoDescriptor.java | 71 ++++++- .../schema/parser/DatabaseMetadataParser.java | 4 +- .../apache/ignite/schema/parser/DbTable.java | 39 +++- .../parser/dialect/DatabaseMetadataDialect.java | 33 +++ .../parser/dialect/JdbcMetadataDialect.java | 57 +++++- .../parser/dialect/OracleMetadataDialect.java | 102 +++++++--- .../yardstick/config/benchmark-store.properties | 69 +++++++ .../yardstick/config/ignite-store-config.xml | 203 +++++++++++++++++++ .../ignite/yardstick/cache/model/SampleKey.java | 88 ++++++++ .../yardstick/cache/model/SampleValue.java | 9 +- .../jdbc/IgniteJdbcStoreAbstractBenchmark.java | 44 ++++ .../store/jdbc/IgniteJdbcStoreGetBenchmark.java | 53 +++++ .../store/jdbc/IgniteJdbcStorePutBenchmark.java | 42 ++++ .../jdbc/IgniteJdbcStorePutGetBenchmark.java | 47 +++++ 21 files changed, 1195 insertions(+), 132 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeFieldMetadata.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeFieldMetadata.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeFieldMetadata.java index 687c97d..7be5b4d 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeFieldMetadata.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeFieldMetadata.java @@ -60,28 +60,28 @@ public class CacheTypeFieldMetadata { /** * @return Column name in database. */ - public String getDbName() { + public String getDatabaseName() { return dbName; } /** * @param dbName Column name in database. */ - public void setDbName(String dbName) { + public void setDatabaseName(String dbName) { this.dbName = dbName; } /** * @return Column JDBC type in database. */ - public int getDbType() { + public int getDatabaseType() { return dbType; } /** * @param dbType Column JDBC type in database. */ - public void setDbType(int dbType) { + public void setDatabaseType(int dbType) { this.dbType = dbType; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java index 3a644f8..1e502c9 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java @@ -18,6 +18,7 @@ package org.apache.ignite.cache; import org.apache.ignite.internal.util.tostring.*; +import org.apache.ignite.lang.*; import java.util.*; @@ -45,6 +46,72 @@ public class CacheTypeMetadata { @GridToStringInclude private Collection<CacheTypeFieldMetadata> valFields; + /** Fields to be queried, in addition to indexed fields. */ + @GridToStringInclude + private Map<String, Class<?>> qryFlds; + + /** Fields to index in ascending order. */ + @GridToStringInclude + private Map<String, Class<?>> ascFlds; + + /** Fields to index in descending order. */ + @GridToStringInclude + private Map<String, Class<?>> descFlds; + + /** Fields to index as text. */ + @GridToStringInclude + private Collection<String> txtFlds; + + /** Fields to create group indexes for. */ + @GridToStringInclude + private Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> grps; + + /** + * Default constructor. + */ + public CacheTypeMetadata() { + keyFields = new ArrayList<>(); + + valFields = new ArrayList<>(); + + qryFlds = new LinkedHashMap<>(); + + ascFlds = new LinkedHashMap<>(); + + descFlds = new LinkedHashMap<>(); + + txtFlds = new LinkedHashSet<>(); + + grps = new LinkedHashMap<>(); + } + + /** + * Copy constructor. + */ + public CacheTypeMetadata(CacheTypeMetadata src) { + dbSchema = src.getDatabaseSchema(); + + dbTbl = src.getDatabaseTable(); + + keyType = getKeyType(); + + valType = getValueType(); + + keyFields = new ArrayList<>(src.getKeyFields()); + + valFields = new ArrayList<>(src.getValueFields()); + + qryFlds = new LinkedHashMap<>(src.getQueryFields()); + + ascFlds = new LinkedHashMap<>(src.getAscendingFields()); + + descFlds = new LinkedHashMap<>(src.getDescendingFields()); + + txtFlds = new LinkedHashSet<>(src.getTextFields()); + + grps = new LinkedHashMap<>(src.getGroups()); + } + /** * Gets database schema name. * @@ -99,6 +166,14 @@ public class CacheTypeMetadata { this.keyType = keyType; } + /** + * Sets key type. + * + * @param cls Key type class. + */ + public void setKeyType(Class<?> cls) { + setKeyType(cls.getName()); + } /** * Gets value type. @@ -119,6 +194,15 @@ public class CacheTypeMetadata { } /** + * Sets value type. + * + * @param cls Value type class. + */ + public void setValueType(Class<?> cls) { + setValueType(cls.getName()); + } + + /** * Gets key fields. * * @return Key fields. @@ -146,6 +230,96 @@ public class CacheTypeMetadata { } /** + * Gets query-enabled fields. + * + * @return Collection of fields available for query. + */ + public Map<String, Class<?>> getQueryFields() { + return qryFlds; + } + + /** + * Sets query fields map. + * + * @param qryFlds Query fields. + */ + public void setQueryFields(Map<String, Class<?>> qryFlds) { + this.qryFlds = qryFlds; + } + + /** + * Gets ascending-indexed fields. + * + * @return Map of ascending-indexed fields. + */ + public Map<String, Class<?>> getAscendingFields() { + return ascFlds; + } + + /** + * Sets ascending-indexed fields. + * + * @param ascFlds Map of ascending-indexed fields. + */ + public void setAscendingFields(Map<String, Class<?>> ascFlds) { + this.ascFlds = ascFlds; + } + + /** + * Gets descending-indexed fields. + * + * @return Map of descending-indexed fields. + */ + public Map<String, Class<?>> getDescendingFields() { + return descFlds; + } + + /** + * Sets descending-indexed fields. + * + * @param descFlds Map of descending-indexed fields. + */ + public void setDescendingFields(Map<String, Class<?>> descFlds) { + this.descFlds = descFlds; + } + + /** + * Gets text-indexed fields. + * + * @return Collection of text indexed fields. + */ + public Collection<String> getTextFields() { + return txtFlds; + } + + /** + * Sets text-indexed fields. + * + * @param txtFlds Text-indexed fields. + */ + public void setTextFields(Collection<String> txtFlds) { + this.txtFlds = txtFlds; + } + + /** + * Gets group-indexed fields. + * + * @return Map of group-indexed fields. + */ + public Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> getGroups() { + return grps; + } + + /** + * Sets group-indexed fields. + * + * @param grps Map of group-indexed fields from index name to index fields. + */ + public void setGroups(Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> grps) { + this.grps = grps; + } + + /** * Sets value fields. * * @param valFields New value fields. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java index 1cd387d..52a7bfc 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcCacheStore.java @@ -437,8 +437,8 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L EntryMapping em = cacheMappings(cacheName).get(keyTypeId); if (em == null) - throw new CacheException("Failed to find mapping description for key: " + key + " in cache: " - + (cacheName != null ? cacheName : "<default>")); + throw new CacheException("Failed to find mapping description [table = " + em.fullTableName() + + ", key=" + key + ", cache=" + (cacheName != null ? cacheName : "<default>") + "]"); return em; } @@ -540,7 +540,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L EntryMapping em = entryMapping(keyTypeId(key), key); if (log.isDebugEnabled()) - log.debug("Start load value from database by key: " + key); + log.debug("Start load value from database [table= " + em.fullTableName()+ ", key=" + key + "]"); Connection conn = null; @@ -559,7 +559,8 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L return buildObject(em.valueType(), em.valueColumns(), rs); } catch (SQLException e) { - throw new CacheLoaderException("Failed to load object by key: " + key, e); + throw new CacheLoaderException("Failed to load object [table=" + em.fullTableName() + + ", key=" + key + "]", e); } finally { end(conn, stmt); @@ -617,45 +618,72 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L * @param entry Cache entry. */ private void writeUpsert(PreparedStatement insStmt, PreparedStatement updStmt, - EntryMapping em, Cache.Entry<? extends K, ? extends V> entry) throws SQLException { - for (int attempt = 0; attempt < MAX_ATTEMPT_WRITE_COUNT; attempt++) { - int i = fillValueParameters(updStmt, 1, em, entry.getValue()); - - fillKeyParameters(updStmt, i, em, entry.getKey()); + EntryMapping em, Cache.Entry<? extends K, ? extends V> entry) throws CacheWriterException { + try { + CacheWriterException we = null; - if (updStmt.executeUpdate() == 0) { - i = fillKeyParameters(insStmt, em, entry.getKey()); + for (int attempt = 0; attempt < MAX_ATTEMPT_WRITE_COUNT; attempt++) { + int i = fillValueParameters(updStmt, 1, em, entry.getValue()); - fillValueParameters(insStmt, i, em, entry.getValue()); + fillKeyParameters(updStmt, i, em, entry.getKey()); - try { - insStmt.executeUpdate(); - } - catch (SQLException e) { - String sqlState = e.getSQLState(); + if (updStmt.executeUpdate() == 0) { + i = fillKeyParameters(insStmt, em, entry.getKey()); - SQLException nested = e.getNextException(); + fillValueParameters(insStmt, i, em, entry.getValue()); - while (sqlState == null && nested != null) { - sqlState = nested.getSQLState(); + try { + insStmt.executeUpdate(); - nested = nested.getNextException(); + if (i > 0) + U.warn(log, "Entry was inserted in database on second try [table=" + em.fullTableName() + + ", entry=" + entry + "]"); } + catch (SQLException e) { + String sqlState = e.getSQLState(); + + SQLException nested = e.getNextException(); + + while (sqlState == null && nested != null) { + sqlState = nested.getSQLState(); + + nested = nested.getNextException(); + } - // The error with code 23505 is thrown when trying to insert a row that - // would violate a unique index or primary key. - // TODO check with all RDBMS - if (sqlState != null && Integer.valueOf(sqlState) == 23505) - continue; + // The error with code 23505 is thrown when trying to insert a row that + // would violate a unique index or primary key. + // TODO check with all RDBMS + if (sqlState != null && Integer.valueOf(sqlState) == 23505) { + if (we == null) + we = new CacheWriterException("Failed insert entry in database, violate a unique" + + " index or primary key [table=" + em.fullTableName() + ", entry=" + entry + "]"); - throw e; + we.addSuppressed(e); + + U.warn(log, "Failed insert entry in database, violate a unique index or primary key" + + " [table=" + em.fullTableName() + ", entry=" + entry + "]"); + + continue; + } + + throw new CacheWriterException("Failed insert entry in database [table=" + em.fullTableName() + + ", entry=" + entry, e); + } } + + if (i > 0) + U.warn(log, "Entry was updated in database on second try [table=" + em.fullTableName() + + ", entry=" + entry + "]"); + + return; } - return; + throw we; + } + catch (SQLException e) { + throw new CacheWriterException("Failed update entry in database [table=" + em.fullTableName() + + ", entry=" + entry + "]", e); } - - throw new CacheWriterException("Failed write entry to database: " + entry); } /** {@inheritDoc} */ @@ -667,7 +695,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L EntryMapping em = entryMapping(keyTypeId(key), key); if (log.isDebugEnabled()) - log.debug("Start write entry to database: " + entry); + log.debug("Start write entry to database [table=" + em.fullTableName() + ", entry=" + entry + "]"); Connection conn = null; @@ -710,7 +738,8 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L } } catch (SQLException e) { - throw new CacheWriterException("Failed to write entry to database: " + entry, e); + throw new CacheWriterException("Failed to write entry to database [table=" + em.fullTableName() + + ", entry=" + entry + "]", e); } finally { closeConnection(conn); @@ -733,6 +762,8 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L PreparedStatement mergeStmt = null; try { + EntryMapping em = null; + LazyValue<Object[]> lazyEntries = new LazyValue<Object[]>() { @Override public Object[] create() { return entries.toArray(); @@ -746,11 +777,11 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L Object keyTypeId = keyTypeId(key); - EntryMapping em = entryMapping(keyTypeId, key); + em = entryMapping(keyTypeId, key); if (currKeyTypeId == null || !currKeyTypeId.equals(keyTypeId)) { if (mergeStmt != null) { - executeBatch(mergeStmt, "writeAll", fromIdx, prepared, lazyEntries); + executeBatch(em, mergeStmt, "writeAll", fromIdx, prepared, lazyEntries); U.closeQuiet(mergeStmt); } @@ -769,14 +800,14 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L mergeStmt.addBatch(); if (++prepared % batchSz == 0) { - executeBatch(mergeStmt, "writeAll", fromIdx, prepared, lazyEntries); + executeBatch(em, mergeStmt, "writeAll", fromIdx, prepared, lazyEntries); prepared = 0; } } if (mergeStmt != null && prepared % batchSz != 0) - executeBatch(mergeStmt, "writeAll", fromIdx, prepared, lazyEntries); + executeBatch(em, mergeStmt, "writeAll", fromIdx, prepared, lazyEntries); } finally { U.closeQuiet(mergeStmt); @@ -832,7 +863,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L EntryMapping em = entryMapping(keyTypeId(key), key); if (log.isDebugEnabled()) - log.debug("Start remove value from database by key: " + key); + log.debug("Start remove value from database [table=" + em.fullTableName() + ", key=" + key + "]"); Connection conn = null; @@ -845,11 +876,15 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L fillKeyParameters(stmt, em, key); - if (stmt.executeUpdate() == 0) - log.warning("Nothing was deleted in database for key: " + key); + int delCnt = stmt.executeUpdate(); + + if (delCnt != 1) + U.warn(log, "Unexpected number of deleted entries [table=" + em.fullTableName() + ", key=" + key + + "expected=1, actual=" + delCnt + "]"); } catch (SQLException e) { - throw new CacheWriterException("Failed to remove value from database by key: " + key, e); + throw new CacheWriterException("Failed to remove value from database [table=" + em.fullTableName() + + ", key=" + key + "]", e); } finally { end(conn, stmt); @@ -857,28 +892,33 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L } /** + * @param em Entry mapping. * @param stmt Statement. - * @param stmtType Statement description for error message. + * @param desc Statement description for error message. * @param fromIdx Objects in batch start from index. * @param prepared Expected objects in batch. * @param lazyObjs All objects used in batch statement as array. */ - private void executeBatch(Statement stmt, String stmtType, int fromIdx, int prepared, LazyValue<Object[]> lazyObjs) - throws SQLException { + private void executeBatch(EntryMapping em, Statement stmt, String desc, int fromIdx, int prepared, + LazyValue<Object[]> lazyObjs) throws SQLException { int[] rowCounts = stmt.executeBatch(); int numOfRowCnt = rowCounts.length; if (numOfRowCnt != prepared) - log.warning("JDBC driver did not return the expected number of updated row counts," + - " actual row count: " + numOfRowCnt + " expected: " + prepared); + U.warn(log, "Unexpected number of updated rows [table=" + em.fullTableName() +", expected=" + prepared + + ", actual=" + numOfRowCnt + "]"); - for (int i = 0; i < numOfRowCnt; i++) - if (rowCounts[i] != 1) { + for (int i = 0; i < numOfRowCnt; i++) { + int cnt = rowCounts[i]; + + if (cnt != 1) { Object[] objs = lazyObjs.value(); - log.warning("Batch " + stmtType + " returned unexpected updated row count for: " + objs[fromIdx + i]); + U.warn(log, "Batch " + desc + " returned unexpected updated row count [table=" + em.fullTableName() + + ", entry=" + objs[fromIdx + i] + ", expected=1, actual=" + cnt + "]"); } + } } /** {@inheritDoc} */ @@ -892,6 +932,8 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L Object currKeyTypeId = null; + EntryMapping em = null; + PreparedStatement delStmt = null; LazyValue<Object[]> lazyKeys = new LazyValue<Object[]>() { @@ -905,7 +947,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L for (Object key : keys) { Object keyTypeId = keyTypeId(key); - EntryMapping em = entryMapping(keyTypeId, key); + em = entryMapping(keyTypeId, key); if (delStmt == null) { delStmt = conn.prepareStatement(em.remQry); @@ -914,7 +956,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L } if (!currKeyTypeId.equals(keyTypeId)) { - executeBatch(delStmt, "deleteAll", fromIdx, prepared, lazyKeys); + executeBatch(em, delStmt, "deleteAll", fromIdx, prepared, lazyKeys); fromIdx += prepared; @@ -928,7 +970,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L delStmt.addBatch(); if (++prepared % batchSz == 0) { - executeBatch(delStmt, "deleteAll", fromIdx, prepared, lazyKeys); + executeBatch(em, delStmt, "deleteAll", fromIdx, prepared, lazyKeys); fromIdx += prepared; @@ -937,7 +979,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L } if (delStmt != null && prepared % batchSz != 0) - executeBatch(delStmt, "deleteAll", fromIdx, prepared, lazyKeys); + executeBatch(em, delStmt, "deleteAll", fromIdx, prepared, lazyKeys); } catch (SQLException e) { throw new CacheWriterException("Failed to remove values from database", e); @@ -950,23 +992,23 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L /** * @param stmt Prepare statement. * @param i Start index for parameters. - * @param type Type description. + * @param em Entry mapping. * @param key Key object. * @return Next index for parameters. */ - protected int fillKeyParameters(PreparedStatement stmt, int i, EntryMapping type, + protected int fillKeyParameters(PreparedStatement stmt, int i, EntryMapping em, Object key) throws CacheException { - for (CacheTypeFieldMetadata field : type.keyColumns()) { - Object fieldVal = extractField(type.keyType(), field.getJavaName(), key); + for (CacheTypeFieldMetadata field : em.keyColumns()) { + Object fieldVal = extractField(em.keyType(), field.getJavaName(), key); try { if (fieldVal != null) stmt.setObject(i++, fieldVal); else - stmt.setNull(i++, field.getDbType()); + stmt.setNull(i++, field.getDatabaseType()); } catch (SQLException e) { - throw new CacheException("Failed to set statement parameter name: " + field.getDbName(), e); + throw new CacheException("Failed to set statement parameter name: " + field.getDatabaseName(), e); } } @@ -999,10 +1041,10 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L if (fieldVal != null) stmt.setObject(i++, fieldVal); else - stmt.setNull(i++, field.getDbType()); + stmt.setNull(i++, field.getDatabaseType()); } catch (SQLException e) { - throw new CacheWriterException("Failed to set statement parameter name: " + field.getDbName(), e); + throw new CacheWriterException("Failed to set statement parameter name: " + field.getDatabaseName(), e); } } @@ -1141,6 +1183,9 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L /** Type metadata. */ private final CacheTypeMetadata typeMeta; + /** Full table name. */ + private final String fullTblName; + /** * @param typeMeta Type metadata. */ @@ -1163,6 +1208,8 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L String tblName = typeMeta.getDatabaseTable(); + fullTblName = schema + "." + tblName; + keyCols = databaseColumns(keyFields); Collection<String> valCols = databaseColumns(valFields); @@ -1199,7 +1246,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L return F.transform(dsc, new C1<CacheTypeFieldMetadata, String>() { /** {@inheritDoc} */ @Override public String apply(CacheTypeFieldMetadata col) { - return col.getDbName(); + return col.getDatabaseName(); } }); } @@ -1259,6 +1306,15 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L protected Collection<CacheTypeFieldMetadata> valueColumns() { return typeMeta.getValueFields(); } + + /** + * Get full table name. + * + * @return <schema>.<table name> + */ + protected String fullTableName() { + return fullTblName; + } } /** @@ -1389,7 +1445,7 @@ public abstract class JdbcCacheStore<K, V> extends CacheStore<K, V> implements L if (fieldVal != null) stmt.setObject(i++, fieldVal); else - stmt.setNull(i++, field.getDbType()); + stmt.setNull(i++, field.getDatabaseType()); } ResultSet rs = stmt.executeQuery(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java index 93e71cc..5a8548c 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/JdbcPojoCacheStore.java @@ -145,7 +145,7 @@ public class JdbcPojoCacheStore extends JdbcCacheStore<Object, Object> { typeMethods.put(valType, new PojoMethodsCache(valType, type.getValueFields())); } - HashMap<String, Map<String, PojoMethodsCache>> newMtdsCache = new HashMap<>(mtdsCache); + Map<String, Map<String, PojoMethodsCache>> newMtdsCache = new HashMap<>(mtdsCache); newMtdsCache.put(cacheName, typeMethods); @@ -161,7 +161,7 @@ public class JdbcPojoCacheStore extends JdbcCacheStore<Object, Object> { try { for (CacheTypeFieldMetadata field : fields) - t.setters.get(field.getJavaName()).invoke(obj, rs.getObject(field.getDbName())); + t.setters.get(field.getJavaName()).invoke(obj, rs.getObject(field.getDatabaseName())); return (R)obj; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/core/src/test/config/store/jdbc/Ignite.xml ---------------------------------------------------------------------- diff --git a/modules/core/src/test/config/store/jdbc/Ignite.xml b/modules/core/src/test/config/store/jdbc/Ignite.xml index de6e560..f0db1a7 100644 --- a/modules/core/src/test/config/store/jdbc/Ignite.xml +++ b/modules/core/src/test/config/store/jdbc/Ignite.xml @@ -30,8 +30,8 @@ <property name="keyFields"> <list> <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> - <property name="dbName" value="ID"/> - <property name="dbType" value="4"/> + <property name="databaseName" value="ID"/> + <property name="databaseType" value="4"/> <property name="javaName" value="id"/> <property name="javaType" value="java.lang.Integer"/> </bean> @@ -40,20 +40,20 @@ <property name="valueFields"> <list> <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> - <property name="dbName" value="ID"/> - <property name="dbType" value="4"/> + <property name="databaseName" value="ID"/> + <property name="databaseType" value="4"/> <property name="javaName" value="id"/> <property name="javaType" value="java.lang.Integer"/> </bean> <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> - <property name="dbName" value="NAME"/> - <property name="dbType" value="12"/> + <property name="databaseName" value="NAME"/> + <property name="databaseType" value="12"/> <property name="javaName" value="name"/> <property name="javaType" value="java.lang.String"/> </bean> <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> - <property name="dbName" value="CITY"/> - <property name="dbType" value="12"/> + <property name="databaseName" value="CITY"/> + <property name="databaseType" value="12"/> <property name="javaName" value="city"/> <property name="javaType" value="java.lang.String"/> </bean> @@ -68,8 +68,8 @@ <property name="keyFields"> <list> <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> - <property name="dbName" value="ID"/> - <property name="dbType" value="4"/> + <property name="databaseName" value="ID"/> + <property name="databaseType" value="4"/> <property name="javaName" value="id"/> <property name="javaType" value="java.lang.Integer"/> </bean> @@ -78,20 +78,20 @@ <property name="valueFields"> <list> <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> - <property name="dbName" value="ID"/> - <property name="dbType" value="4"/> + <property name="databaseName" value="ID"/> + <property name="databaseType" value="4"/> <property name="javaName" value="id"/> <property name="javaType" value="java.lang.Integer"/> </bean> <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> - <property name="dbName" value="ORG_ID"/> - <property name="dbType" value="4"/> + <property name="databaseName" value="ORG_ID"/> + <property name="databaseType" value="4"/> <property name="javaName" value="orgId"/> <property name="javaType" value="java.lang.Integer"/> </bean> <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> - <property name="dbName" value="NAME"/> - <property name="dbType" value="12"/> + <property name="databaseName" value="NAME"/> + <property name="databaseType" value="12"/> <property name="javaName" value="name"/> <property name="javaType" value="java.lang.String"/> </bean> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java index c12eff7..63b5b11 100644 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/PojoJdbcCacheStoreTest.java @@ -606,7 +606,6 @@ public class PojoJdbcCacheStoreTest extends GridCommonAbstractTest { @Override protected void beforeTest() throws Exception { super.beforeTest(); - Class.forName("org.h2.Driver"); Connection conn = DriverManager.getConnection(DFLT_CONN_URL, "sa", ""); Statement stmt = conn.createStatement(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java index 2fbef79..9de6912 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java @@ -18,6 +18,7 @@ package org.apache.ignite.schema.generator; import org.apache.ignite.cache.*; +import org.apache.ignite.lang.*; import org.apache.ignite.schema.model.*; import org.apache.ignite.schema.ui.*; import org.w3c.dom.*; @@ -157,8 +158,8 @@ public class XmlGenerator { for (PojoField field : fields) { Element item = addBean(doc, list, CacheTypeFieldMetadata.class); - addProperty(doc, item, "dbName", field.dbName()); - addProperty(doc, item, "dbType", String.valueOf(field.dbType())); + addProperty(doc, item, "databaseName", field.dbName()); + addProperty(doc, item, "databaseType", String.valueOf(field.dbType())); addProperty(doc, item, "javaName", field.javaName()); addProperty(doc, item, "javaType", field.javaTypeName()); } @@ -166,6 +167,60 @@ public class XmlGenerator { } /** + * Add query fields to xml document. + * + * @param doc XML document. + * @param parent Parent XML node. + * @param name Property name. + * @param fields Map with fields. + */ + private static void addQueryFields(Document doc, Node parent, String name, Collection<PojoField> fields) { + if (!fields.isEmpty()) { + Element prop = addProperty(doc, parent, name, null); + + Element map = addElement(doc, prop, "map"); + + for (PojoField field : fields) + addElement(doc, map, "entry", "key", field.javaName(), "value", field.javaTypeName()); + } + } + + /** + * Add indexes to xml document. + * + * @param doc XML document. + * @param parent Parent XML node. + * @param groups Map with indexes. + */ + private static void addQueryGroups(Document doc, Node parent, + Map<String, Map<String, IgniteBiTuple<String, Boolean>>> groups) { + if (!groups.isEmpty()) { + Element prop = addProperty(doc, parent, "groups", null); + + Element map = addElement(doc, prop, "map"); + + for (Map.Entry<String, Map<String, IgniteBiTuple<String, Boolean>>> group : groups.entrySet()) { + Element entry1 = addElement(doc, map, "entry", "key", group.getKey()); + + Element val1 = addElement(doc, entry1, "map"); + + Map<String, IgniteBiTuple<String, Boolean>> fields = group.getValue(); + + for (Map.Entry<String, IgniteBiTuple<String, Boolean>> field : fields.entrySet()) { + Element entry2 = addElement(doc, val1, "entry", "key", field.getKey()); + + Element val2 = addBean(doc, entry2, IgniteBiTuple.class); + + IgniteBiTuple<String, Boolean> idx = field.getValue(); + + addElement(doc, val2, "constructor-arg", null, null, "value", idx.get1()); + addElement(doc, val2, "constructor-arg", null, null, "value", String.valueOf(idx.get2())); + } + } + } + } + + /** * Add element with type metadata to XML document. * * @param doc XML document. @@ -188,6 +243,14 @@ public class XmlGenerator { addFields(doc, bean, "keyFields", pojo.keyFields()); addFields(doc, bean, "valueFields", pojo.valueFields(includeKeys)); + + addQueryFields(doc, bean, "queryFields", pojo.fields()); + + addQueryFields(doc, bean, "ascendingFields", pojo.ascendingFields()); + + addQueryFields(doc, bean, "descendingFields", pojo.descendingFields()); + + addQueryGroups(doc, bean, pojo.groups()); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java index 9ad36cd..70b682c 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/model/PojoDescriptor.java @@ -20,6 +20,7 @@ package org.apache.ignite.schema.model; import javafx.beans.property.*; import javafx.beans.value.*; import javafx.collections.*; +import org.apache.ignite.lang.*; import org.apache.ignite.schema.parser.*; import java.math.*; @@ -64,6 +65,9 @@ public class PojoDescriptor { /** Java class fields. */ private final ObservableList<PojoField> fields; + /** Fields map for quick access. */ + private final Map<String, PojoField> fieldsMap; + /** * Constructor of POJO descriptor. * @@ -87,14 +91,20 @@ public class PojoDescriptor { List<PojoField> flds = new ArrayList<>(cols.size()); + fieldsMap = new HashMap<>(cols.size()); + for (DbColumn col : cols) { - PojoField fld = new PojoField(col.name(), col.type(), - toJavaFieldName(col.name()), toJavaType(col.type(), col.nullable()).getName(), + String colName = col.name(); + + PojoField fld = new PojoField(colName, col.type(), + toJavaFieldName(colName), toJavaType(col.type(), col.nullable()).getName(), col.key(), col.nullable()); fld.owner(this); flds.add(fld); + + fieldsMap.put(colName, fld); } fields = FXCollections.observableList(flds); @@ -262,6 +272,63 @@ public class PojoDescriptor { } /** + * @return Ascending fields. + */ + public Collection<PojoField> ascendingFields() { + Collection<PojoField> res = new ArrayList<>(); + + Set<String> asc = tbl.ascendingColumns(); + + for (PojoField field : fields) + if (field.use() && asc.contains(field.dbName())) + res.add(field); + + return res; + } + + /** + * @return Descending fields. + */ + public Collection<PojoField> descendingFields() { + Collection<PojoField> res = new ArrayList<>(); + + Set<String> desc = tbl.descendingColumns(); + + for (PojoField field : fields) + if (field.use() && desc.contains(field.dbName())) + res.add(field); + + return res; + } + + /** + * Gets indexes groups. + */ + public Map<String, Map<String, IgniteBiTuple<String, Boolean>>> groups() { + Map<String, Map<String, Boolean>> idxs = tbl.indexes(); + + Map<String, Map<String, IgniteBiTuple<String, Boolean>>> groups = new LinkedHashMap<>(idxs.size()); + + for (Map.Entry<String, Map<String, Boolean>> idx : idxs.entrySet()) { + String idxName = idx.getKey(); + + Map<String, Boolean> idxCols = idx.getValue(); + + Map<String, IgniteBiTuple<String, Boolean>> grp = new LinkedHashMap<>(); + + groups.put(idxName, grp); + + for (Map.Entry<String, Boolean> idxCol : idxCols.entrySet()) { + PojoField fld = fieldsMap.get(idxCol.getKey()); + + grp.put(fld.javaName(), new IgniteBiTuple<>(fld.javaTypeName(), idxCol.getValue())); + } + } + + return groups; + } + + /** * @return Key class name property. */ public StringProperty keyClassNameProperty() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java index dfc3a75..a849bd2 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java @@ -67,7 +67,9 @@ public class DatabaseMetadataParser { Collection<PojoDescriptor> children = childrens.get(schema); if (parent == null) { - parent = new PojoDescriptor(null, new DbTable(schema, "", Collections.<DbColumn>emptyList())); + parent = new PojoDescriptor(null, new DbTable(schema, "", Collections.<DbColumn>emptyList(), + Collections.<String>emptySet(), Collections.<String>emptySet(), + Collections.<String, Map<String, Boolean>>emptyMap())); children = new ArrayList<>(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java index 91c69b6..35c7d91 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/DbTable.java @@ -32,17 +32,33 @@ public class DbTable { /** Columns. */ private final Collection<DbColumn> cols; + /** Columns in ascending order. */ + private final Set<String> ascCols; + + /** Columns in descending order. */ + private final Set<String> descCols; + + /** Indexes. */ + private final Map<String, Map<String, Boolean>> idxs; + /** * Default columns. * * @param schema Schema name. * @param tbl Table name. * @param cols Columns. + * @param ascCols Columns in ascending order. + * @param descCols Columns in descending order. + * @param idxs Indexes; */ - public DbTable(String schema, String tbl, Collection<DbColumn> cols) { + public DbTable(String schema, String tbl, Collection<DbColumn> cols, Set<String> ascCols, Set<String> descCols, + Map<String, Map<String, Boolean>> idxs) { this.schema = schema; this.tbl = tbl; this.cols = cols; + this.ascCols = ascCols; + this.descCols = descCols; + this.idxs = idxs; } /** @@ -65,4 +81,25 @@ public class DbTable { public Collection<DbColumn> columns() { return cols; } + + /** + * @return Fields in ascending order + */ + public Set<String> ascendingColumns() { + return ascCols; + } + + /** + * @return Fields in descending order + */ + public Set<String> descendingColumns() { + return descCols; + } + + /** + * @return Indexes. + */ + public Map<String, Map<String, Boolean>> indexes() { + return idxs; + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/DatabaseMetadataDialect.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/DatabaseMetadataDialect.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/DatabaseMetadataDialect.java index 91a4aa4..0d17567 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/DatabaseMetadataDialect.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/DatabaseMetadataDialect.java @@ -42,4 +42,37 @@ public abstract class DatabaseMetadataDialect { public Set<String> systemSchemas() { return Collections.singleton("INFORMATION_SCHEMA"); } + + /** + * Create table descriptor. + * + * @param schema Schema name. + * @param tbl Table name. + * @param cols Table columns. + * @param idxs Table indexes. + * @return New {@code DbTable} instance. + */ + protected DbTable table(String schema, String tbl, Collection<DbColumn> cols, Map<String, Map<String, Boolean>>idxs) { + Set<String> ascCols = new HashSet<>(); + + Set<String> descCols = new HashSet<>(); + + for (Map<String, Boolean> idx : idxs.values()) { + if (idx.size() == 1) + for (Map.Entry<String, Boolean> idxCol : idx.entrySet()) { + String colName = idxCol.getKey(); + + Boolean desc = idxCol.getValue(); + + if (desc != null) { + if (desc) + descCols.add(colName); + else + ascCols.add(colName); + } + } + } + + return new DbTable(schema, tbl, cols, ascCols, descCols, idxs); + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java index 51b1568..38b095a 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/JdbcMetadataDialect.java @@ -39,20 +39,28 @@ public class JdbcMetadataDialect extends DatabaseMetadataDialect { private static final int SCHEMA_CATALOG_IDX = 2; /** Table name index. */ - private static final int TABLE_NAME_IDX = 3; + private static final int TBL_NAME_IDX = 3; /** Primary key column name index. */ - private static final int PK_COLUMN_NAME_IDX = 4; + private static final int PK_COL_NAME_IDX = 4; /** Column name index. */ - private static final int COLUMN_NAME_IDX = 4; + private static final int COL_NAME_IDX = 4; /** Column data type index. */ - private static final int COLUMN_DATA_TYPE_IDX = 5; + private static final int COL_DATA_TYPE_IDX = 5; /** Column nullable index. */ - private static final int COLUMN_NULLABLE_IDX = 11; + private static final int COL_NULLABLE_IDX = 11; + /** Index name index. */ + private static final int IDX_NAME_IDX = 6; + + /** Index column name index. */ + private static final int IDX_COL_NAME_IDX = 9; + + /** Index column descend index. */ + private static final int IDX_ASC_OR_DESC_IDX = 10; /** {@inheritDoc} */ @Override public Collection<DbTable> tables(Connection conn, boolean tblsOnly) throws SQLException { @@ -75,30 +83,57 @@ public class JdbcMetadataDialect extends DatabaseMetadataDialect { try (ResultSet tblsRs = dbMeta.getTables(catalog, schema, "%", tblsOnly ? TABLES_ONLY : TABLES_AND_VIEWS)) { while (tblsRs.next()) { - String tblName = tblsRs.getString(TABLE_NAME_IDX); + String tblName = tblsRs.getString(TBL_NAME_IDX); Set<String> pkCols = new HashSet<>(); try (ResultSet pkRs = dbMeta.getPrimaryKeys(catalog, schema, tblName)) { while (pkRs.next()) - pkCols.add(pkRs.getString(PK_COLUMN_NAME_IDX)); + pkCols.add(pkRs.getString(PK_COL_NAME_IDX)); } List<DbColumn> cols = new ArrayList<>(); try (ResultSet colsRs = dbMeta.getColumns(catalog, schema, tblName, null)) { while (colsRs.next()) { - String colName = colsRs.getString(COLUMN_NAME_IDX); + String colName = colsRs.getString(COL_NAME_IDX); cols.add(new DbColumn( colName, - colsRs.getInt(COLUMN_DATA_TYPE_IDX), + colsRs.getInt(COL_DATA_TYPE_IDX), pkCols.contains(colName), - colsRs.getInt(COLUMN_NULLABLE_IDX) == DatabaseMetaData.columnNullable)); + colsRs.getInt(COL_NULLABLE_IDX) == DatabaseMetaData.columnNullable)); + } + } + + Map<String, Map<String, Boolean>> idxs = new LinkedHashMap<>(); + + try (ResultSet idxRs = dbMeta.getIndexInfo(catalog, schema, tblName, false, true)) { + while (idxRs.next()) { + String idxName = idxRs.getString(IDX_NAME_IDX); + + String colName = idxRs.getString(IDX_COL_NAME_IDX); + + if (idxName == null || colName == null) + continue; + + Map<String, Boolean> idx = idxs.get(idxName); + + if (idx == null) { + idx = new LinkedHashMap<>(); + + idxs.put(idxName, idx); + } + + String askOrDesc = idxRs.getString(IDX_ASC_OR_DESC_IDX); + + Boolean desc = askOrDesc != null ? "D".equals(askOrDesc) : null; + + idx.put(colName, desc); } } - tbls.add(new DbTable(schema, tblName, cols)); + tbls.add(table(schema, tblName, cols, idxs)); } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java index 0c14a89..307d608 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/parser/dialect/OracleMetadataDialect.java @@ -39,16 +39,22 @@ public class OracleMetadataDialect extends DatabaseMetadataDialect { private static final String SQL_PRIMARY_KEYS = "SELECT b.column_name" + " FROM all_constraints a" + " INNER JOIN all_cons_columns b ON a.owner = b.owner AND a.constraint_name = b.constraint_name" + - " WHERE a.table_name = ? AND a.constraint_type = 'P'"; + " WHERE a.owner = ? and a.table_name = ? AND a.constraint_type = 'P'"; + + /** SQL to get indexes metadata. */ + private static final String SQL_INDEXES = "select index_name, column_name, descend" + + " FROM all_ind_columns" + + " WHERE index_owner = ? and table_name = ?" + + " ORDER BY index_name, column_position"; /** Owner index. */ private static final int OWNER_IDX = 1; /** Table name index. */ - private static final int TABLE_NAME_IDX = 2; + private static final int TBL_NAME_IDX = 2; /** Column name index. */ - private static final int COLUMN_NAME_IDX = 3; + private static final int COL_NAME_IDX = 3; /** Nullable index. */ private static final int NULLABLE_IDX = 4; @@ -62,12 +68,21 @@ public class OracleMetadataDialect extends DatabaseMetadataDialect { /** Numeric scale index. */ private static final int DATA_SCALE_IDX = 7; + /** Index name index. */ + private static final int IDX_NAME_IDX = 1; + + /** Index column name index. */ + private static final int IDX_COL_NAME_IDX = 2; + + /** Index column sort order index. */ + private static final int IDX_COL_DESCEND_IDX = 3; + /** * @param rs Result set with column type metadata from Oracle database. * @return JDBC type. * @throws SQLException If failed to decode type. */ - private static int decodeType(ResultSet rs) throws SQLException { + private int decodeType(ResultSet rs) throws SQLException { switch (rs.getString(DATA_TYPE_IDX)) { case "CHAR": case "NCHAR": @@ -140,12 +155,43 @@ public class OracleMetadataDialect extends DatabaseMetadataDialect { return OTHER; } - /** - * @param nullable Column nullable attribute from Oracle database. - * @return {@code true} - */ - private static boolean decodeNullable(String nullable) { - return "Y".equals(nullable); + private Set<String> primaryKeys(PreparedStatement stmt, String owner, String tbl) throws SQLException { + Set<String> pkCols = new HashSet<>(); + + stmt.setString(1, tbl); + + try (ResultSet pkRs = stmt.executeQuery()) { + while(pkRs.next()) + pkCols.add(pkRs.getString(1)); + } + + return pkCols; + } + + private Map<String, Map<String, Boolean>> indexes(PreparedStatement stmt, String owner, String tbl) + throws SQLException { + Map<String, Map<String, Boolean>> idxs = new LinkedHashMap<>(); + + stmt.setString(1, owner); + stmt.setString(2, tbl); + + try (ResultSet idxsRs = stmt.executeQuery()) { + while (idxsRs.next()) { + String idxName = idxsRs.getString(IDX_NAME_IDX); + + Map<String, Boolean> idx = idxs.get(idxName); + + if (idx == null) { + idx = new LinkedHashMap<>(); + + idxs.put(idxName, idx); + } + + idx.put(idxsRs.getString(IDX_COL_NAME_IDX), "DESC".equals(idxsRs.getString(IDX_COL_DESCEND_IDX))); + } + } + + return idxs; } /** {@inheritDoc} */ @@ -154,57 +200,55 @@ public class OracleMetadataDialect extends DatabaseMetadataDialect { PreparedStatement pkStmt = conn.prepareStatement(SQL_PRIMARY_KEYS); + PreparedStatement idxStmt = conn.prepareStatement(SQL_INDEXES); + try (Statement colsStmt = conn.createStatement()) { Collection<DbColumn> cols = new ArrayList<>(); - Set<String> pkCols = new HashSet<>(); + Set<String> pkCols = Collections.emptySet(); + Map<String, Map<String, Boolean>> idxs = Collections.emptyMap(); - String owner = conn.getMetaData().getUserName().toUpperCase(); + String user = conn.getMetaData().getUserName().toUpperCase(); String sql = String.format(SQL_COLUMNS, - tblsOnly ? "INNER JOIN all_tables b on a.table_name = b.table_name" : "", owner); + tblsOnly ? "INNER JOIN all_tables b on a.table_name = b.table_name" : "", user); try (ResultSet colsRs = colsStmt.executeQuery(sql)) { String prevSchema = ""; String prevTbl = ""; while (colsRs.next()) { - String schema = colsRs.getString(OWNER_IDX); - String tbl = colsRs.getString(TABLE_NAME_IDX); - - if (!prevSchema.equals(schema) || !prevTbl.equals(tbl)) { - pkCols.clear(); + String owner = colsRs.getString(OWNER_IDX); + String tbl = colsRs.getString(TBL_NAME_IDX); - pkStmt.setString(1, tbl); + if (!prevSchema.equals(owner) || !prevTbl.equals(tbl)) { + pkCols = primaryKeys(pkStmt, owner, tbl); - try (ResultSet pkRs = pkStmt.executeQuery()) { - while(pkRs.next()) - pkCols.add(pkRs.getString(1)); - } + idxs = indexes(idxStmt, owner, tbl); } if (prevSchema.isEmpty()) { - prevSchema = schema; + prevSchema = owner; prevTbl = tbl; } - if (!schema.equals(prevSchema) || !tbl.equals(prevTbl)) { - tbls.add(new DbTable(prevSchema, prevTbl, cols)); + if (!owner.equals(prevSchema) || !tbl.equals(prevTbl)) { + tbls.add(new DbTable(prevSchema, prevTbl, cols, null, null, null)); // TODO !!! - prevSchema = schema; + prevSchema = owner; prevTbl = tbl; cols = new ArrayList<>(); } - String colName = colsRs.getString(COLUMN_NAME_IDX); + String colName = colsRs.getString(COL_NAME_IDX); cols.add(new DbColumn(colName, decodeType(colsRs), pkCols.contains(colName), !"N".equals(colsRs.getString(NULLABLE_IDX)))); } if (!cols.isEmpty()) - tbls.add(new DbTable(prevSchema, prevTbl, cols)); + tbls.add(table(prevSchema, prevTbl, cols, idxs)); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/yardstick/config/benchmark-store.properties ---------------------------------------------------------------------- diff --git a/modules/yardstick/config/benchmark-store.properties b/modules/yardstick/config/benchmark-store.properties new file mode 100644 index 0000000..fcf3eb7 --- /dev/null +++ b/modules/yardstick/config/benchmark-store.properties @@ -0,0 +1,69 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Contains all benchmarks for: +# - ATOMIC cache +# - TRANSACTIONAL cache +# - SQL queries +# + +# JVM options. +JVM_OPTS=${JVM_OPTS}" -DGRIDGAIN_QUIET=false" + +# Uncomment to enable concurrent garbage collection (GC) if you encounter long GC pauses. +# JVM_OPTS=${JVM_OPTS}" \ +# -XX:+UseParNewGC \ +# -XX:+UseConcMarkSweepGC \ +# -XX:+UseTLAB \ +# -XX:NewSize=128m \ +# -XX:MaxNewSize=128m \ +# -XX:MaxTenuringThreshold=0 \ +# -XX:SurvivorRatio=1024 \ +# -XX:+UseCMSInitiatingOccupancyOnly \ +# -XX:CMSInitiatingOccupancyFraction=60 \ +#" + +# List of default probes. +# Add DStatProbe or VmStatProbe if your OS supports it (e.g. if running on Linux). +BENCHMARK_DEFAULT_PROBES=ThroughputLatencyProbe,PercentileProbe + +# Packages where the specified benchmark is searched by reflection mechanism. +BENCHMARK_PACKAGES=org.yardstickframework,org.apache.ignite.yardstick + +# Probe point writer class name. +# BENCHMARK_WRITER= + +# Comma-separated list of the hosts to run BenchmarkServers on. 2 nodes on local host are enabled by default. +SERVER_HOSTS=localhost + +# Comma-separated list of the hosts to run BenchmarkDrivers on. 1 node on local host is enabled by default. +DRIVER_HOSTS=localhost + +# Remote username. +# REMOTE_USER= + +# Number of nodes, used to wait for the specified number of nodes to start. +nodesNum=$((`echo ${SERVER_HOSTS} | tr ',' '\n' | wc -l` + `echo ${DRIVER_HOSTS} | tr ',' '\n' | wc -l`)) + +# Run configuration which contains all benchmarks. +# Note that each benchmark is set to run for 300 seconds (5 mins) with warm-up set to 60 seconds (1 minute). +CONFIGS="\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStoreGetBenchmark -sn IgniteNode -ds atomic-get,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutBenchmark -sn IgniteNode -ds atomic-put,\ +-cfg ${SCRIPT_DIR}/../config/ignite-store-config.xml -nn ${nodesNum} -b 1 -w 60 -d 300 -t 64 -sm PRIMARY_SYNC -dn IgniteJdbcStorePutGetBenchmark -sn IgniteNode -ds atomic-put-get\ +" http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/yardstick/config/ignite-store-config.xml ---------------------------------------------------------------------- diff --git a/modules/yardstick/config/ignite-store-config.xml b/modules/yardstick/config/ignite-store-config.xml new file mode 100644 index 0000000..ee6515a --- /dev/null +++ b/modules/yardstick/config/ignite-store-config.xml @@ -0,0 +1,203 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<!-- + Ignite Spring configuration file to startup grid. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> + + <bean id="sampleTypeMetadata" class="org.apache.ignite.cache.CacheTypeMetadata"> + <property name="databaseSchema" value="PUBLIC"/> + <property name="databaseTable" value="SAMPLE"/> + <property name="keyType" value="org.apache.ignite.yardstick.cache.model.SampleKey"/> + <property name="valueType" value="org.apache.ignite.yardstick.cache.model.SampleValue"/> + <property name="keyFields"> + <list> + <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> + <property name="databaseName" value="ID"/> + <property name="databaseType" value="4"/> + <property name="javaName" value="id"/> + <property name="javaType" value="int"/> + </bean> + </list> + </property> + <property name="valueFields"> + <list> + <bean class="org.apache.ignite.cache.CacheTypeFieldMetadata"> + <property name="databaseName" value="ID"/> + <property name="databaseType" value="4"/> + <property name="javaName" value="id"/> + <property name="javaType" value="java.lang.Integer"/> + </bean> + </list> + </property> + </bean> + + <bean class="org.apache.ignite.configuration.IgniteConfiguration" > + <property name="peerClassLoadingEnabled" value="false"/> + + <property name="marshaller"> + <bean class="org.apache.ignite.marshaller.optimized.IgniteOptimizedMarshaller"> + <property name="requireSerializable" value="true"/> + <property name="classNames"> + <list> + <value>org.apache.ignite.yardstick.cache.model.SampleKey</value> + <value>org.apache.ignite.yardstick.cache.model.SampleValue</value> + <value>org.apache.ignite.yardstick.cache.model.Person</value> + <value>org.apache.ignite.yardstick.cache.model.Organization</value> + <value>org.apache.ignite.yardstick.compute.model.NoopTask$NoopJob</value> + <value>org.apache.ignite.yardstick.compute.model.NoopCallable</value> + <value>org.apache.ignite.yardstick.compute.IgniteRunBenchmark$NoopRunnable</value> + <value>org.apache.ignite.yardstick.compute.IgniteApplyBenchmark$NoopClosure</value> + </list> + </property> + </bean> + </property> + + <property name="cacheConfiguration"> + <list> + <bean class="org.apache.ignite.cache.CacheConfiguration"> + <property name="name" value="atomic"/> + + <property name="cacheMode" value="PARTITIONED"/> + + <property name="atomicityMode" value="ATOMIC"/> + + <property name="swapEnabled" value="false"/> + + <property name="queryIndexEnabled" value="false"/> + + <property name="typeMetadata"> + <list> + <ref bean="sampleTypeMetadata"/> + </list> + </property> + + <property name="cacheStoreFactory"> + <bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory"> + <constructor-arg> + <bean class="org.apache.ignite.cache.store.jdbc.JdbcPojoCacheStore"> + <property name="dataSource"> + <bean class="org.h2.jdbcx.JdbcConnectionPool" factory-method="create"> + <constructor-arg value="jdbc:h2:tcp://localhost//Users/nva/work/h2-test"/> + <constructor-arg value="sa"/> + <constructor-arg value=""/> + </bean> + </property> + </bean> + </constructor-arg> + </bean> + </property> + + <property name="readThrough" value="false"/> + + <property name="writeThrough" value="false"/> + + <property name="writeBehindEnabled" value="false"/> + </bean> + + <bean class="org.apache.ignite.cache.CacheConfiguration"> + <property name="name" value="tx"/> + + <property name="cacheMode" value="PARTITIONED"/> + + <property name="atomicityMode" value="TRANSACTIONAL"/> + + <property name="swapEnabled" value="false"/> + + <property name="queryIndexEnabled" value="false"/> + + <property name="typeMetadata"> + <list> + <ref bean="sampleTypeMetadata"/> + </list> + </property> + + <property name="cacheStoreFactory"> + <bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory"> + <constructor-arg> + <bean class="org.apache.ignite.cache.store.jdbc.JdbcPojoCacheStore"> + <property name="dataSource"> + <bean class="org.h2.jdbcx.JdbcConnectionPool" factory-method="create"> + <constructor-arg value="jdbc:h2:tcp://localhost//Users/nva/work/h2-test"/> + <constructor-arg value="sa"/> + <constructor-arg value=""/> + </bean> + </property> + </bean> + </constructor-arg> + </bean> + </property> + + <property name="readThrough" value="false"/> + + <property name="writeThrough" value="false"/> + + <property name="writeBehindEnabled" value="false"/> + </bean> + </list> + </property> + + <property name="restEnabled" value="false"/> + + <property name="includeEventTypes"> + <list/> + </property> + + <property name="loadBalancingSpi"> + <bean class="org.apache.ignite.spi.loadbalancing.roundrobin.RoundRobinLoadBalancingSpi"> + <property name="perTask" value="false"/> + </bean> + </property> + + <property name="communicationSpi"> + <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi"> + <property name="sharedMemoryPort" value="-1"/> + </bean> + </property> + + <property name="localHost" value="127.0.0.1"/> + + <property name="discoverySpi"> + <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> + <property name="ipFinder"> + <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> + <property name="addresses"> + <list> + <value>127.0.0.1:47500</value> + <value>127.0.0.1:47501</value> + <value>127.0.0.1:47502</value> + <value>127.0.0.1:47503</value> + <value>127.0.0.1:47504</value> + <value>127.0.0.1:47505</value> + <value>127.0.0.1:47506</value> + <value>127.0.0.1:47507</value> + <value>127.0.0.1:47508</value> + <value>127.0.0.1:47509</value> + </list> + </property> + </bean> + </property> + </bean> + </property> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java new file mode 100644 index 0000000..345aa98 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache.model; + +import java.io.*; + +/** + * Key class for benchmark. + */ +public class SampleKey implements Externalizable { + /** */ + private int id; + + /** */ + public SampleKey() { + // No-op. + } + + /** + * @param id Id. + */ + public SampleKey(int id) { + this.id = id; + } + + /** + * @param id Id. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return Id. + */ + public int getId() { + return id; + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + id = in.readInt(); + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + out.writeInt(id); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + SampleKey key = (SampleKey)o; + + return id == key.id; + + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "Key [id=" + id + ']'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java index b6cb5d1..a79c72d 100644 --- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java @@ -39,9 +39,16 @@ public class SampleValue implements Externalizable { } /** + * @param id Id. + */ + public void setId(int id) { + this.id = id; + } + + /** * @return Id. */ - public int id() { + public int getId() { return id; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStoreAbstractBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStoreAbstractBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStoreAbstractBenchmark.java new file mode 100644 index 0000000..5719dd7 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStoreAbstractBenchmark.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache.store.jdbc; + +import org.apache.ignite.*; +import org.apache.ignite.yardstick.*; +import org.yardstickframework.*; + +/** + * Abstract class for Ignite benchmarks which use cache. + */ +public abstract class IgniteJdbcStoreAbstractBenchmark extends IgniteAbstractBenchmark { + /** Cache. */ + protected IgniteCache<Object, Object> cache; + + /** {@inheritDoc} */ + @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { + super.setUp(cfg); + + cache = cache(); + } + + /** + * Each benchmark must determine which cache will be used. + * + * @return GridCache Cache to use. + */ + protected abstract IgniteCache<Object, Object> cache(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStoreGetBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStoreGetBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStoreGetBenchmark.java new file mode 100644 index 0000000..3ff3079 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStoreGetBenchmark.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache.store.jdbc; + +import org.apache.ignite.*; +import org.apache.ignite.yardstick.cache.model.*; +import org.yardstickframework.*; + +import java.util.*; + +/** + * Ignite JDBC cache store benchmark that performs get operations. + */ +public class IgniteJdbcStoreGetBenchmark extends IgniteJdbcStoreAbstractBenchmark { + /** Cache. */ + protected IgniteCache<Object, Object> cache; + + /** {@inheritDoc} */ + @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { + super.setUp(cfg); + + cache = cache(); + } + + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + int id = nextRandom(args.range()); + + cache().get(new SampleKey(id)); + + return true; + } + + /** {@inheritDoc} */ + @Override protected IgniteCache<Object, Object> cache() { + return ignite().jcache("atomic"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStorePutBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStorePutBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStorePutBenchmark.java new file mode 100644 index 0000000..baac812 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStorePutBenchmark.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache.store.jdbc; + +import org.apache.ignite.*; +import org.apache.ignite.yardstick.cache.model.*; + +import java.util.*; + +/** + * Ignite benchmark that performs put operations. + */ +public class IgniteJdbcStorePutBenchmark extends IgniteJdbcStoreAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + int id = nextRandom(args.range()); + + cache.put(new SampleKey(id), new SampleValue(id)); + + return true; + } + + /** {@inheritDoc} */ + @Override protected IgniteCache<Object, Object> cache() { + return ignite().jcache("atomic"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9b132b7f/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStorePutGetBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStorePutGetBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStorePutGetBenchmark.java new file mode 100644 index 0000000..dfcf2da --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/store/jdbc/IgniteJdbcStorePutGetBenchmark.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache.store.jdbc; + +import org.apache.ignite.*; +import org.apache.ignite.yardstick.cache.model.*; + +import java.util.*; + +/** + * Ignite benchmark that performs put and get operations. + */ +public class IgniteJdbcStorePutGetBenchmark extends IgniteJdbcStoreAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + int id = nextRandom(args.range()); + + Object val = cache.get(new SampleKey(id)); + + if (val != null) + id = nextRandom(args.range()); + + cache.put(new SampleKey(id), new SampleValue(id)); + + return true; + } + + /** {@inheritDoc} */ + @Override protected IgniteCache<Object, Object> cache() { + return ignite().jcache("atomic"); + } +}