Examples of PkGenerator


Examples of org.apache.cayenne.dba.PkGenerator

                        "Primary Key autogeneration only works for a single attribute.");
            }

            // finally, use database generation mechanism
            try {
                PkGenerator pkGenerator = node.getAdapter().getPkGenerator();
                Object pkValue = pkGenerator.generatePk(node, dbAttr);
                snapshot.put(dbAttrName, pkValue);
                autoPkDone = true;
            }
            catch (Exception ex) {
                throw new CayenneRuntimeException("Error generating PK: "
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

                        "Primary Key autogeneration only works for a single attribute.");
            }

            // finally, use database generation mechanism
            try {
                PkGenerator pkGenerator = node.getAdapter().getPkGenerator();
                Object pkValue = pkGenerator.generatePk(node, dbAttr);
                snapshot.put(dbAttrName, pkValue);
                autoPkDone = true;
            }
            catch (Exception ex) {
                throw new CayenneRuntimeException("Error generating PK: "
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

                        "Primary Key autogeneration only works for a single attribute.");
            }

            // finally, use database generation mechanism
            try {
                PkGenerator pkGenerator = node.getAdapter().getPkGenerator();
                Object pkValue = pkGenerator.generatePk(node, dbAttr);
                snapshot.put(dbAttrName, pkValue);
                autoPkDone = true;
            }
            catch (Exception ex) {
                throw new CayenneRuntimeException("Error generating PK: "
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

        DataContext context = (DataContext) this.context;
        DataDomain domain = context.getParentDataDomain();

        // setup mockup PK generator that will blow on PK request
        // to emulate an exception
        PkGenerator newGenerator = new JdbcPkGenerator(new JdbcAdapter()) {

            @Override
            public Object generatePk(DataNode node, DbAttribute pk) throws Exception {
                throw new CayenneRuntimeException("Intentional");
            }
        };

        PkGenerator oldGenerator = domain
                .getDataNodes()
                .iterator()
                .next()
                .getAdapter()
                .getPkGenerator();
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

            // build constraints
            createConstraints.put(name, createConstraintsQueries(dbe));
        }

        PkGenerator pkGenerator = adapter.getPkGenerator();
        dropPK = pkGenerator.dropAutoPkStatements(dbEntitiesRequiringAutoPK);
        createPK = pkGenerator.createAutoPkStatements(dbEntitiesRequiringAutoPK);
    }
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

        DbEntity entity = descriptor.getDbEntity();

        DataNode node = parent.getDomain().lookupDataNode(entity.getDataMap());
        boolean supportsGeneratedKeys = node.getAdapter().supportsGeneratedKeys();

        PkGenerator pkGenerator = node.getAdapter().getPkGenerator();

        for (Persistent object : objects) {
            ObjectId id = object.getObjectId();
            if (id == null || !id.isTemporary()) {
                continue;
            }

            // modify replacement id directly...
            Map<String, Object> idMap = id.getReplacementIdMap();

            boolean autoPkDone = false;

            for (DbAttribute dbAttr : entity.getPrimaryKeys()) {
                String dbAttrName = dbAttr.getName();

                if (idMap.containsKey(dbAttrName)) {
                    continue;
                }

                // handle meaningful PK
                ObjAttribute objAttr = objEntity.getAttributeForDbAttribute(dbAttr);
                if (objAttr != null) {

                    Object value = descriptor.getClassDescriptor().getProperty(
                            objAttr.getName()).readPropertyDirectly(object);

                    if (value != null) {
                        Class<?> javaClass = objAttr.getJavaClass();
                        if (javaClass.isPrimitive()
                                && value instanceof Number
                                && ((Number) value).intValue() == 0) {
                            // primitive 0 has to be treated as NULL, or otherwise we
                            // can't generate PK for POJO's
                        }
                        else {

                            idMap.put(dbAttrName, value);
                            continue;
                        }
                    }
                }

                // skip db-generated
                if (supportsGeneratedKeys && dbAttr.isGenerated()) {
                    continue;
                }

                // skip propagated
                if (isPropagated(dbAttr)) {
                    continue;
                }

                // only a single key can be generated from DB... if this is done already
                // in this loop, we must bail out.
                if (autoPkDone) {
                    throw new CayenneRuntimeException(
                            "Primary Key autogeneration only works for a single attribute.");
                }

                // finally, use database generation mechanism
                try {
                    Object pkValue = pkGenerator.generatePk(node, dbAttr);
                    idMap.put(dbAttrName, pkValue);
                    autoPkDone = true;
                }
                catch (Exception ex) {
                    throw new CayenneRuntimeException("Error generating PK: "
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

            // build constraints
            createConstraints.put(name, createConstraintsQueries(dbe));
        }

        PkGenerator pkGenerator = adapter.getPkGenerator();
        dropPK = pkGenerator.dropAutoPkStatements(dbEntitiesRequiringAutoPK);
        createPK = pkGenerator.createAutoPkStatements(dbEntitiesRequiringAutoPK);
    }
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

                        "Primary Key autogeneration only works for a single attribute.");
            }

            // finally, use database generation mechanism
            try {
                PkGenerator pkGenerator = node.getAdapter().getPkGenerator();
                Object pkValue = pkGenerator.generatePk(node, dbAttr);
                snapshot.put(dbAttrName, pkValue);
                autoPkDone = true;
            }
            catch (Exception ex) {
                throw new CayenneRuntimeException("Error generating PK: "
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

        DbEntity entity = descriptor.getDbEntity();

        DataNode node = parent.getDomain().lookupDataNode(entity.getDataMap());
        boolean supportsGeneratedKeys = node.getAdapter().supportsGeneratedKeys();

        PkGenerator pkGenerator = node.getAdapter().getPkGenerator();

        for (Persistent object : objects) {
            ObjectId id = object.getObjectId();
            if (id == null || !id.isTemporary()) {
                continue;
            }

            // modify replacement id directly...
            Map<String, Object> idMap = id.getReplacementIdMap();

            boolean autoPkDone = false;

            for (DbAttribute dbAttr : entity.getPrimaryKeys()) {
                String dbAttrName = dbAttr.getName();

                if (idMap.containsKey(dbAttrName)) {
                    continue;
                }

                // handle meaningful PK
                ObjAttribute objAttr = objEntity.getAttributeForDbAttribute(dbAttr);
                if (objAttr != null) {

                    Object value = descriptor.getClassDescriptor().getProperty(
                            objAttr.getName()).readPropertyDirectly(object);

                    if (value != null) {
                        Class<?> javaClass = objAttr.getJavaClass();
                        if (javaClass.isPrimitive()
                                && value instanceof Number
                                && ((Number) value).intValue() == 0) {
                            // primitive 0 has to be treated as NULL, or otherwise we
                            // can't generate PK for POJO's
                        }
                        else {

                            idMap.put(dbAttrName, value);
                            continue;
                        }
                    }
                }

                // skip db-generated
                if (supportsGeneratedKeys && dbAttr.isGenerated()) {
                    continue;
                }

                // skip propagated
                if (isPropagated(dbAttr)) {
                    continue;
                }

                // only a single key can be generated from DB... if this is done already
                // in this loop, we must bail out.
                if (autoPkDone) {
                    throw new CayenneRuntimeException(
                            "Primary Key autogeneration only works for a single attribute.");
                }

                // finally, use database generation mechanism
                try {
                    Object pkValue = pkGenerator.generatePk(node, dbAttr);
                    idMap.put(dbAttrName, pkValue);
                    autoPkDone = true;
                }
                catch (Exception ex) {
                    throw new CayenneRuntimeException("Error generating PK: "
View Full Code Here

Examples of org.apache.cayenne.dba.PkGenerator

            // build constraints
            createConstraints.put(name, createConstraintsQueries(dbe));
        }

        PkGenerator pkGenerator = adapter.getPkGenerator();
        dropPK = pkGenerator.dropAutoPkStatements(dbEntitiesRequiringAutoPK);
        createPK = pkGenerator.createAutoPkStatements(dbEntitiesRequiringAutoPK);
    }
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.