Search in sources :

Example 21 with GoraException

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

the class IgniteStore method deleteByQuery.

@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
    String deleteQuery;
    if (query.getFields() != null && query.getFields().length < igniteMapping.getFields().size()) {
        List<String> dbFields = new ArrayList<>();
        for (String af : query.getFields()) {
            dbFields.add(igniteMapping.getFields().get(af).getName());
        }
        deleteQuery = IgniteSQLBuilder.createDeleteQueryWithFields(igniteMapping, dbFields);
    } else {
        deleteQuery = IgniteSQLBuilder.createDeleteQueryMultipleRecords(igniteMapping);
    }
    String selectQueryWhere = IgniteSQLBuilder.createWhereClause(igniteMapping, query.getStartKey(), query.getEndKey(), query.getLimit());
    try (PreparedStatement stmt = connection.prepareStatement(deleteQuery + selectQueryWhere)) {
        IgniteSQLBuilder.fillWhereClause(stmt, query.getStartKey(), query.getEndKey());
        stmt.executeUpdate();
        return 0;
    } catch (SQLException ex) {
        throw new GoraException(ex);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 22 with GoraException

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

the class IgniteStore method put.

@Override
public void put(K key, T obj) throws GoraException {
    try {
        if (obj.isDirty()) {
            Schema schema = obj.getSchema();
            List<Schema.Field> fields = schema.getFields();
            Map<Column, Object> data = new HashMap<>();
            if (igniteMapping.getPrimaryKey().size() == 1) {
                Column getKey = igniteMapping.getPrimaryKey().get(0);
                data.put(getKey, key);
            } else {
            // Composite keys pending..
            }
            for (Schema.Field field : fields) {
                Column mappedColumn = igniteMapping.getFields().get(field.name());
                Object fieldValue = obj.get(field.pos());
                if (mappedColumn != null && fieldValue != null) {
                    Schema fieldSchema = field.schema();
                    Object serializedObj = serializeFieldValue(fieldSchema, fieldValue);
                    data.put(mappedColumn, serializedObj);
                }
            }
            String baseInsertStatement = IgniteSQLBuilder.createInsertQuery(igniteMapping, data);
            try (PreparedStatement stmt = connection.prepareStatement(baseInsertStatement)) {
                IgniteSQLBuilder.fillInsertQuery(stmt, data);
                stmt.executeUpdate();
            } catch (SQLException ex) {
                throw new GoraException(ex);
            }
        } else {
            LOG.info("Ignored putting object {} in the store as it is neither " + "new, neither dirty.", new Object[] { obj });
        }
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SQLException(java.sql.SQLException) Schema(org.apache.avro.Schema) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException) GoraException(org.apache.gora.util.GoraException)

Example 23 with GoraException

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

the class HiveDataContext method executeHiveQL.

/**
 * Execute hive query sql
 *
 * @param hiveQuery query to be executed
 * @throws GoraException throw if a SQLException is thrown
 */
public void executeHiveQL(String hiveQuery) throws GoraException {
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Executing the query : {}", hiveQuery);
        }
        Connection connection = getDataContext().getConnection();
        Statement statement = connection.createStatement();
        statement.execute(hiveQuery);
        statement.close();
    } catch (SQLException e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 24 with GoraException

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

the class IgniteStoreMetadataAnalyzer method initialize.

@Override
public void initialize() throws GoraException {
    try {
        Properties createProps = DataStoreFactory.createProps();
        igniteParameters = IgniteParameters.load(createProps);
        connection = IgniteStore.acquireConnection(igniteParameters);
    } catch (ClassNotFoundException | SQLException ex) {
        throw new GoraException(ex);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) SQLException(java.sql.SQLException) Properties(java.util.Properties)

Example 25 with GoraException

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

the class HiveStore method put.

/**
 * Put an persistent object into the hive store Though we use a key value, currently hive does not
 * validate integrity constraints and Hive server may not support update queries on a particular
 * key
 *
 * @param key the key of the object.
 * @param obj the Persistent object.
 * @throws GoraException throws if putting object is failed
 */
@Override
public void put(K key, T obj) throws GoraException {
    try {
        List<Object> parementerList = new ArrayList<>();
        String sql = queryBuilder.buildInsertQuery(key, obj, fieldMap, parementerList);
        PreparedStatement statement = dataContext.getPreparedStatement(sql);
        for (int i = 0; i < parementerList.size(); i++) {
            statement.setObject(i + 1, parementerList.get(i));
        }
        statement.execute();
    } catch (IOException | SQLException e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) 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