Commits

Tuukka Norri committed f8da748

Bug fix
- Removed an unneeded method from BXPGInterface.
- Fixed a bug which might have caused hidden attributes to become included when resetting attribute exclusion.

Comments (0)

Files changed (7)

Sources/BXAttributeDescription.m

 	[super dealloc];
 }
 
+#if 0
 - (id) initWithCoder: (NSCoder *) decoder
 {
 	if ((self = [super initWithCoder: decoder]))
 	{
 		[self setPrimaryKey: [decoder decodeBoolForKey: @"isPrimaryKey"]];
+		//FIXME: excludedByDefault
 		[self setExcluded: [decoder decodeBoolForKey: @"isExcluded"]];
 		mRelationshipsUsing = PGTSSetCreateMutableStrongRetainingForNSRD ();
 	}
 - (void) encodeWithCoder: (NSCoder *) coder
 {
 	[coder encodeBool: [self isPrimaryKey] forKey: @"isPrimaryKey"];
+	//FIXME: excludedByDefault
 	[coder encodeBool: [self isExcluded] forKey: @"isExcluded"];
 	[super encodeWithCoder: coder];
 }
+#endif
 
 /** \brief Whether the attribute is part of the primary key of its entity. */
 - (BOOL) isPrimaryKey
 	}
 }
 
+- (void) setExcludedByDefault: (BOOL) aBool
+{
+	if (![self isPrimaryKey])
+	{
+		if (aBool)
+			mFlags |= kBXPropertyExcludedByDefault;
+		else
+			mFlags &= ~kBXPropertyExcludedByDefault;
+	}
+}
+
+- (void) resetAttributeExclusion
+{
+	if (kBXPropertyExcludedByDefault & mFlags)
+		mFlags |= kBXPropertyExcluded;
+	else
+		mFlags &= ~kBXPropertyExcluded;
+}
+
 - (void) setAttributeValueClass: (Class) aClass
 {
 	mAttributeClass = aClass;

Sources/BXAttributeDescriptionPrivate.h

 + (id) attributeWithName: (NSString *) name entity: (BXEntityDescription *) entity;
 - (void) setPrimaryKey: (BOOL) aBool;
 - (void) setExcluded: (BOOL) aBool;
+- (void) setExcludedByDefault: (BOOL) aBool;
 - (void) setPrimaryKey: (BOOL) aBool;
 
 - (void) setAttributeValueClass: (Class) aClass;

Sources/BXDatabaseContext.m

 #import "BXLocalizedString.h"
 #import "BXDatabaseObjectModel.h"
 #import "BXDatabaseObjectModelStorage.h"
+#import "BXAttributeDescriptionPrivate.h"
 
 #import "NSURL+BaseTenAdditions.h"
 
 			if (nil != excludedFields)
 			{
 				excludedFields = [entity attributes: excludedFields];
-				[excludedFields setValue: [NSNumber numberWithBool: YES] forKey: @"excluded"];
+				[[excludedFields PGTSDo] setExcluded: YES];
 			}
 			
 			if (BASETEN_BEGIN_FETCH_ENABLED ())

Sources/BXEntityDescription.m

 
 - (void) resetAttributeExclusion
 {
-	BXEnumerate (currentProp, e, [mAttributes objectEnumerator])
-		[currentProp setExcluded: NO];
+	[[mAttributes PGTSDo] resetAttributeExclusion];
 }
 
 - (NSArray *) attributes: (NSArray *) strings

Sources/BXPGInterface.h

 
 
 @interface BXPGInterface (Visitor) <PGTSQueryVisitor>
-- (void) addAttributeFor: (PGTSColumnDescription *) field into: (NSMutableDictionary *) attrs 
-				  entity: (BXEntityDescription *) entity primaryKeyFields: (NSSet *) pkey;
 @end

Sources/BXPGInterface.m

 					//Internal fields are excluded by default.
 					NSInteger idx = [column index];
 					if (idx <= 0)
+					{
+						[attr setExcludedByDefault: YES];
 						[attr setExcluded: YES];					
+					}
 					
 					NSLog (@"table: %@ column: %@ idx: %d isEx: %d", [table name], name, idx, [attr isExcluded]);
 					[currentAttributes setObject: attr forKey: name];
 	}
 	return nil;
 }
-
-- (void) addAttributeFor: (PGTSColumnDescription *) field into: (NSMutableDictionary *) attrs 
-				  entity: (BXEntityDescription *) entity primaryKeyFields: (NSSet *) pkey
-{
-	NSString* name = [field name];
-	BXAttributeDescription* desc = [attrs objectForKey: name];
-	if (! desc)
-		desc = [BXAttributeDescription attributeWithName: name entity: entity];
-	
-	BOOL isPrimaryKey = [pkey containsObject: field];
-	BOOL isOptional = (! ([field isNotNull] || isPrimaryKey));
-	[desc setOptional: isOptional];
-	[desc setPrimaryKey: isPrimaryKey];
-	
-	PGTSConnection* connection = [mTransactionHandler connection];
-	PGTSTypeDescription* typeDesc = [field type];
-	NSString* typeName = [typeDesc name];
-	[desc setDatabaseTypeName: typeName];
-	
-	NSDictionary* classDict = [connection deserializationDictionary];
-	[desc setAttributeValueClass: [classDict objectForKey: typeName]];
-	
-	//Internal fields are excluded by default.
-	if ([field index] <= 0)
-		[desc setExcluded: YES];
-	
-	[attrs setObject: desc forKey: name];
-}
 @end

Sources/BXPropertyDescription.h

 
 enum BXPropertyFlag
 {
-	kBXPropertyNoFlag		= 0,
-	kBXPropertyOptional		= 1 << 0,
-	kBXPropertyPrimaryKey	= 1 << 1,
-	kBXPropertyExcluded		= 1 << 2,
-	kBXPropertyIsArray		= 1 << 3	
+	kBXPropertyNoFlag				= 0,
+	kBXPropertyOptional				= 1 << 0,
+	kBXPropertyPrimaryKey			= 1 << 1,
+	kBXPropertyExcluded				= 1 << 2,
+	kBXPropertyIsArray				= 1 << 3,
+	kBXPropertyExcludedByDefault	= 1 << 4
 };
 
 #ifdef __cplusplus