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