Skip to content

Commit

Permalink
- New sample data model
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-zhuk committed Jun 4, 2011
1 parent 1b5673c commit 2f85dc5
Show file tree
Hide file tree
Showing 28 changed files with 1,659 additions and 45 deletions.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,20 +1,133 @@
//
// main.m
// PonsoTest
//
// Created by mkc on 6/4/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
/*
Copyright 2011 Marko Karppinen & Co. LLC.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
main.m
mogenerator / PONSO
Created by Nikita Zhuk on 22.1.2011.
*/

#import <Foundation/Foundation.h>
#import "ModelCompany.h"
#import "ModelDepartment.h"
#import "ModelDepartmentAssistant.h"
#import "ModelDepartmentEmployee.h"
#import "ModelEmployee.h"
#import "ModelAssistant.h"

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// insert code here...
NSLog(@"Hello, World!");
ModelCompany *company1 = [[[ModelCompany alloc] init] autorelease];
company1.name = @"Our company";
company1.yearFoundedValue = 2003;

ModelEmployee *emp1 = [[[ModelEmployee alloc] init] autorelease];
ModelEmployee *emp2 = [[[ModelEmployee alloc] init] autorelease];

emp1.name = @"John The Engineer";
emp1.birthDate = [NSDate dateWithTimeIntervalSince1970:60*60];
emp1.isOnVacationValue = YES;

emp2.name = @"Mike The Tester";

ModelAssistant *as1 = [[[ModelAssistant alloc] init] autorelease];
ModelAssistant *as2 = [[[ModelAssistant alloc] init] autorelease];

as1.name = @"First assistant";
as1.birthDate = [NSDate date];

as2.name = @"Second assistant";
as2.birthDate = [NSDate date];

[company1 addEmployeesObject:emp1];
[company1 addEmployeesObject:emp2];
[company1 addAssistantsObject:as1];
[company1 addAssistantsObject:as2];

emp1.assistant = as2;
as2.boss = emp1; // Currently one-to-one relationships' inverse must be set manually

emp2.assistant = as1;
as1.boss = emp2; // Currently one-to-one relationships' inverse must be set manually

ModelDepartment *dep1 = [[[ModelDepartment alloc] init] autorelease];
ModelDepartment *dep2 = [[[ModelDepartment alloc] init] autorelease];
dep1.name = @"R&D Department";
dep2.name = @"QA Department";

// Setup workers of dep1
ModelDepartmentEmployee *depEmp1 = [[[ModelDepartmentEmployee alloc] init] autorelease];
depEmp1.employee = emp1;
depEmp1.startedWorking = [NSDate dateWithTimeIntervalSince1970:10000];
[dep1 addEmployeesObject:depEmp1];

ModelDepartmentEmployee *depEmp2 = [[[ModelDepartmentEmployee alloc] init] autorelease];
depEmp2.employee = emp2;
depEmp2.startedWorking = [NSDate dateWithTimeIntervalSince1970:20000];
[dep1 addEmployeesObject:depEmp2];

ModelDepartmentAssistant *depAs1 = [[[ModelDepartmentAssistant alloc] init] autorelease];
depAs1.assistant = as1;
depAs1.startedWorking = [NSDate dateWithTimeIntervalSince1970:30000];
[dep1 addAssistantsObject:depAs1];

// Setup workers of dep2
depEmp2 = [[[ModelDepartmentEmployee alloc] init] autorelease];
depEmp2.employee = emp2;
depEmp2.startedWorking = [NSDate dateWithTimeIntervalSince1970:40000];
[dep2 addEmployeesObject:depEmp2];

depAs1 = [[[ModelDepartmentAssistant alloc] init] autorelease];
depAs1.assistant = as1;
depAs1.startedWorking = [NSDate dateWithTimeIntervalSince1970:50000];
[dep2 addAssistantsObject:depAs1];

ModelDepartmentAssistant *depAs2 = [[[ModelDepartmentAssistant alloc] init] autorelease];
depAs2.assistant = as2;
depAs2.startedWorking = [NSDate dateWithTimeIntervalSince1970:60000];
[dep2 addAssistantsObject:depAs2];

[company1 addDepartmentsObject:dep1];
[company1 addDepartmentsObject:dep2];

// Test NSDictionary serialization
ModelCompany *recreatedCompany = [[[ModelCompany alloc] initWithDictionaryRepresentation:[company1 dictionaryRepresentation]] autorelease];
[recreatedCompany awakeFromDictionaryRepresentationInit];

NSDictionary *recreatedCompanyDict = [recreatedCompany dictionaryRepresentation];

NSLog(@"%@", [company1 dictionaryRepresentation]);
NSLog(@"%@", recreatedCompanyDict);

NSCAssert([recreatedCompanyDict isEqualToDictionary:[company1 dictionaryRepresentation]], @"ModelCompany serialization roundtrip failed.");
NSCAssert([recreatedCompany.employees count] == 2, @"");
NSCAssert([recreatedCompany.assistants count] == 2, @"");
NSCAssert([recreatedCompany.departments count] == 2, @"");

