use of org.apache.gora.util.GoraException in project gora by apache.
the class JCacheCacheLoader method load.
@Override
public T load(K key) throws CacheLoaderException {
T persistent = null;
try {
persistent = dataStore.get(key);
LOG.info("Loaded data bean from persistent datastore on key {}.", key.toString());
} catch (GoraException ex) {
throw new CacheLoaderException(ex);
}
return persistent;
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class JCacheCacheWriter method write.
@Override
public void write(Cache.Entry<? extends K, ? extends T> entry) throws CacheWriterException {
try {
dataStore.put(entry.getKey(), entry.getValue());
LOG.info("Written data bean to persistent datastore on key {}.", entry.getKey().toString());
} catch (GoraException e) {
throw new CacheWriterException(e);
}
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class JCacheStore method createSchema.
@Override
public void createSchema() throws GoraException {
try {
if (manager.getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass) == null) {
cacheEntryList.clear();
cache = manager.createCache(persistentClass.getSimpleName(), cacheConfig);
}
cache.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(JCacheCacheFactoryBuilder.factoryOfEntryListener(new JCacheCacheEntryListener<K, T>(cacheEntryList)), null, true, true));
persistentDataStore.createSchema();
LOG.info("Created schema on persistent store and initialized cache for persistent bean {}.", super.getPersistentClass().getSimpleName());
} catch (GoraException e) {
throw e;
} catch (Exception e) {
throw new GoraException(e);
}
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class JCacheStore method initialize.
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
super.initialize(keyClass, persistentClass, properties);
String cachingProviderKey = properties.getProperty(GORA_DEFAULT_JCACHE_PROVIDER_KEY);
if (cachingProviderKey != null) {
cachingProvider = Caching.getCachingProvider(cachingProviderKey);
} else {
cachingProvider = Caching.getCachingProvider();
}
try {
this.persistentDataStore = DataStoreFactory.getDataStore(keyClass, persistentClass, new Configuration());
} catch (GoraException ex) {
LOG.error("Couldn't initialize persistent DataStore.", ex);
throw ex;
}
manager = cachingProvider.getCacheManager();
if (((properties.getProperty(JCACHE_AUTO_CREATE_CACHE_PROPERTY_KEY) != null) && Boolean.valueOf(properties.getProperty(JCACHE_AUTO_CREATE_CACHE_PROPERTY_KEY))) || ((manager.getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass) == null))) {
cacheEntryList = new ConcurrentSkipListSet<>();
MutableConfiguration mutableCacheConfig = new MutableConfiguration<>();
mutableCacheConfig.setTypes(keyClass, persistentClass);
if (properties.getProperty(JCACHE_READ_THROUGH_PROPERTY_KEY) != null) {
mutableCacheConfig.setReadThrough(Boolean.valueOf(properties.getProperty(JCACHE_READ_THROUGH_PROPERTY_KEY)));
} else {
mutableCacheConfig.setReadThrough(true);
}
if (properties.getProperty(JCACHE_WRITE_THROUGH_PROPERTY_KEY) != null) {
mutableCacheConfig.setWriteThrough(Boolean.valueOf(properties.getProperty(JCACHE_WRITE_THROUGH_PROPERTY_KEY)));
} else {
mutableCacheConfig.setWriteThrough(true);
}
if (properties.getProperty(JCACHE_STORE_BY_VALUE_PROPERTY_KEY) != null) {
mutableCacheConfig.setStoreByValue(Boolean.valueOf(properties.getProperty(JCACHE_STORE_BY_VALUE_PROPERTY_KEY)));
}
if (properties.getProperty(JCACHE_STATISTICS_PROPERTY_KEY) != null) {
mutableCacheConfig.setStatisticsEnabled(Boolean.valueOf(properties.getProperty(JCACHE_STATISTICS_PROPERTY_KEY)));
}
if (properties.getProperty(JCACHE_MANAGEMENT_PROPERTY_KEY) != null) {
mutableCacheConfig.setStatisticsEnabled(Boolean.valueOf(properties.getProperty(JCACHE_MANAGEMENT_PROPERTY_KEY)));
}
if (properties.getProperty(JCACHE_EXPIRE_POLICY_PROPERTY_KEY) != null) {
String expiryPolicyIdentifier = properties.getProperty(JCACHE_EXPIRE_POLICY_PROPERTY_KEY);
if (expiryPolicyIdentifier.equals(JCACHE_ACCESSED_EXPIRY_IDENTIFIER)) {
mutableCacheConfig.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new AccessedExpiryPolicy(new Duration(TimeUnit.SECONDS, Integer.valueOf(properties.getProperty(JCACHE_EXPIRE_POLICY_DURATION_PROPERTY_KEY))))));
} else if (expiryPolicyIdentifier.equals(JCACHE_CREATED_EXPIRY_IDENTIFIER)) {
mutableCacheConfig.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, Integer.valueOf(properties.getProperty(JCACHE_EXPIRE_POLICY_DURATION_PROPERTY_KEY))))));
} else if (expiryPolicyIdentifier.equals(JCACHE_MODIFIED_EXPIRY_IDENTIFIER)) {
mutableCacheConfig.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new ModifiedExpiryPolicy(new Duration(TimeUnit.SECONDS, Integer.valueOf(properties.getProperty(JCACHE_EXPIRE_POLICY_DURATION_PROPERTY_KEY))))));
} else if (expiryPolicyIdentifier.equals(JCACHE_TOUCHED_EXPIRY_IDENTIFIER)) {
mutableCacheConfig.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new TouchedExpiryPolicy(new Duration(TimeUnit.SECONDS, Integer.valueOf(properties.getProperty(JCACHE_EXPIRE_POLICY_DURATION_PROPERTY_KEY))))));
}
}
mutableCacheConfig.setCacheLoaderFactory(JCacheCacheFactoryBuilder.factoryOfCacheLoader(this.persistentDataStore, keyClass, persistentClass));
mutableCacheConfig.setCacheWriterFactory(JCacheCacheFactoryBuilder.factoryOfCacheWriter(this.persistentDataStore, keyClass, persistentClass));
cache = manager.createCache(persistentClass.getSimpleName(), mutableCacheConfig);
cacheConfig = mutableCacheConfig;
} else {
cache = manager.getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass);
this.populateLocalCacheEntrySet(cache);
}
cache.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(JCacheCacheFactoryBuilder.factoryOfEntryListener(new JCacheCacheEntryListener<K, T>(cacheEntryList)), null, true, true));
LOG.info("JCache Gora datastore initialized successfully.");
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class OrientDBStore method execute.
/**
* {@inheritDoc}
*/
@Override
public Result<K, T> execute(Query<K, T> query) throws GoraException {
String[] fields = getFieldsToQuery(query.getFields());
OrientDBQuery dataStoreQuery;
if (query instanceof OrientDBQuery) {
dataStoreQuery = ((OrientDBQuery) query);
} else {
dataStoreQuery = (OrientDBQuery) ((PartitionQueryImpl<K, T>) query).getBaseQuery();
}
dataStoreQuery.populateOrientDBQuery(orientDBMapping, fields, getFields());
try (ODatabaseDocumentTx selectTx = connectionPool.acquire()) {
selectTx.activateOnCurrentThread();
OConcurrentResultSet<ODocument> result = selectTx.command(dataStoreQuery.getOrientDBQuery()).execute(dataStoreQuery.getParams());
result.setLimit((int) query.getLimit());
return new OrientDBResult<K, T>(this, query, result);
} catch (Exception e) {
throw new GoraException(e);
}
}
Aggregations