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

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.