Search in sources :

Example 71 with GoraException

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;
}
Also used : GoraException(org.apache.gora.util.GoraException) CacheLoaderException(javax.cache.integration.CacheLoaderException)

Example 72 with GoraException

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);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 73 with GoraException

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);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 74 with GoraException

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.");
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) Duration(javax.cache.expiry.Duration) AccessedExpiryPolicy(javax.cache.expiry.AccessedExpiryPolicy) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) MutableConfiguration(javax.cache.configuration.MutableConfiguration) GoraException(org.apache.gora.util.GoraException) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) ModifiedExpiryPolicy(javax.cache.expiry.ModifiedExpiryPolicy)

Example 75 with GoraException

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);
    }
}
Also used : OrientDBQuery(org.apache.gora.orientdb.query.OrientDBQuery) OrientDBResult(org.apache.gora.orientdb.query.OrientDBResult) GoraException(org.apache.gora.util.GoraException) PartitionQueryImpl(org.apache.gora.query.impl.PartitionQueryImpl) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

GoraException (org.apache.gora.util.GoraException)174 IOException (java.io.IOException)119 ArrayList (java.util.ArrayList)30 Schema (org.apache.avro.Schema)25 SQLException (java.sql.SQLException)17 HashMap (java.util.HashMap)17 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 PreparedStatement (java.sql.PreparedStatement)11 Map (java.util.Map)11 PersistentBase (org.apache.gora.persistency.impl.PersistentBase)9 SolrServerException (org.apache.solr.client.solrj.SolrServerException)9 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)8 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)8 Field (org.apache.avro.Schema.Field)8 KuduException (org.apache.kudu.client.KuduException)8 ResultSet (com.datastax.driver.core.ResultSet)7 SimpleStatement (com.datastax.driver.core.SimpleStatement)7 SAXBuilder (org.jdom.input.SAXBuilder)7 InputStream (java.io.InputStream)6