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);
}
}
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);
}
}
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();
}
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);
}
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);
}
}
Aggregations