// Test file serialization (uses NSDictionary)
NSString *tempFile = [[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]] stringByAppendingPathExtension:@"ponso-temp-plist"];
BOOL result = [company1 writeToFile:tempFile];
NSCAssert(result, @"");

ModelCompany *recreatedCompany2 = [ModelCompany createModelObjectFromFile:tempFile];
NSDictionary *recreatedCompany2Dict = [recreatedCompany2 dictionaryRepresentation];
[[NSFileManager defaultManager] removeItemAtPath:tempFile error:nil];

NSCAssert([recreatedCompany2Dict isEqualToDictionary:[company1 dictionaryRepresentation]], @"ModelCompany serialization roundtrip failed.");

[pool drain];
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ModelAssistant.h
//
// $Id$
//

#import "_ModelAssistant.h"

@interface ModelAssistant : _ModelAssistant <_ModelAssistant>
// Custom logic goes here.
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ModelAssistant.m
//
// $Id$
//

#import "ModelAssistant.h"

@implementation ModelAssistant

#pragma mark Abstract method overrides




// Custom logic goes here.

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ModelCompany.h
//
// $Id$
//

#import "_ModelCompany.h"

@interface ModelCompany : _ModelCompany <_ModelCompany>
// Custom logic goes here.
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ModelCompany.m
//
// $Id$
//

#import "ModelCompany.h"

@implementation ModelCompany

#pragma mark Abstract method overrides




// Custom logic goes here.

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ModelDepartment.h
//
// $Id$
//

#import "_ModelDepartment.h"

@interface ModelDepartment : _ModelDepartment <_ModelDepartment>
// Custom logic goes here.
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ModelDepartment.m
//
// $Id$
//

#import "ModelDepartment.h"

@implementation ModelDepartment

#pragma mark Abstract method overrides




// Custom logic goes here.

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ModelDepartmentAssistant.h
//
// $Id$
//

#import "_ModelDepartmentAssistant.h"

@interface ModelDepartmentAssistant : _ModelDepartmentAssistant <_ModelDepartmentAssistant>
// Custom logic goes here.
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ModelDepartmentAssistant.m
//
// $Id$
//

#import "ModelDepartmentAssistant.h"
#import "ModelDepartment.h"
#import "ModelCompany.h"

@implementation ModelDepartmentAssistant

#pragma mark Abstract method overrides


- (ModelAssistant *)fetchAssistantObjectWithIDForAssistantRelationship:(id)objectID
{
NSAssert(self.department.company != nil, @"");

return [[self.department.company.assistants filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name = %@", objectID]] lastObject];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ModelDepartmentEmployee.h
//
// $Id$
//

#import "_ModelDepartmentEmployee.h"

@interface ModelDepartmentEmployee : _ModelDepartmentEmployee <_ModelDepartmentEmployee>
// Custom logic goes here.
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ModelDepartmentEmployee.m
//
// $Id$
//

#import "ModelDepartmentEmployee.h"
#import "ModelDepartment.h"
#import "ModelCompany.h"

@implementation ModelDepartmentEmployee

#pragma mark Abstract method overrides


- (ModelEmployee *)fetchEmployeeObjectWithIDForEmployeeRelationship:(id)objectID
{
NSAssert(self.department.company != nil, @"");

return [[self.department.company.employees filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name = %@", objectID]] lastObject];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ModelEmployee.h
//
// $Id$
//

#import "_ModelEmployee.h"

@interface ModelEmployee : _ModelEmployee <_ModelEmployee>
// Custom logic goes here.
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// ModelEmployee.m
//
// $Id$
//

#import "ModelEmployee.h"
#import "ModelCompany.h"

@implementation ModelEmployee

#pragma mark Abstract method overrides

- (ModelAssistant *)fetchAssistantObjectWithIDForAssistantRelationship:(id)objectID
{
NSAssert(self.company != nil, @"");

return [[self.company.assistants filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name = %@", objectID]] lastObject];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// ModelAssistant.h
//
// $Id$
//
// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to ModelAssistant.h instead.
//


#import <Foundation/Foundation.h>
#import "ModelObject.h"

@class ModelEmployee;
@class ModelCompany;
@class ModelDepartmentAssistant;


@protocol _ModelAssistant

@end


@interface _ModelAssistant : ModelObject
{
NSDate *birthDate;
NSString *name;


ModelEmployee *boss;

ModelCompany *company;

NSArray *departments;

}

@property (nonatomic, retain, readwrite) NSDate *birthDate;
@property (nonatomic, retain, readwrite) NSString *name;

@property (nonatomic, assign, readwrite) ModelEmployee *boss;

@property (nonatomic, assign, readwrite) ModelCompany *company;

@property (nonatomic, retain, readonly) NSArray *departments;




- (void)addDepartmentsObject:(ModelDepartmentAssistant*)value_;
- (void)removeDepartmentsObjects;
- (void)removeDepartmentsObject:(ModelDepartmentAssistant*)value_;


@end
Loading

0 comments on commit 2f85dc5

Please sign in to comment.