//private object _physicalInfo;

		public OrderByItem(string item, FieldMap fieldInfo, bool ascending, OrderByJoin join)
		{
			this.Item = item;
			this.FieldInfo = fieldInfo;
			this.Ascending = ascending;
			this.Join = join;
		}
        // Includes Null-Value Assistance from Tim Byng (http://www.missioninc.com)
        internal void AddField(string member, string field, string nullValue, string alias,
                               string parameter, PersistType persistType, CustomProvider provider)
        {
            this.AddMember(member);
            FieldMap[] tempFields = new FieldMap[this.fields.Length + 1];
            this.fields.CopyTo(tempFields, 0);
            tempFields[this.fields.Length] = new FieldMap(member, field, nullValue,
                                                          parameter, persistType, EntityMap.GetType(this.Member(member)), provider);
            int keyIndex = -1;

            for (int index = 0; index < this.keyMembers.Length; index++)
            {
                if (this.keyMembers[index].Equals(member))
                {
                    keyIndex = index;
                }
            }
            if (keyIndex > -1)
            {
                FieldMap[] tempKeyFields = new FieldMap[this.keyFields.Length + 1];
                this.keyFields.CopyTo(tempKeyFields, 0);
                tempKeyFields[this.keyFields.Length] = tempFields[this.fields.Length];
                this.keyFields = tempKeyFields;
            }
            if (persistType == PersistType.ReadOnly)
            {
                this.readOnlyCount++;
            }
            if (persistType == PersistType.Concurrent)
            {
                this.concurrentCount++;
            }
            this.fields = tempFields;
            this.helper.Add(alias, this.fields.Length - 1);

            if (this.baseEntity != null && !this.baseEntity.subFields.ContainsKey(field))
            {
                this.baseEntity.subFields.Add(field, this.fields[this.fields.Length - 1]);
            }
        }
Exemple #3
0
 private void AddSelectField(StringBuilder fieldList, StringBuilder fromList, Hashtable lookupTables, FieldMap field)
 {
     if (!field.IsLookup) {
         fieldList.Append(this.GetDelimited(this.entity.Table, field.Field) + ", ");
     }
     else {
         LookupMap lookup = field as LookupMap;
         string lookupKey = string.Format("{0};{1};{2}", lookup.Table.ToUpper(),
             string.Join(",", lookup.Source).ToUpper(), string.Join(",", lookup.Dest).ToUpper());
         if (!lookupTables.ContainsKey(lookupKey)) {
             lookup.tableAlias = lookup.Table + "_" + (lookupTables.Count + 1).ToString();
             lookupTables.Add(lookupKey, lookup.tableAlias);
             StringBuilder join = new StringBuilder();
             join.AppendFormat(" LEFT JOIN {0} {1} {2} ON", this.GetDelimited(lookup.Table),
                     this.provider.ColumnAliasKeyword, this.GetDelimited(lookup.TableAlias));
             for (int fkey = 0; fkey < lookup.Source.Length; fkey++) {
                 join.AppendFormat(" {0} = {1} AND", this.GetDelimited(this.entity.Table, lookup.Source[fkey]),
                     this.GetDelimited(lookup.TableAlias, lookup.Dest[fkey]));
             }
             fromList.Append(join.Remove(join.Length - 4, 4).ToString() + ")");
         }
         else {
             lookup.tableAlias = (string)lookupTables[lookupKey];
         }
         fieldList.AppendFormat("{0} {1} {2}, ", this.GetDelimited(lookup.TableAlias, lookup.Field),
             this.provider.ColumnAliasKeyword, this.GetDelimited(lookup.FieldAlias));
     }
 }
