Relationship between objects and information stored in a database

I've got a question that's pretty broad... but maybe someone can help with it.
I'm writing a couple of classes, one called "Customer" and the other "Store". Store can contain any number of customers, which it keeps in an array. A customer object has name and address fields, as well as an array of the current movies the customer has checked out. A third "Driver" class has the main method which calls the other two classes. When a new customer is created, it is put into the array in an object of store, and written to disk in a file named with the customer's ID number.
My question is, I'm not really sure how objects tie in with the actual database on the hard disk. For example, if I run the program once and add 3 customers, all three get written to disk, and exist in memory as objects. However, when I exit the program, I lose all 3 of those objects from the array of customers in the store object.
So, when I run the program a second time, the array is gone, though the customer information remains on disk. I have methods to delete/add customer objects to an object of store, but those don't do me any good without the array in memory. I thought that I could just load all data from disk, and put them back into the array, but isn't that inefficient if the database is very large? Is there a better way to deal with this?
I hope that was reasonably clear. I'd appreciate any help. Thanks.

i would make the store a manager of the customer objects whose
responsibilities include read and writing the objects as well as caching
them.
here is some sample code for this.
public class Customer(){
  int id;
  /* the id field is the unique identifier for each Customer.
     this field should probably be our primary key in our database
     table. you don't have to use a number but whatever it is it
     needs to be unique */      
  boolean updated;
  public Customer(int customerId){
    id = customerId;
    updated = false;
  public int getCustomerId(){
    return id;
  /* if the customer object has been changed and needs to flushed back
     to the database this returns true. */
  public boolean needsFlushing(){
    return updated;
  /* and your other methods go here... */
}and now for the Store...
public class Store{
  private Customer[] cache;
  public Store(){
    cache = new Customer[10];
    /* here i have hard coded as 10, you could change this or for more
       flexibility use a Vector or such. */
  /* spin through the cache and return the matching customer. if the
     customer is not in the cache load it in the database. */
  public Customer getCustomer(int customerId)throws SQLException{
    for(int j=0;j<cache.length;j++){
      if((cache[j]!=null)&&(cache[j].getCustomerId()==customerId)){
        return cache[j];
    Customer c = loadCustomer(customerId);
    addToCache(c);
    return c;
  public void addCustomer(Customer c)throws SQLException{
    /* adds a new (non-existing customer) */
    saveCustomer(c);
    addToCache(c);
  public void close()throws SQLException{
    /* flushes back any updated customers */
    for(int j=0;j<cache.length;j++){
      if((cache[j]!=null)&&(cache[j].needsFlushing())){
        saveCustomer(cache[j]);
    cache = null;   
  private Customer loadCustomer(int customerId)throws SQLException{
    /* here would be code for loading a customer object from the
       database that matches the customerId. */
    return new Customer(customerId);//temporary 
  private void saveCustomer(Customer c)throws SQLException{
    /* here would be the code for saving the customer c into the
       database */
  private void addToCache(Customer c){
    /* this method adds the customer c to the cache. it may have to
       to remove an older customer from the cache to do this. i leave
       the algorithm for deciding this up to you */

Similar Messages

  • OTL - Table Relationship between Timecard and Workflow

    Hi All,
    Our employees work multiple projects and charge their time thru OTL to each of individual project as appropriate every pay period. Each project has it's own project manager. When an employee sumbits his timecard for approval the workflow routes an approval notification to EACH project manager. Every project manager must approve the employee's timecard before the "overall" timecard status is APPROVED.
    For example, an employee works on four diffent projects - each project has a different PM. When the employee submits his timecard for approval an approval notification is sent to all four PMs. However, more than occasionally at least one of the PMs doesn't approve the timecard in a timely fashion so the employee's timecard is "hung up" waiting for approval.
    I need to write a query in which I specifiy both an employee and particular pay period, and the query returns for the employee/pay peirod EACH Project Name, the PM for the respective project, and whether or not the the PM has approved the employee's time for the respective PM's project in the specified pay period.
    Unfortunately I don't really know where to start. I don't know if there is an HXC or group of HXC tables that would allow me to report on the individual project manager's 'status' (i.e., has a PM approved his project in the employee's timecard)...or do I need to allow include some workflow tables such as (maybe ?) wf_notifications ? And if I need to include some WF tables can someone help me understand where the relationship between timecard and WF is definded/stored (in other words, for a particular timecard how can I query a WF table - for example, wf_notifications - and find all the respective notifications associated with that particular timecard ?
    I hope my question is clear, but please advise if you have any questions. Thanks in advance for the help !!
    Jeff

    Hi Jeff,
    Did you ever get an answer on this question, as I have similar issues.
    One question you may be able to answer - Do all approvals on the project side need to be done for ANY project information to pull into Project Accounting, or as each Project Manager approves their portion does it pull in to PA?
    Thanks very much!!
    Lori

  • Difference/relationship between XML and XSD

    Hi All,
    Correct me if i am wrong,
    When we create a source and a target datatype in IR automatically objects will be created in XSD.
    The same way it does when we create message type.
    In message mapping, We map source and target message type and when we test with sample data, we can view source and target in xml
    My question is what is the difference/relationship between XML and XSD ?
    Thanks,
    ss

    Hi,
    XML (Extensible Markup Language) is a W3C initiative that allows information and services to be encoded with meaningful structure and semantics that computers and humans can understand. XML is great for information exchange, and can easily be extended to include user-specified and industry-specified tags.
    Whereas
    An XML Schema Definition (XSD) is an instance of an XML schema written in the XML Schema language. An XSD defines a type of XML document in terms of constraints upon what elements and attributes may appear, their relationship to each other, what types of data may be in them, and other things. It can be used with validation software in order to ascertain whether a particular XML document is of that type, and to produce a Post-Schema Validation Infoset.
    I hope this clarifies.
    Regards.
    Praveen

  • 2-way Trust Relationship between Windows and Mac Domain

    Hi guys I hope someone can help me.
    Just a quick explanation of what I am trying to do.
    I have an Xserve running OSX 10.5.8 server, which is the OD Master. On that server I’m running Kerio mail server. I have a Microsoft 2003 server running AD.
    The problem is I need to run BlackBerry Enterprise on the Windows server as the BlackBerry need active directory to work.
    Since I have both system already running, I do not want to destroy my open directory just to get the BlackBerry working.
    So what I have tried to do is create a 2-way Trust Relationship between the 2 domains, so the BlackBerry server will talk to the Kerio mail server.
    The trust relationship appears to create fine from the Windows server side, but I’m not able to retrieve LDAP information from the open directory server.
    The creation from the OSX server starts fine automated but then I had to finish it manually.
    Has anyone else here created a 2-way trust relationship between Windows and Mac’s before? Any help on how you did it would be appreciated. Thanks

    Have you checked on when the computer last checked in and changed the computer account password with the domain?  When a computer changes it's password, Active Directory will store only the current password and it does not expire.  The workstation
    will store both the current password and the previous password.  This for cases when you may restore Active Directory to a point before the computer password change.  
    To handle this, the workstation will try it's current password, then it's previous.
    If you're restoring the workstation to a previous point in time, you may be rolling the stored passwords back too far for Active Directory to accept.  I would only imagine this to be the case a handful of times if you're going back 1-2 days.
    Are you experiencing 100% failure?

  • Relationship between Objects Not Found in PA

    Dear all,
    I have uploaded objects (Org Unit, Job, and Position) and the relationships between objects separately using LSMW.
    When i checked the update of the relationship between objects in PA30, but the relationship between objects (Org Unit, Job, and Position) did not exist, yet exists in PP02.
    I tried to upload the relationships between objects using holder (A008) in LSMW again, still I could not find the relationships in PA30, but exist in PP02.
    Then I tried to run rhinte00 and rhinte30 to link the relationship between objects. I managed to get through rhinte00, but failed to run rhinte30.
    Below is the report log when I tried to run rhinte30.
    Report log:   
    Processing mode:   Processing successful 
    Number of personnel nos. selected :   0 
    Personnel numbers with errors:

    Check the following.
    1. Check if integration is active in T77S0 table PLOGI PLOGI = Your active plan version & PLOGI ORGA = X
    2. Check if all your objects are created with this active plan version
    3. Check the feature PLOGI to see if your PA PSA etc for the employee are integrated.
    cheers
    Ajay

  • Trust Relationship between PC and Domain broken\failed after System Restore

    We are currently faced with a problem that every time we do a System Restore on our Windows 7 workstation, upon login attempt, we an login failed because the Trust Relationship between PC and Domain is broken. 
    As solution: we have to log in as a local admin,  remove the workstation account from the domain, then re-add the workstation back to the domain.
    Does anybody know if there is a hotfix for this or how we can bypass having to remove and re-add the workstation to the domain in order to login?

    Have you checked on when the computer last checked in and changed the computer account password with the domain?  When a computer changes it's password, Active Directory will store only the current password and it does not expire.  The workstation
    will store both the current password and the previous password.  This for cases when you may restore Active Directory to a point before the computer password change.  
    To handle this, the workstation will try it's current password, then it's previous.
    If you're restoring the workstation to a previous point in time, you may be rolling the stored passwords back too far for Active Directory to accept.  I would only imagine this to be the case a handful of times if you're going back 1-2 days.
    Are you experiencing 100% failure?

  • What's the relationship between Flex and AIR?

    What's the relationship between Flex and AIR?
    I only know that Flex is a Framework and the AIR is a runtime,
    Can any one tell me more about these two object in detail,thanks a lot!

    AIR is a runtime that supports a superset of the Flash Player API. You use it to run mobile and desktop applications, as opposed to browser apps.
    Flex is a set of technologies for building either AIR apps or browser apps. It includes a framework of runtime classes (e.g, Button, DataGrid, etc.) to use in your applications, an SDK with a command-line compiler, and an IDE called Flash Builder (formerly Flex Builder) that supports intelligent editing, a design view, and a debugger.
    So, a brief statement of their relationship is that you can use Flex to build AIR apps.
    Gordon Smith
    Adobe Flex SDK Team

  • Any relationship between Fa_Mass_Additions and Fa_Additions_B?

    Dear all,
    I am looking for any relationship between Fa_Mass_Additions and Fa_Additions_B?
    Because it is not_ an asset in Fa_Mass_Additions table, and it becomes an asset in Fa_Additions_B.
    I just wondering any relationship I can track between these two?
    Thanks.

    Hello.
    FA_ADDITIONS_B contains descriptive information to help you identify your assets.
    The relation is:
    Table           Foreign Table      Foreign Key Column
    FA_MASS_ADDITIONS FA_ADDITIONS_B FA_MASS_ADDITIONS.ADD_TO_ASSET_ID
    Hope this helps.
    Octavio

  • Separate document no. for SD revision document and detagging relationship between invoice and SD document no.

    HI,
    Country specific settings for India - Business transactions enables SD revision vide table TE872_SDCTRL_IND.
    Whenever SD revision takes place system issue similar document no. as that of invoice and tagged it with XBLNR as per standard process.
    Now issue that if that invoice is reversed, subsequent SD also gets reversed.
    So business requires to have separate document no. for SD revision document and detagged relationship between invoice and SD document no.
    I have explored event R507, 0010, 0060 and R436 but couldn't find input structure where such separate document can be assigned.
    So can you provide hint which can assist in issue resolution?
    Regards,
    Paresh

    Check this thread, if this helps.
    [url] Link between MKPF table and EKKO or RBKP table [url]
    I've done this as well earlier to create a custom document flow for archived documents where from the EBELN i've found all the related documents. Hope this helps.

  • Could I build 1:N relationship between CMP and BMP?

    Hi, as subject, Could I build 1:N relationship between CMP and BMP?
    Thanks a lot!
    a13519

    Container managed relationships only apply to CMP beans. You can look at the DTD in appendix B of the EJB spec or chapter 10 where they make this distinction.

  • Copy and paste styles between objects and entire slides

    Hi,
    In Keynote 5 I was able to copy and paste styles between objects and even between entire slides.
    cmd+alt+c on one object (like a circle) and all its details like shadows, colors and animations could be transferred to another object.
    One could even do it with entire slides and transfer one animation style to all the other slides.
    THAT DOES NOT WORK ANYMORE.
    Does anybody else miss these features?
    Or is it just me?

    object animations tools are:
    copy animation:   Format > Copy Animation
    paste animation   Format > Paste Animation
         there are no keyboard short commands for these.
    There are no tools to copy or paste transitions between slides, you could duplicate the slide then add the content.

  • Differences Between Object And System Privileges

    Hi,
    Whats the difference between object and system privileges in oracle?
    Cheers
    Paul

    System Privileges
    A system privilege is the right to perform a particular action, or to perform an action on any schema objects of a particular type. For example, the privileges to create tablespaces and to delete the rows of any table in a database are system privileges.
    Schema Object Privileges
    A schema object privilege is a privilege or right to perform a particular action on a specific schema object:
    For example, the privilege to delete rows from the departments table is an object privilege.
    Some schema objects, such as clusters, indexes, triggers, and database links, do not have associated object privileges. Their use is controlled with system privileges. For example, to alter a cluster, a user must own the cluster or have the ALTER ANY CLUSTER system privilege.
    A schema object and its synonym are equivalent with respect to privileges. That is, the object privileges granted for a table, view, sequence, procedure, function, or package apply whether referencing the base object by name or using a synonym.
    Granting object privileges on a table, view, sequence, procedure, function, or package to a synonym for the object has the same effect as if no synonym were used. When a synonym is dropped, all grants for the underlying schema object remain in effect, even if the privileges were granted by specifying the dropped synonym.

  • Differences between object and object references

    What's the differences between object and object references? To me, it seems the same, but I am sure there are differences.
    Student s = new Student("Joe",20);
    s is an object of class Student. Can we say s is an object reference of class Student?
    Please clarify. thanks!!

    Student s = new Student("Joe",20);
    s is an object of class Student. Can we say s is an
    object reference of class Student?The thing you created via "new Student()" is an object. The variable you declared via "Student s" contains a reference to that object. People say all kinds of things but I find it clearer to differentiate between variables and the objects they refer to.

  • What is rfc of creating relationship between ibase and partner?

    I need bapi or rfc for assign a partner to ibase.
         create relationship between ibase and parten.
    pls.

    Hi
    check this link
    Re: BAPI for creating IBASE structure
    Regards
    Pavan

  • Many to many relationships between Fact and Dimension

    Hi All,
    I have to solve two kind of many to many relationships between Fact and Dimension.
    1. Many to Many relationship between Fact and Dimension, using a bridge table, with FKs in fact and dimension to bridge table’s PK.
    2. Many to Many relationship between Fact and Dimension, using a bridge table, and an intersection table, with FK in fact to bridge table, and 2 FKs in intersection table to Dimension and to bridge table.
    I need help on implementing (how the mapping has to look like) them in OWB 9.2.0.2.8.
    Thanks,
    Aurelian Cojocaru

    Aurelian,
    Unfortunately, you cannot implement this in the dimensional model. You would have to use relational tables and relationships between those in order to implement your scenario.
    Thanks,
    Mark.

Maybe you are looking for