Package org.apache.cayenne.jpa.map

Examples of org.apache.cayenne.jpa.map.JpaDiscriminatorColumn


                AnnotatedElement element,
                AnnotationProcessorStack context) {

            DiscriminatorColumn annotation = element
                    .getAnnotation(DiscriminatorColumn.class);
            entity.setDiscriminatorColumn(new JpaDiscriminatorColumn(annotation));
        }
View Full Code Here


                dbRelationship.setToDependentPK(true);
                dbRelationship.setToMany(false);
            }

            // init discriminator column
            JpaDiscriminatorColumn discriminator = entity.lookupDiscriminatorColumn();
            if (discriminator != null) {

                if (cayennePrimaryTable.getAttribute(discriminator.getName()) == null) {
                    DbAttribute dbAttribute = new DbAttribute(discriminator.getName());

                    switch (discriminator.getDiscriminatorType()) {
                        case CHAR:
                            dbAttribute.setType(Types.CHAR);
                            dbAttribute.setMaxLength(1);
                            break;
                        case STRING:
                            dbAttribute.setType(Types.VARCHAR);
                            dbAttribute.setMaxLength(discriminator.getLength());
                            break;
                        case INTEGER:
                            dbAttribute.setType(Types.INTEGER);
                            break;
                    }

                    dbAttribute.setMandatory(false);
                    cayennePrimaryTable.addAttribute(dbAttribute);
                }

                String valueString = entity.getDiscriminatorValue();
                if (valueString != null && valueString.length() > 0) {

                    Object value = null;
                    switch (discriminator.getDiscriminatorType()) {
                        case CHAR:
                            value = valueString.charAt(0);
                            break;
                        case STRING:
                            value = valueString;
                            break;
                        case INTEGER:
                            try {
                                value = Integer.valueOf(valueString);
                            }
                            catch (NumberFormatException e) {
                                recordConflict(
                                        path,
                                        "Invalid integer discriminator value '"
                                                + valueString);
                            }
                            break;
                    }

                    if (value != null) {
                        cayenneEntity.setDeclaredQualifier(ExpressionFactory.matchDbExp(
                                discriminator.getName(),
                                value));
                    }

                }
            }
View Full Code Here

    final class DiscriminatorColumnVisitor extends BaseTreeVisitor {

        @Override
        public boolean onStartNode(ProjectPath path) {

            JpaDiscriminatorColumn column = (JpaDiscriminatorColumn) path.getObject();
            if (column.getName() == null) {
                column.setName("DTYPE");
            }

            if (column.getDiscriminatorType() == null) {
                column.setDiscriminatorType(DiscriminatorType.STRING);
            }

            if (column.getLength() == 0
                    && column.getDiscriminatorType() == DiscriminatorType.STRING) {
                column.setLength(31);
            }

            return false;
        }
View Full Code Here

                        }
                    }
                }
            }

            JpaDiscriminatorColumn discriminator = entity.lookupDiscriminatorColumn();
            if (discriminator != null) {

                if (entity.getDiscriminatorValue() == null) {
                    switch (discriminator.getDiscriminatorType()) {

                        case STRING:
                            entity.setDiscriminatorValue(entity.getName());
                            break;
                        default:
                            context.recordConflict(new SimpleValidationFailure(
                                    entity,
                                    "Can't guess default discriminator value for non-String discriminator column: "
                                            + discriminator.getName()));
                    }
                }
            }
        }
View Full Code Here

                AnnotatedElement element,
                AnnotationProcessorStack context) {

            DiscriminatorColumn annotation = element
                    .getAnnotation(DiscriminatorColumn.class);
            entity.setDiscriminatorColumn(new JpaDiscriminatorColumn(annotation));
        }
