Search in sources :

Example 91 with IgniteException

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);
    }
}
Also used : SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) Connection(java.sql.Connection)

Example 92 with IgniteException

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);
    }
}
Also used : SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) Connection(java.sql.Connection)

Example 93 with IgniteException

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);
    }
}
Also used : SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 94 with IgniteException

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Map(java.util.Map)

Example 95 with IgniteException

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.");
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteException(org.apache.ignite.IgniteException) UUID(java.util.UUID)

Aggregations

IgniteException (org.apache.ignite.IgniteException)414 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)114 Ignite (org.apache.ignite.Ignite)82 ClusterNode (org.apache.ignite.cluster.ClusterNode)47 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 ArrayList (java.util.ArrayList)40 UUID (java.util.UUID)40 CountDownLatch (java.util.concurrent.CountDownLatch)40 IOException (java.io.IOException)32 HashMap (java.util.HashMap)32 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 CacheException (javax.cache.CacheException)31 Transaction (org.apache.ignite.transactions.Transaction)28 CyclicBarrier (java.util.concurrent.CyclicBarrier)21 Map (java.util.Map)20 IgniteCache (org.apache.ignite.IgniteCache)19 ClusterStartNodeResult (org.apache.ignite.cluster.ClusterStartNodeResult)18 Nullable (org.jetbrains.annotations.Nullable)18 List (java.util.List)17 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)16