Saturday, May 9, 2009

Generate Torque Schema from existing DB

I came across a situation where there is the excellent DB schema available, but no torque schema to generate the Peer and Maper classes. Solution>

Setup an eclipse JAVA project. create a lib folder add all the torque lib and generator jars from lib folder of each projects. Now we need a build.properties and torque-build.xml. We can get both of them from the generator project. Now setup the build.properties to point to your existing database. point the database name, username password and connection url and don't forget to place the db driver on the lib folder. Run the torque-build.xml ant script when the ant generator dialogue comes select the jdbc option unselect the main task. Make sure to point the place where the generated schema.xml should be put. This can be specified on the build.properties. example builld.properties. ------------------------- torque.project = starcraft torque.schema.dir=. application.root = . torque.database.name = konakart torque.database.type = mysql torque.database.user = starcraft torque.database.password = star torque.database.driver = com.mysql.jdbc.Driver torque.database.url = jdbc:mysql://142.148.1.142:3306/starcraft torque.database.validationQuery = SELECT 1 torque.sameJavaName = false This will dump a torque schema.xml on the root of the project directory. How to Run the torque Schema.xml to generate Java classes. Modify the schema.xml to your database name here ( starcraft-schema.xml) and inside the schema check the database name is correct and all the can be wrong if you have not specified the database property in the build.properties. Now fire the Ant this time select the task OM. This should generate the java classes. You may need to readjust the packages of the generated classes if the package is not properly specified on the build.properties. If any time ant complaints about torquexxx task not found make sure all jars assosiated to the task in the lib folder of the project. Use your Ctrl+ALT+T key for search the task on the eclipse project space.

Wednesday, May 6, 2009

Weblogic startup failed after password change in admin console

weblogic.security.SecurityInitializationException: Authentication denied: Boot i dentity not valid; The user name and/or password from the boot identity file (bo ot.properties) is not valid. The boot identity may have been changed since the b oot identity file was created. Please edit and update the boot identity file wit h the proper values of username and password. The first time the updated boot id entity file is used to start the server, these new values are encrypted. at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.do BootAuthorization(Unknown Source) at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.in itialize(Unknown Source) at weblogic.security.service.SecurityServiceManager.initialize(Unknown S ource) at weblogic.security.SecurityService.start(SecurityService.java:141) at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64) Truncated. see log file for complete stacktrace
Solution --------- C:\bea1001\user_projects\domains\otc_domain\servers\AdminServer\security find the boot.properties backup the property file. Edit,it will look like this: username={3DES}3xhQwbNOXngKswp63s8oqg== password={3DES}B+/Hy/ELjHZztOCHsMxzpg==
change to your admin password you changed in plain like: username=weblogic password=weblogic
run your C:\bea1001\user_projects\domains\otc_domain\bin>startWebLogic.cmd Nice server started Look at your boo.properties now it should like this after startup password={3DES}3xhQwbNOXngKswp63s8oqg\=\= username={3DES}3xhQwbNOXngKswp63s8oqg\=\=
Good your are safe and good to go!

Friday, April 17, 2009

Screen Graber Deamon

This was a hack to grab the questions from a paid online quiz. Idea here is, this program will run as a deamon in the background and take the screen shot every 10 second and save it into a jpeg file on temp directory.

public void captureFullScreen() { try { Robot robot = new Robot(); Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); File target = new File(saveLocation, imageName + "_" + System.currentTimeMillis() + "." + imageType); saveImageToFile(robot.createScreenCapture(area), target); } catch (AWTException e) { System.err.println("Exception while capturing screen. " + e); } } /** * Saves the specified RenderedImage to the specified File. * * @param renderedImage the image to write to file. * @param target the file to write the image to. */ private void saveImageToFile(RenderedImage renderedImage, File target) { try { ImageIO.write(renderedImage, imageType, target); } catch (IOException e) { System.err.println(e); } }
and now the Deamon
public static void main(String args[]) throws InterruptedException { while(true) { new ScreenGraber().captureFullScreen(); Thread.sleep(10000); // will sleep for 10 seconds } }

Wednesday, April 8, 2009

JPA OneToMany using FetchType.EAGER

Scenario: Want to insert multiple address to basket header with a unique basketId.

BasketHeader.java @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn(name = "basketId", nullable = false) public Set getBasketBillTos() { return basketBillTos; }
By specifying @JoinColumn basketId is set as the foreign key column name for the relationship. Otherwise a default name will be given for the foreign key column. If you are mapping to an existing database schema you will typically require setting the @JoinColumn, otherwise the defaults are probably fine. Implementation on action
Set basketBillToSet = new HashSet(); basketBillToSet.add(basketBillTo); basketHeader.setBasketBillTos(basketBillToSet);

Wednesday, April 1, 2009

Struts 2 OGNL variable evaluation

< s: set name="startIndex" value="%{#parameters['start'][0]}"/ > < s: property value="@java.lang.Integer@parseInt(#startIndex)+4"/ >
Here the first statement grab the query string value using parameter object and assign it as a string, the '%{}' syntax is used for this purpose. The second statement convert the string to int and add the two integers.
IMPORTANT: for the parseInt to work you should enable the constant in struts.xml < constant name="struts.ognl.allowStaticMethodAccess" value="true" / >

Monday, March 30, 2009

SVN with Eclipse Ganymede

  1. Install svn server for windows, use the msi package.
  2. Create Repository
svnadmin create "c:\svnrepo"
Navigate to the folder we just created. Within that folder, uncomment the following lines in the /conf/svnserve.conf file:
[general] anon-access = read auth-access = write password-db = passwd
Next, uncomment these lines in the /conf/passwd file:
[users] harry = harryssecret sally = sallyssecret
3. Install subeclipse 1.6.x package for Ganymede. 4. check in the project using these parameters
host svn://localhost use default port repository svnrepo
In Linux if you have created a subversion group, don't forget to change the file group permission, like this.
sudo chown :subversion directory/
Do not forget to commit the project at the end.

Wednesday, December 31, 2008

Auto create tables JPA

< property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"> < property name="hibernate.hbm2ddl.auto" value="create-drop"> < property name="hibernate.show_sql" value="true"> < property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"> < /property>