protected void initComponentPropertyPaths( final String path, final AbstractComponentType type, final String[] columns, String[] formulaTemplates, final Mapping factory) throws MappingException { Type[] types = type.getSubtypes(); String[] properties = type.getPropertyNames(); int begin = 0; for (int i = 0; i < properties.length; i++) { String subpath = extendPath(path, properties[i]); try { int length = types[i].getColumnSpan(factory); String[] columnSlice = ArrayHelper.slice(columns, begin, length); String[] formulaSlice = formulaTemplates == null ? null : ArrayHelper.slice(formulaTemplates, begin, length); initPropertyPaths(subpath, types[i], columnSlice, formulaSlice, factory); begin += length; } catch (Exception e) { throw new MappingException("bug in initComponentPropertyPaths", e); } } }
protected void initPropertyPaths( final String path, final Type type, String[] columns, final String[] formulaTemplates, final Mapping factory) throws MappingException { if (columns.length != type.getColumnSpan(factory)) { throw new MappingException("broken column mapping for: " + path + " of: " + getEntityName()); } if (type.isAssociationType()) { AssociationType actype = (AssociationType) type; if (actype.useLHSPrimaryKey()) { columns = getIdentifierColumnNames(); } else { String foreignKeyProperty = actype.getLHSPropertyName(); if (foreignKeyProperty != null && !path.equals(foreignKeyProperty)) { // TODO: this requires that the collection is defined after the // referenced property in the mapping file (ok?) columns = (String[]) columnsByPropertyPath.get(foreignKeyProperty); if (columns == null) return; // get em on the second pass! } } } if (path != null) addPropertyPath(path, type, columns, formulaTemplates); if (type.isComponentType()) { AbstractComponentType actype = (AbstractComponentType) type; initComponentPropertyPaths(path, actype, columns, formulaTemplates, factory); if (actype.isEmbedded()) { initComponentPropertyPaths( path == null ? null : StringHelper.qualifier(path), actype, columns, formulaTemplates, factory); } } else if (type.isEntityType()) { initIdentifierPropertyPaths(path, (EntityType) type, columns, factory); } }
public CascadeStyle getCascadeStyle() throws MappingException { Type type = value.getType(); if (type.isComponentType() && !type.isAnyType()) { AbstractComponentType actype = (AbstractComponentType) type; int length = actype.getSubtypes().length; for (int i = 0; i < length; i++) { if (actype.getCascadeStyle(i) != CascadeStyle.NONE) return CascadeStyle.ALL; } return CascadeStyle.NONE; } else if (cascade == null || cascade.equals("none")) { return CascadeStyle.NONE; } else { StringTokenizer tokens = new StringTokenizer(cascade, ", "); CascadeStyle[] styles = new CascadeStyle[tokens.countTokens()]; int i = 0; while (tokens.hasMoreTokens()) { styles[i++] = CascadeStyle.getCascadeStyle(tokens.nextToken()); } return new CascadeStyle.MultipleCascadeStyle(styles); } }