home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / visualj / msdev / samples / microsoft / olecontrols / sample_database.java < prev    next >
Encoding:
Java Source  |  1996-08-27  |  4.1 KB  |  113 lines

  1. import java.util.Date;
  2. import employee;
  3.  
  4. // mock-up of "sample database.mdb" used in DAOSample and RDOSample
  5. public class sample_database
  6. {
  7.     // Array of employee records
  8.     employee db[];
  9.     private int length = 31;
  10.  
  11.     // Constructor which initialize the "database"
  12.     sample_database()
  13.     {
  14.         db = new employee[length];
  15.         db[0] = new employee("Maria Anders","mariaa","chrisp",
  16.             "x4321","GL-30","May 1, 92",false);
  17.         db[1] = new employee("Ana Trujillo","anat","thomash",
  18.             "x4629","GL-14","Aug 14, 92",true);
  19.         db[2] = new employee("Antonio Moreno","antoniom","annd",
  20.             "x3932","GL-12","Apr 1, 92",false);
  21.         db[3] = new employee("Thomas Hardy","thomash","pedroa",
  22.             "x7788","GL-22","May 3, 93",true);
  23.         db[4] = new employee("Christina Berglund","chrisb","mariaa",
  24.             "x0921","GL-32","Dec 18, 92",true);
  25.         db[5] = new employee("Hanna Moos","hannam","chrisp",
  26.             "x0621","KJ-33","Oct 17, 93",false);
  27.         db[6] = new employee("FrΘdΘrique Citeaux","fredc","annd",
  28.             "x8860","GL-13","Jan 2, 94",true);
  29.         db[7] = new employee("Martφn Sommer","martins","mariaa",
  30.             "x2282","GL-36","Mar 5, 94",true);
  31.         db[8] = new employee("Laurence Lebihan","larryl","annd",
  32.             "x4540","GL-14","Nov 15, 94",false);
  33.         db[9] = new employee("Elizabeth Lincoln","elizl","pedroa",
  34.             "x4729","GL-29","Sep 23, 91",false);
  35.         db[10] = new employee("Chris Park","chrisp","chrisp",
  36.             "x1212","KJ-30","Feb 14, 91",false);
  37.         db[11] = new employee("Patricio Simpson","patricios","thomash",
  38.             "x5785","GL-11","May 30, 94",true);
  39.         db[12] = new employee("Francisco Chang","franc","chrisp",
  40.             "x3392","KJ-34","Jun 1, 92",false);
  41.         db[13] = new employee("Yang Wang","yangw","annd",
  42.             "x6545","GL-16","Mar 30, 92",true);
  43.         db[14] = new employee("Pedro Afonso","pedroa","mariaa",
  44.             "x7647","GL-20","Feb 24, 92",true);
  45.         db[15] = new employee("Elizabeth Brown","lizb","pedroa",
  46.             "x2382","GL-27","Sep 28, 95",false);
  47.         db[16] = new employee("Sven Ottlieb","sveno","chrisp",
  48.             "x9123","KJ-24","Mar 30, 94",false);
  49.         db[17] = new employee("Janine Labrune","janinel","sveno",
  50.             "x0678","KJ-27","Jun 17, 94",false);
  51.         db[18] = new employee("Ann Devon","annd","mariaa",
  52.             "x0297","GL-10","Apr 22, 91",true);
  53.         db[19] = new employee("Roland Mendel","rolandm","annd",
  54.             "x3425","GL-17","Aug 31, 92",true);
  55.         db[20] = new employee("Aria Cruz","ariac","sveno",
  56.             "x9857","KJ-26","May 23, 94",true);
  57.         db[21] = new employee("Diego Roel","diegor","peterf",
  58.             "x9444","KJ-22","Jun 23, 93",false);
  59.         db[22] = new employee("Martine RancΘ","martiner","sveno",
  60.             "x1016","KJ-25","Jul 20, 92",false);
  61.         db[23] = new employee("Maria Larsson","marial","peterf",
  62.             "x0695","KJ-21","May 13, 91",true);
  63.         db[24] = new employee("Peter Franken","peterf","chrisp",
  64.             "x7310","KJ-20","Jul 22, 92",false);
  65.         db[25] = new employee("Carine Schmitt","carines","mariaa",
  66.             "x3211","GL-33","Jun 3, 91",false);
  67.         db[26] = new employee("Paolo Accorti","paoloa","pedroa",
  68.             "x8260","GL-26","May 17, 93",true);
  69.         db[27] = new employee("Lino Rodriguez ","linar","pedroa",
  70.             "x2534","GL-23","Oct 21, 91",true);
  71.         db[28] = new employee("Eduardo Saavedra","eduardos","peterf",
  72.             "x4560","KJ-23","Mar 22, 93",false);
  73.         db[29] = new employee("JosΘ Pedro Freyre","josepf","thomash",
  74.             "x5828","GL-15","Jul 15, 91",false);
  75.         db[30] = new employee("AndrΘ Fonseca","andref","sveno",
  76.             "x9482","KJ-29","Aug 19, 93",true);
  77.      }
  78.  
  79.     // Imitate a Select where email=[parameter]
  80.     public employee find(String email)
  81.     {
  82.         for(int i = 0; i < length; i++)
  83.             if(db[i].email.equals(email))
  84.                 return db[i];
  85.         return null;
  86.     }
  87.  
  88.     // Imitate a Select where manager=[parameter]
  89.     public String[] findReports(String mgr)
  90.     {
  91.         // Create a temporary holding String array
  92.         String temp[] = new String[15];
  93.         int count = 0;
  94.  
  95.         // Search the "database" for matching records
  96.         for(int i = 0; i < length; i++)
  97.             if(db[i].manager.equals(mgr))
  98.             {
  99.                 temp[count] = db[i].email;
  100.                 count ++;
  101.             }
  102.  
  103.         // Create an array that is just the right size
  104.         String result[] = new String[count];
  105.  
  106.         // Copy the found records in to the result array
  107.         for(int i = 0; i < count; i++)
  108.             result[i] = temp[i];
  109.  
  110.         return result;
  111.     }
  112. }
  113.