|
The Developer's Resource & Community Site
|
Three-Tier Architecture for a Bank Checking Account - Developing The Bank Account IDL
Author: Gopalan Suresh Raj
Date Submitted: January 26th 2000
Level of Difficulty: Advanced
Subjects Covered: Microsoft Transaction Server
Pre-required Reading: Microsoft Transaction Server
The source code for this example is available as a zip file for download here.
To work with any of these samples you will need the following:
- Microsoft Visual J++ ver 6.0
- Windows NT 4.0 Options Pack
- guidgen.exe and midl.exe from Microsoft Visual C++ ver 6.0
In Visual J++, the most simplest method to create an MTS server component is to first write your server code in pure Java and then create a COM wrapper for it. However, creating the component from scratch using the IDL will allow you more flexibility and control in coding the server component. Hence, we will develop our Bank Account from scratch using IDL.
The Steps involved in developing the MTS Server component are:
- Code the IDL
- Compile the IDL and generate the type library
1. Code the IDL
Write the code for the IDL as follows. Use guidgen.exe where necessary to generate new UUIDs. Code the Checking and Savings Account interfaces and create interfaces to access the Primary Key so that if we need to have a collection of keys that form our primary key, we can work easier.
Bank.idl |
[
uuid (07D690F0-FB95-11d2-97E3-006097A7D34F),
version (1.0)
]
library Bank { /*
* Primary Key Interface for accounts
*/
importlib ("stdole32.tlb");
[
uuid
(07D690F1-FB95-11d2-97E3-006097A7D34F),
dual
]
interface IAccountKey : IDispatch
{
HRESULT setKey ([in] int key);
}
/*
* Checking creation interface
*/
[
uuid
(07D690F2-FB95-11d2-97E3-006097A7D34F),
dual
]
interface ICheckingHome :
IDispatch {
HRESULT create ([in]
IAccountKey* key,
[in] BSTR name,
[in] double startingBalance);
}
/*
* Checking Interface for business rules
*/
[
uuid(07D690F3-FB95-11d2-97E3-006097A7D34F),
dual
]
interface IChecking : IDispatch {
HRESULT credit ([in] double
amount,
[in] IAccountKey* key);
HRESULT debit ([in] double
amount,
[in] IAccountKey* key);
HRESULT getBalance ([in]
IAccountKey* key,
[out, retval] double* balance);
HRESULT getCustomerName ([in]
IAccountKey* key,
[out, retval] BSTR* name);
}
/*
* Checking Primary Key class
*/
[
uuid(07D690F4-FB95-11d2-97E3-006097A7D34F)
]
coclass CheckingPK {
interface IAccountKey;
};
/*
* Checking class
*/
[
uuid(07D690F5-FB95-11d2-97E3-006097A7D34F)
]
coclass Checking {
interface ICheckingHome;
interface IChecking;
};
/*
* Savings creation interface
*/
[
uuid
(07D690F6-FB95-11d2-97E3-006097A7D34F),
dual
]
interface ISavingsHome :
IDispatch {
HRESULT create ([in]
IAccountKey* key,
[in] BSTR name,
[in] float interestRate,
[in] double startingBalance);
}
/*
* Savings Interface for business rules
*/
[
uuid(07D690F7-FB95-11d2-97E3-006097A7D34F),
dual
]
interface ISavings : IDispatch {
HRESULT credit ([in] double
amount,
[in] IAccountKey* key);
HRESULT debit ([in] double
amount,
[in] IAccountKey* key);
HRESULT getBalance ([in]
IAccountKey* key,
[out, retval] double* balance);
HRESULT getCustomerName ([in]
IAccountKey* key,
[out, retval] BSTR* name);
HRESULT getInterestRate ([in]
IAccountKey* key,
[out, retval] float* rate);
}
/*
* Savings Primary Key
*/
[
uuid(07D690F8-FB95-11d2-97E3-006097A7D34F)
]
coclass SavingsPK {
interface IAccountKey;
};
/*
* Savings class
*/
[
uuid(07D690F9-FB95-11d2-97E3-006097A7D34F)
]
coclass Savings {
interface ISavingsHome;
interface ISavings;
};
};
|
2. Generate the type library from the IDL
Use the midl.exe that comes with your VC++ to compile the IDL files. If the VC++ environment variables are not loaded use the full path to midl.exe. Notice that Bank.tlb will now appear.
MS
DOS Command Prompt |
E:\com\gopalan\AccountMTS>
E:\com\gopalan\AccountMTS>midl Bank.idl
Microsoft (R) MIDL Compiler Version 5.01.0164
Copyright (c) Microsoft Corp 1991-1997. All rights
reserved.
Processing .\Bank.idl
Bank.idl
Processing D:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\oaidl.idl
oaidl.idl
Processing D:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\objidl.idl
objidl.idl
Processing D:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\unknwn.idl
unknwn.idl
Processing D:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\wtypes.idl
wtypes.idl
E:\com\gopalan\AccountMTS>
|
Next Page....Developing the Checking account MTS Server
What do you think of this article?
Have your say about the article. You can make your point about the article by mailing [email protected] (If you haven't allready joined, you can join by going to https://www.onelist.com/community/dev-java).
You can also write a review. We will publish the best ones here on this article. Send your review to [email protected]. Please include the title of the article you are reviewing.
Further Reading
The MTS Series by Gopalan Suresh Raj:
Microsoft Transaction Server By Gopalan Suresh Raj.
Gopalans introductory article on Microsoft Transaction Server intorduces the basics to MTS, and leads in to the example articles included in the series.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: None
Developing a Simple MTS Server Component By Gopalan Suresh Raj.
Part 1 of a two part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server
Developing a Simple MTS Client Application By Gopalan Suresh Raj.
Part 2 of a two part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing a Simple MTS Server Component
MTS Server Component By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the second part of this three part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing The Bank Account IDL
MTS Client By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the third part of this three part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing The Bank Account IDL, MTS Server Component
Author: Gopalan Suresh Raj
You can meet Gopalan, and the other iDevResource authors in Author Central. Gopalan also maintains his own site at https://www.execpc.com/~gopalan/.
Contributors to iDevResource.com get their own site at Author Central. Why not write an article and become a member of the iDevResource community.
© Copyright 1997-2000 Gopalan Suresh Raj. Reproduced with Permission
|