prefs.xml(java.utils.prefs.Preference) automatically refrsh by Glassfish - java

In my current application we are using Glassfish to deploy my ear file and We read the user specific values from different places and store it into java.util.prefs.Preference to user it latter. We also have options to change the java.util.prefs.Preference externally. Now the questions are:
a) Recently I found, whenever I am starting my application in Glassfish, Glassfish creating a prefs.xml file containing all the preference I set under /.java/.userPrefs/. But no where I have written code to store the same in this location. So, is that Glassfish's default behavior to store the preferences in this location? or is there any settings?
b) Now if the answer is yes for the question a. Then I am changing the prefernce value in the prefs.xml but after that if I am fetching the values from java.util.Preference, I am getting the old values only not the new value. Why java not refreshing the values? or prefs.xml is only for import/Export prefernces?
c) Whenever I am changing my Preference value externally, its not refreshing the value in prefs.xml. Is that a one time process of server restart?
Any help on the questing would be very much helpful to me.

a) Recently I found, whenever I am starting my application in Glassfish, Glassfish creating a prefs.xml file containing all the preference I set under /.java/.userPrefs/. But no where I have written code to store the same in this location. So, is that Glassfish's default behavior to store the preferences in this location? or is there any settings?
Answer: Glass fish do it automatically. It fetch the preference and then store into the same.
b) Now if the answer is yes for the question a. Then I am changing the prefernce value in the prefs.xml but after that if I am fetching the values from java.util.Preference, I am getting the old values only not the new value. Why java not refreshing the values? or prefs.xml is only for import/Export prefernces?
Ans: Only for import and export.
c) Whenever I am changing my Preference value externally, its not refreshing the value in prefs.xml. Is that a one time process of server restart?
Ans: prefs.xml only used as a back up copy. If you update the through java.util.Preference then also it will not be reflected in prefs.xml. Fir better understanding, change value in prefs.xml then restart server. You will find glassfish replaces your values with the value set through java code.

Related

Detect whether Web application is running for the first time

I am developing a web application to migrate images from CVS to Adobe CQ. There is a requirement to maintain versioning for the images in a database table. The flow is as follows:
Check Out files from CVS -- returns a list of all files checked out, but does not tell whether a file was updated or newly added to CVS! (Due to the files being binary file, it seems it is not able to detect updates and all files are treated as additions)
Check if this is application's first run, if yes, then treat all files as additions. If not, for every file, check database for presence of record corresponding to this file. If record present, treat as update, else insert
... Carry on with other operations
For every insert, add an entry in the database
I have to detect if the application is running for the first time, or has been run previously. This also needs to support future tasks such as resetting everything and starting the application from scratch.
What would be a good way to do this? The application is hosted in WebSphere in Linux. I have thought of two ways:
a. creating an entry in a file with a flag set to true, which I will have to reset to false after the first run - difficult for a user to reset later
b. creating a .firstrun or similar file in the app folder somewhere and check presence of this file to determine first run, easier to reset for any user
Which of this is a better way? Or is there any other way to do it better?
You mentioned database. Why not to store in db, in even more extended way: when what version, # of runs, etc.

How to get the current state i.e. ChangeSet/UUID/version-number of a project/file by using RTC Java APIs 5.2

How to get the current state i.e. ChangeSet/UUID/version-number of a project/file by using RTC Java APIs 5.2 (residing on Jazz server) along with its contents.
Suppose I load a particular file into my local sandbox, then I deleted
that file from my local workspace/sandbox, And other developer
checked-in the changes into the same file, so How to get that file
previous contents ignoring the latest state updated by someone else???
Thanks in advance!!!
If you reload your local sandbox (based on your repo workspace), you would recover that file (without any further modification)
You would get the other developer work only if you accepted incomming change sets into your repository workspace.
If you didn't accept anything, simply reloading would be enough.
(as illustrated in this thread, using ILoadOperation)

Updating the version and dumping shared preferences into database

I developed an android app ver 1.0 in which i stored the user data in shared preferences.
Now I am developing ver 2.0 and I have the following questions about updating it
1.How to detect if version 1.0 is already installed? I mean if it is a pure install(direct 2.0 install) or update from 1.0
2.If it is detected as 1.0 I want to dump the shared preferences values into database. Will the shared preferences be overwritten during update? How to prevent this? If they are not overwritten I want to write an activity which loads the values and dumps them into db
What parameter should i set so that market gives notification that update is available. Should i set that in android manifest with same keystore?
Please kindly help me out
Thanking You,
ChinniKrishna Kothapalli
The Android Documentation has a part explaining how to update your apps.
Basically you increase the number of your android:versionCode in the manifest. You should also change the android:versionName field so your users can see it's a different version.
As for your problem with dumping preferences into a database: The preferences allow you to use a default value if a certain preference is not found (when the downloads a fresh install).
I'm not sure if there is a way of detecting wether your application has been installed or not, except if you have something like a database already in your earlier version, then you could just check if it exists or not. Might not be the best practice to solve this tough.

set up database directory

I am working on a Java Desktop program which upon its installation will designate a default database directory and working directory. Where should I save such information so that the next time the user open the program, the program knows where to look for database and working directory?
Things that come to mind:
store everything in the registry (well, did that in MATLAB version and if there is another way, definitely will not go there).
set up another database attached in the jar file to store everything
Is this a so called persistence problem? What are Java Persistence or Java Data Object? Do they have the way to make it working?
any other suggestions?
Take a look at the Java Preferences API. It is a standard Java SE mechanism for storing preferences that does so in a platform specific, but application neutral way. Uses the Registry on Windows, Preferences files on OS X, and I believe ~/.files on Unix.
The Preferences class was created to store things like... preferences in an OS-neutral fashion.
You could also just specify a directory location manually, through a launcher script, or create a default directory in the user's home, and keep both configuration and DB files there.
Your persistent memory is your hard drive, of course, so you need to store data there if you want it to persist from execution to execution. Really, anything goes. You could store the configuration in an XML file -- makes it user-readable outside of the application, which is really nice for debugging, and Java comes with libraries for XML parsing and generation. It would be OS-independent, unlike a registry solution, which is Windows specific. And you could use the XML approach to share information between apps, if that matters. Something to consider.
Update: Preferences are cool! Never saw that one before.

modifying properties-service.xml

I have a question related to the properties-service.xml. There is a value inside this file that needs to be updated every once in a while programmatically. So I have the following questions about this operation which I wasn't able to find some details about them:
Is there a way to update properties-service.xml programatically other than parsing it and changing the value? If parsing is the only way, is there an available method of retrieving the location of the used properties file?
Can we reload the properties-service.xml after the update without restarting jboss or do I need to set the property manually?
Any help is appreciated.
Thanks,
Sami
To get location of the properties file - acquire System property "jboss.server.home.dir" and suffix "/deploy/properties-service.xml" to it.
Once you save your changes to properties files, JBoss will hot-deploy it as it scans for changes every 5 seconds. If it doesn't hot deploy check value of attribute "ScanEnabled" in /conf/jboss-service.xml to confirm that hot deploy is enabled

Categories