Search in sources :

Example 91 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class Oracle8LOBInsertBatchTranslator method getValuesForLOBUpdateParameters.

@Override
List<Object> getValuesForLOBUpdateParameters(BatchQueryRow row) {
    List<DbAttribute> dbAttributes = query.getDbAttributes();
    int len = dbAttributes.size();
    List<Object> values = new ArrayList<>(len);
    for (int i = 0; i < len; i++) {
        Object value = row.getValue(i);
        DbAttribute attribute = dbAttributes.get(i);
        if (isUpdateableColumn(value, attribute.getType())) {
            values.add(value);
        }
    }
    return values;
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) ArrayList(java.util.ArrayList)

Example 92 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class Oracle8LOBUpdateBatchTranslator method getValuesForLOBUpdateParameters.

@Override
List<Object> getValuesForLOBUpdateParameters(BatchQueryRow row) {
    int len = query.getDbAttributes().size();
    UpdateBatchQuery updateBatch = (UpdateBatchQuery) query;
    List<Object> values = new ArrayList<>(len);
    List<DbAttribute> qualifierAttributes = updateBatch.getQualifierAttributes();
    List<DbAttribute> updatedDbAttributes = updateBatch.getUpdatedAttributes();
    int updatedLen = updatedDbAttributes.size();
    int qualifierLen = qualifierAttributes.size();
    for (int i = 0; i < updatedLen; i++) {
        DbAttribute attribute = updatedDbAttributes.get(i);
        Object value = row.getValue(i);
        if (isUpdateableColumn(value, attribute.getType())) {
            values.add(value);
        }
    }
    for (int i = 0; i < qualifierLen; i++) {
        values.add(row.getValue(updatedLen + i));
    }
    return values;
}
Also used : UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) ArrayList(java.util.ArrayList) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 93 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class OracleAdapter method updatesLOBColumns.

/**
 * Utility method that returns <code>true</code> if the query will update at
 * least one BLOB or CLOB DbAttribute.
 *
 * @since 1.2
 */
static boolean updatesLOBColumns(BatchQuery query) {
    boolean isInsert = query instanceof InsertBatchQuery;
    boolean isUpdate = query instanceof UpdateBatchQuery;
    if (!isInsert && !isUpdate) {
        return false;
    }
    List<DbAttribute> updatedAttributes = (isInsert) ? query.getDbAttributes() : ((UpdateBatchQuery) query).getUpdatedAttributes();
    for (DbAttribute attr : updatedAttributes) {
        int type = attr.getType();
        if (type == Types.CLOB || type == Types.BLOB) {
            return true;
        }
    }
    return false;
}
Also used : InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 94 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class PostgresBatchAction method prepareStatement.

@Override
protected PreparedStatement prepareStatement(Connection connection, String queryStr, DbAdapter adapter, boolean generatedKeys) throws SQLException {
    if (generatedKeys) {
        Collection<DbAttribute> generatedAttributes = query.getDbEntity().getGeneratedAttributes();
        String[] generatedPKColumns = new String[generatedAttributes.size()];
        int i = 0;
        for (DbAttribute generatedAttribute : generatedAttributes) {
            if (generatedAttribute.isPrimaryKey()) {
                generatedPKColumns[i++] = generatedAttribute.getName().toLowerCase();
            }
        }
        return connection.prepareStatement(queryStr, Arrays.copyOf(generatedPKColumns, i));
    }
    return connection.prepareStatement(queryStr);
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 95 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class DbAttributePathComboBoxEditor method createTreeModelForComboBox.

@Override
protected EntityTreeModel createTreeModelForComboBox(int attributeIndexInTable) {
    ObjAttribute attribute = model.getAttribute(attributeIndexInTable).getValue();
    Entity firstEntity = null;
    if (attribute.getDbAttribute() == null) {
        if (attribute.getParent() instanceof ObjEntity) {
            DbEntity dbEnt = ((ObjEntity) attribute.getParent()).getDbEntity();
            if (dbEnt != null) {
                Collection<DbAttribute> attributes = dbEnt.getAttributes();
                Collection<DbRelationship> rel = dbEnt.getRelationships();
                if (!attributes.isEmpty()) {
                    Iterator<DbAttribute> iterator = attributes.iterator();
                    firstEntity = iterator.next().getEntity();
                } else if (!rel.isEmpty()) {
                    Iterator<DbRelationship> iterator = rel.iterator();
                    firstEntity = iterator.next().getSourceEntity();
                }
            }
        }
    } else {
        firstEntity = getFirstEntity(attribute);
    }
    if (firstEntity != null) {
        EntityTreeModel treeModel = new EntityTreeModel(firstEntity);
        treeModel.setFilter(new EntityTreeAttributeRelationshipFilter());
        return treeModel;
    }
    return null;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) Iterator(java.util.Iterator)

Aggregations

DbAttribute (org.apache.cayenne.map.DbAttribute)194 DbEntity (org.apache.cayenne.map.DbEntity)109 Test (org.junit.Test)67 ObjEntity (org.apache.cayenne.map.ObjEntity)36 DbRelationship (org.apache.cayenne.map.DbRelationship)35 ObjAttribute (org.apache.cayenne.map.ObjAttribute)32 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)21 DbJoin (org.apache.cayenne.map.DbJoin)18 HashMap (java.util.HashMap)16 ObjRelationship (org.apache.cayenne.map.ObjRelationship)16 ArrayList (java.util.ArrayList)14 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)12 DataMap (org.apache.cayenne.map.DataMap)11 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)10 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)10 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)10 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)10 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)10 ObjectId (org.apache.cayenne.ObjectId)9 Expression (org.apache.cayenne.exp.Expression)8