Equivalent to [i]this[/i] and [i]getClass()[/i] inside a static method

All business objects of my application (Customer, Car, etc.) extend a root class (RootObject) which performs retrieving operations. Such operations are delegated to a static Loader that calls the respective method according to the type of the business object (loadAllCustomers for Customers, loadAllCars for Cars, etc). The problem is that I am unable to know which class is calling RootObject.loadAll() (a Customer or a Car) because both this and getClass() cannot be used inside static methods.
So, my question is : how can I determine which class is extending RootObject from inside its static loadAll() method ? It is either a Customer or a Car, but I cannot figure out how to get such information.
public class Customer extends RootObject { /*...*/ }
public class Car extends RootObject { /*...*/ }
public class RootObject {
  protected static Loader loader = new Loader();
  public static RootObject[] loadAll() {
    return loader.loadAll(getClass());  // does not compile
public class Loader {
  public RootObject[] loadAll(Class classe) {
    if (classe == Customer.class) return loadAllCustomers();
    if (classe == Car.class) return loadAllCars();
    return null;
public static void main(String args[]) {
  Car cars[] = (Car[]) Car.loadAll();
  System.out.println("number of cars = " + cars.length);
}Thank you.

Thank you guys.
We are trying to simulate an object-oriented database
on top of a relational one (or a file, or whatever).Sounds like you really want ORM, like Hibernate or TopLink.
Then, to retrieve a given car, we could be able to do
Car car = new Car();
car.setId("C1");
car.load();Instead, to retrieve a list of cars, I think it is
more intuitive to use a class method instead of an
instance one because we'll return a list, not a
single object :
Car cars[] = (Car[]) Car.loadAll();instead of
Car car = new Car();
Car cars[] = (Car[]) car.loadAll();  // a little odd,
isn't it ?Then, it is a design choice to make loadAll()
a static method.Sounds to me like you're trying to create objects that know how to persist themselves. That's one way to do it.
Another would be to separate the persistence code into a separate, interface-based class called a Data Access Object (DAO) or Repository that would handle this for you:
public interface CarRepository
    List<Car> find();
    Car find(Long id);
    void save(Car c);
    void update(Car c);
    delete(Car c);
}Now you can have different implementations for this interface, depending on how to wanted to tackle persistence. If it happens to be relational, all the SQL code is hidden from clients in the interface implementation.
%

Similar Messages

  • TS4291 I can't send mail from my iPad apps, I just get the error message, 'The recipient- was rejected by the server because it does not allow relaying.' Does anyone know what this means and how to fix the problem.

    I can't send mail from my iPad apps, I just get the error message, 'The recipient… was rejected by the server because it does not allow relaying.' Does anyone know what this means and how to fix the problem.

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    Setting up and troubleshooting Mail
    http://www.apple.com/support/ipad/assistant/mail/
    Using a POP account with multiple devices
    http://support.apple.com/kb/ht3228
    iOS: Adding an email account
    http://support.apple.com/kb/HT4810
    iOS: Setting up an Outlook.com, Hotmail, Live, or MSN email account
    http://support.apple.com/kb/ht1694
    Server does not allow relaying email error, fix
    http://appletoolbox.com/2012/01/server-does-not-allow-relaying-email-error-fix/
    Why Does My iPad Say "Cannot Connect to Server"?
    http://www.ehow.co.uk/info_8693415_ipad-say-cannot-connect-server.html
    How to Sync Contacts with Your iPad Using iTunes
    http://www.dummies.com/how-to/content/how-to-sync-contacts-with-your-ipad-using- itunes.html
    iOS: 'Mailbox Locked', account is in use on another device, or prompt to re-enter POP3 password
    http://support.apple.com/kb/ts2621
    eMail Groups - You can use a third party app that many users recommend.
    MailShot -  https://itunes.apple.com/us/app/mailshot-pro-group-email-done/id445996226?mt=8
    Group Email  -  https://itunes.apple.com/us/app/group-email!-mail-client-attachments/id380690305 ?mt=8
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Configuration problems with IMAP e-mail on iOS with a non-standard SSL port.
    http://colinrobbins.me/2013/02/09/configuration-problems-with-imap-e-mail-on-ios -with-a-non-standard-ssl-port/
    Try this first - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.)
    Or this - Delete the account in Mail and then set it up again. Settings->Mail, Contacts, Calendars -> Accounts   Tap on the Account, then on the red button that says Remove Account.
     Cheers, Tom

  • I am trying to import developed images from LightRoom 5 in o Photoshop 6.  I am receiving this message and the images will not open.....'Could not open scratch file because the file is locked, you do not have necessary access permissions or another progra

    I am trying to import developed images from LightRoom 5 Photoshop 6 for further editing.  I am receiving this message and the images will not open.....'Could not open scratch file because the file is locked, or you do not have necessary access permissions or another program is using the file.  Use the 'Properties' command in the Windows Explorer to unlock the file. How do I fix this?  I would greatly appreciate it if you would respond with terms and procedures that a computer ignorant user, such as me, will understand.   Thanks.

    Have you tried restoring the Preferences yet?

  • I'm getting this error statement: XULRUNNER error: platform version 6.0.2 is not compatible with min etc max etc6.0.1 - what is this about and how can it be corrected?

    This is what I think may have happened. The other day, Thursday Sept 8th, I shut down my pc in the middle of a Firefox upgrade. Now when I try to access Firefox on my pc, I get this error message:
    XULRUNNER Error: Platform version '6.0.2 is not compatible with min Version >= 6.0.1 max Version < 6.0.1
    What is this about and how can I retsore access to Firefox on my pc?

    If you use ZoneAlarm Extreme Security then try to disable Virtualization.
    Do a clean reinstall and delete the Firefox program folder.
    * http://kb.mozillazine.org/Browser_will_not_start_up#XULRunner_error_after_an_update
    *[[/questions/869812]]
    *[[/questions/869951]]

  • My iPod Touch 3rd Gen died this morning and doesn't work but comes up on iTunes on my Mac. Why is it doing this?

    Ok so I was using my iPod touch this morning and listenig to music on the dock and I took it off and now the iPod does'nt turn on and when I plug it in to my MacBook Pro it comes up and im not sure whats wrong with it.

    Hi,
    Try a Reset... You will Not Lose Any Data...
    Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
    The Apple logo will Appear and then Disappear...
    Usually takes about 15 - 20 Seconds...
    Release the Buttons...
    Turn the iPod On...
    You may have to try this several times...

  • I have two separate itune accounts under two different email accounts and would like to combine them under one account.  Is this possible and if so, how do I do it?

    I have two separate itune accounts under two different email accounts and would like to combine them under one account.  Is this possible and if so, how do I do it?

    If you go to Settings > iTunes & AppStore , you can sign out from your account, and sign in with the one you've used to purchase apps.This will not remove any apps you already have on it.
    Then you can go to AppStore and download apps you've purchased (either via "Purchased" button in "Updates", or simply search for them and download them.
    That way you can have multiple accounts' apps on your iPad. When updating, you will be prompted for the credentials for account you've purchased given App with.

  • HT201250 I use Time Machine to back up my entire computer with my external hard drive. I am getting a brand new iMac this month and was wondering what is the process of using this back up to restore my new computer exactly how my old computer was?

    I use Time Machine to back up my entire computer with my external hard drive. I am getting a brand new iMac this month and was wondering what is the process of using this back up to restore my new computer exactly how my old computer was? I want to make sure I will still have various important files on my new computer, like my songs in iTunes, my photos in iPhoto, etc, etc. Thanks so much in advance!

    Welcome to the Apple Support Communities
    When you turn on the new iMac for the first time, Setup Assistant will ask you to restore a backup, so connect the external disk and follow steps to restore all your files to your new iMac. Your new Mac will have the same settings and programs as your old computer.
    In other cases, I would recommend to restore the whole backup without using Migration Assistant or Setup Assistant, but a Late 2012 iMac uses a special OS X build, so the OS X version that you're using on your old Mac won't work on the new one. For more information, see > http://pondini.org/OSX/Home.html

  • I have just sought  to update my lightroom and am now unable to access the develop function and get a note stating that I have reduced functionality what it this about and how do I get my product back

    I have just sought  to update my lightroom and am now unable to access the develop function and get a note stating that I have reduced functionality what it this about and how do I get my product back

    Hi there
    I have version 5.7 and every time I opened it I was told that updates are available and to click on the icon to access these.  Instead it just took me to the
    adobe page with nowhere visible to update.  I then  sought to download lightroom cc and this is when I could not access the 'develop' section due to reduced
    functionality  It was apparent that my photos had been put in cc but no way to access them unless I wanted to subscribe. 
    I have since remedied the problem as  my original lightroom 5.7 icon is still available on the desktop and have gone back to that.  I do feel that this is a bit
    of a rip off and an unnecessary waste of my time though.
    Thank you for your prompt reply by the way.
    Carlo
    Message Received: May 04 2015, 04:52 PM
    From: "dj_paige" <[email protected]>
    To: "Carlo Bragagnolo" <[email protected]>
    Cc:
    Subject:  I have just sought  to update my lightroom and am now unable to access the develop function and get a note stating that I have
    reduced functionality what it this about and how do I get my product back
    dj_paige  created the discussion
    "I have just sought  to update my lightroom and am now unable to access the develop function and get a note stating that I have reduced functionality what it
    this about and how do I get my product back"
    To view the discussion, visit: https://forums.adobe.com/message/7510559#7510559
    >

  • I need to upgrade my MacBook 13" white 2008 hard drive.  I have found a WD6400BPVT western digital Scorpio blue 640GB (5400rpm) SATA 8MB 2.5" will this fit and work? Many thanks for any help

    I need to upgrade my MacBook 13" white 2008 hard drive.  I have found a WD6400BPVT western digital Scorpio blue 640GB (5400rpm) SATA 8MB 2.5" will this fit and work? Many thanks for any help

    I had a 640GB HDD in my Early 2008 Macbook and it was just too much it would always freeze up the computer a bit for only a few seconds but ya. Then I realized that it was the size of the HDD that was causing it since the Early 2008 Macbook models can only handle a MAX od 500GB while the Early 2008 Macbook Pros could have a MAX of 640GB (Lucked out there!) lol But ya the Early 2008 Mocbooks can only handle a MAX HDD size of 500GB and that's it!! lol

  • I downloaded the latest update of Itunes, and now I have no music.  NONE.  how do I uninstall this mess and go back to what I had, without having to  put it all back in manually.  I am really hating ITUNES right now.

    What happened to my music when I downloaded the latest version of Itunes?  I had quite a few songs there and now NOTHING. I want to uninstall this version and go back to the older one.  how do I do this without wiping out whatever else is left on there?  I am already ticked off that I will have to put all my music back an there manually    ( I don't want all my music collection on Itunes.  I am really hating Itunes right now.  So what can I do?

    Hi,
    [https://addons.mozilla.org/en-US/firefox/addon/xmarks-sync/?src=search Xmarks] is a bookmarks/history/tabs backup/sync utility. It is not a feature of Firefox. It is an extension which had to be manually added or perhaps could have come with another extension.
    If you have registered with the service you have to enter the username and password to log in to the service. Otherwise try pressing the '''Esc''' key on the keyboard and after Firefox opens, go to '''Tools''' ('''Alt''' + '''T''') > '''Add-ons''', click Extensions on the left and look for Xmarks and '''Disable''' to disable it or '''Remove''' to uninstall it. If that doesn't work, start Firefox in [https://support.mozilla.com/en-US/kb/Safe%20Mode Safe Mode.] In the first screen choose '''Disable all add-ons''' and '''Make Changes and Restart''' and repeat the above procedure, but this time, re-enable all the needed extensions except Xmarks. You may also have to re-enable the plugins after clicking '''Plugins''' on the left).
    [https://support.mozilla.org/en-US/kb/Uninstalling%20add-ons?s=add-ons+tab&r=3&e=sph&as=s Uninstalling Add-ons]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes Troubleshooting Extensions and Themes]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20plugins Troubleshooting Plugins]

  • Trying to sync iPod with library, but receive this message, "The iPod is synced with another itunes library.  Do you want to erase this ipod and sync with this itunes library".  I do not want to erase my iPod... Any suggestions??  Please help!!

    Trying to sync ipod with itunes library, but I keep getting this message, "  The ipod is synced with another itunes library.  Do you want to erase this ipod and sync with this i tunes library?" 
    I do not want to erase my ipod!!!  Any suggestions?? please help!

    Another way. You can use a USB flash drive & the camera connection kit.
    Plug the USB flash drive (works the same with an SD card) into your computer & create a new folder titled DCIM. Then put your movie/photo files into the folder. The files must have a filename with exactly 8 characters long (no spaces) plus the file extension (i.e., my-movie.mov; DSCN0164.jpg).
    Now plug the flash drive into the iPad using the camera connection kit. Open the Photos app, the movie/photo files should appear & you can import. (You can not export using the camera connection kit.)
    Using The iPad Camera Connection Kit
    http://support.apple.com/kb/HT4101
     Cheers, Tom

  • All my excel files were converted to pdf. Why would this happen and how do i stop it from doing so?

    All my excel files were converted to pdf. Why would this happen and how do i stop it from doing so?

    shloimypt wrote:
    All my excel files were converted to pdf. Why would this happen and how do i stop it from doing so?
    Relax, they weren't converted to PDF.
    You can tell by right clicking ANY of them and choosing "Properties". You'll see there that they're STILL .xls or .xlsx files. The "association" has changed and Windows now indicates that they open with Reader, which isn't right.
    Where it says "Open With" under the General tab, you can click "Change" and re-select Excel as the default app to open thim.
    See: http://helpx.adobe.com/acrobat/kb/application-file-icons-change-acrobat.html

  • HT204053 there is a new email on my phone apple id when I try to make an app purchase my own apple id does not work. How does this happen and how can I change it back?

    There is a new email address on my phone in the apple id password box.  My password will not work.  How did this happen and how can I change it back?

    Of course your password shouldn't work on a different Apple ID. This can happen for many reasons, no worries, just sign out back back in using your own ID.
    iOS: Changing the signed-in iTunes Store account
              http://support.apple.com/kb/HT1311

  • Hii guys! I need your help now! I want to buy Gems in the game 'Clash of clans' and it doesn't work! It comes always a caskat inthere is ' Contact iTunes Store Support to complete this transaction' and I don't now know what i should do ? Help me please :)

    Clash of clans

    If you haven't already done so then you can contact iTunes support via this page and ask them why the message is appearing (these are user-to-user forums, we won't know why) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • Can anyone explain this behavior and tell me how to fix it?

    Using NetBeans 6.5 on Windows, Glassfish v2.1
    I have a JSF application with a page that has a tab set.
    On one of the tabs I have a panel with company information.
    One of the components on the page is an InputText field with the value bound to a session bean variable.
    The tab also has an Add button.
    Here is what the JSP looks like for the input text and button components
       <h:inputText binding="#{MainPage.companyNameTF}" id="companyNameTF" readonly="#{SessionBean1.readOnlyFlag}"
       <h:commandButton action="#{MainPage.mainAddBtn_action}" disabled="#{SessionBean1.disableEdit}" id="mainAddBtn"
            style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; left: 425px; top: 380px; position: absolute; width: 75px" value="Add"/>
         This is all plain vanilla stuff and I would expect that when the Add button is pushed, the session bean property would be filled with
    the value entered in the input text field.
    In the java code for the page, I have a method to process the Add button push.
    Originally, it just called a method in the session bean to check that a value was entered in the input text field by checking the bound
    session bean property.
    For some reason, that was not getting filled and I was getting either a null or empty string rather than the value in the text field.
    I added some checking in the method that processes the Add button push so I could check the values in the debugger.
    Here is a sample of that code:
        public String mainAddBtn_action() {
            String s = sb1.getCompanyName();
            s = (String)this.companyNameTF.getValue();
            s = (String)this.companyNameTF.getSubmittedValue();I check this in the debugger and NONE of the variants that I have listed have the value that was entered into the text field.
    The submittedValue is null and the others are empty strings (that is what they were initalized to).
    This is all pertty straight forward stuff and I am at a loss to explain what is happening.
    Can anyone expain this behavior, and, most important, how can I force the values to be present when the Add button is pushed.
    I have never experienced this problem before, and have no clue what is causing it.
    Thanks.

    Basically, the component bindings are just being used in plain vanilla get/set modes.
    I set them to "" when I do a clear for the fields and they are set to a value via the text field.
    No other action other than to read the values via get to insert them into the database.
    And, I always use the get/set methods rather than just setting the value directly.
    This is what is so strange about this behavior - I have created dozens of database add/update/delete pages using this same model and have not had a problem with them - even in a tab context.
    Not a clue why this one is different.
    I did notice that I had an error on the page (in IE7, you get a small triangle warning sign when something is not right).
    I figured that might be the problem - maybe buggering up the rendering process.
    I tracked that down and do not get that anymore (it had to do with the PDF display I was trying to get working a while back), but that did not resolve the problem.
    I don't think there are any tab conflicts - none of the components are shared between tabs, but I will see what happens when I move a couple of the components out of the tab context.
    I noticed that it seems to skip a cycle. Here is what I can do.
    1) Fill in text fields and add a record - works fine the first time.
    2) Clear the text fields
    3) Enter new data in the text fields and push Add
    4) I get an error saying fields are blank from my data check process.
    5) Enter new data and push Add - the record is added with the new data.
    My work around is to not enter data in step 3 and just accept the error message in step 4, then go ahead and enter the real data in step 5.
    Very ugly, but it works every time.

Maybe you are looking for

  • How to delete some pages in a document in pages without deleting all the pages

    How do I delete some pages in a document?  I have 7 pages listed and I want to delete the last two pages of the document and when I do the thumbnail to delete the pages it wants to delete all the pages in the document.

  • Stage follow in CUP when risk are mitigated

    Hi, We haven't implemented Mitigation Controls yet but we have the following question: In case certain risks are mitigated within CUP by selecting Mitigation Controls, which condition is true afterwards? Option A) The request includes risks Option B)

  • So to use a mouse with iPad

    I Use iMovie a lot and the iPads great but would love the ease of editing with a mouse, I saw the videos for jbking and installing a mouse, so should I?

  • I am using pse 2 and cannot load it onto a new netbook which has widows xp

    I am a gate automation engineer and use a pressure device during the install which was bought 4 yrs ago and uses windows xp operating system. As I needed a new in the field laptop I went for a small new HP netbook which is ideal for use from vehicle

  • Sorting a crosstab

    Post Author: foghat CA Forum: General Hey all,Is there anyway to sort the crosstab rows based on the summary field total in a crosstab? I have a crosstab report which displays Account Description as the rows, Production Months as the columns, and an