use of siena.SienaException in project siena by mandubian.
the class HBaseDdlGenerator method dropTables.
public void dropTables() {
HBaseConfiguration config = new HBaseConfiguration();
try {
HBaseAdmin admin = new HBaseAdmin(config);
HTableDescriptor[] descriptors = admin.listTables();
for (HTableDescriptor hTableDescriptor : descriptors) {
String name = hTableDescriptor.getNameAsString();
admin.disableTable(name);
admin.deleteTable(name);
}
} catch (IOException e) {
throw new SienaException(e);
}
}
use of siena.SienaException in project siena by mandubian.
the class AbstractConnectionManager method beginTransaction.
public void beginTransaction() {
try {
Connection c = getConnection();
c.setAutoCommit(false);
} catch (SQLException e) {
logger.severe(e, e);
throw new SienaException(e);
}
}
use of siena.SienaException in project siena by mandubian.
the class H2PersistenceManager method save.
@Override
public void save(Object obj) {
JdbcClassInfo classInfo = JdbcClassInfo.getClassInfo(obj.getClass());
List<String> keyNames = new ArrayList<String>();
for (Field field : classInfo.keys) {
keyNames.add(field.getName());
}
PreparedStatement ps = null;
try {
Field idField = classInfo.info.getIdField();
Object idVal = Util.readField(obj, idField);
if (idVal == null) {
insert(obj);
} else {
// in H2 "on duplicate" is not supported but MERGE is
// merge into employees (id, first_name, last_name) values(1, 'test2', 'test2');
List<String> allColumns = new ArrayList<String>();
JdbcClassInfo.calculateColumns(classInfo.allFields, allColumns, null, "");
String[] is = new String[allColumns.size()];
Arrays.fill(is, "?");
ps = getConnection().prepareStatement("MERGE INTO " + classInfo.tableName + " (" + Util.join(allColumns, ",") + ") " + "VALUES(" + Util.join(Arrays.asList(is), ",") + ")");
int i = 1;
i = addParameters(obj, classInfo.allFields, ps, i);
ps.executeUpdate();
}
} catch (SienaException e) {
throw e;
} catch (Exception e) {
throw new SienaException(e);
} finally {
JdbcDBUtils.closeStatementAndConnection(this, ps);
}
}
use of siena.SienaException in project siena by mandubian.
the class GaePersistenceManager method mapJoins.
protected <T> T mapJoins(Query<T> query, T model) {
try {
// join queries
Map<Field, ArrayList<Key>> fieldMap = GaeQueryUtils.buildJoinFieldKeysMap(query);
// creates the list of joined entity keys to extract
for (Field field : fieldMap.keySet()) {
Key key = GaeMappingUtils.getKey(field.get(model));
List<Key> keys = fieldMap.get(field);
if (!keys.contains(key))
keys.add(key);
}
Map<Field, Map<Key, Entity>> entityMap = new HashMap<Field, Map<Key, Entity>>();
try {
// retrieves all joined entities per field
for (Field field : fieldMap.keySet()) {
Map<Key, Entity> entities = ds.get(fieldMap.get(field));
entityMap.put(field, entities);
}
} catch (Exception ex) {
throw new SienaException(ex);
}
// associates linked models to their models
// linkedModels is just a map to contain entities already mapped
Map<Key, Object> linkedModels = new HashMap<Key, Object>();
Object linkedObj;
Entity entity;
for (Field field : fieldMap.keySet()) {
Object objVal = field.get(model);
Key key = GaeMappingUtils.getKey(objVal);
linkedObj = linkedModels.get(key);
if (linkedObj == null) {
entity = entityMap.get(field).get(key);
linkedObj = objVal;
GaeMappingUtils.fillModel(linkedObj, entity);
linkedModels.put(key, linkedObj);
}
field.set(model, linkedObj);
}
return model;
} catch (IllegalAccessException ex) {
throw new SienaException(ex);
}
}
use of siena.SienaException in project siena by mandubian.
the class GaePersistenceManager method mapJoins.
protected <T> List<T> mapJoins(Query<T> query, List<T> models) {
try {
// join queries
Map<Field, ArrayList<Key>> fieldMap = GaeQueryUtils.buildJoinFieldKeysMap(query);
// creates the list of joined entity keys to extract
for (final T model : models) {
for (Field field : fieldMap.keySet()) {
Object objVal = Util.readField(model, field);
// our object is not linked to another object...so it doesn't have any key
if (objVal == null) {
continue;
}
Key key = GaeMappingUtils.getKey(objVal);
List<Key> keys = fieldMap.get(field);
if (!keys.contains(key))
keys.add(key);
}
}
Map<Field, Map<Key, Entity>> entityMap = new HashMap<Field, Map<Key, Entity>>();
try {
// retrieves all joined entities per field
for (Field field : fieldMap.keySet()) {
Map<Key, Entity> entities = ds.get(fieldMap.get(field));
// gets the future here because we need it so we wait for it
entityMap.put(field, entities);
}
} catch (Exception ex) {
throw new SienaException(ex);
}
// associates linked models to their models
// linkedModels is just a map to contain entities already mapped
Map<Key, Object> linkedModels = new HashMap<Key, Object>();
Object linkedObj;
Entity entity;
for (final T model : models) {
for (Field field : fieldMap.keySet()) {
Object objVal = Util.readField(model, field);
// our object is not linked to another object...so it doesn't have any key
if (objVal == null) {
continue;
}
Key key = GaeMappingUtils.getKey(objVal);
linkedObj = linkedModels.get(key);
if (linkedObj == null) {
entity = entityMap.get(field).get(key);
linkedObj = objVal;
GaeMappingUtils.fillModel(linkedObj, entity);
linkedModels.put(key, linkedObj);
}
field.set(model, linkedObj);
}
}
return models;
} catch (IllegalAccessException ex) {
throw new SienaException(ex);
}
}
Aggregations