use of javax.cache.CacheException in project pratilipi by Pratilipi.
the class MemcacheGaeImpl method flush.
@Override
public void flush() {
try {
Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
cache.clear();
} catch (CacheException ex) {
logger.log(Level.SEVERE, "Failed to create cache instance.", ex);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteH2Indexing method queryDistributedSqlFields.
/** {@inheritDoc} */
@Override
public FieldsQueryCursor<List<?>> queryDistributedSqlFields(String schemaName, SqlFieldsQuery qry, boolean keepBinary, GridQueryCancel cancel, @Nullable Integer mainCacheId) {
final String sqlQry = qry.getSql();
Connection c = connectionForSchema(schemaName);
final boolean enforceJoinOrder = qry.isEnforceJoinOrder();
final boolean distributedJoins = qry.isDistributedJoins();
final boolean grpByCollocated = qry.isCollocated();
final DistributedJoinMode distributedJoinMode = distributedJoinMode(qry.isLocal(), distributedJoins);
GridCacheTwoStepQuery twoStepQry = null;
List<GridQueryFieldMetadata> meta;
final H2TwoStepCachedQueryKey cachedQryKey = new H2TwoStepCachedQueryKey(schemaName, sqlQry, grpByCollocated, distributedJoins, enforceJoinOrder, qry.isLocal());
H2TwoStepCachedQuery cachedQry = twoStepCache.get(cachedQryKey);
if (cachedQry != null) {
twoStepQry = cachedQry.query().copy();
meta = cachedQry.meta();
} else {
final UUID locNodeId = ctx.localNodeId();
// Here we will just parse the statement, no need to optimize it at all.
H2Utils.setupConnection(c, /*distributedJoins*/
false, /*enforceJoinOrder*/
true);
GridH2QueryContext.set(new GridH2QueryContext(locNodeId, locNodeId, 0, PREPARE).distributedJoinMode(distributedJoinMode));
PreparedStatement stmt = null;
Prepared prepared;
boolean cachesCreated = false;
try {
try {
while (true) {
try {
// Do not cache this statement because the whole query object will be cached later on.
stmt = prepareStatement(c, sqlQry, false);
break;
} catch (SQLException e) {
if (!cachesCreated && (e.getErrorCode() == ErrorCode.SCHEMA_NOT_FOUND_1 || e.getErrorCode() == ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1 || e.getErrorCode() == ErrorCode.INDEX_NOT_FOUND_1)) {
try {
ctx.cache().createMissingQueryCaches();
} catch (IgniteCheckedException ignored) {
throw new CacheException("Failed to create missing caches.", e);
}
cachesCreated = true;
} else
throw new IgniteSQLException("Failed to parse query: " + sqlQry, IgniteQueryErrorCode.PARSING, e);
}
}
prepared = GridSqlQueryParser.prepared(stmt);
if (qry instanceof JdbcSqlFieldsQuery && ((JdbcSqlFieldsQuery) qry).isQuery() != prepared.isQuery())
throw new IgniteSQLException("Given statement type does not match that declared by JDBC driver", IgniteQueryErrorCode.STMT_TYPE_MISMATCH);
if (prepared.isQuery()) {
bindParameters(stmt, F.asList(qry.getArgs()));
twoStepQry = GridSqlQuerySplitter.split((JdbcPreparedStatement) stmt, qry.getArgs(), grpByCollocated, distributedJoins, enforceJoinOrder, this);
assert twoStepQry != null;
}
} finally {
GridH2QueryContext.clearThreadLocal();
}
// It is a DML statement if we did not create a twoStepQuery.
if (twoStepQry == null) {
if (DmlStatementsProcessor.isDmlStatement(prepared)) {
try {
return dmlProc.updateSqlFieldsDistributed(schemaName, stmt, qry, cancel);
} catch (IgniteCheckedException e) {
throw new IgniteSQLException("Failed to execute DML statement [stmt=" + sqlQry + ", params=" + Arrays.deepToString(qry.getArgs()) + "]", e);
}
}
if (DdlStatementsProcessor.isDdlStatement(prepared)) {
try {
return ddlProc.runDdlStatement(sqlQry, stmt);
} catch (IgniteCheckedException e) {
throw new IgniteSQLException("Failed to execute DDL statement [stmt=" + sqlQry + ']', e);
}
}
}
LinkedHashSet<Integer> caches0 = new LinkedHashSet<>();
assert twoStepQry != null;
int tblCnt = twoStepQry.tablesCount();
if (mainCacheId != null)
caches0.add(mainCacheId);
if (tblCnt > 0) {
for (QueryTable tblKey : twoStepQry.tables()) {
GridH2Table tbl = dataTable(tblKey);
int cacheId = CU.cacheId(tbl.cacheName());
caches0.add(cacheId);
}
}
if (caches0.isEmpty())
twoStepQry.local(true);
else {
//Prohibit usage indices with different numbers of segments in same query.
List<Integer> cacheIds = new ArrayList<>(caches0);
checkCacheIndexSegmentation(cacheIds);
twoStepQry.cacheIds(cacheIds);
twoStepQry.local(qry.isLocal());
}
meta = H2Utils.meta(stmt.getMetaData());
} catch (IgniteCheckedException e) {
throw new CacheException("Failed to bind parameters: [qry=" + sqlQry + ", params=" + Arrays.deepToString(qry.getArgs()) + "]", e);
} catch (SQLException e) {
throw new IgniteSQLException(e);
} finally {
U.close(stmt, log);
}
}
if (log.isDebugEnabled())
log.debug("Parsed query: `" + sqlQry + "` into two step query: " + twoStepQry);
twoStepQry.pageSize(qry.getPageSize());
if (cancel == null)
cancel = new GridQueryCancel();
int[] partitions = qry.getPartitions();
if (partitions == null && twoStepQry.derivedPartitions() != null) {
try {
partitions = calculateQueryPartitions(twoStepQry.derivedPartitions(), qry.getArgs());
} catch (IgniteCheckedException e) {
throw new CacheException("Failed to calculate derived partitions: [qry=" + sqlQry + ", params=" + Arrays.deepToString(qry.getArgs()) + "]", e);
}
}
QueryCursorImpl<List<?>> cursor = new QueryCursorImpl<>(runQueryTwoStep(schemaName, twoStepQry, keepBinary, enforceJoinOrder, qry.getTimeout(), cancel, qry.getArgs(), partitions), cancel);
cursor.fieldsMeta(meta);
if (cachedQry == null && !twoStepQry.explain()) {
cachedQry = new H2TwoStepCachedQuery(meta, twoStepQry.copy());
twoStepCache.putIfAbsent(cachedQryKey, cachedQry);
}
return cursor;
}
use of javax.cache.CacheException in project ignite by apache.
the class GridQueryProcessor method querySqlFieldsNoCache.
/**
* Query SQL fields without strict dependency on concrete cache.
*
* @param qry Query.
* @param keepBinary Keep binary flag.
* @return Cursor.
*/
public FieldsQueryCursor<List<?>> querySqlFieldsNoCache(final SqlFieldsQuery qry, final boolean keepBinary) {
checkxEnabled();
validateSqlFieldsQuery(qry);
if (qry.isLocal())
throw new IgniteException("Local query is not supported without specific cache.");
if (qry.getSchema() == null)
qry.setSchema(QueryUtils.DFLT_SCHEMA);
if (!busyLock.enterBusy())
throw new IllegalStateException("Failed to execute query (grid is stopping).");
try {
IgniteOutClosureX<FieldsQueryCursor<List<?>>> clo = new IgniteOutClosureX<FieldsQueryCursor<List<?>>>() {
@Override
public FieldsQueryCursor<List<?>> applyx() throws IgniteCheckedException {
GridQueryCancel cancel = new GridQueryCancel();
return idx.queryDistributedSqlFields(qry.getSchema(), qry, keepBinary, cancel, null);
}
};
return executeQuery(GridCacheQueryType.SQL_FIELDS, qry.getSql(), null, clo, true);
} catch (IgniteCheckedException e) {
throw new CacheException(e);
} finally {
busyLock.leaveBusy();
}
}
use of javax.cache.CacheException in project ignite by apache.
the class CacheConfiguration method processAnnotationsInClass.
/**
* Process annotations for class.
*
* @param key If given class relates to key.
* @param cls Class.
* @param type Type descriptor.
* @param parent Parent in case of embeddable.
*/
private static void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor type, @Nullable ClassProperty parent) {
if (U.isJdk(cls) || QueryUtils.isGeometryClass(cls)) {
if (parent == null && !key && QueryUtils.isSqlType(cls)) {
// We have to index primitive _val.
String idxName = cls.getSimpleName() + "_" + QueryUtils.VAL_FIELD_NAME + "_idx";
type.addIndex(idxName, QueryUtils.isGeometryClass(cls) ? QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED);
type.addFieldToIndex(idxName, QueryUtils.VAL_FIELD_NAME, 0, false);
}
return;
}
if (parent != null && parent.knowsClass(cls))
throw new CacheException("Recursive reference found in type: " + cls.getName());
if (parent == null) {
// Check class annotation at top level only.
QueryTextField txtAnnCls = cls.getAnnotation(QueryTextField.class);
if (txtAnnCls != null)
type.valueTextIndex(true);
QueryGroupIndex grpIdx = cls.getAnnotation(QueryGroupIndex.class);
if (grpIdx != null)
type.addIndex(grpIdx.name(), QueryIndexType.SORTED);
QueryGroupIndex.List grpIdxList = cls.getAnnotation(QueryGroupIndex.List.class);
if (grpIdxList != null && !F.isEmpty(grpIdxList.value())) {
for (QueryGroupIndex idx : grpIdxList.value()) type.addIndex(idx.name(), QueryIndexType.SORTED);
}
}
for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
for (Field field : c.getDeclaredFields()) {
QuerySqlField sqlAnn = field.getAnnotation(QuerySqlField.class);
QueryTextField txtAnn = field.getAnnotation(QueryTextField.class);
if (sqlAnn != null || txtAnn != null) {
ClassProperty prop = new ClassProperty(field);
prop.parent(parent);
// Add parent property before its possible nested properties so that
// resulting parent column comes before columns corresponding to those
// nested properties in the resulting table - that way nested
// properties override will happen properly (first parent, then children).
type.addProperty(prop, key, true);
processAnnotation(key, sqlAnn, txtAnn, cls, c, field.getType(), prop, type);
}
}
}
}
use of javax.cache.CacheException in project caffeine by ben-manes.
the class JmxRegistration method getObjectName.
/** Returns the object name of the management bean. */
private static ObjectName getObjectName(Cache<?, ?> cache, MBeanType type) {
String cacheManagerName = sanitize(cache.getCacheManager().getURI().toString());
String cacheName = sanitize(cache.getName());
try {
String name = String.format("javax.cache:type=Cache%s,CacheManager=%s,Cache=%s", type, cacheManagerName, cacheName);
return new ObjectName(name);
} catch (MalformedObjectNameException e) {
String msg = String.format("Illegal ObjectName for cacheManager=[%s], cache=[%s]", cacheManagerName, cacheName);
throw new CacheException(msg, e);
}
}
Aggregations