Search in sources :

Example 96 with SienaException

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);
    }
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) IOException(java.io.IOException) SienaException(siena.SienaException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 97 with SienaException

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SienaException(siena.SienaException)

Example 98 with SienaException

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);
    }
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) SienaException(siena.SienaException) SQLException(java.sql.SQLException) SienaException(siena.SienaException)

Example 99 with SienaException

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);
    }
}
Also used : Entity(com.google.appengine.api.datastore.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SienaException(siena.SienaException) EntityNotFoundException(com.google.appengine.api.datastore.EntityNotFoundException) Field(java.lang.reflect.Field) SienaException(siena.SienaException) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.google.appengine.api.datastore.Key)

Example 100 with SienaException

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);
    }
}
Also used : Entity(com.google.appengine.api.datastore.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SienaException(siena.SienaException) EntityNotFoundException(com.google.appengine.api.datastore.EntityNotFoundException) Field(java.lang.reflect.Field) SienaException(siena.SienaException) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.google.appengine.api.datastore.Key)

Aggregations

SienaException (siena.SienaException)214 Field (java.lang.reflect.Field)65 TransactionAccountFrom (siena.base.test.model.TransactionAccountFrom)52 ArrayList (java.util.ArrayList)46 IOException (java.io.IOException)40 SQLException (java.sql.SQLException)38 TransactionAccountTo (siena.base.test.model.TransactionAccountTo)34 SienaRestrictedApiException (siena.SienaRestrictedApiException)33 PreparedStatement (java.sql.PreparedStatement)25 ClassInfo (siena.ClassInfo)21 HashMap (java.util.HashMap)19 List (java.util.List)18 Discovery (siena.base.test.model.Discovery)18 Entity (com.google.appengine.api.datastore.Entity)15 Key (com.google.appengine.api.datastore.Key)14 ResultSet (java.sql.ResultSet)14 Id (siena.Id)14 AmazonClientException (com.amazonaws.AmazonClientException)12 Collection (java.util.Collection)10 DiscoveryStringId (siena.base.test.model.DiscoveryStringId)9