Exemple #4
0
 public string CreateUpdate(FieldMap[] fieldMaps)
 {
     StringBuilder fieldList = new StringBuilder();
     for (int index = 0; index < fieldMaps.Length; index++) {
         fieldList.Append(this.GetDelimited(fieldMaps[index].Field) + " = "
                 + fieldMaps[index].Parameter + ", ");
     }
     if (fieldList.Length >= 2) fieldList.Remove(fieldList.Length - 2, 2);
     return this.updatePreSet + fieldList.ToString() + this.updatePostSet;
 }
Exemple #5
0
        private void UpdateObject(Transaction transaction)
        {
            int changedCount = 0;
            int paramCount = this.entity.FieldCount - this.entity.ReadOnlyCount;
            if (this.initial == InitialState.Unchanged && this.entity.ChangesOnly && this.entity.UpdateSP.Length == 0) {
                for (int index = 0; index < this.entity.FieldCount; index++) {
                    if (this.entity[index].PersistType == PersistType.Persist
                        && !this.entity.IsKeyMember(this.entity[index].Member)) {
                        if (this.IsDirty(index)) {
                            changedCount++;
                        }
                        else {
                            paramCount--;
                        }
                    }
                }
                if (changedCount == 0) return;
            }

            Parameter[] parameters = new Parameter[paramCount];
            FieldMap[] changedFields = new FieldMap[changedCount];
            int paramIndex = 0;
            int changedIndex = 0;
            int concurrentIndex = paramCount - 1;
            for (int index = 0; index < this.entity.FieldCount; index++) {
                if (this.entity[index].PersistType != PersistType.ReadOnly
                    && !this.entity.IsKeyMember(this.entity[index].Member)) {
                    string name = this.entity[index].Parameter;
                    object nullValue = this.entity[index].NullValue;
                    object value = this.GetField(this.entity[index].Member);
                    if (this.entity[index].PersistType == PersistType.Concurrent) {
                        parameters[concurrentIndex] = new Parameter(name, value, nullValue);
                        concurrentIndex--;
                    }
                    else { // PersistType.Persist
                        if (changedCount == 0 || this.IsDirty(index)) {
                            parameters[paramIndex] = new Parameter(name, value, nullValue);
                            paramIndex++;
                            if (changedCount > 0) {
                                changedFields[changedIndex] = this.entity[index];
                                changedIndex++;
                            }
                        }
                    }
                }
            }

            FieldMap[] keyFields = this.entity.KeyFields;
            for (int index = 0; index < keyFields.Length; index++) {
                string keyName = keyFields[index].Parameter;
                object keyNullValue = keyFields[index].NullValue;
                object keyValue = this.GetField(keyFields[index].Member);
                parameters[paramIndex] = new Parameter(keyName, keyValue, keyNullValue);
                paramIndex++;
            }
            string update;
            if (changedCount == 0) {
                update = this.commands.Update;
            }
            else {
                update = this.commands.CreateUpdate(changedFields);
            }
            int output = this.context.Connection.TransactionCommand(transaction.id, this.EntityObject.GetType(), CommandInfo.Update,
                transaction.transaction, update, parameters);
            if (output <= 0) {
                throw new PersistenceException("ObjectSpace: Entity Object was not Updated - " + this.entity.Type);
            }
        }
Exemple #6
0
 internal object SetField(FieldMap member, object value)
 {
     return this.SetField(member.Member, value);
 }
Exemple #7
0
 internal object GetField(FieldMap member)
 {
     return this.GetField(member.Member);
 }
Exemple #8
0
		internal void AddLookup(string member, string field, string nullValue, string alias,
				string parameter, string table, string source, string dest, CustomProvider provider) {
			this.AddMember(member);
			FieldMap[] tempFields = new FieldMap[this.fields.Length + 1];
			this.fields.CopyTo(tempFields, 0);
			tempFields[this.fields.Length] = new LookupMap(member, field, nullValue,
				parameter, table, source, dest, EntityMap.GetType(this.Member(member)), provider);
			this.readOnlyCount++;
			this.fields = tempFields;
			this.helper.Add(alias, this.fields.Length - 1);

			if (this.baseEntity != null && !this.baseEntity.subFields.ContainsKey(field)) {
				this.baseEntity.subFields.Add(field, this.fields[this.fields.Length - 1]);
			}
		}
