Examples of DbEntity


Examples of org.apache.cayenne.map.DbEntity

            // these will be initailzed every time a new target entity
            // is found in the result set (which should be ordered by table name among
            // other things)
            DbRelationship forwardRelationship = null;
            DbRelationshipDetected reverseRelationship = null;
            DbEntity fkEntity = null;

            do {
                short keySeq = rs.getShort("KEY_SEQ");
                if (keySeq == 1) {

                    if (forwardRelationship != null) {
                        postprocessMasterDbRelationship(forwardRelationship);
                        forwardRelationship = null;
                    }

                    // start new entity
                    String fkEntityName = rs.getString("FKTABLE_NAME");
                    String fkName = rs.getString("FK_NAME");
                   
                    if (!includeTableName(fkEntityName)) {
                        continue;
                    }
                   
                    fkEntity = map.getDbEntity(fkEntityName);

                    if (fkEntity == null) {
                        logObj.info("FK warning: no entity found for name '"
                                + fkEntityName
                                + "'");
                    } else if (skippedEntities.contains(pkEntity) && skippedEntities.contains(fkEntity)) {
                        // cay-479 - don't load relationships between two
                        // skipped entities.
                        continue;
                    }
                    else {

                        // init relationship
                        forwardRelationship = new DbRelationship(DbLoader
                                .uniqueRelName(pkEntity, fkEntityName, true));

                        forwardRelationship.setSourceEntity(pkEntity);
                        forwardRelationship.setTargetEntity(fkEntity);
                        pkEntity.addRelationship(forwardRelationship);

                        reverseRelationship = new DbRelationshipDetected(uniqueRelName(
                                fkEntity,
                                pkEntName,
                                false));
                        reverseRelationship.setFkName(fkName);
                        reverseRelationship.setToMany(false);
                        reverseRelationship.setSourceEntity(fkEntity);
                        reverseRelationship.setTargetEntity(pkEntity);
                        fkEntity.addRelationship(reverseRelationship);
                    }
                }

                if (fkEntity != null) {
                    // 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.DbEntity

                validator.registerWarning("ObjRelationship "
                        + objRelationshipIdentifier(rel)
                        + " has no DbRelationship mapping.", path);
            }
            else {
                DbEntity expectedSrc = ((ObjEntity) rel.getSourceEntity()).getDbEntity();
                DbEntity expectedTarget = ((ObjEntity) rel.getTargetEntity())
                        .getDbEntity();

                if ((dbRels.get(0)).getSourceEntity() != expectedSrc
                        || (dbRels.get(dbRels.size() - 1))
                                .getTargetEntity() != expectedTarget) {
View Full Code Here

Examples of org.apache.cayenne.map.DbEntity

            // root DbEntity
            {
                DbEntityClassDescriptor dbEntityDescriptor = new DbEntityClassDescriptor(
                        descriptor);
                DbEntity dbEntity = dbEntityDescriptor.getDbEntity();

                Collection<DbEntityClassDescriptor> descriptors = descriptorsByDbEntity
                        .get(dbEntity);
                if (descriptors == null) {
                    descriptors = new ArrayList<DbEntityClassDescriptor>(1);
                    dbEntities.add(dbEntity);
                    descriptorsByDbEntity.put(dbEntity, descriptors);
                }

                descriptors.add(dbEntityDescriptor);
            }

            // secondary DbEntities...

            // Note that this logic won't allow flattened attributes to span multiple
            // databases...
            for (ObjAttribute objAttribute : descriptor.getEntity().getAttributes()) {

                if (objAttribute.isFlattened()) {
                    DbEntityClassDescriptor dbEntityDescriptor = new DbEntityClassDescriptor(
                            descriptor,
                            objAttribute);

                    DbEntity dbEntity = dbEntityDescriptor.getDbEntity();
                    Collection<DbEntityClassDescriptor> descriptors = descriptorsByDbEntity
                            .get(dbEntity);

                    if (descriptors == null) {
                        descriptors = new ArrayList<DbEntityClassDescriptor>(1);
View Full Code Here

Examples of org.apache.cayenne.map.DbEntity

        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) {
                StringBuilder msg = new StringBuilder();
                msg
                        .append("DB_NAME expressions can only support ")
                        .append("targets with a single column PK. ")
View Full Code Here

Examples of org.apache.cayenne.map.DbEntity

    @Override
    protected boolean interceptPaginatedQuery() {
        if (metadata.getPageSize() > 0) {

            DbEntity dbEntity = metadata.getDbEntity();
            List<?> paginatedList = dbEntity != null
                    && dbEntity.getPrimaryKeys().size() == 1
                    ? new SimpleIdIncrementalFaultList<Object>(
                            (DataContext) actingContext,
                            query)
                    : new IncrementalFaultList<Object>((DataContext) actingContext, query);
View Full Code Here

Examples of org.apache.cayenne.map.DbEntity

    private void appendJoinSubtree(Appendable out, JoinTreeNode node) throws IOException {

        DbRelationship relationship = node.getRelationship();

        DbEntity targetEntity = (DbEntity) relationship.getTargetEntity();
        String srcAlias = node.getSourceTableAlias();
        String targetAlias = node.getTargetTableAlias();

        switch (node.getJoinType()) {
            case INNER:
                out.append(" JOIN");
                break;
            case LEFT_OUTER:
                out.append(" LEFT JOIN");
                break;
            default:
                throw new IllegalArgumentException("Unsupported join type: "
                        + node.getJoinType());
        }

        out.append(' ').append(targetEntity.getFullyQualifiedName()).append(' ').append(
                targetAlias).append(" ON (");

        List<DbJoin> joins = relationship.getJoins();
        int len = joins.size();
        for (int i = 0; i < len; i++) {
View Full Code Here

Examples of org.apache.cayenne.map.DbEntity

        attributes = new HashMap<String, DbAttribute>(rel.getJoins().size() * 2);

        if (rel.isToMany() || !rel.isToPK()) {

            // match on target PK
            DbEntity ent = (DbEntity) rel.getTargetEntity();

            // index by name
            for (DbAttribute pkAttr : ent.getPrimaryKeys()) {
                attributes.put(pkAttr.getName(), pkAttr);
            }
        }
        else {

View Full Code Here

Examples of org.apache.cayenne.map.DbEntity

    public String createSqlString() throws Exception {
        StringBuffer queryBuf = new StringBuffer();
        queryBuf.append("UPDATE ");

        // 1. append table name
        DbEntity dbEnt = getRootEntity().getDbEntity();
        queryBuf.append(dbEnt.getFullyQualifiedName());

        // 2. build "set ..." clause
        buildSetClause(queryBuf, (UpdateQuery) query);

        // 3. build qualifier
View Full Code Here

Examples of org.apache.cayenne.map.DbEntity

        Iterator attrIt = updAttrs.entrySet().iterator();

        if (!attrIt.hasNext())
            throw new CayenneRuntimeException("Nothing to update.");

        DbEntity dbEnt = getRootEntity().getDbEntity();
        queryBuf.append(" SET ");

        // append updated attribute values
        boolean appendedSomething = false;

        // now process other attrs in the loop
        while (attrIt.hasNext()) {
            Map.Entry entry = (Map.Entry) attrIt.next();
            String nextKey = (String) entry.getKey();
            Object attrVal = entry.getValue();

            if (appendedSomething)
                queryBuf.append(", ");

            queryBuf.append(nextKey).append(" = ?");
            super.addToParamList((DbAttribute) dbEnt.getAttribute(nextKey), attrVal);
            appendedSomething = true;
        }
    }
View Full Code Here

Examples of org.apache.cayenne.map.DbEntity

    @Override
    public String createSqlString() throws Exception {
        StringBuilder queryBuf = new StringBuilder("DELETE FROM ");

        // 1. append table name
        DbEntity dbEnt = getRootDbEntity();
        queryBuf.append(dbEnt.getFullyQualifiedName());

        // 2. build qualifier
        StringBuilder qualifier = new StringBuilder();
        adapter.getQualifierTranslator(this).appendPart(qualifier);
        if (qualifier.length() > 0)
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.