use of org.apache.ignite.IgniteException in project ignite by apache.
the class H2CacheStoreStrategy method putToStore.
/** {@inheritDoc} */
@Override
public void putToStore(Object key, Object val) {
Connection conn = null;
try {
conn = connection();
H2CacheStore.putToDb(conn, key, val);
} catch (SQLException e) {
throw new IgniteException(e);
} finally {
U.closeQuiet(conn);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class H2CacheStoreStrategy method removeFromStore.
/** {@inheritDoc} */
@Override
public void removeFromStore(Object key) {
Connection conn = null;
try {
conn = connection();
H2CacheStore.removeFromDb(conn, key);
} catch (SQLException e) {
throw new IgniteException(e);
} finally {
U.closeQuiet(conn);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class H2CacheStoreStrategy method querySingleInt.
/**
* Retrieves single int value from {@link ResultSet} returned by given query.
*
* @param qry Query string (fully populated, with params).
* @param errorMsg Message for {@link IgniteException} to bear in case of failure.
* @return Requested value
*/
private int querySingleInt(String qry, String errorMsg) {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = connection();
stmt = conn.prepareStatement(qry);
rs = stmt.executeQuery();
if (rs.next())
return rs.getInt(1);
else
throw new IgniteException(errorMsg);
} catch (SQLException e) {
throw new IgniteException(e);
} finally {
U.closeQuiet(rs);
U.closeQuiet(stmt);
U.closeQuiet(conn);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class H2CacheStoreStrategy method putAllToStore.
/** {@inheritDoc} */
@Override
public void putAllToStore(Map<?, ?> data) {
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = connection();
stmt = conn.prepareStatement(H2CacheStore.MERGE);
for (Map.Entry<?, ?> e : data.entrySet()) {
stmt.setBinaryStream(1, new ByteArrayInputStream(H2CacheStore.serialize(e.getKey())));
stmt.setBinaryStream(2, new ByteArrayInputStream(H2CacheStore.serialize(e.getValue())));
stmt.addBatch();
}
stmt.executeBatch();
} catch (SQLException e) {
throw new IgniteException(e);
} finally {
U.closeQuiet(stmt);
U.closeQuiet(conn);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class IgniteCacheConfigVariationsFullApiTest method primaryIgnite.
/**
* @param key Key.
* @return Ignite instance of the primary node for the specified key.
*/
protected Ignite primaryIgnite(String key) {
ClusterNode node = grid(0).affinity(cacheName()).mapKeyToNode(key);
if (node == null)
throw new IgniteException("Failed to find primary node.");
UUID nodeId = node.id();
for (int i = 0; i < gridCount(); i++) {
if (grid(i).localNode().id().equals(nodeId))
return ignite(i);
}
throw new IgniteException("Failed to find primary node.");
}
Aggregations