View Full Code Here

                dbRelationship.setToDependentPK(true);
                dbRelationship.setToMany(false);
            }

            // init discriminator column
            JpaDiscriminatorColumn discriminator = entity.lookupDiscriminatorColumn();
            if (discriminator != null) {

                if (cayennePrimaryTable.getAttribute(discriminator.getName()) == null) {
                    DbAttribute dbAttribute = new DbAttribute(discriminator.getName());

                    switch (discriminator.getDiscriminatorType()) {
                        case CHAR:
                            dbAttribute.setType(Types.CHAR);
                            dbAttribute.setMaxLength(1);
                            break;
                        case STRING:
                            dbAttribute.setType(Types.VARCHAR);
                            dbAttribute.setMaxLength(discriminator.getLength());
                            break;
                        case INTEGER:
                            dbAttribute.setType(Types.INTEGER);
                            break;
                    }

                    dbAttribute.setMandatory(false);
                    cayennePrimaryTable.addAttribute(dbAttribute);
                }

                String valueString = entity.getDiscriminatorValue();
                if (valueString != null && valueString.length() > 0) {

                    Object value = null;
                    switch (discriminator.getDiscriminatorType()) {
                        case CHAR:
                            value = valueString.charAt(0);
                            break;
                        case STRING:
                            value = valueString;
                            break;
                        case INTEGER:
                            try {
                                value = Integer.valueOf(valueString);
                            }
                            catch (NumberFormatException e) {
                                recordConflict(
                                        path,
                                        "Invalid integer discriminator value '"
                                                + valueString);
                            }
                            break;
                    }

                    if (value != null) {
                        cayenneEntity.setDeclaredQualifier(ExpressionFactory.matchDbExp(
                                discriminator.getName(),
                                value));
                    }

                }
            }
View Full Code Here

                AnnotatedElement element,
                AnnotationProcessorStack context) {

            DiscriminatorColumn annotation = element
                    .getAnnotation(DiscriminatorColumn.class);
            entity.setDiscriminatorColumn(new JpaDiscriminatorColumn(annotation));
        }
View Full Code Here

    final class DiscriminatorColumnVisitor extends BaseTreeVisitor {

        @Override
        public boolean onStartNode(ProjectPath path) {

            JpaDiscriminatorColumn column = (JpaDiscriminatorColumn) path.getObject();
            if (column.getName() == null) {
                column.setName("DTYPE");
            }

            if (column.getDiscriminatorType() == null) {
                column.setDiscriminatorType(DiscriminatorType.STRING);
            }

            if (column.getLength() == 0
                    && column.getDiscriminatorType() == DiscriminatorType.STRING) {
                column.setLength(31);
            }

            return false;
        }
View Full Code Here

                        }
                    }
                }
            }

            JpaDiscriminatorColumn discriminator = entity.lookupDiscriminatorColumn();
            if (discriminator != null) {

                if (entity.getDiscriminatorValue() == null) {
                    switch (discriminator.getDiscriminatorType()) {

                        case STRING:
                            entity.setDiscriminatorValue(entity.getName());
                            break;
                        default:
                            context.recordConflict(new SimpleValidationFailure(
                                    entity,
                                    "Can't guess default discriminator value for non-String discriminator column: "
                                            + discriminator.getName()));
                    }
                }
            }
        }
View Full Code Here

                dbRelationship.setToDependentPK(true);
                dbRelationship.setToMany(false);
            }

            // init discriminator column
            JpaDiscriminatorColumn discriminator = entity.lookupDiscriminatorColumn();
            if (discriminator != null) {

                if (cayennePrimaryTable.getAttribute(discriminator.getName()) == null) {
                    DbAttribute dbAttribute = new DbAttribute(discriminator.getName());

                    switch (discriminator.getDiscriminatorType()) {
                        case CHAR:
                            dbAttribute.setType(Types.CHAR);
                            dbAttribute.setMaxLength(1);
                            break;
                        case STRING:
                            dbAttribute.setType(Types.VARCHAR);
                            dbAttribute.setMaxLength(discriminator.getLength());
                            break;
                        case INTEGER:
                            dbAttribute.setType(Types.INTEGER);
                            break;
                    }

                    dbAttribute.setMandatory(false);
                    cayennePrimaryTable.addAttribute(dbAttribute);
                }

                String valueString = entity.getDiscriminatorValue();
                if (valueString != null && valueString.length() > 0) {

                    Object value = null;
                    switch (discriminator.getDiscriminatorType()) {
                        case CHAR:
                            value = valueString.charAt(0);
                            break;
                        case STRING:
                            value = valueString;
                            break;
                        case INTEGER:
                            try {
                                value = Integer.valueOf(valueString);
                            }
                            catch (NumberFormatException e) {
                                recordConflict(
                                        path,
                                        "Invalid integer discriminator value '"
                                                + valueString);
                            }
                            break;
                    }

                    if (value != null) {
                        cayenneEntity.setDeclaredQualifier(ExpressionFactory.matchDbExp(
                                discriminator.getName(),
                                value));
                    }

                }
            }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.jpa.map.JpaDiscriminatorColumn

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.