Search in sources :

Example 6 with GoraException

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);
    }
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Document(org.w3c.dom.Document) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) GoraException(org.apache.gora.util.GoraException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) GoraException(org.apache.gora.util.GoraException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Pair(org.apache.accumulo.core.util.Pair)

Example 7 with GoraException

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

Example 8 with GoraException

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

Example 9 with GoraException

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

Example 10 with GoraException

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);
        }
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) GoraException(org.apache.gora.util.GoraException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

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