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

  1. #ifdef COMP_BCB
  2. // BORLAND C++ BUILDER INCLUDES
  3. #include <condefs.h>
  4. #else
  5. #define USELIB( arg )
  6. #endif
  7.  
  8.  
  9. //---------------------------------------------------------------------------
  10. // ORIENT DIRECT INCLUDE HEADER
  11. #include "ojust.h"
  12. //---------------------------------------------------------------------------
  13. // ORIENT HEADERS FOR SCHEMA CREATION
  14. #include "oLibrary.h"
  15. #include "oOrient.h"
  16. #include "oInterfaceManager.h"
  17. #include "oClass.h"
  18. #include "oMember.h"
  19. //---------------------------------------------------------------------------
  20. #include <stdio.h>
  21. //---------------------------------------------------------------------------
  22. // BORLAND C++ BUILDER DIRECTIVES
  23. USELIB("..\..\..\lib\win32\bcb\ojust.lib");
  24.  
  25.  
  26.  
  27. bool registerUserClasses();
  28.  
  29. //---------------------------------------------------------------------------
  30. int main(int argc, char* argv[])
  31. {
  32.   // REGISTER USER CLASSES
  33.   registerUserClasses();
  34.  
  35.   // START TRY/CATCH BLOCK FOR EXCEPTIONS CATCHING
  36.   try
  37.   {
  38.     d_Database    db;
  39.     d_Project     proj;
  40.  
  41.       // CREATE DATABASE
  42.        db.create( proj, "database/business", 10000000, 1000000, 5000000, 500000 );
  43.   }
  44.   catch( d_Error &e )
  45.   {
  46.     // DATABASE ERROR
  47.       cout << "Database error: " << e.what() << endl;
  48.   }
  49.   catch( ... )
  50.   {
  51.     // APPLICATION ERROR
  52.       cout << "Generic error" << endl;
  53.   }
  54.  
  55.   return 0;
  56. }
  57.  
  58.  
  59.  
  60. bool registerUserClasses()
  61. {
  62.   // REGISTER PERSONA CLASS
  63.   oClass *    clsPerson;
  64.  
  65.   clsPerson = new oClass( "Person" );
  66.   clsPerson->makePersistent();
  67.   clsPerson->addProperty( "name", oMember::D_STRING, oMember::PERSISTENT );
  68.   clsPerson->addProperty( "surname", oMember::D_STRING, oMember::PERSISTENT );
  69.   clsPerson->addProperty( "age", oMember::D_SHORT, oMember::PERSISTENT );
  70.   oInterfaceManager::registerInterface( "business", clsPerson );
  71.  
  72.   // REGISTER CLIENTE CLASS
  73.   oClass *    clsCustomer;
  74.  
  75.   clsCustomer = new oClass( "Customer" );
  76.   clsCustomer->addBase( clsPerson );
  77.   clsCustomer->addProperty( "code", oMember::D_ULONG, oMember::PERSISTENT );
  78.   clsCustomer->addProperty( "notes", oMember::D_STRING, oMember::PERSISTENT );
  79.   clsCustomer->addMethod( "display", 0 );
  80.   oInterfaceManager::registerInterface( "business", clsCustomer );
  81.  
  82.   // REGISTER MERCE CLASS
  83.   oClass *    clsProduct;
  84.  
  85.   clsProduct = new oClass( "Product" );
  86.   clsProduct->makePersistent();
  87.   clsProduct->addProperty( "name", oMember::D_STRING, oMember::PERSISTENT );
  88.   clsProduct->addProperty( "price", oMember::D_LONG, oMember::PERSISTENT );
  89.   oInterfaceManager::registerInterface( "business", clsProduct );
  90.  
  91.   // REGISTER FATTURA CLASS
  92.   oClass *    clsInvoice;
  93.  
  94.   clsInvoice = new oClass( "Invoice" );
  95.   clsInvoice->makePersistent();
  96.   clsInvoice->addProperty( "number", oMember::D_LONG, oMember::PERSISTENT );
  97.   clsInvoice->addProperty( "ownCustomer", oMember::D_REF, oMember::PERSISTENT, "business::Customer" );
  98.   clsInvoice->addProperty( "products", oMember::EMBEDDED, oMember::PERSISTENT, "System::d_Varray" );
  99.   oInterfaceManager::registerInterface( "business", clsInvoice );
  100.  
  101.   return true;
  102. }
  103.  
  104.  
  105.