package com.db4o.samples;

import com.db4o.*;
import com.db4o.lib.Logger;

public class S10_Joining_Objects
{
	public static void main(String[] args)
	{
		ObjectContainer db = Db4o.openFile("samples.yap");
		Logger.log("*** S10 Adding all Individual to first Company as Employees");

		ObjectSet individuals = db.get(new Individual());
		ObjectSet companies = db.get(new Company());

		Company company = (Company)companies.next();
		company.employees = new Individual[individuals.size()];
		int i = 0;
		while(individuals.hasNext()){
				
				
			company.employees[i ++] = (Individual)individuals.next();
			// The employees array on company is filled with existing 
			// Individual objects retrieved from the database
				
				
		}

		
		db.set(company);
		// A single call to set() updates the company object in the database.
		
		
		db.close();
		S11_Instantiation_Depth.main(null);
		// S11 logs the result.
		
	}
}
