LEARN, PUBLISH, COMMENT & LEARN....
Saturday, February 19, 2011
Recover root password MySQL
Thankfully I came across this particular "HowTos" post and recovered my password..
Follow the simple steps given in the link and recover your precious root password for MySQL db.
Link
Monday, February 22, 2010
CALL JAVA REMOTE OBJECT IN FLEX (STEPS)
At the server-side:
1.Create your remote java class, a POJO.
2.Compile your java file and place the .class file in webapps/blazeds/classes
3.Place dependent jar files in blazeds/WEB-INF/lib
4.Edit blazeds/WEB-INF/flex/remoting-config to create a destination mapped to your POJO.
Sample:
<destination id="itemdelegate">
<properties>
<source>com.stockmgr.dataservices.delegates.ItemDelegate</source>
<scope>request</scope>
</properties>
</destination>
At the client-side
5. Define a RemoteObject component to point the created destination at step 4
Sample:
<mx:RemoteObject id="remoteItemDelegate"
showBusyCursor="true" destination="itemdelegate"
result="resultHandler(event)" fault="faultHandler(event)" />
6.Now call the remote method of your POJO with the id declared in step 5 in
action-script just like old times.
Sample:
remoteItemDelegate.getItem(itemID);
Thursday, December 10, 2009
Reporting with "Jasper Reports"
Wednesday, November 11, 2009
Narrow the lookup...EJB
But this will not do with J2EE.
We should use javax.rmi.PortableObject.narrow method to narrow the EJB look-up to home interface.
And the reason is, J2EE implementation requires RMI-IIOP to implement the remote interfaces.This RMI-IIOP demands that the real object must be wrapped around with a portable object.
This portable object encapsulates information about the real remote object.The client has to interogate the portable object to find the real remote object.This process ( of obtaining the real object from the portable object) is called "narrowing".
Monday, November 2, 2009
@TableGenerator - ID for your entities
In a recent project with MySQL as the backend , I couldn’t create a sequence and tie it up with the JPA entity ( Still wondering how to do that…)
To resolve this, I made use of @TableGenerator annotation , created a table to store the latest id and tied it up with the entity.
@Id
@Column(name="STUDENT_ID")
@TableGenerator(name="studentkey",
table="tbl_keys",
valueColumnName="std_key",
pkColumnName="std_key_name",
pkColumnValue="studentkey",
allocationSize=1)
@GeneratedValue(strategy=GenerationType.TABLE,
generator="studentkey")
private long studentId;
The @TableGenerator annotation defines that “TBL_KEYS” is the table to store the generated id for the entity.
STD_KEY is the column to store the generated id
STD_KEY_NAME is the column which has the key-name entries. The key name here is “studentkey” .
You can add another entry in TBL_KEYS named “mark_key” and map it to another entity TBL_MARKS.
@GeneratedValue annotation specifies that the id generated is of GenerationType.TABLE type and maps the already defined @TableGenerator with given name.
Tuesday, October 20, 2009
Spring & JPA for your web-application
Prerequisites:
1. Make sure you have these SPRING .jars in your classpath
spring.jar
spring-aspects.jar
common-logging.jar
log4j.jar
common-beanutils.jar
common-collections.jar
common-digester.jar
2. Make sure you have your JPA-persistence API in your classpath. You can get it from OpenJPA / Jboss Hibernate.
In my case I chose ejb3-persistence.jar from hibernate.
3. Make sure you have your persistence provider jars in classpath (hibernate / toplink / openjpa)
In my case I chose toplink and kept these jars in classpath.
toplink-essentials.jar
toplink-essentials-agent.jar
Note: Toplink requires class transformation when loading and unloading entities, so you should start your server with spring-agent.jar
In my case I started my tomcat6 server with this VM argument
-javaagent:\spring-framework-2.5\dist\weaving\spring-agent.jar
4. Make sure that you have your jdbc driver jars in classpath.
I copied mysql-connector-java.jar to tomcat's lib directory.
Steps to configure JPA + Spring in your web-application
Steps:1.Define your entities in my-persistence.xml
Note: We didn't define/write a "persistence.xml" so that the servlet containerwill not bring up the default persistence unit.
2.Define your spring listeners in web.xml
<context-param> <param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
3.Define a spring configuration file (WEB-INF/applicationContext.xml)
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd "></beans>
4.Define your datasource in applicationContext.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/dbname" /> <property name="username" value="username" /> <property name="password" value="password" /> </bean>
5.Define your entityManagerFactory in applicationContext.xml
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter" > <property name="showSql" value="true" /> <property name="generateDdl" value="false" /> <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.MySQL4Platform" /> </bean> </property>
<property name="persistenceXmlLocation" value="META-INF/my-persistence.xml" /> </bean>
6. Define your transactionManager in applicationContext.xml
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" > <property name="entityManagerFactory" ref="entityManagerFactory" /> <property name="dataSource" ref="dataSource" /> </bean>
7.Define your advice & point-cuts for transaction demarcation.I am using spring annotation for transaction demarcation.
<tx:annotation-driven />
8.Make sure that you configure these beans in applicationContext.xml for processing your JPA annotations
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
Thats it !!! You have configured Spring with JPA in your web-application.
Thursday, October 8, 2009
The SPRING season...
Spring plumbs together your components (POJOs) of a modular java application, may it be enterprise or web and stays out of your code.
At the core of Spring framework is the Spring Container that constructs your POJOs (on demand) and wire them together with dependency injection (a form of IoC - Inversion of Control ) to construct the application.
Spring comes with ready-made modules to support ORM,Java Enterprise Apps,Web MVC,Remoting & AOP.
Straight forward applications of Spring are
1) Plumbing / Wiring POJOs together to construct a modular application
2) Aspect Oriented Programming (AOP)
3) Dependency Injection
4) Abstraction of data access through DAO pattern
5) Abstraction of various ORMs (Hibernate, Toplink, JPA) and uniform simple access to all.