Search in sources :

Example 56 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class DynamoDBStore method initialize.

/**
 * Initialize the data store by reading the credentials, setting the client's properties up and
 * reading the mapping file. Initialize is called when then the call to
 * {@link org.apache.gora.store.DataStoreFactory#createDataStore} is made.
 *
 * @param keyClass
 * @param persistentClass
 * @param properties
 */
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
    try {
        LOG.debug("Initializing DynamoDB store");
        setDynamoDBProperties(properties);
        dynamoDbStore = DynamoDBFactory.buildDynamoDBStore(getSerializationType());
        dynamoDbStore.setDynamoDBStoreHandler(this);
        dynamoDbStore.initialize(keyClass, persistentClass, properties);
    } 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) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 57 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class DynamoDBStore method deleteSchema.

@Override
public void deleteSchema() throws GoraException {
    try {
        if (getDynamoDbMapping().getTables().isEmpty())
            // Nothing to delete
            return;
        if (preferredSchema == null) {
            LOG.debug("Delete schemas");
            if (getDynamoDbMapping().getTables().isEmpty())
                throw new IllegalStateException("There are not tables defined.");
            // read the mapping object
            for (String tableName : getDynamoDbMapping().getTables().keySet()) executeDeleteTableRequest(tableName);
            LOG.debug("All schemas deleted successfully.");
        } else {
            LOG.debug("create schema " + preferredSchema);
            executeDeleteTableRequest(preferredSchema);
        }
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) GoraException(org.apache.gora.util.GoraException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 58 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class GoraDynamoDBCompiler method readMapping.

/**
 * Reads the schema file and converts it into a data structure to be used
 * @param pMapFile
 *          schema file to be mapped into a table
 * @return
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private DynamoDBMapping readMapping(File pMapFile) throws IOException {
    DynamoDBMappingBuilder mappingBuilder = new DynamoDBMappingBuilder();
    try {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(pMapFile);
        if (doc == null || doc.getRootElement() == null)
            throw new GoraException("Unable to load " + MAPPING_FILE + ". Please check its existance!");
        Element root = doc.getRootElement();
        List<Element> tableElements = root.getChildren("table");
        boolean keys = false;
        for (Element tableElement : tableElements) {
            String tableName = tableElement.getAttributeValue("name");
            long readCapacUnits = Long.parseLong(tableElement.getAttributeValue("readcunit"));
            long writeCapacUnits = Long.parseLong(tableElement.getAttributeValue("writecunit"));
            this.packageName = tableElement.getAttributeValue("package");
            mappingBuilder.setProvisionedThroughput(tableName, readCapacUnits, writeCapacUnits);
            log.debug("Table properties have been set for name, package and provisioned throughput.");
            // Retrieving attributes
            List<Element> fieldElements = tableElement.getChildren("attribute");
            for (Element fieldElement : fieldElements) {
                String key = fieldElement.getAttributeValue("key");
                String attributeName = fieldElement.getAttributeValue("name");
                String attributeType = fieldElement.getAttributeValue("type");
                mappingBuilder.addAttribute(tableName, attributeName, attributeType);
                // Retrieving key's features
                if (key != null) {
                    mappingBuilder.setKeySchema(tableName, attributeName, key);
                    keys = true;
                }
            }
            log.debug("Attributes for table '{}' have been read.", tableName);
            if (!keys)
                log.warn("Keys for table '{}' have NOT been set.", tableName);
        }
    } catch (IOException ex) {
        log.error("Error while performing xml mapping.", ex.getMessage());
        throw new RuntimeException(ex);
    } catch (Exception ex) {
        log.error("An error occured whilst reading the xml mapping file!", ex.getMessage());
        throw new IOException(ex);
    }
    return mappingBuilder.build();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) GoraException(org.apache.gora.util.GoraException) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) Element(org.jdom.Element) DynamoDBMappingBuilder(org.apache.gora.dynamodb.store.DynamoDBMapping.DynamoDBMappingBuilder) IOException(java.io.IOException) Document(org.jdom.Document) IOException(java.io.IOException) GoraException(org.apache.gora.util.GoraException)

Example 59 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class JCacheStore method execute.

@Override
public Result<K, T> execute(Query<K, T> query) throws GoraException {
    K startKey = query.getStartKey();
    K endKey = query.getEndKey();
    if (startKey == null) {
        if (!cacheEntryList.isEmpty()) {
            startKey = (K) cacheEntryList.first();
        }
    }
    if (endKey == null) {
        if (!cacheEntryList.isEmpty()) {
            endKey = (K) cacheEntryList.last();
        }
    }
    query.setFields(getFieldsToQuery(query.getFields()));
    NavigableSet<K> cacheEntrySubList = null;
    if (startKey != null && endKey != null) {
        try {
            cacheEntrySubList = cacheEntryList.subSet(startKey, true, endKey, true);
        } catch (Exception e) {
            throw new GoraException(e);
        }
    } else {
        // Empty
        cacheEntrySubList = Collections.emptyNavigableSet();
    }
    return new JCacheResult<>(this, query, cacheEntrySubList);
}
Also used : GoraException(org.apache.gora.util.GoraException) JCacheResult(org.apache.gora.jcache.query.JCacheResult) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 60 with GoraException

use of org.apache.gora.util.GoraException in project gora by apache.

the class InfinispanStore method deleteByQuery.

@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
    try {
        ((InfinispanQuery<K, T>) query).build();
        LOG.debug("deleteByQuery(" + query.toString() + ")");
        InfinispanQuery<K, T> q = (InfinispanQuery) query;
        q.build();
        for (T t : q.list()) {
            infinispanClient.deleteByKey((K) t.get(primaryFieldPos));
        }
        return q.getResultSize();
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) InfinispanQuery(org.apache.gora.infinispan.query.InfinispanQuery) IOException(java.io.IOException) GoraException(org.apache.gora.util.GoraException)

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