/** * Validates that given cache key has overridden equals and hashCode methods and * implements {@link Externalizable}. * * @param key Cache key. * @throws IllegalArgumentException If validation fails. */ protected final void validateCacheKey(Object key) { if (keyCheck) { CU.validateCacheKey(key); keyCheck = false; } }
/** * Validates that given cache keys have overridden equals and hashCode methods and * implement {@link Externalizable}. * * @param keys Cache keys. * @throws IgniteException If validation fails. */ protected final void validateCacheKeys(Iterable<?> keys) { if (keys == null) return; if (keyCheck) { for (Object key : keys) { if (key == null || key instanceof GridCacheInternal) continue; CU.validateCacheKey(key); keyCheck = false; } } }
@Override public Void call() throws Exception { CU.validateCacheKey(key); return null; } }, IllegalArgumentException.class, null);
/** */ @Test public void testCacheKeyValidation() throws IgniteCheckedException { CU.validateCacheKey("key"); CU.validateCacheKey(1); CU.validateCacheKey(1L); CU.validateCacheKey(1.0); CU.validateCacheKey(new ExtendsClassWithEqualsAndHashCode()); CU.validateCacheKey(new ExtendsClassWithEqualsAndHashCode2()); assertThrowsForInvalidKey(new NoEqualsAndHashCode()); assertThrowsForInvalidKey(new NoEquals()); assertThrowsForInvalidKey(new NoHashCode()); assertThrowsForInvalidKey(new WrongEquals()); BinaryObjectBuilderImpl binBuilder = new BinaryObjectBuilderImpl(binaryContext(), EqualsAndHashCode.class.getName()); BinaryObject binObj = binBuilder.build(); CU.validateCacheKey(binObj); BinaryObjectBuilderImpl binBuilder2 = new BinaryObjectBuilderImpl((BinaryObjectImpl) binObj); CU.validateCacheKey(binBuilder2.build()); }
/** * Validates that given cache key has overridden equals and hashCode methods and * implements {@link Externalizable}. * * @param key Cache key. * @throws IllegalArgumentException If validation fails. */ protected final void validateCacheKey(Object key) { if (keyCheck) { CU.validateCacheKey(key); keyCheck = false; } }
/** * Validates that given cache keys have overridden equals and hashCode methods and * implement {@link Externalizable}. * * @param keys Cache keys. * @throws IgniteException If validation fails. */ protected final void validateCacheKeys(Iterable<?> keys) { if (keys == null) return; if (keyCheck) { for (Object key : keys) { if (key == null || key instanceof GridCacheInternal) continue; CU.validateCacheKey(key); keyCheck = false; } } }