Package org.apache.cayenne.map

Examples of org.apache.cayenne.map.DbAttribute


    if(currentRow == null)
      return;

    ObjEntity objEntity = currentRow.getObjEntity();
    for (ObjAttribute attr : objEntity.getAttributes()) {
      DbAttribute dbAttribute = attr.getDbAttribute();
      if(dbAttribute.isGenerated() || dbAttribute.isForeignKey())
        continue;
      addField(jp, y++, attr, currentRow);
    }
    for (ObjRelationship rel : objEntity.getRelationships()) {
      if(rel.isToMany())
View Full Code Here


    if(currentRow == null)
      return false;

    ObjEntity objEntity = currentRow.getObjEntity();
    for (ObjAttribute attr : objEntity.getAttributes()) {
      DbAttribute dbAttribute = attr.getDbAttribute();
      if(dbAttribute.isGenerated() || dbAttribute.isForeignKey())
        continue;

      final Object value_frm = data.get(attr).getValue();
      final Object value_db = currentRow.readProperty(attr.getName());
View Full Code Here

        // before saving objects, let's manually access PKGenerator to get a base PK value
        // for comparison
        DbEntity joinTableEntity = context.getEntityResolver().getDbEntity(
                joinTable.getTableName());
        DbAttribute pkAttribute = (DbAttribute) joinTableEntity.getAttribute("ID");
        Number pk = (Number) adapter.getPkGenerator().generatePk(node, pkAttribute);

        GeneratedF1 f1 = context.newObject(GeneratedF1.class);
        GeneratedF2 f2 = context.newObject(GeneratedF2.class);
        f1.addToF2(f2);
View Full Code Here

            else {
                out.append(" AND ");
            }

            String key = it.next();
            DbAttribute attr = objectMatchTranslator.getAttribute(key);
            Object val = objectMatchTranslator.getValue(key);

            processColumn(attr);
            out.append(objectMatchTranslator.getOperation());
            appendLiteral(val, attr, objectMatchTranslator.getExpression());
View Full Code Here

        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

        // ... handle special case - PK.size == 1
        // use some not-so-significant optimizations...

        if (pk.size() == 1) {
            DbAttribute attribute = pk.iterator().next();

            String key = (prefix) ? namePrefix + attribute.getName() : attribute
                    .getName();

            Object val = dataRow.get(key);

            // this is possible when processing left outer joint prefetches
            if (val == null) {
                return null;
            }

            // PUT without a prefix
            return new ObjectId(objEntity.getName(), attribute.getName(), val);
        }

        // ... handle generic case - PK.size > 1

        Map<String, Object> idMap = new HashMap<String, Object>(pk.size() * 2);
        for (final DbAttribute attribute : pk) {

            String key = (prefix) ? namePrefix + attribute.getName() : attribute
                    .getName();

            Object val = dataRow.get(key);

            // this is possible when processing left outer joint prefetches
            if (val == null) {
                return null;
            }

            // PUT without a prefix
            idMap.put(attribute.getName(), val);
        }

        return new ObjectId(objEntity.getName(), idMap);
    }
View Full Code Here

        DbEntity dae = getDbEntity(map, "ARTIST");
        assertNotNull(
                "Null 'ARTIST' entity, other DbEntities: " + map.getDbEntityMap(),
                dae);
        assertEquals("ARTIST", dae.getName().toUpperCase());
        DbAttribute a = getDbAttribute(dae, "ARTIST_ID");
        assertNotNull(a);
        assertTrue(a.isPrimaryKey());
    }
View Full Code Here

    }

    private void assertLobDbEntities(DataMap map) {
        DbEntity blobEnt = getDbEntity(map, "BLOB_TEST");
        assertNotNull(blobEnt);
        DbAttribute blobAttr = getDbAttribute(blobEnt, "BLOB_COL");
        assertNotNull(blobAttr);
        assertTrue(msgForTypeMismatch(Types.BLOB, blobAttr), Types.BLOB == blobAttr
                .getType()
                || Types.LONGVARBINARY == blobAttr.getType());
        DbEntity clobEnt = getDbEntity(map, "CLOB_TEST");
        assertNotNull(clobEnt);
        DbAttribute clobAttr = getDbAttribute(clobEnt, "CLOB_COL");
        assertNotNull(clobAttr);
        assertTrue(msgForTypeMismatch(Types.CLOB, clobAttr), Types.CLOB == clobAttr
                .getType()
                || Types.LONGVARCHAR == clobAttr.getType());
    }
View Full Code Here

        return de;
    }

    private DbAttribute getDbAttribute(DbEntity ent, String name) {
        DbAttribute da = (DbAttribute) ent.getAttribute(name);
        // sometimes table names get converted to lowercase
        if (da == null) {
            da = (DbAttribute) ent.getAttribute(name.toLowerCase());
        }
View Full Code Here

     */
    public void checkTypes(DataMap map) {
        DbEntity dbe = getDbEntity(map, "PAINTING");
        DbEntity floatTest = getDbEntity(map, "FLOAT_TEST");
        DbEntity smallintTest = getDbEntity(map, "SMALLINT_TEST");
        DbAttribute integerAttr = getDbAttribute(dbe, "PAINTING_ID");
        DbAttribute decimalAttr = getDbAttribute(dbe, "ESTIMATED_PRICE");
        DbAttribute varcharAttr = getDbAttribute(dbe, "PAINTING_TITLE");
        DbAttribute floatAttr = getDbAttribute(floatTest, "FLOAT_COL");
        DbAttribute smallintAttr = getDbAttribute(smallintTest, "SMALLINT_COL");

        // check decimal
        assertTrue(
                msgForTypeMismatch(Types.DECIMAL, decimalAttr),
                Types.DECIMAL == decimalAttr.getType()
                        || Types.NUMERIC == decimalAttr.getType());
        assertEquals(2, decimalAttr.getScale());

        // check varchar
        assertEquals(
                msgForTypeMismatch(Types.VARCHAR, varcharAttr),
                Types.VARCHAR,
                varcharAttr.getType());
        assertEquals(255, varcharAttr.getMaxLength());
        // check integer
        assertEquals(
                msgForTypeMismatch(Types.INTEGER, integerAttr),
                Types.INTEGER,
                integerAttr.getType());
        // check float
        assertTrue(msgForTypeMismatch(Types.FLOAT, floatAttr), Types.FLOAT == floatAttr
                .getType()
                || Types.DOUBLE == floatAttr.getType()
                || Types.REAL == floatAttr.getType());

        // check smallint
        assertTrue(
                msgForTypeMismatch(Types.SMALLINT, smallintAttr),
                Types.SMALLINT == smallintAttr.getType()
                        || Types.INTEGER == smallintAttr.getType());
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.map.DbAttribute

Copyright © 2018 www.massapicom. 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.