List of usage examples for org.hibernate.mapping Column setCustomRead
public void setCustomRead(String customRead)
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a Column instance to the Hibernate meta model * * @param property The Grails domain class property * @param parentProperty/* w w w.ja v a 2 s.co m*/ * @param column The column to bind * @param path * @param table The table name * @param sessionFactoryBeanName the session factory bean name */ protected void bindColumn(GrailsDomainClassProperty property, GrailsDomainClassProperty parentProperty, Column column, ColumnConfig cc, String path, Table table, String sessionFactoryBeanName) { if (cc != null) { column.setComment(cc.getComment()); column.setDefaultValue(cc.getDefaultValue()); column.setCustomRead(cc.getRead()); column.setCustomWrite(cc.getWrite()); } Class<?> userType = getUserType(property); String columnName = getColumnNameForPropertyAndPath(property, path, cc, sessionFactoryBeanName); if ((property.isAssociation() || property.isBasicCollectionType()) && userType == null) { // Only use conventional naming when the column has not been explicitly mapped. if (column.getName() == null) { column.setName(columnName); } if (property.isManyToMany()) { column.setNullable(false); } else if (property.isOneToOne() && property.isBidirectional() && !property.isOwningSide()) { if (property.getOtherSide().isHasOne()) { column.setNullable(false); } else { column.setNullable(true); } } else if ((property.isManyToOne() || property.isOneToOne()) && property.isCircular()) { column.setNullable(true); } else { column.setNullable(property.isOptional()); } } else { column.setName(columnName); column.setNullable(property.isOptional() || (parentProperty != null && parentProperty.isOptional())); // Use the constraints for this property to more accurately define // the column's length, precision, and scale ConstrainedProperty constrainedProperty = getConstrainedProperty(property); if (constrainedProperty != null) { if (String.class.isAssignableFrom(property.getType()) || byte[].class.isAssignableFrom(property.getType())) { bindStringColumnConstraints(column, constrainedProperty); } if (Number.class.isAssignableFrom(property.getType())) { bindNumericColumnConstraints(column, constrainedProperty, cc); } } } handleUniqueConstraint(property, column, path, table, columnName, sessionFactoryBeanName); bindIndex(columnName, column, cc, table); if (!property.getDomainClass().isRoot()) { Mapping mapping = getMapping(property.getDomainClass()); if (mapping == null || mapping.getTablePerHierarchy()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName() + "] for column name [" + column.getName() + "] set to nullable"); column.setNullable(true); } else { column.setNullable(property.isOptional()); } } if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] bound property [" + property.getName() + "] to column name [" + column.getName() + "] in table [" + table.getName() + "]"); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a Column instance to the Hibernate meta model * * @param property The Grails domain class property * @param parentProperty/* w w w .j ava 2 s . com*/ * @param column The column to bind * @param path * @param table The table name * @param sessionFactoryBeanName the session factory bean name */ protected void bindColumn(PersistentProperty property, PersistentProperty parentProperty, Column column, ColumnConfig cc, String path, Table table, String sessionFactoryBeanName) { if (cc != null) { column.setComment(cc.getComment()); column.setDefaultValue(cc.getDefaultValue()); column.setCustomRead(cc.getRead()); column.setCustomWrite(cc.getWrite()); } Class<?> userType = getUserType(property); String columnName = getColumnNameForPropertyAndPath(property, path, cc, sessionFactoryBeanName); if ((property instanceof Association) && userType == null) { Association association = (Association) property; // Only use conventional naming when the column has not been explicitly mapped. if (column.getName() == null) { column.setName(columnName); } if (property instanceof ManyToMany) { column.setNullable(false); } else if (property instanceof org.grails.datastore.mapping.model.types.OneToOne && association.isBidirectional() && !association.isOwningSide()) { if (isHasOne(((Association) property).getInverseSide())) { column.setNullable(false); } else { column.setNullable(true); } } else if ((property instanceof ToOne) && association.isCircular()) { column.setNullable(true); } else { column.setNullable(property.isNullable()); } } else { column.setName(columnName); column.setNullable(property.isNullable() || (parentProperty != null && parentProperty.isNullable())); // Use the constraints for this property to more accurately define // the column's length, precision, and scale if (String.class.isAssignableFrom(property.getType()) || byte[].class.isAssignableFrom(property.getType())) { bindStringColumnConstraints(column, property); } if (Number.class.isAssignableFrom(property.getType())) { bindNumericColumnConstraints(column, property, cc); } } handleUniqueConstraint(property, column, path, table, columnName, sessionFactoryBeanName); bindIndex(columnName, column, cc, table); final PersistentEntity owner = property.getOwner(); if (!owner.isRoot()) { Mapping mapping = getMapping(owner); if (mapping == null || mapping.getTablePerHierarchy()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName() + "] for column name [" + column.getName() + "] set to nullable"); column.setNullable(true); } else { column.setNullable(property.isNullable()); } } if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] bound property [" + property.getName() + "] to column name [" + column.getName() + "] in table [" + table.getName() + "]"); }