Tuesday, May 31, 2011

Db2 26 Byte Timestamp in Java

I was looking for the db2 Timestamp format for long days and finally got the solution
public static Object getCurrentTimeStamp(int returnType) {
long timeInMillis = System.currentTimeMillis();
long timeInNanos = System.nanoTime();
Timestamp timeStamp = new Timestamp(timeInMillis);
timeStamp.setNanos((int) (timeInNanos % 1000000000));
if (returnType == ReturnType.TIMESTAMP)
return timeStamp;
else {
String db2TimeStamp;
db2TimeStamp = timeStamp.toString().replace(' ', '-');
db2TimeStamp = db2TimeStamp.replace(':', '.');
System.out.println(db2TimeStamp.substring(0, 26));
return db2TimeStamp.substring(0, 26);

The time in millis does not represent the time in nanos. More precise it simply can't be. You're supposed to use Timestamp#setNanos() to set the real nanos.
java.sql.Timestamp constructor go like this:
public Timestamp(long time) {
nanos = (int)((time%1000) * 1000000);
if (nanos < 0) {
nanos = 1000000000 + nanos;     

It basically accepts time in millisecond and then extracts the last 3 digits and makes it nanos. So for a millisecond value of 1304135631 421, I'm getting Timestamp.getnanos() as 421000000. This is plain calculation (adding 6 zeroes at the end).

Saturday, May 14, 2011

Interfaces of EJB in Client Server

An EJB container is the heart of an EJB environment, in the same way an ORB is the heart of a CORBA environment. The container registers EJB objects for remote access, manages transactions between clients and EJB objects, provides access control over specific methods on the EJB, and manages the creation, pooling, and destruction of enterprise beans. The container also registers the home interface for each type of bean under a given name in a JNDI namespace, allowing remote clients to find the home interfaces and use them to create enterprise beans.
Once you provide the EJB container with the home and remote interfaces and the implementation class for your bean, along with a deployment descriptor, the container is responsible for generating the various classes that connect these components, as shown in Figure. The home and remote interfaces you provide are RMI Remote interfaces; the container generates both the client stubs and the server-side implementation for these interfaces. When a client looks up a bean's home interface through JNDI, it receives an instance of the home stub class. All methods invoked on this stub are remotely invoked, via RMI, on the corresponding home implementation object on the EJB server. Similarly, if the client creates or finds any beans through the home stub, the client receives remote object stubs, and methods invoked on the stubs are passed through RMI to corresponding implementation objects on the server. These remote objects are linked, through the EJB container, to a corresponding enterprise bean object, which is an instance of your bean-implementation class. Optionally, the EJB container may also generate a container-specific subclass of your bean implementation (e.g., if it wants to augment some of your bean methods to facilitate synchronization with the container).

Monday, May 9, 2011

My first post on Java

I am coming back to Java after 6 years. I am a software professional working on Mainframe 3270 screen coding CICS/Cobol program. I studied java, c, c++ and .net languages at college. In college, my nick name is Dennis Ritchie.. I am very much interested in object oriented languages, but I got job to work on mainframe environment.
Thanks to IBM who brings Java on mainframe - System z Application Assist Processor (zAAP) and Pershing who gives me an opportunity to work on this ..
What is zAPP?
zAAP, which runs asynchronously alongside general-purpose processors, is designed specifically to execute Java programming under the control of the IBM JVM and assist the general-purpose processors by executing the Java cycles. Utilizing zAAP, therefore, customers can expect to realize reduced demands and capacity requirements on their general-purpose processors, which can be better utilized by other, non-Java workloads.

First Post on Java