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