use of org.apache.gora.util.GoraException in project gora by apache.
the class AccumuloStore method readMapping.
protected AccumuloMapping readMapping(String filename) throws IOException {
try {
AccumuloMapping mapping = new AccumuloMapping();
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document dom = db.parse(getClass().getClassLoader().getResourceAsStream(filename));
Element root = dom.getDocumentElement();
NodeList nl = root.getElementsByTagName("class");
for (int i = 0; i < nl.getLength(); i++) {
Element classElement = (Element) nl.item(i);
if (classElement.getAttribute("keyClass").equals(keyClass.getCanonicalName()) && classElement.getAttribute("name").equals(persistentClass.getCanonicalName())) {
mapping.tableName = getSchemaName(classElement.getAttribute("table"), persistentClass);
mapping.encoder = classElement.getAttribute("encoder");
NodeList fields = classElement.getElementsByTagName("field");
for (int j = 0; j < fields.getLength(); j++) {
Element fieldElement = (Element) fields.item(j);
String name = fieldElement.getAttribute("name");
String family = fieldElement.getAttribute("family");
String qualifier = fieldElement.getAttribute("qualifier");
if ("".equals(qualifier))
qualifier = null;
Pair<Text, Text> col = new Pair<>(new Text(family), qualifier == null ? null : new Text(qualifier));
mapping.fieldMap.put(name, col);
mapping.columnMap.put(col, name);
}
}
}
if (mapping.tableName == null) {
throw new GoraException("Please define the accumulo 'table' name mapping in " + filename + " for " + persistentClass.getCanonicalName());
}
nl = root.getElementsByTagName("table");
for (int i = 0; i < nl.getLength(); i++) {
Element tableElement = (Element) nl.item(i);
if (tableElement.getAttribute("name").equals(mapping.tableName)) {
NodeList configs = tableElement.getElementsByTagName("config");
for (int j = 0; j < configs.getLength(); j++) {
Element configElement = (Element) configs.item(j);
String key = configElement.getAttribute("key");
String val = configElement.getAttribute("value");
mapping.tableConfig.put(key, val);
}
}
}
return mapping;
} catch (Exception ex) {
throw new IOException("Unable to read " + filename, ex);
}
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class DataStoreFactory method getDataStore.
/**
* Instantiate a new {@link DataStore}. Uses default properties. Uses 'null' schema.
*
* @param <K> The class of keys in the datastore.
* @param <T> The class of persistent objects in the datastore.
* @param dataStoreClass The datastore implementation class <i>as string</i>.
* @param keyClass The key class <i>as string</i>.
* @param persistentClass The value class <i>as string</i>.
* @param props Gora properties configuration
* @param conf {@link Configuration} to be used be the store.
* @return A new store instance.
* @throws GoraException If any error occurred.
*/
@SuppressWarnings({ "unchecked" })
public static <K, T extends Persistent> DataStore<K, T> getDataStore(String dataStoreClass, String keyClass, String persistentClass, Properties props, Configuration conf) throws GoraException {
try {
Class<? extends DataStore<K, T>> c = (Class<? extends DataStore<K, T>>) Class.forName(dataStoreClass);
Class<K> k = (Class<K>) ClassLoadingUtils.loadClass(keyClass);
Class<T> p = (Class<T>) ClassLoadingUtils.loadClass(persistentClass);
if (props == null || props.size() == 0) {
props = createProps();
}
return createDataStore(c, k, p, conf, props, null);
} catch (GoraException ex) {
throw ex;
} catch (Exception ex) {
throw new GoraException(ex);
}
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class WSDataStoreFactory method getDataStore.
/**
* Instantiate a new {@link DataStore}. Uses default properties. Uses 'null' schema.
*
* @param dataStoreClass The datastore implementation class <i>as string</i>.
* @param keyClass The key class <i>as string</i>.
* @param persistentClass The value class <i>as string</i>.
* @param auth an authentication {@link Object} to be used for communication.
* @return A new store instance.
* @throws GoraException
*/
@SuppressWarnings({ "unchecked" })
public static <K, T extends Persistent> DataStore<K, T> getDataStore(String dataStoreClass, String keyClass, String persistentClass, Object auth) throws GoraException {
try {
Class<? extends DataStore<K, T>> c = (Class<? extends DataStore<K, T>>) Class.forName(dataStoreClass);
Class<K> k = (Class<K>) ClassLoadingUtils.loadClass(keyClass);
Class<T> p = (Class<T>) ClassLoadingUtils.loadClass(persistentClass);
return createDataStore(c, k, p, auth, createProps(), null);
} catch (GoraException ex) {
throw ex;
} catch (Exception ex) {
throw new GoraException(ex);
}
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class WSDataStoreFactory method getDataStore.
/**
* Instantiate <i>the default</i> {@link DataStore}. Uses default properties. Uses 'null' schema.
*
* @param keyClass The key class.
* @param persistent The value class.
* @param auth an authentication {@link Object} to be used for communication.
* @return A new store instance.
* @throws GoraException
*/
@SuppressWarnings("unchecked")
public static <K, T extends Persistent> DataStore<K, T> getDataStore(Class<K> keyClass, Class<T> persistent, Object auth) throws GoraException {
Properties createProps = createProps();
Class<? extends DataStore<K, T>> c;
try {
c = (Class<? extends DataStore<K, T>>) Class.forName(getDefaultDataStore(createProps));
} catch (Exception ex) {
throw new GoraException(ex);
}
return createDataStore(c, keyClass, persistent, auth, createProps, null);
}
use of org.apache.gora.util.GoraException in project gora by apache.
the class HBaseStore method createSchema.
@Override
public void createSchema() throws GoraException {
Admin admin = null;
try {
admin = table.getAdmin();
if (schemaExists()) {
return;
}
TableDescriptor tableDesc = mapping.getTable();
admin.createTable(tableDesc);
} catch (GoraException e) {
throw e;
} catch (Exception e) {
throw new GoraException(e);
} finally {
try {
if (admin != null) {
admin.close();
}
} catch (IOException e) {
LOG.error("An error occurred whilst closing HBase Admin. ", e);
}
}
}
Aggregations