Search in sources :

Example 86 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class CacheAbstractJdbcStore method resolveDialect.

/**
     * Perform dialect resolution.
     *
     * @return The resolved dialect.
     * @throws CacheException Indicates problems accessing the metadata.
     */
protected JdbcDialect resolveDialect() throws CacheException {
    Connection conn = null;
    String dbProductName = null;
    try {
        conn = openConnection(false);
        dbProductName = conn.getMetaData().getDatabaseProductName();
    } catch (SQLException e) {
        throw new CacheException("Failed access to metadata for detect database dialect.", e);
    } finally {
        U.closeQuiet(conn);
    }
    if ("H2".equals(dbProductName))
        return new H2Dialect();
    if ("MySQL".equals(dbProductName))
        return new MySQLDialect();
    if (dbProductName.startsWith("Microsoft SQL Server"))
        return new SQLServerDialect();
    if ("Oracle".equals(dbProductName))
        return new OracleDialect();
    if (dbProductName.startsWith("DB2/"))
        return new DB2Dialect();
    U.warn(log, "Failed to resolve dialect (BasicJdbcDialect will be used): " + dbProductName);
    return new BasicJdbcDialect();
}
Also used : MySQLDialect(org.apache.ignite.cache.store.jdbc.dialect.MySQLDialect) SQLServerDialect(org.apache.ignite.cache.store.jdbc.dialect.SQLServerDialect) H2Dialect(org.apache.ignite.cache.store.jdbc.dialect.H2Dialect) OracleDialect(org.apache.ignite.cache.store.jdbc.dialect.OracleDialect) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) Connection(java.sql.Connection) BasicJdbcDialect(org.apache.ignite.cache.store.jdbc.dialect.BasicJdbcDialect) DB2Dialect(org.apache.ignite.cache.store.jdbc.dialect.DB2Dialect)

Example 87 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class CacheJdbcPojoStore method extractPojoParameter.

/**
     * Get field value from POJO for use as query parameter.
     *
     * @param cacheName Cache name.
     * @param typeName Type name.
     * @param fldName Field name.
     * @param obj Cache object.
     * @return Field value from object.
     * @throws CacheException in case of error.
     */
@Nullable
private Object extractPojoParameter(@Nullable String cacheName, String typeName, String fldName, Object obj) throws CacheException {
    try {
        Map<String, PojoPropertiesCache> cacheProps = pojosProps.get(cacheName);
        if (cacheProps == null)
            throw new CacheException("Failed to find POJO type metadata for cache: " + U.maskName(cacheName));
        PojoPropertiesCache ppc = cacheProps.get(typeName);
        if (ppc == null)
            throw new CacheException("Failed to find POJO type metadata for type: " + typeName);
        ClassProperty prop = ppc.props.get(fldName);
        if (prop == null)
            throw new CacheLoaderException("Failed to find property in POJO class [class=" + typeName + ", prop=" + fldName + "]");
        return prop.get(obj);
    } catch (Exception e) {
        throw new CacheException("Failed to read object property [cache=" + U.maskName(cacheName) + ", type=" + typeName + ", prop=" + fldName + "]", e);
    }
}
Also used : CacheException(javax.cache.CacheException) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheLoaderException(javax.cache.integration.CacheLoaderException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class IgniteReflectionFactory method setWithMethod.

/**
     * @param obj Object to initialize with properties.
     * @param fieldName Field name.
     * @param val Value to set.
     * @return {@code True} if property was set.
     */
private boolean setWithMethod(T obj, String fieldName, Serializable val) {
    StringBuilder sb = new StringBuilder("set");
    sb.append(fieldName);
    sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
    Class paramCls = val.getClass();
    while (paramCls != null) {
        try {
            Method mtd = obj.getClass().getMethod(sb.toString(), paramCls);
            mtd.invoke(obj, val);
            return true;
        } catch (InvocationTargetException e) {
            throw new CacheException(e.getCause());
        } catch (NoSuchMethodException | IllegalAccessException ignore) {
            // try next class.
            paramCls = paramCls.getSuperclass();
        }
    }
    // Try interfaces.
    for (Class<?> itf : val.getClass().getInterfaces()) {
        try {
            Method mtd = obj.getClass().getMethod(sb.toString(), itf);
            mtd.invoke(obj, val);
            return true;
        } catch (InvocationTargetException e) {
            throw new CacheException(e.getCause());
        } catch (NoSuchMethodException | IllegalAccessException ignore) {
        // try next interface.
        }
    }
    return false;
}
Also used : CacheException(javax.cache.CacheException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 89 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class CacheManager method createCache.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String cacheName, C cacheCfg) throws IllegalArgumentException {
    kernalGateway.readLock();
    try {
        if (cacheCfg == null)
            throw new NullPointerException();
        if (cacheName == null)
            throw new NullPointerException();
        CacheConfiguration<K, V> igniteCacheCfg;
        if (cacheCfg instanceof CompleteConfiguration)
            igniteCacheCfg = new CacheConfiguration<>((CompleteConfiguration<K, V>) cacheCfg);
        else {
            igniteCacheCfg = new CacheConfiguration<>();
            igniteCacheCfg.setTypes(cacheCfg.getKeyType(), cacheCfg.getValueType());
        }
        igniteCacheCfg.setName(cacheName);
        IgniteCache<K, V> res = ignite.createCache(igniteCacheCfg);
        if (res == null)
            throw new CacheException();
        ((IgniteCacheProxy<K, V>) res).setCacheManager(this);
        if (igniteCacheCfg.isManagementEnabled())
            enableManagement(cacheName, true);
        if (igniteCacheCfg.isStatisticsEnabled())
            enableStatistics(cacheName, true);
        return res;
    } finally {
        kernalGateway.readUnlock();
    }
}
Also used : CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) CacheException(javax.cache.CacheException) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 90 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class CacheManager method enableManagement.

/** {@inheritDoc} */
@Override
public void enableManagement(String cacheName, boolean enabled) {
    kernalGateway.readLock();
    try {
        IgniteCache<?, ?> cache = getCache0(cacheName);
        if (cache == null)
            throw new CacheException("Cache not found: " + cacheName);
        if (enabled)
            registerCacheObject(cache.mxBean(), cacheName, CACHE_CONFIGURATION);
        else
            unregisterCacheObject(cacheName, CACHE_CONFIGURATION);
        cache.getConfiguration(CacheConfiguration.class).setManagementEnabled(enabled);
    } finally {
        kernalGateway.readUnlock();
    }
}
Also used : CacheException(javax.cache.CacheException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheException (javax.cache.CacheException)144 Ignite (org.apache.ignite.Ignite)42 IgniteException (org.apache.ignite.IgniteException)36 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)26 Transaction (org.apache.ignite.transactions.Transaction)25 ArrayList (java.util.ArrayList)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 IgniteCache (org.apache.ignite.IgniteCache)18 CountDownLatch (java.util.concurrent.CountDownLatch)17 List (java.util.List)16 Map (java.util.Map)16 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)15 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)13 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)13 HashMap (java.util.HashMap)12 IgniteTransactions (org.apache.ignite.IgniteTransactions)12 CyclicBarrier (java.util.concurrent.CyclicBarrier)11 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)10 Cache (javax.cache.Cache)9