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);
}
}
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);
}
}
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);
}
}
}
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();
}
}
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);
}
}
Aggregations