home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / orient / Linux / demo / writeCustomer.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-15  |  1.7 KB  |  75 lines

  1. #ifdef COMP_BCB
  2. // BORLAND C++ BUILDER INCLUDES
  3. #include <condefs.h>
  4. #else
  5. #define USEUNIT( arg )
  6. #define USELIB( arg )
  7. #endif
  8.  
  9.  
  10. //---------------------------------------------------------------------------
  11. // CUSTOM DATABASE HEADER
  12. #include "business.h"
  13. //---------------------------------------------------------------------------
  14. #include <stdio.h>
  15. //---------------------------------------------------------------------------
  16. // BORLAND C++ BUILDER DIRECTIVES
  17. USELIB("..\..\..\lib\win32\bcb\ojust.lib");
  18. //---------------------------------------------------------------------------
  19. int main(int argc, char* argv[])
  20. {
  21.   int     customers = 1;
  22.  
  23.   if( argc > 1 )
  24.     // GET CUSTOMERS 
  25.     customers = atoi( argv[1] );
  26.  
  27.   // START TRY/CATCH BLOCK FOR EXCEPTIONS CATCHING
  28.   try
  29.   {
  30.     d_Database    db;
  31.     d_Transaction tx;
  32.     
  33.     // OPEN DATABASE
  34.     db.open( "database/business" );
  35.  
  36.     // START TRANSACTION
  37.     tx.begin();
  38.  
  39.     d_Ref<Customer>    cli;
  40.  
  41.       // CREATE <CUSTOMERS> CUSTOMERS
  42.     for( int i = 0; i < customers; ++i )
  43.     {
  44.         // CREATE NEW PERSISTENT OBJECT INTO DATABASE PREVOIUSLY OPEN
  45.       cli = new( &db, "Customer" ) Customer;
  46.  
  47.         // FILL OBJECT
  48.       cli->code       =    i;
  49.       cli->name       =    "Luke";
  50.       cli->surname    =    "Green";
  51.       cli->notes      =    "This is a test";
  52.       cli->age        =    32;
  53.  
  54.       cli.delete_object();
  55.     }
  56.  
  57.     // COMMIT TRANSACTION
  58.     tx.commit();
  59.   }
  60.   catch( d_Error &e )
  61.   {
  62.     // DATABASE ERROR
  63.       cout << "Database error: " << e.what() << endl;
  64.   }
  65.   catch( ... )
  66.   {
  67.     // APPLICATION ERROR
  68.       cout << "Generic error" << endl;
  69.   }
  70.  
  71.   return 0;
  72. }
  73.  
  74.  
  75.