/** * Creates a MappingsContext instance to handle a set of mappings operations using * the same parameters * @param m The mappings instance to use * @param direction The mappings direction * @param version The version of SIF to use for evaluating rule filters on field mappings * @param elementDef The ElementDef representing the object type being mapped * @return A new MappingsContext, initialized to map using the specified parameters */ public static MappingsContext Create(Mappings m, MappingDirection direction, SifVersion version, IElementDef elementDef) { // Get the rules associated with the element type MappingsContext mc = new MappingsContext(m, direction, version, elementDef); ObjectMapping om = m.GetRules(elementDef.Name, true); mc.AddRules(om); return(mc); }
/** * Creates a MappingsContext instance to handle a set of mappings operations using * the same parameters * @param m The mappings instance to use * @param direction The mappings direction * @param version The version of SIF to use for evaluating rule filters on field mappings * @param elementDef The ElementDef representing the object type being mapped * @return A new MappingsContext, initialized to map using the specified parameters */ public static MappingsContext Create(Mappings m, MappingDirection direction, SifVersion version, IElementDef elementDef) { // Get the rules associated with the element type MappingsContext mc = new MappingsContext(m, direction, version, elementDef); ObjectMapping om = m.GetRules(elementDef.Name, true); mc.AddRules(om); return mc; }
/// <summary> /// Adds SQLFields to represent each field rule in the specified MappingsContext /// </summary> /// <param name="context"></param> /// <param name="dialect"></param> public void AddFields( MappingsContext context, Dialect dialect ) { foreach ( FieldMapping mapping in context.FieldMappings ) { Rule rule = mapping.fRule; if ( rule is XPathRule ) { TypeConverter converter = null; XPathRule xRule = (XPathRule) rule; IElementDef targetDef = xRule.LookupTargetDef( context.ObjectDef ); if ( targetDef != null ) { converter = targetDef.TypeConverter; } if ( converter == null ) { converter = SifTypeConverters.STRING; } if ( mapping.ValueSetID != null ) { ValueSet vs = context.Mappings.GetValueSet( mapping.ValueSetID, true ); if ( vs != null ) { //Create the lookup table for generating the SQL lookup StringBuilder buffer = new StringBuilder(); // e.g. CircRecord.PatronType{StudentPersonal=1;StaffPersonal=2} //buffer.Append( tablePrefix ); buffer.Append( mapping.FieldName ); buffer.Append( '{' ); ValueSetEntry[] entries = vs.Entries; for ( int a = 0; a < entries.Length; a++ ) { if ( a > 0 ) { buffer.Append( ';' ); } buffer.Append( entries[a].Value ); buffer.Append( '=' ); ; buffer.Append( entries[a].Name ); } buffer.Append( '}' ); SQLField f = new SQLField( buffer.ToString(), converter.DbType, dialect ); AddField( xRule.XPath, f ); continue; } } SQLField field = new SQLField( mapping.FieldName, converter.DbType, dialect ); AddField( xRule.XPath, field ); } } }
/// <summary> /// Adds SQLFields to represent each field rule in the specified MappingsContext. /// </summary> /// <param name="context"></param> public void AddFields(MappingsContext context) { AddFields(context, SqlDialect.DEFAULT); }