Examples of ObjAttribute


Examples of org.apache.cayenne.map.ObjAttribute

        assertTokensAndExecute(node, map, 1, 0);
        assertTokensAndExecute(node, map, 0, 0);

        ObjEntity objEntity = new ObjEntity("NewTable");
        objEntity.setDbEntity(dbEntity);
        ObjAttribute oatr1 = new ObjAttribute("name");
        oatr1.setDbAttributePath(column2.getName());
        oatr1.setType("java.lang.String");
        objEntity.addAttribute(oatr1);
        map.addObjEntity(objEntity);

        // try to insert some rows to check that pk stuff is working
        DataContext ctxt = createDataContext();
        DataMap sourceMap = map;//ctxt.getEntityResolver().getDataMap("testmap");

        try {
            sourceMap.addDbEntity(dbEntity);
            sourceMap.addObjEntity(objEntity);

            for (int i = 0; i < 5; i++) {
                CayenneDataObject dao = (CayenneDataObject) ctxt.newObject(objEntity
                        .getName());
                dao.writeProperty(oatr1.getName(), "test " + i);
            }
            ctxt.commitChanges();
        }
        finally {
            sourceMap.removeObjEntity(objEntity.getName(), true);
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

            return "untitledAttr";
        }

        @Override
        protected Object create(String name, Object namingContext) {
            return new ObjAttribute(name, null, (ObjEntity) namingContext);
        }
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

        assertTokensAndExecute(node, map, 1, 0);
        assertTokensAndExecute(node, map, 0, 0);

        ObjEntity objEntity = new ObjEntity("NewTable");
        objEntity.setDbEntity(dbEntity);
        ObjAttribute oatr1 = new ObjAttribute("name");
        oatr1.setDbAttributePath(column2.getName());
        oatr1.setType("java.lang.String");
        objEntity.addAttribute(oatr1);
        map.addObjEntity(objEntity);

        // force drop table in db
        MergerToken token = mergerFactory().createDropTableToDb(dbEntity);
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

        assertTokensAndExecute(node, map, 0, 0);

        // create ObjEntities
        ObjEntity objEntity1 = new ObjEntity("NewTable");
        objEntity1.setDbEntity(dbEntity1);
        ObjAttribute oatr1 = new ObjAttribute("name");
        oatr1.setDbAttributePath(e1col2.getName());
        oatr1.setType("java.lang.String");
        objEntity1.addAttribute(oatr1);
        map.addObjEntity(objEntity1);
        ObjEntity objEntity2 = new ObjEntity("NewTable2");
        objEntity2.setDbEntity(dbEntity2);
        ObjAttribute o2a1 = new ObjAttribute("name");
        o2a1.setDbAttributePath(e2col3.getName());
        o2a1.setType("java.lang.String");
        objEntity2.addAttribute(o2a1);
        map.addObjEntity(objEntity2);
       
        // create ObjRelationships
        assertEquals(0, objEntity1.getRelationships().size());
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

        assertTrue(dbEntity.getAttributes().contains(column));
        assertEquals(column, dbEntity.getAttribute(column.getName()));
        assertTokensAndExecute(node, map, 1, 0);

        // need obj attr to be able to query
        ObjAttribute objAttr = new ObjAttribute("newcol2");
        objAttr.setDbAttributePath(column.getName());
        objEntity.addAttribute(objAttr);

        // check that is was merged
        assertTokensAndExecute(node, map, 0, 0);

        // set not null
        column.setMandatory(true);

        // merge to db
        assertTokensAndExecute(node, map, 2, 0);

        // check that is was merged
        assertTokensAndExecute(node, map, 0, 0);

        // check values for null
        Expression qual = ExpressionFactory.matchExp(
                objAttr.getName(),
                DEFAULT_VALUE_STRING);
        SelectQuery query = new SelectQuery("Painting", qual);
        List<Persistent> rows = ctxt.performQuery(query);
        assertEquals(nrows, rows.size());
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

        assertTokensAndExecute(node, map, 1, 0);
        assertTokensAndExecute(node, map, 0, 0);

        ObjEntity objEntity = new ObjEntity("NewTable");
        objEntity.setDbEntity(dbEntity);
        ObjAttribute oatr1 = new ObjAttribute("name");
        oatr1.setDbAttributePath(column2.getName());
        oatr1.setType("java.lang.String");       
        objEntity.addAttribute(oatr1);
        map.addObjEntity(objEntity);

        // force drop name column in db
        MergerToken token = mergerFactory().createDropColumnToDb(dbEntity, column2);
        execute(token);

        List<MergerToken> tokens = createMergeTokens();
        assertEquals(1, tokens.size());
        token = tokens.get(0);
        if (token.getDirection().isToDb()) {
            token = token.createReverse(mergerFactory());
        }
        assertTrue(token instanceof DropColumnToModel);
        execute(token);
        assertNull(dbEntity.getAttribute(column2.getName()));
        assertNull(objEntity.getAttribute(oatr1.getName()));

        DataContext ctxt = createDataContext();

        // clear up
        map.removeObjEntity(objEntity.getName(), true);
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

        assertSame(rel2To1, rel1To2.getReverseRelationship());

        // create ObjEntities
        ObjEntity objEntity1 = new ObjEntity("NewTable");
        objEntity1.setDbEntity(dbEntity1);
        ObjAttribute oatr1 = new ObjAttribute("name");
        oatr1.setDbAttributePath(e1col2.getName());
        oatr1.setType("java.lang.String");
        objEntity1.addAttribute(oatr1);
        map.addObjEntity(objEntity1);
        ObjEntity objEntity2 = new ObjEntity("NewTable2");
        objEntity2.setDbEntity(dbEntity2);
        ObjAttribute o2a1 = new ObjAttribute("name");
        o2a1.setDbAttributePath(e2col3.getName());
        o2a1.setType("java.lang.String");
        objEntity2.addAttribute(o2a1);
        map.addObjEntity(objEntity2);
       
        // create ObjRelationships
        assertEquals(0, objEntity1.getRelationships().size());
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

        assertTokensAndExecute(node, map, 1, 0);
        assertTokensAndExecute(node, map, 0, 0);

        ObjEntity objEntity = new ObjEntity("NewTable");
        objEntity.setDbEntity(dbEntity);
        ObjAttribute oatr1 = new ObjAttribute("name");
        oatr1.setDbAttributePath(column2.getName());
        oatr1.setType("java.lang.String");
        objEntity.addAttribute(oatr1);
        map.addObjEntity(objEntity);

       
        // remove name column
        objEntity.removeAttribute(oatr1.getName());
        dbEntity.removeAttribute(column2.getName());
        assertNull(objEntity.getAttribute(oatr1.getName()));
        assertEquals(0, objEntity.getAttributes().size());
        assertNull(dbEntity.getAttribute(column2.getName()));

        List<MergerToken> tokens = createMergeTokens();
        assertEquals(1, tokens.size());
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

            // TODO: andrus, 2/20/2007 - handle embedded attribute
            if (next instanceof EmbeddedAttribute) {
                continue;
            }

            ObjAttribute objAttribute = (ObjAttribute) next;
            DbAttribute dbAttribute = objAttribute.getDbAttribute();

            if (dbAttribute == null) {
                throw new CayenneRuntimeException("ObjAttribute '"
                        + objAttribute.getName()
                        + "' does not have a corresponding DbAttribute");
            }

            // pk may still be generated
            if (dbAttribute.isPrimaryKey()) {
                continue;
            }

            Object value = this.readPropertyDirectly(objAttribute.getName());
            if (dbAttribute.isMandatory()) {
                ValidationFailure failure = BeanValidationFailure.validateNotNull(
                        this,
                        objAttribute.getName(),
                        value);

                if (failure != null) {

                    if (failedDbAttributes == null) {
                        failedDbAttributes = new HashMap<String, ValidationFailure>();
                    }

                    failedDbAttributes.put(dbAttribute.getName(), failure);
                    continue;
                }
            }

            // validate length
            if (value != null && dbAttribute.getMaxLength() > 0) {

                if (value.getClass().isArray()) {
                    int len = Array.getLength(value);
                    if (len > dbAttribute.getMaxLength()) {
                        String message = "\""
                                + objAttribute.getName()
                                + "\" exceeds maximum allowed length ("
                                + dbAttribute.getMaxLength()
                                + " bytes): "
                                + len;
                        validationResult.addFailure(new BeanValidationFailure(
                                this,
                                objAttribute.getName(),
                                message));
                    }
                }
                else if (value instanceof CharSequence) {
                    int len = ((CharSequence) value).length();
                    if (len > dbAttribute.getMaxLength()) {
                        String message = "\""
                                + objAttribute.getName()
                                + "\" exceeds maximum allowed length ("
                                + dbAttribute.getMaxLength()
                                + " chars): "
                                + len;
                        validationResult.addFailure(new BeanValidationFailure(
                                this,
                                objAttribute.getName(),
                                message));
                    }
                }
            }
        }
View Full Code Here

Examples of org.apache.cayenne.map.ObjAttribute

                        String path = node.getOperand(0).toString();
                        final DbAttribute attribute = (DbAttribute) dbEntity
                                .getAttribute(path);
                        if (attribute != null) {

                            ObjAttribute objectAttribute = descriptor
                                    .getEntity()
                                    .getAttributeForDbAttribute(attribute);

                            if (objectAttribute == null) {
                                objectAttribute = new ObjAttribute(attribute.getName()) {

                                    @Override
                                    public DbAttribute getDbAttribute() {
                                        return attribute;
                                    }
                                };

                                // we semi-officially DO NOT support inheritance
                                // descriptors based on related entities, so here we
                                // assume that DbAttribute is rooted in the root
                                // DbEntity, and no relationship is involved.
                                objectAttribute.setDbAttributePath(attribute.getName());
                                objectAttribute.setType(TypesMapping
                                        .getJavaBySqlType(attribute.getType()));
                            }

                            attributes.add(objectAttribute);
                        }
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.