/// <summary> /// Returns the syntax to get the data type of a field from a stored procedure /// return value. Note it assumes the command used to execute the stored /// procedure is named "cmd". Currently only used with Velocity generator. /// </summary> /// <param name="property">Property whose reader syntax is needed.</param> /// <returns>Reader syntax to use.</returns> public String GetProcedureReturnString(PropertyElement property) { String readerMethod = "(Int32)(cmd.Parameters[\"RETURN_VALUE\"].Value)"; if (property.Type.ConvertFromSqlTypeFormat.Length > 0) { readerMethod = String.Format(property.Type.ConvertFromSqlTypeFormat, "", "", readerMethod, "", ""); } return(readerMethod); }
public static void BuildElement(XmlNode finderNode, FinderElement finderElement) { finderElement.Name = GetAttributeValue(finderNode, NAME, finderElement.Name); finderElement.Sort = GetAttributeValue(finderNode, SORT, finderElement.Sort); finderElement.Expression = GetAttributeValue(finderNode, EXPRESSION, finderElement.Expression); finderElement.Unique = Boolean.Parse(GetAttributeValue(finderNode, UNIQUE, finderElement.Unique.ToString())); finderElement.Limit = Boolean.Parse(GetAttributeValue(finderNode, LIMIT, finderElement.Limit.ToString())); PropertyElement.ParseFromXml(GetChildNodeByName(finderNode, PROPERTIES), finderElement.Fields); }
/// <summary> /// Returns the syntax to get the data type of a field from a DataReader object. /// Currently only used with Velocity generator. /// </summary> /// <param name="field">Field whose reader syntax is needed.</param> /// <returns>Reader syntax to use.</returns> public String GetReaderString(PropertyElement field) { String readerMethod = String.Format(field.Column.SqlType.ReaderMethodFormat, "dataReader", field.Column.Name); if (field.Type.ConvertFromSqlTypeFormat.Length > 0) { readerMethod = String.Format(field.Type.ConvertFromSqlTypeFormat, "data", field.GetMethodFormat(), readerMethod, "dataReader", field.Column.Name); } return(readerMethod); }
/// <summary> /// Parse only method. Parses and adds all entities found in the given node and adds them to the given /// list. /// </summary> /// <param name="node"></param> /// <param name="entityElements"></param> public static void ParseFromXml(XmlNode node, IList propertyElements) { if (node != null && propertyElements != null) { foreach (XmlNode propertyNode in node.ChildNodes) { if (propertyNode.NodeType.Equals(XmlNodeType.Element)) { PropertyElement propertyElement = new PropertyElement(); BuildElement(propertyElement, propertyNode); propertyElements.Add(propertyElement); } } } }
/// <summary> /// Second pass parse and validation. /// </summary> /// <param name="options">Configuration options.</param> /// <param name="doc">Document being parsed.</param> /// <param name="sqltypes">List of sql types defined.</param> /// <param name="types">List of .Net types defined.</param> /// <param name="entities">List of EntityElement objects defined.</param> /// <param name="vd">Validation delegate for error reporting.</param> /// <returns>Validated list of report extractions.</returns> public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, IList entities, ParserValidationDelegate vd) { ArrayList reportExtractions = new ArrayList(); XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("reportextraction"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } ReportExtractionElement reportExtraction = new ReportExtractionElement(); if (node.Attributes[NAME] != null) { reportExtraction.Name = node.Attributes[NAME].Value; } else { vd(ParserValidationArgs.NewError("A report extraction must have a name.")); } if (node.Attributes[HINTS] != null) { reportExtraction.Hints = (string)(node.Attributes[HINTS].Value); } if (node.Attributes[HAVING] != null) { reportExtraction.Having = (string)(node.Attributes[HAVING].Value); } reportExtraction.EntityReferences = EntityReferenceElement.ParseFromXml(options, GetChildNodeByName(node, ENTITY_REFERENCES), reportExtraction, types, sqltypes, entities, vd); XmlNode computedProperties = GetChildNodeByName(node, COMPUTED_PROPERTIES); if (computedProperties != null) { reportExtraction.ComputedProperties = PropertyElement.ParseFromXml(computedProperties, entities, reportExtraction, sqltypes, types, false, vd); } reportExtraction.ValidateFilters(vd); reportExtraction.ValidateExpressions(vd); reportExtraction.ValidateUniqueNames(vd); reportExtraction.ValidateDatabases(vd); reportExtractions.Add(reportExtraction); reportExtraction.Having = Configuration.PrepareExpression(reportExtraction.Having, reportExtraction, "having attribute in report extraction " + reportExtraction.Name, vd); // Make sure finders get prepared expressions! reportExtraction.Comparers = ComparerElement.ParseFromXml(node, entities, reportExtraction, sqltypes, types, vd); reportExtraction.Finders = ReportExtractionFinderElement.ParseFromXml(node, entities, reportExtraction, sqltypes, types, vd); } return(reportExtractions); }
/// <summary> /// Populates this property element with values from the specified element. Usually used to intitalize a derived class instance. /// </summary> /// <param name="element">Element to populate from.</param> public virtual void PopulatePropertyElement(PropertyElement element) { this.Column = (ColumnElement)element.Column.Clone(); this.ConcreteType = element.ConcreteType; this.ConvertFromSqlTypeFormat = element.ConvertFromSqlTypeFormat; this.ConvertToSqlTypeFormat = element.ConvertToSqlTypeFormat; this.Description = element.Description; this.Entity = element.Entity; this.Name = element.Name; this.Prefix = element.Prefix; this.Readable = element.Readable; this.Type = (TypeElement)element.Type.Clone(); this.Writable = element.Writable; this.Derived = element.Derived; this.Encrypted = element.Encrypted; }
/// <summary> /// Parse only method. Parses and adds all entities found in the given node and adds them to the given /// list. /// </summary> /// <param name="node"></param> /// <param name="entityElements"></param> public static void ParseFromXml(XmlNode node, IList comparerElements) { if (node != null && comparerElements != null) { foreach (XmlNode comparerNode in node.ChildNodes) { if (comparerNode.NodeType.Equals(XmlNodeType.Element)) { ComparerElement comparerElement = new ComparerElement(); comparerElement.Name = GetAttributeValue(comparerNode, NAME, comparerElement.Name); PropertyElement.ParseFromXml(GetChildNodeByName(comparerNode, PROPERTIES), comparerElement.Fields); comparerElements.Add(comparerElement); } } } }
/// <summary> /// Finds a property reference or computed property. /// </summary> /// <param name="name">Name of property to find.</param> /// <returns>property reference or computed property element found.</returns> public PropertyElement FindFieldByName(String name) { PropertyElement retVal = null; PropertyElement rp = this.FindComputedFieldByName(name); if (rp != null) { retVal = rp; } else { PropertyElement pr = this.FindReferenceFieldByName(name); if (pr != null) { retVal = pr; } } return(retVal); }
public IList GetPrimaryKeyFields() { ArrayList list = new ArrayList(); PropertyElement id = GetIdentityField(); if (id != null) { list.Add(id); } else { foreach (PropertyElement field in properties) { if (sqlEntity.IsPrimaryKeyColumn(field.Column.Name)) { list.Add(field); } } } return(list); }
public string GetExpressionSubstitution(string substitutionExpression, string idString, ParserValidationDelegate vd) { int parm = -1; try { parm = Int32.Parse(substitutionExpression); } catch (Exception) { } if (parm > -1) { if (parm >= fields.Count) { if (vd != null) { vd(ParserValidationArgs.NewError("Substitution string " + substitutionExpression + " in " + idString + " refers to a parameter number larger that the number of parameters.")); } return(""); } String param = "@" + ((PropertyElement)(this.Fields[parm])).GetPropertyName(); return(param.Replace(".", "_")); } else { PropertyElement p = this.container.FindFieldByName(substitutionExpression); if (p == null) { if (vd != null) { vd(ParserValidationArgs.NewError("Substitution string " + substitutionExpression + " in " + idString + " refers to a property that does not occur in the finder's entity.")); } return(""); } else { return(GetSqlExpression(p)); } } }
/// <summary> /// Parse only method. Parses and adds all entities found in the given node and adds them to the given /// list. /// </summary> /// <param name="node">Node containing the enty reference elements.</param> /// <param name="EntityReferenceElements">returned list of entity reference elements parsed.</param> public static void ParseFromXml(XmlNode node, IList entityReferenceElements) { if (node != null && entityReferenceElements != null) { foreach (XmlNode refNode in node.ChildNodes) { if (refNode.NodeType.Equals(XmlNodeType.Element)) { EntityReferenceElement entityReferenceElement = new EntityReferenceElement(); entityReferenceElement.Name = GetAttributeValue(refNode, NAME, entityReferenceElement.Name); entityReferenceElement.Entity.Name = GetAttributeValue(refNode, ENTITY, entityReferenceElement.Entity.Name); entityReferenceElement.AliasPrefix = GetAttributeValue(refNode, ALIAS_PREFIX, entityReferenceElement.AliasPrefix); entityReferenceElement.Hints = GetAttributeValue(refNode, HINTS, entityReferenceElement.Hints); entityReferenceElement.Filter = GetAttributeValue(refNode, FILTER, entityReferenceElement.Filter); entityReferenceElement.JoinModifier = GetAttributeValue(refNode, JOIN_MODIFIER, entityReferenceElement.JoinModifier); PropertyElement.ParseFromXml(GetChildNodeByName(refNode, PROPERTY_REFERENCES), entityReferenceElement.PropertyReferences); entityReferenceElements.Add(entityReferenceElement); } } } }
public static void BuildElement(XmlNode node, IPropertyContainer entity, MessageElement message, ParserValidationDelegate vd) { if (node.Attributes["text"] != null) { message.Text = node.Attributes["text"].Value; } message.container = entity; // Make sure the parameter names are specified and unique.unique. for (int nameChanging = 0; nameChanging < message.Fields.Count; nameChanging++) { PropertyElement field = (PropertyElement)(message.Fields[nameChanging]); if (field.ParameterName == String.Empty) { field.ParameterName = field.Name; } int sequence = 1; string pName = field.ParameterName; bool changedName = true; while (changedName) { changedName = false; for (int nameChecking = 0; nameChecking < nameChanging; nameChecking++) { PropertyElement p = (PropertyElement)(message.Fields[nameChecking]); if (pName.Equals(p.ParameterName)) { sequence++; pName = pName + sequence.ToString(); changedName = true; } } } field.ParameterName = pName; } }
/// <summary> /// Parse only method. Parses and adds all entities found in the given node and adds them to the given /// list. /// </summary> /// <param name="node">Node to look in for the report extractions.</param> /// <param name="ReportExtractionElements">List of report extractions created (returned)</param> public static void ParseFromXml(XmlNode node, IList ReportExtractionElements) { if (node != null && ReportExtractionElements != null) { foreach (XmlNode entityNode in node.ChildNodes) { if (entityNode.NodeType.Equals(XmlNodeType.Element)) { ReportExtractionElement reportExtractionElement = new ReportExtractionElement(); reportExtractionElement.Name = GetAttributeValue(entityNode, NAME, reportExtractionElement.Name); reportExtractionElement.Hints = GetAttributeValue(entityNode, HINTS, reportExtractionElement.Name); reportExtractionElement.Having = GetAttributeValue(entityNode, HAVING, reportExtractionElement.Name); EntityReferenceElement.ParseFromXml(GetChildNodeByName(entityNode, ENTITY_REFERENCES), reportExtractionElement.entityReferences); PropertyElement.ParseFromXml(GetChildNodeByName(entityNode, COMPUTED_PROPERTIES), reportExtractionElement.ComputedProperties); ComparerElement.ParseFromXml(GetChildNodeByName(entityNode, COMPARERS), reportExtractionElement.Comparers); ReportExtractionFinderElement.ParseFromXml(GetChildNodeByName(entityNode, FINDERS), reportExtractionElement.Finders); ReportExtractionElements.Add(reportExtractionElement); } } } }
/// <summary> /// Second pass parsing and validation. /// </summary> /// <param name="options">Configuration options</param> /// <param name="reportExtractionNode">Node contaiing the entity references.</param> /// <param name="reportExtraction">ReportExtraction element to contain the parsed entity references.</param> /// <param name="types">List of .Net types defined.</param> /// <param name="entities">List of entities defined.</param> /// <param name="vd">Validation delegate for error reporting.</param> /// <returns>List of entity references parsed.</returns> public static ArrayList ParseFromXml(Configuration options, XmlNode reportExtractionNode, ReportExtractionElement reportExtraction, Hashtable types, Hashtable sqltypes, IList entities, ParserValidationDelegate vd) { ArrayList entityReferences = new ArrayList(); foreach (XmlNode node in reportExtractionNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } EntityReferenceElement entityReference = new EntityReferenceElement(reportExtraction); if (entityReference.Name != null) { entityReference.Name = node.Attributes[NAME].Value; } else { vd(ParserValidationArgs.NewError("Entity reference specified in report extraction " + reportExtraction.Name + " with no name.")); } if (node.Attributes[ENTITY] != null) { EntityElement ee = EntityElement.FindEntityByName(entities, node.Attributes[ENTITY].Value); if (ee != null) { entityReference.Entity = ee; if (entityReference.Entity.SqlEntity.Name == String.Empty) { vd(ParserValidationArgs.NewError("Entity Reference " + entityReference.Name + " refers to entity " + node.Attributes[ENTITY].Value + " which does not have an associated SQL entity.")); } } else { vd(ParserValidationArgs.NewError("Entity Reference " + entityReference.Name + " refers to entity " + node.Attributes[ENTITY].Value + " which does not exist.")); } } else { vd(ParserValidationArgs.NewError("Entity Reference " + node.Attributes[NAME].Value + " has no entity attribute.")); } if (node.Attributes[ALIAS_PREFIX] != null) { entityReference.aliasPrefix = node.Attributes[ALIAS_PREFIX].Value; } if (node.Attributes[HINTS] != null) { entityReference.Hints = node.Attributes[HINTS].Value; } if (node.Attributes[FILTER] != null) { entityReference.Filter = node.Attributes[FILTER].Value; } if (node.Attributes[JOIN_MODIFIER] != null) { entityReference.JoinModifier = node.Attributes[JOIN_MODIFIER].Value; if (entityReference.JoinModifier.ToUpper() != JOIN_LEFT && entityReference.JoinModifier.ToUpper() != JOIN_RIGHT && entityReference.JoinModifier.ToUpper() != JOIN_FULL) { vd(ParserValidationArgs.NewError("Entity Reference " + node.Attributes[NAME].Value + " has join modifier other than left, right or full.")); } } entityReference.ReportExtraction = reportExtraction; // Note we pass entityReference.Entity because the fields refer to fields in the entity. entityReference.propertyReferences = PropertyElement.ParseFromXml(GetChildNodeByName(node, PROPERTY_REFERENCES), entities, entityReference.Entity, sqltypes, types, true, vd); entityReference.ProcessAsteriskName(vd); entityReference.AdjustSqlAlias(); entityReferences.Add(entityReference); } return(entityReferences); }
/* * /// <summary> * /// Replaces embedded property references in the string with sql cocde. * /// </summary> * /// <param name="withEmbedded">Expression to be replaced.</param> * /// <param name="idString">Id to use when reporting errors.</param> * /// <param name="vd">Validation delegate for error reporting.</param> * /// <returns>String with embedded references replaced.</returns> * private string PrepareExpression(string withEmbedded, string idString, ParserValidationDelegate vd) * { * string checkExpression = withEmbedded; * string retVal = String.Empty; * int leftBrace = 0; * int startPos = 0; * for(leftBrace=checkExpression.IndexOf("{", startPos); startPos >=0; leftBrace=checkExpression.IndexOf("{", startPos)) * { * if (leftBrace == -1) * { * // No more strings to replace. * retVal += checkExpression.Substring(startPos, checkExpression.Length - startPos); * break; * } * else * { * // Concatenate portion of string without embedded references. * retVal += checkExpression.Substring(startPos, leftBrace - startPos); * } * int rightBrace = checkExpression.IndexOf("}", leftBrace); * if (rightBrace == -1) * { * if (vd != null) * { * vd(ParserValidationArgs.NewError("The " + idString + " has a left brace({} with no corresonding right brace(}}")); * } * return ""; * } * * // Isolate the property reference. * string expression = checkExpression.Substring(leftBrace+1, rightBrace - leftBrace - 1); * * // Create list of property references seen to check for circular references. * ArrayList repeList = new ArrayList(); * * string[] parts = expression.Split('.'); * string leftPart = ""; * string rightPart = ""; * if (parts.Length == 1) * { * // Default the left part to this report extraction if not specified. * leftPart = this.Name; * rightPart = parts[0]; * } * else if (parts.Length == 2) * { * leftPart = parts[0]; * rightPart = parts[1]; * } * else * { * if (vd != null) * { * vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " does not contain exactly one dot(.).")); * } * return ""; * } * * * if (leftPart.ToLower() == this.Name.ToLower()) * { * // Refers to a property in this report extraction. * ReportExtractionPropertyElement repe = this.FindComputedFieldByName(rightPart); * if (repe != null) * { * // Refers to a computed property. Check for circular references. * foreach(ReportExtractionPropertyElement repel in repeList) * { * if(repel.Name == repe.Name) * { * if (vd != null) * { * vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " has a circular reference.")); * } * return ""; * } * } * * // Add in the expansion of this property.e * retVal += "(" + repe.GetSqlExpression() + ")"; * } * else * { * EntityReferencePropertyElement pre = this.FindReferenceFieldByName(rightPart); * if (pre != null) * { * // Refers to a property reference. Get the expression. * retVal += pre.GetSqlExpression(); * } * else * { * if (vd != null) * { * vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to a property in the report extraction that does not exist.")); * } * return ""; * } * } * } * else * { * EntityReferenceElement er = FindEntityReferenceByName(leftPart); * if (er == null) * { * if (vd != null) * { * vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to an entity that is not an entity reference in the extraction nor the extraction itself.")); * } * return ""; * } * else * { * // Refers to an entity reference. * EntityReferencePropertyElement pre = er.FindFieldBySqlAlias(rightPart); * if (pre != null) * { * // Refers to a property reference in the entity. * retVal += pre.GetSqlExpression(); * } * else * { * PropertyElement p = er.Entity.FindFieldByName(rightPart); * if (p != null) * { * // Refers to a property in the entity referenced that is not in the property referenced. * retVal += "[" + er.Name + "].[" + p.Column.Name + "]"; * } * else * { * if (vd != null) * { * vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to a property that is not in the referenced entity reference nor it's associated entity.")); * } * else * { * return ""; * } * } * } * } * } * * startPos = rightBrace + 1; * } * * return retVal; * }*/ public string GetExpressionSubstitution(string substitutionExpression, string idString, ParserValidationDelegate vd) { // Create list of property references seen to check for circular references. ArrayList repeList = new ArrayList(); string[] parts = substitutionExpression.Split('.'); string leftPart = ""; string rightPart = ""; if (parts.Length == 1) { // Default the left part to this report extraction if not specified. leftPart = this.Name; rightPart = parts[0]; } else if (parts.Length == 2) { leftPart = parts[0]; rightPart = parts[1]; } else { if (vd != null) { vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " does not contain exactly one dot(.).")); } return(""); } if (leftPart.ToLower() == this.Name.ToLower()) { // Refers to a property in this report extraction. PropertyElement repe = this.FindComputedFieldByName(rightPart); if (repe != null) { // Refers to a computed property. Check for circular references. foreach (PropertyElement repel in repeList) { if (repel.Name == repe.Name) { if (vd != null) { vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " has a circular reference.")); } return(""); } } // Add in the expansion of this property.e return("(" + repe.GetSqlExpression() + ")"); } else { PropertyElement pre = this.FindReferenceFieldByName(rightPart); if (pre != null) { // Refers to a property reference. Get the expression. return(pre.GetSqlExpression()); } else { if (vd != null) { vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to a property in the report extraction that does not exist.")); } return(""); } } } else { EntityReferenceElement er = FindEntityReferenceByName(leftPart); if (er == null) { if (vd != null) { vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to an entity that is not an entity reference in the extraction nor the extraction itself.")); } return(""); } else { // Refers to an entity reference. PropertyElement pre = er.FindFieldBySqlAlias(rightPart); if (pre != null) { // Refers to a property reference in the entity. return(pre.GetSqlExpression()); } else { PropertyElement p = er.Entity.FindFieldByName(rightPart); if (p != null) { // Refers to a property in the entity referenced that is not in the property referenced. return("[" + er.Name + "].[" + p.Column.Name + "]"); } else { if (vd != null) { vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to a property that is not in the referenced entity reference nor it's associated entity.")); } return(""); } } } } }
public static PropertyElement BuildElement(XmlNode node, Hashtable types, Hashtable sqltypes, IPropertyContainer entity, bool isReference, ParserValidationDelegate vd) { PropertyElement field = new PropertyElement(); if (node.Attributes["name"] != null) { field.Name = node.Attributes["name"].Value; } else { vd(ParserValidationArgs.NewError("Property in " + entity.Name + " has no name.")); } if (isReference && field.Name != "*") { PropertyElement refProperty = entity.FindFieldByName(field.Name); if (refProperty == null) { vd(ParserValidationArgs.NewError("Property " + field.Name + " in " + entity.Name + " refers to a property that does not exist.")); } else { field = (PropertyElement)(refProperty.Clone()); } } if (node.Attributes["column"] != null) { if (node.Attributes["column"].Value.Equals("*")) { field.Column.Name = field.Name; } else { field.Column.Name = node.Attributes["column"].Value; } // Column only occurs on entity eement. SqlEntityElement sqlEntity = ((EntityElement)entity).SqlEntity; ColumnElement column = sqlEntity.FindColumnByName(field.Column.Name); if (column != null) { field.Column = (ColumnElement)column.Clone(); if (types.Contains(field.Column.SqlType.Type)) { field.Type = (TypeElement)((TypeElement)types[field.Column.SqlType.Type]).Clone(); } else { vd(ParserValidationArgs.NewError("Type " + field.Column.SqlType.Type + " was not defined [property=" + field.name + "]")); } } else { vd(ParserValidationArgs.NewError("column (" + field.Column.Name + ") specified for property (" + field.Name + ") on entity (" + entity.Name + ") was not found in sql entity (" + sqlEntity.Name + ")")); } } field.Description = node.InnerText.Trim(); if (node.Attributes["accessmodifier"] != null) { field.AccessModifier = node.Attributes["accessmodifier"].Value; } // the concrete type is the *real* type, type can be the same or can be in interface or coersable type if (node.Attributes["type"] != null) { String type = node.Attributes[TYPE].Value; String concreteType = type; if (node.Attributes[CONCRETE_TYPE] != null) { concreteType = node.Attributes[CONCRETE_TYPE].Value; } // if the data type is defined, default it as the property and left be overridden if (types.Contains(concreteType)) { field.Type = (TypeElement)((TypeElement)types[concreteType]).Clone(); field.Type.Name = type; } else { vd(ParserValidationArgs.NewError("Type " + concreteType + " was not defined for property " + field.Name + " in " + entity.Name + ".")); } String dataObjectTypeName = concreteType + "Data"; if (types.Contains(dataObjectTypeName)) { field.DataObjectType = (TypeElement)((TypeElement)types[dataObjectTypeName]).Clone(); } else { field.DataObjectType = field.Type; } } if (node.Attributes["convertfromsqltypeformat"] != null) { field.Type.ConvertFromSqlTypeFormat = node.Attributes["convertfromsqltypeformat"].Value; } if (node.Attributes["converttosqltypeformat"] != null) { field.Type.ConvertToSqlTypeFormat = node.Attributes["converttosqltypeformat"].Value; } if (node.Attributes[PARAMETER_NAME] != null) { field.ParameterName = node.Attributes[PARAMETER_NAME].Value; } if (node.Attributes[EXPRESSION] != null) { field.Expression = node.Attributes[EXPRESSION].Value; } if (node.Attributes[GROUP_FUNCTION] != null) { field.GroupFunction = node.Attributes[GROUP_FUNCTION].Value; if (field.GroupFunction.ToLower() != GROUP_FUNCTION_SUM && field.GroupFunction.ToLower() != GROUP_FUNCTION_MIN && field.GroupFunction.ToLower() != GROUP_FUNCTION_MAX && field.GroupFunction.ToLower() != GROUP_FUNCTION_AVG && field.GroupFunction.ToLower() != GROUP_FUNCTION_STDEV && field.GroupFunction.ToLower() != GROUP_FUNCTION_STDEVP && field.GroupFunction.ToLower() != GROUP_FUNCTION_VAR && field.GroupFunction.ToLower() != GROUP_FUNCTION_VARP) { vd(ParserValidationArgs.NewError("Invalid group function specified for entity reference property " + field.Name + " in " + entity.Name)); } } if (node.Attributes[GROUP_BY] != null) { field.GroupBy = Boolean.Parse(node.Attributes[GROUP_BY].Value); } if (node.Attributes[SQL_TYPE] != null) { field.Column.SqlType.Name = node.Attributes[SQL_TYPE].Value; if (sqltypes.ContainsKey(field.Column.SqlType.Name)) { field.Column.SqlType = (SqlTypeElement)((SqlTypeElement)sqltypes[field.Column.SqlType.Name]).Clone(); } else { vd(ParserValidationArgs.NewError("SqlType " + field.Column.SqlType.Name + " was not defined in " + entity.Name + " for property " + field.Name + ".")); } } if (node.Attributes[ALIAS] != null) { field.Alias = node.Attributes[ALIAS].Value; } field.container = entity; if (node.Attributes["readable"] != null) { field.Readable = Boolean.Parse(node.Attributes["readable"].Value); } if (node.Attributes["writable"] != null) { field.Writable = Boolean.Parse(node.Attributes["writable"].Value); } if (node.Attributes["derived"] != null) { field.Derived = Boolean.Parse(node.Attributes["derived"].Value); } if (node.Attributes["encrypted"] != null) { field.Encrypted = Boolean.Parse(node.Attributes["encrypted"].Value); } if (node.Attributes["log"] != null) { field.DoLog = Boolean.Parse(node.Attributes["log"].Value); } if (node.Attributes["returnasidentity"] != null) { field.ReturnAsIdentity = Boolean.Parse(node.Attributes["returnasidentity"].Value); } if (node.Attributes[DIRECTION] == null) { field.Direction = ASCENDING; } else if (node.Attributes["direction"].Value != ASCENDING && node.Attributes["direction"].Value != DESCENDING) { vd(ParserValidationArgs.NewError("Comparer in entity " + entity.Name + " has direction value other than 'ascending' or 'descending'")); } else { field.Direction = node.Attributes[DIRECTION].Value; } if (node.Attributes[CONVERT_FOR_COMPARE] != null) { field.Type.ConvertForCompare = node.Attributes[CONVERT_FOR_COMPARE].Value; } if (node.Attributes[USE_ENTITY_DAO] != null) { field.UseEntityDao = Boolean.Parse(node.Attributes[USE_ENTITY_DAO].Value); } if (node.Attributes["entity"] != null) { field.Entity.Name = node.Attributes["entity"].Value; } if (node.Attributes["prefix"] != null) { field.Prefix = node.Attributes["prefix"].Value; } else { field.Prefix = field.Entity.Name + "_"; } return(field); }
public static ArrayList ParseFromXml(XmlNode propertiesNode, IList entities, IPropertyContainer entity, Hashtable sqltypes, Hashtable types, bool isReference, ParserValidationDelegate vd) { ArrayList fields = new ArrayList(); if (propertiesNode != null) { foreach (XmlNode node in propertiesNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } PropertyElement field = BuildElement(node, types, sqltypes, entity, isReference, vd); //Adds all attributes including all non defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!field.Attributes.ContainsKey(attribute.Name)) { field.Attributes.Add(attribute.Name, attribute.Value); } } fields.Add(field); // Add in any subfields... if (field.Entity.Name.Length > 0 && !field.UseEntityDao) { String subEntityName = node.Attributes["entity"].Value; EntityElement subentity = EntityElement.FindEntityByName((ArrayList)entities, subEntityName); // check to see if subentity is self if (subentity == null && entity.Name == subEntityName) { subentity = (EntityElement)entity; } if (subentity != null) { // Only entity elements have entity atttribute SqlEntityElement sqlEntity = ((EntityElement)entity).SqlEntity; String prefix = subentity.Name + "_"; if (node.Attributes["prefix"] != null) { prefix = node.Attributes["prefix"].Value; } foreach (PropertyElement f in subentity.Fields) { PropertyElement subfield = (PropertyElement)f.Clone(); subfield.Name = field.Name + "." + subfield.Name; // if field has sql column defined if (!f.Column.Name.Equals(String.Empty)) { ColumnElement column = sqlEntity.FindColumnByName(prefix + subfield.Column.Name); if (column != null) { subfield.Column = (ColumnElement)column.Clone(); } else { vd(ParserValidationArgs.NewError("column (" + prefix + subfield.Column.Name + ") specified for property (" + subfield.Name + ") on entity (" + entity.Name + ") was not found in sql entity (" + sqlEntity.Name + ")")); } } fields.Add(subfield); } } else { vd(ParserValidationArgs.NewError("Entity " + entity.Name + " referenced another entity that was not defined (or defined below this one): " + node.Attributes["entity"].Value)); } } } } return(fields); }
public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ArrayList sqlentities, ParserValidationDelegate vd) { ArrayList entities = new ArrayList(); XmlNode entitiesNode = doc.DocumentElement.Cast <XmlNode>().FirstOrDefault(x => x.Name.ToLowerInvariant() == "entities"); if (entitiesNode == null) { return(entities); } IEnumerable <XmlNode> elements = entitiesNode.ChildNodes.Cast <XmlNode>().Where(x => x.Name.ToLowerInvariant() == "entity"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } EntityElement entity = new EntityElement(); entity.Name = node.Attributes["name"].Value; if (node.Attributes["namespace"] != null) { entity.Namespace = node.Attributes["namespace"].Value; } if (node.Attributes["sqlentity"] != null) { SqlEntityElement sqlentity = SqlEntityElement.FindByName(sqlentities, node.Attributes["sqlentity"].Value); if (sqlentity != null) { entity.SqlEntity = (SqlEntityElement)sqlentity.Clone(); } else { entity.SqlEntity.Name = node.Attributes["sqlentity"].Value; vd(ParserValidationArgs.NewError("sqlentity (" + entity.SqlEntity.Name + ") specified in entity " + entity.Name + " could not be found as an defined sql entity")); } } if (node.Attributes["baseentity"] != null) { EntityElement baseentity = EntityElement.FindEntityByName(entities, node.Attributes["baseentity"].Value); if (baseentity != null) { entity.BaseEntity = (EntityElement)baseentity.Clone(); } else { entity.BaseEntity.Name = node.Attributes["baseentity"].Value; vd(ParserValidationArgs.NewError("baseentity (" + entity.BaseEntity.Name + ") specified in entity " + entity.Name + " could not be found as an defined entity (or is defined after this entity in the config file)")); } } if (node.Attributes["abstract"] != null) { entity.IsAbstract = Boolean.Parse(node.Attributes["abstract"].Value); } if (node.Attributes["namespace"] != null) { entity.HasNamespace = !String.IsNullOrEmpty(node.Attributes["namespace"].Value); } if (node.Attributes["log"] != null) { entity.DoLog = Boolean.Parse(node.Attributes["log"].Value); } if (node.Attributes["returnwholeobject"] != null) { entity.ReturnWholeObject = Boolean.Parse(node.Attributes["returnwholeobject"].Value); } if (node.Attributes["prepareforinsert"] != null) { entity.PrepareForInsert = Boolean.Parse(node.Attributes["prepareforinsert"].Value); } if (node.Attributes["dependententity"] != null) { entity.DependentEntity = Boolean.Parse(node.Attributes["dependententity"].Value); } if (node.Attributes["jointable"] != null) { entity.JoinTable = Boolean.Parse(node.Attributes["jointable"].Value); } XmlNode descriptionNode = node.SelectSingleNode(DESCRIPTION); if (descriptionNode != null) { entity.Description = descriptionNode.InnerText.Trim(); } //Adds all attributes including all not defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!entity.Attributes.ContainsKey(attribute.Name)) { entity.Attributes.Add(attribute.Name, attribute.Value); } } entity.dependents = ParseDependentsFromXml(node, vd); entity.fields = PropertyElement.ParseFromXml(doc, entities, entity, sqltypes, types, vd); entity.finders = FinderElement.ParseFromXml(doc, node, entities, entity, sqltypes, types, vd); entity.comparers = ComparerElement.ParseFromXml(node, entities, entity, sqltypes, types, vd); entities.Add(entity); } StringCollection names = new StringCollection(); foreach (EntityElement entity in entities) { if (names.Contains(entity.Name)) { vd(new ParserValidationArgs(ParserValidationSeverity.ERROR, "duplicate entity definition for " + entity.Name)); } else { names.Add(entity.Name); } } return(entities); }
protected override string GetSqlExpression(PropertyElement p) { return(p.GetSqlExpression(true)); }
public static void BuildElement(XmlNode messageNode, MessageElement messageElement) { messageElement.Name = GetAttributeValue(messageNode, NAME, messageElement.Name); messageElement.Text = GetAttributeValue(messageNode, TEXT, messageElement.Text); PropertyElement.ParseFromXml(GetChildNodeByName(messageNode, PROPERTIES), messageElement.Fields); }
/// <summary> /// Returns the phrase to use to get the sql format of a type. Currently /// only used with Velocity generator. /// </summary> /// <param name="field">Field whose sql format is needed.</param> /// <returns>String for converting the field to sql format (like artProjectId.DBValue)</returns> public String GetSqlConversion(PropertyElement field) { return(String.Format(field.Type.ConvertToSqlTypeFormat, "", field.GetFieldFormat(), "", "", field.GetFieldFormat())); }
public static void BuildElement(XmlNode node, IPropertyContainer entity, FinderElement finder, ParserValidationDelegate vd) { if (node.Attributes["sort"] != null) { finder.Sort = node.Attributes["sort"].Value; } if (node.Attributes[EXPRESSION] != null) { finder.Expression = node.Attributes[EXPRESSION].Value; } if (node.Attributes["unique"] != null) { finder.Unique = Boolean.Parse(node.Attributes["unique"].Value); } if (node.Attributes[LIMIT] != null) { finder.Limit = Boolean.Parse(node.Attributes[LIMIT].Value); } // Default sort to all finder properties if none specified. if (finder.Sort == String.Empty) { foreach (PropertyElement p in finder.Fields) { if (finder.Sort != String.Empty) { finder.Sort += ", "; } finder.Sort += p.GetSqlAlias(); } } //Adds all attributes including all non defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!finder.Attributes.ContainsKey(attribute.Name)) { finder.Attributes.Add(attribute.Name, attribute.Value); } } finder.container = entity; // Make sure the parameter names are specified and unique.unique. for (int nameChanging = 0; nameChanging < finder.Fields.Count; nameChanging++) { PropertyElement field = (PropertyElement)(finder.Fields[nameChanging]); if (field.ParameterName == String.Empty) { field.ParameterName = field.Name; } int sequence = 1; string pName = field.ParameterName; bool changedName = true; while (changedName) { changedName = false; for (int nameChecking = 0; nameChecking < nameChanging; nameChecking++) { PropertyElement p = (PropertyElement)(finder.Fields[nameChecking]); if (pName.Equals(p.ParameterName)) { sequence++; pName = pName + sequence.ToString(); changedName = true; } } } field.ParameterName = pName; } // Validate the expression, if any. if (finder.Expression != String.Empty) { finder.Expression = Configuration.PrepareExpression(finder.Expression, finder, " finder " + finder.Name + " in " + entity.Name + " ", vd); } }
protected virtual string GetSqlExpression(PropertyElement p) { return(p.GetSqlExpression()); }