Exemple #9
0
		// Includes Null-Value Assistance from Tim Byng (http://www.missioninc.com)
		internal void AddField(string member, string field, string nullValue, string alias,
				string parameter, PersistType persistType, CustomProvider provider) {
			this.AddMember(member);
			FieldMap[] tempFields = new FieldMap[this.fields.Length + 1];
			this.fields.CopyTo(tempFields, 0);
			tempFields[this.fields.Length] = new FieldMap(member, field, nullValue,
				parameter, persistType, EntityMap.GetType(this.Member(member)), provider);
			int keyIndex = -1;
			for (int index = 0; index < this.keyMembers.Length; index++) {
				if (this.keyMembers[index].Equals(member)) keyIndex = index;
			}
			if (keyIndex > -1) {
				FieldMap[] tempKeyFields = new FieldMap[this.keyFields.Length + 1];
				this.keyFields.CopyTo(tempKeyFields, 0);
				tempKeyFields[this.keyFields.Length] = tempFields[this.fields.Length];
				this.keyFields = tempKeyFields;
			}
			if (persistType == PersistType.ReadOnly) this.readOnlyCount++;
			if (persistType == PersistType.Concurrent) this.concurrentCount++;
			this.fields = tempFields;
			this.helper.Add(alias, this.fields.Length - 1);

			if (this.baseEntity != null && !this.baseEntity.subFields.ContainsKey(field)) {
				this.baseEntity.subFields.Add(field, this.fields[this.fields.Length - 1]);
			}
		}
		private string[] GetFieldNames(FieldMap[] fields)
		{
			string[] fieldNames = new string[fields.Length];
			for( int i = 0; i < fields.Length; i++ )
			{
				fieldNames[i] = fields[i].Field;
			}
			return fieldNames;
		}
Exemple #11
0
 private void AddSelectField(StringBuilder fieldList, StringBuilder fromList, Hashtable lookupTables, FieldMap field)
 {
     if (!field.IsLookup)
     {
         fieldList.Append(this.GetDelimited(this.entity.Table, field.Field) + ", ");
     }
     else
     {
         LookupMap lookup    = field as LookupMap;
         string    lookupKey = string.Format("{0};{1};{2}", lookup.Table.ToUpper(),
                                             string.Join(",", lookup.Source).ToUpper(), string.Join(",", lookup.Dest).ToUpper());
         if (!lookupTables.ContainsKey(lookupKey))
         {
             string lookupTable = lookup.Table.Substring(lookup.Table.LastIndexOf('.') + 1);
             lookup.tableAlias = lookupTable + "_" + (lookupTables.Count + 1).ToString();
             lookupTables.Add(lookupKey, lookup.tableAlias);
             StringBuilder join = new StringBuilder();
             join.AppendFormat(" LEFT JOIN {0} {1} {2} ON", this.GetDelimited(lookup.Table),
                               this.provider.ColumnAliasKeyword, this.GetDelimited(lookup.TableAlias, true) + this.GetPostHint());
             for (int fkey = 0; fkey < lookup.Source.Length; fkey++)
             {
                 join.AppendFormat(" {0} = {1} AND", this.GetDelimited(this.entity.Table, lookup.Source[fkey]),
                                   this.GetDelimited(lookup.TableAlias, lookup.Dest[fkey]));
             }
             fromList.Append(join.Remove(join.Length - 4, 4).ToString() + ")");
         }
         else
         {
             lookup.tableAlias = (string)lookupTables[lookupKey];
         }
         fieldList.AppendFormat("{0} {1} {2}, ", this.GetDelimited(lookup.TableAlias, lookup.Field),
                                this.provider.ColumnAliasKeyword, this.GetDelimited(lookup.FieldAlias));
     }
 }