baseten / Sources / BXPGAdditions.m

//
// BXPGAdditions.m
// BaseTen
//
// Copyright (C) 2006-2008 Marko Karppinen & Co. LLC.
//
// Before using this software, please review the available licensing options
// by visiting http://basetenframework.org/licensing/ or by contacting
// us at sales@karppinen.fi. Without an additional license, this software
// may be distributed only in compliance with the GNU General Public License.
//
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, version 2.0,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
// $Id$
//

#import "PGTSAdditions.h"
#import "BXPGAdditions.h"
#import "BXDatabaseAdditions.h"
#import "BXPropertyDescriptionPrivate.h"
#import "BXAttributeDescriptionPrivate.h"
#import "BXDatabaseObjectPrivate.h"
#import "BXLogger.h"


@implementation NSObject (BXPGAdditions)
- (NSString *) BXPGEscapedName: (PGTSConnection *) connection
{
	return [self PGTSEscapedName: connection];
}

- (NSString *) BXPGQualifiedName: (PGTSConnection *) connection
{
	return [self BXPGEscapedName: connection];
}
@end


@implementation BXEntityDescription (BXPGInterfaceAdditions)
- (NSString *) BXPGQualifiedName: (PGTSConnection *) connection
{
	NSString* schemaName = [[self schemaName] BXPGEscapedName: connection];
	NSString* name = [[self name] BXPGEscapedName: connection];
    return [NSString stringWithFormat: @"%@.%@", schemaName, name];
}
@end


@implementation BXAttributeDescription (BXPGInterfaceAdditions)
- (NSString *) BXPGQualifiedName: (PGTSConnection *) connection
{    
	return [NSString stringWithFormat: @"%@.%@", 
			[[self entity] BXPGQualifiedName: connection], [[self name] BXPGEscapedName: connection]];
}

- (NSString *) BXPGEscapedName: (PGTSConnection *) connection
{
	return [[self name] BXPGEscapedName: connection];
}

- (id) PGTSConstantExpressionValue: (NSMutableDictionary *) context
{
    PGTSConnection* connection = [context objectForKey: kPGTSConnectionKey];
    BXAssertValueReturn (nil != connection, nil, @"Expected connection not to be nil.");
    return [self BXPGQualifiedName: connection];
}
@end


@implementation PGTSFieldDescriptionProxy (BXPGAttributeDescription)
- (NSString *) BXPGEscapedName: (PGTSConnection *) connection
{
	return [[(id) self name] BXPGEscapedName: connection];
}
@end


@implementation NSURL (BXPGInterfaceAdditions)
#define SetIf( VALUE, KEY ) if ((VALUE)) [connectionDict setObject: VALUE forKey: KEY];
- (NSMutableDictionary *) BXPGConnectionDictionary
{
	NSMutableDictionary* connectionDict = nil;
	if (0 == [@"pgsql" caseInsensitiveCompare: [self scheme]])
	{
		connectionDict = [NSMutableDictionary dictionary];    
		
		NSString* relativePath = [self relativePath];
		if (1 <= [relativePath length])
			SetIf ([relativePath substringFromIndex: 1], kPGTSDatabaseNameKey);
		
		SetIf ([self host], kPGTSHostKey);
		SetIf ([[self user] BXURLDecodedString], kPGTSUserNameKey);
		SetIf ([[self password] BXURLDecodedString], kPGTSPasswordKey);
		SetIf ([self port], kPGTSPortKey);
	}
	return connectionDict;
}
@end


@implementation BXDatabaseObject (BXPGInterfaceAdditions)
- (void) PGTSSetRow: (int) row resultSet: (PGTSResultSet *) res
{
    [res goToRow: row];
    [self setCachedValuesForKeysWithDictionary: [res currentRowAsDictionary]];
}
@end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.