Search in sources :

Example 16 with CacheException

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

the class CacheJdbcPojoStore method buildBinaryObject.

/**
     * Construct binary object from query result.
     *
     * @param typeName Type name.
     * @param fields Fields descriptors.
     * @param loadColIdxs Select query columns index.
     * @param rs ResultSet.
     * @return Constructed binary object.
     * @throws CacheLoaderException If failed to construct binary object.
     */
protected Object buildBinaryObject(String typeName, JdbcTypeField[] fields, Map<String, Integer> loadColIdxs, ResultSet rs) throws CacheLoaderException {
    try {
        BinaryObjectBuilder builder = ignite.binary().builder(typeName);
        for (JdbcTypeField field : fields) {
            Integer colIdx = columnIndex(loadColIdxs, field.getDatabaseFieldName());
            Object colVal = transformer.getColumnValue(rs, colIdx, field.getJavaFieldType());
            builder.setField(field.getJavaFieldName(), colVal, (Class<Object>) field.getJavaFieldType());
        }
        return builder.build();
    } catch (SQLException e) {
        throw new CacheException("Failed to read binary object: " + typeName, e);
    }
}
Also used : SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 17 with CacheException

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

the class CacheAbstractJdbcStore method checkTypeConfiguration.

/**
     * Checks if type configured properly.
     *
     * @param cacheName Cache name to check mapping for.
     * @param typeName Type name.
     * @param flds Fields descriptors.
     * @throws CacheException If failed to check type configuration.
     */
private void checkTypeConfiguration(@Nullable String cacheName, TypeKind kind, String typeName, JdbcTypeField[] flds) throws CacheException {
    try {
        if (kind == TypeKind.BUILT_IN) {
            if (flds.length != 1)
                throw new CacheException("More than one field for built in type " + "[cache=" + U.maskName(cacheName) + ", type=" + typeName + " ]");
            JdbcTypeField field = flds[0];
            if (field.getDatabaseFieldName() == null)
                throw new CacheException("Missing database name in mapping description [cache=" + U.maskName(cacheName) + ", type=" + typeName + " ]");
            field.setJavaFieldType(Class.forName(typeName));
        } else
            for (JdbcTypeField field : flds) {
                if (field.getDatabaseFieldName() == null)
                    throw new CacheException("Missing database name in mapping description " + "[cache=" + U.maskName(cacheName) + ", type=" + typeName + " ]");
                if (field.getJavaFieldName() == null)
                    throw new CacheException("Missing field name in mapping description " + "[cache=" + U.maskName(cacheName) + ", type=" + typeName + " ]");
                if (field.getJavaFieldType() == null)
                    throw new CacheException("Missing field type in mapping description " + "[cache=" + U.maskName(cacheName) + ", type=" + typeName + " ]");
            }
    } catch (ClassNotFoundException e) {
        throw new CacheException("Failed to find class: " + typeName, e);
    }
}
Also used : CacheException(javax.cache.CacheException)

Example 18 with CacheException

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

the class CacheManager method unregisterCacheObject.

/**
     * UnRegisters the mxbean if registered already.
     *
     * @param name Cache name.
     * @param beanType Mxbean name.
     */
private void unregisterCacheObject(String name, String beanType) {
    MBeanServer mBeanSrv = ignite.configuration().getMBeanServer();
    Set<ObjectName> registeredObjNames = mBeanSrv.queryNames(getObjectName(name, beanType), null);
    //should just be one
    for (ObjectName registeredObjectName : registeredObjNames) {
        try {
            mBeanSrv.unregisterMBean(registeredObjectName);
        } catch (Exception e) {
            throw new CacheException("Error unregistering object instance " + registeredObjectName + " . Error was " + e.getMessage(), e);
        }
    }
}
Also used : CacheException(javax.cache.CacheException) CacheException(javax.cache.CacheException) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 19 with CacheException

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

the class CacheManager method enableStatistics.

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

Example 20 with CacheException

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

the class CacheManager method registerCacheObject.

/**
     * @param mxbean MXBean.
     * @param name Cache name.
     * @param beanType Bean type.
     */
private void registerCacheObject(Object mxbean, String name, String beanType) {
    MBeanServer mBeanSrv = ignite.configuration().getMBeanServer();
    ObjectName registeredObjName = getObjectName(name, beanType);
    try {
        if (mBeanSrv.queryNames(registeredObjName, null).isEmpty()) {
            IgniteStandardMXBean bean = beanType.equals(CACHE_CONFIGURATION) ? new IgniteStandardMXBean((CacheMXBean) mxbean, CacheMXBean.class) : new IgniteStandardMXBean((CacheStatisticsMXBean) mxbean, CacheStatisticsMXBean.class);
            mBeanSrv.registerMBean(bean, registeredObjName);
        }
    } catch (Exception e) {
        throw new CacheException("Failed to register MBean: " + registeredObjName, e);
    }
}
Also used : CacheStatisticsMXBean(javax.cache.management.CacheStatisticsMXBean) CacheException(javax.cache.CacheException) IgniteStandardMXBean(org.apache.ignite.internal.mxbean.IgniteStandardMXBean) CacheMXBean(javax.cache.management.CacheMXBean) CacheException(javax.cache.CacheException) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

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