Examples of DbAttribute


Examples of org.apache.cayenne.map.DbAttribute

    }

    static class DbAttributeFactory extends ObjAttributeFactory {
        @Override
        protected Object create(String name, Object namingContext) {
            return new DbAttribute(
                name,
                TypesMapping.NOT_DEFINED,
                (DbEntity) namingContext);
        }
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

                            decimalDigits = -1;
                        }
                    }

                    // create attribute delegating this task to adapter
                    DbAttribute attr = adapter.buildAttribute(
                            columnName,
                            typeName,
                            columnType,
                            columnSize,
                            decimalDigits,
                            allowNulls);
                    attr.setEntity(dbEntity);
                    dbEntity.addAttribute(attr);
                }
            }
            finally {
                rs.close();
            }

            map.addDbEntity(dbEntity);

            // notify delegate
            if (delegate != null) {
                delegate.dbEntityAdded(dbEntity);
            }

            // delegate might have thrown this entity out... so check if it is still
            // around  before continuing processing
            if (map.getDbEntity(dbEntity.getName()) == dbEntity) {
                this.dbEntityList.add(dbEntity);
            }
        }
       
        // get primary keys for each table and store it in dbEntity
        for (final DbEntity dbEntity : map.getDbEntities()) {
            String tableName = dbEntity.getName();
            ResultSet rs = metaData.getPrimaryKeys(null, dbEntity.getSchema(), tableName);

            try {
                while (rs.next()) {
                    String keyName = rs.getString(4);
                    DbAttribute attribute = (DbAttribute) dbEntity.getAttribute(keyName);

                    if (attribute != null) {
                        attribute.setPrimaryKey(true);
                    }
                    else {
                        // why an attribute might be null is not quiet clear
                        // but there is a bug report 731406 indicating that it is possible
                        // so just print the warning, and ignore
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

                    // Create and append joins
                    String pkName = rs.getString("PKCOLUMN_NAME");
                    String fkName = rs.getString("FKCOLUMN_NAME");

                    // skip invalid joins...
                    DbAttribute pkAtt = (DbAttribute) pkEntity.getAttribute(pkName);
                    if (pkAtt == null) {
                        logObj.info("no attribute for declared primary key: "
                                + pkName);
                        continue;
                    }

                    DbAttribute fkAtt = (DbAttribute) fkEntity.getAttribute(fkName);
                    if (fkAtt == null) {
                        logObj.info("no attribute for declared foreign key: "
                                + fkName);
                        continue;
                    }
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

        if (values != null && values.size() > 0) {
            int len = values.size();
            for (int i = 0; i < len; i++) {
                Object val = values.get(i);

                DbAttribute attr = attributes.get(i);

                // null DbAttributes are a result of inferior qualifier processing
                // (qualifier can't map parameters to DbAttributes and therefore
                // only supports standard java types now)
                // hence, a special moronic case here:
                if (attr == null) {
                    stmt.setObject(i + 1, val);
                }
                else {
                    adapter.bindParameter(stmt, val, i + 1, attr.getType(), attr
                            .getScale());
                }
            }
        }
    }
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

        // if at least one of the sibling operands is a
        // OBJ_PATH or DB_PATH expression, use its attribute type as
        // a final answer.

        // find attribute or relationship matching the value
        DbAttribute attribute = null;
        DbRelationship relationship = null;
        for (int i = 0; i < len; i++) {
            Object op = e.getOperand(i);

            if (op instanceof Expression) {
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

            throw new CayenneRuntimeException(msg.toString());
        }

        DbJoin join = joins.get(0);

        DbAttribute attribute = null;

        if (rel.isToMany()) {
            DbEntity ent = (DbEntity) join.getRelationship().getTargetEntity();
            Collection<DbAttribute> pk = ent.getPrimaryKeys();
            if (pk.size() != 1) {
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

    Map<String, Object> createQualifierSnapshot(ObjectDiff diff) {
        int len = attributes.size();

        Map<String, Object> map = new HashMap<String, Object>(len * 2);
        for (int i = 0; i < len; i++) {
            DbAttribute attribute = attributes.get(i);
            if (!map.containsKey(attribute.getName())) {

                Object value = valueTransformers.get(i).transform(diff);
                map.put(attribute.getName(), value);
            }
        }

        return map;
    }
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

           
            DbRelationship masterDependentDbRel = descriptor.getPathFromMaster().get(0);

            if (masterDependentDbRel != null) {
                for (final DbJoin dbAttrPair : masterDependentDbRel.getJoins()) {
                    DbAttribute dbAttribute = dbAttrPair.getTarget();
                    if (!attributes.contains(dbAttribute)) {

                        attributes.add(dbAttribute);
                        valueTransformers.add(new Transformer() {

                            public Object transform(Object input) {
                                ObjectId id = (ObjectId) ((ObjectDiff) input).getNodeId();
                                return id.getIdSnapshot().get(dbAttrPair.getSourceName());
                            }
                        });
                    }
                }
            }
        }

        if (usingOptimisticLocking) {

            for (final ObjAttribute attribute : descriptor.getEntity().getAttributes()) {

                if (attribute.isUsedForLocking()) {
                    // only care about first step in a flattened attribute
                    DbAttribute dbAttribute = (DbAttribute) attribute
                            .getDbPathIterator()
                            .next();

                    if (!attributes.contains(dbAttribute)) {
                        attributes.add(dbAttribute);

                        valueTransformers.add(new Transformer() {

                            public Object transform(Object input) {
                                return ((ObjectDiff) input).getSnapshotValue(attribute
                                        .getName());
                            }
                        });
                    }
                }
            }

            for (final ObjRelationship relationship : descriptor
                    .getEntity()
                    .getRelationships()) {

                if (relationship.isUsedForLocking()) {
                    // only care about the first DbRelationship
                    DbRelationship dbRelationship = relationship
                            .getDbRelationships()
                            .get(0);

                    for (final DbJoin dbAttrPair : dbRelationship.getJoins()) {
                        DbAttribute dbAttribute = dbAttrPair.getSource();

                        // relationship transformers override attribute transformers for
                        // meaningful FK's... why meaningful FKs can go out of sync is
                        // another story (CAY-595)
                        int index = attributes.indexOf(dbAttribute);
                        if (index >= 0 && !dbAttribute.isForeignKey()) {
                            continue;
                        }

                        Transformer transformer = new Transformer() {
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

     * Indexes attributes
     */
    protected void indexQualifierAttributes() {
        int len = this.dbAttributes.size();
        for (int i = 0; i < len; i++) {
            DbAttribute attribute = this.dbAttributes.get(i);
            int type = attribute.getType();
            qualifierAttributes[i] = attribute.isPrimaryKey();
            allLOBAttributes[i] = (type == Types.BLOB || type == Types.CLOB);
        }
    }
View Full Code Here

Examples of org.apache.cayenne.map.DbAttribute

        List<DbAttribute> dbAttributes = query.getDbAttributes();
        int attributeCount = dbAttributes.size();

        // must use an independent counter "j" for prepared statement index
        for (int i = 0, j = 0; i < attributeCount; i++) {
            DbAttribute attribute = dbAttributes.get(i);
            if (includeInBatch(attribute)) {
                j++;
                Object value = query.getValue(i);
                adapter.bindParameter(statement, value, j, attribute.getType(), attribute
                        .getScale());
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.