• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Static fields in java classes from DB record
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Static fields in java classes from DB record


  • Subject: Re: Static fields in java classes from DB record
  • From: Kieran Kelleher <email@hidden>
  • Date: Sat, 20 Aug 2005 10:29:05 -0400

You could put your paths into the Properties file, like this

myapp.path.files=/var/xyx/abc

and in code, put

protected final static String MY_PATH = System.getProperty( "myapp.path.files" );


OR better use lazy initialization......

protected static String _myPath;

public static String myPath() {
	if ( _myPath == null ) {
		_myPath = System.getProperty( "myapp.path.files" );

		// Check the path here to make sure it is valid, exists, etc
	}

	return _myPath;
}

static vars get created the first time a class is loaded

HTH, Kieran

On Aug 20, 2005, at 8:32 AM, Florijan Stamenkovic wrote:

Hi all.


In most of the apps I am working on I have some File IO handling. To keep the logic in one place, I use utility classes for such things. However, there are several kinds of files that I am reading or writing, in several different locations. The absolute folder paths are stored in the database (in a special table named DB info), so they can be easily changeable. In this construction however, I am all the time getting the stored folder paths and passing them to utility methods. Those utility methods then have to check if it is a folder, if it exists, create it, etc etc.


What I want to do is to store the paths in a static field in the FileIO utility class (and or wherever other class where needed), set them up once (let's say on application or session startup), by checking if those fields are null (to disable multiple setups of the same thing). If yes, test the start paths, create the folders, and store the file paths into the static fields of classes where I need them. What makes my file writing easier and more lightweight as less checking is involved. And I always have all the start paths I need at hand.

I am not sure however, do the class definitions get loaded per application instance, or what? In translation: in a bit more complicated scenario, does this system create pitfalls???

Thanks in advance
Flor

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Static fields in java classes from DB record
      • From: Florijan Stamenkovic <email@hidden>
References: 
 >Static fields in java classes from DB record (From: Florijan Stamenkovic <email@hidden>)

  • Prev by Date: No form data left for WOFileUpload
  • Next by Date: Re: Static fields in java classes from DB record
  • Previous by thread: Static fields in java classes from DB record
  • Next by thread: Re: Static fields in java classes from DB record
  • Index(es):
    • Date
    • Thread