My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Saturday, February 15, 2014

Wrap Method parameters in new line in IDE


Here is an alternative to format method params as you wish
1. Windows--> Preferences-->Java -->Code Style-->Formatter
2. Under the profile name even default choose the tab Line Wrapping
3. Image shown below for various options

Adjust settings for CTRL + SHIFT + F in eclipse


In many a situations, your code will be line wraps after 80 characters by default.
You may want to change it for readability purpose.
Here is an alternative to change this settings in your eclipse.

1. Windows--> Preferences-->Java -->Code Style-->Formatter
2. Select Java Conventions [Built-in] from the Active Profile
3. Click on Edit
4. Go to the TAB named “Line Wrapping”.
5. Under General Settings  , change the Maximum Line Width fro, 80 to your number
6. Under the preview section, Set Line Width for preview window from 80 to your number
7. You may have to rename the profile as MyProfile_Java_Profile since built ins are READ-ONLY
Now go to your source and press CTRL + SHIFT +F , you will see that all line breaks are after your number

Thursday, February 6, 2014

Mule to return multiple rows from a JDBC query as a single transaction


Mule to return multiple rows from a JDBC query as a single transaction 


Option -1
 
  
  
  


Option -2
Setting transactionPerMessage to 'false' on the connector should work if you ALSO set transactionPerMessage property to 'true' on the endpoint and add a transaction like so


    
    
    

Sunday, January 5, 2014

Hibernate Tools and Eclipse


 
  1. In Eclipse IDE, menu bar, select “Help” >> “Install New Software …” , put the Eclipse update site URL.
  2. Copy this site's URL into Eclipse, and hit Enter.
  3. From the Abridged JBoss Tools 4.0, the JBoss Hibenate Tools section
  4. Hibernate Tools (HT) from Application Development
  5. HT from JBoss Data Services
  6. JBoss Maven Hibernate Configurator from Maven Support and
  7. HT from Web and Java EE Development
  8. After the download progress is completed, restart Eclipse to take effect.
  9. If Hibernate tools is installed properly, you are able to see the -->Hibernate Perspective--> in -->Windows--> >> -->Open Perspective--> >> -->Others-->. 
 
For generating entity files from the DB, please follow the steps in the URL
 
 

Tuesday, November 5, 2013

Hibernate – useFollowOnLocking warning


WARN  org.hibernate.loader.Loader - HHH000444: Encountered request for locking however dialect reports that database prefers locking be done in a separate select (follow-on locking); results will be locked after initial query executes

Solution
This appears to happen with Oracle and the fix is to create a custom dialect as follows

import org.hibernate.dialect.Oracle10gDialect;

public class BatchOracleDialect extends Oracle10gDialect{
          @Override
          public boolean useFollowOnLocking() {
             return false;
          }
}

Now change your hibernate.cfg.xml as follows
<property name="hibernate.dialect"><<package>>.BatchOracleDialect</property>

Thursday, October 17, 2013

Message Queue Depth


import com.ibm.mq.MQC;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;

public class QueueDepthTest extends ServerConfig {

 /**o
  * @param args
  */
 public static void main(String[] args) {

  QueueDepthTest classObj = null;
  try {
   classObj = new QueueDepthTest();
   final MQRegion env_region = MQRegion.DEV;
   final String queueName = MQQueueNames.CALC_REQUEST
     .getName(env_region);

   classObj.loadConfig(env_region);

   // Set up MQSeries environment
   final String mqQMgr = classObj.cf.getQueueManager();
   MQEnvironment.hostname = classObj.cf.getHostName();
   MQEnvironment.port = classObj.cf.getPort();
   MQEnvironment.channel = classObj.cf.getChannel();
   MQEnvironment.userID = classObj.cf.getClientID();

   System.out.println("******IBM MQ values*****");
   System.out.println("QMgr=" + mqQMgr);
   System.out.println("hostname=" + MQEnvironment.hostname);
   System.out.println("port=" + MQEnvironment.port);
   System.out.println("channel=" + MQEnvironment.channel);

   System.out.println("queue =" + queueName);
   final MQQueueManager qMgr = new MQQueueManager(mqQMgr);
   int openOptions = MQC.MQOO_INQUIRE;
   // int openOptions = CMQC.MQOO_INQUIRE + CMQC.MQOO_FAIL_IF_QUIESCING
   // + CMQC.MQOO_INPUT_SHARED;

   MQQueue destQueue = qMgr.accessQueue(queueName, openOptions);

   final int depth = destQueue.getCurrentDepth();
   System.out.println("printing the queue depth =" + queueName
     + " is=" + depth);
   destQueue.close();
   qMgr.disconnect();
  } catch (Exception err) {
   err.printStackTrace();
  }
 }
}


public enum MQRegion {
 DEV ("hostname", port, "channel","QMgr","ClientID");
 
 
 private String hostName;
 private long port;
 private String channel;
 private String queueManager;
 private String clientId;
 MQRegion(String hostName, int port,  String channel, String queueManager, String clientId) {
  this.hostName = hostName ;
  this.port = port;
  this.channel =channel;
  this.queueManager=queueManager;
  this.clientId = clientId;
 }
 public String getHostName() {
  return hostName;
 }
 public String getChannel() {
  return channel;
 }
 public String getQueueManager() {
  return queueManager;
 }
 public String getClientId() {
  return clientId;
 }
 public long getPort() {
  return port;
 }
}

public enum MQQueueNames {
 QUEUE_NAME("QUEUE_NAME");
 
 
 MQQueueNames(String name) {
  this.name = name;
 }

 private String name;

 public String getName(MQRegion region) {
  switch(region) {
  case DEV:
   return name + ".DEV2";
  case SIN:
   return name + ".SIN1";
  case UAT:
   return name + ".UAT3";
  }
  return name;
 }
}

import javax.jms.BytesMessage;
import javax.jms.ConnectionConsumer;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;

import com.bnym.test.common.ConstantsEnum;
import com.ibm.jms.JMSMessage;
import com.ibm.mq.MQC;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.mq.jms.MQQueueSender;
import com.ibm.mq.jms.MQQueueSession;

public class ServerConfig {

 protected MQQueueConnectionFactory cf = null;
 protected boolean needConcurrent = false;
 
 protected void loadConfig(MQRegion region) throws JMSException {
  cf = new MQQueueConnectionFactory();
  cf.setHostName(region.getHostName());
  cf.setPort((int) region.getPort());
  cf.setTransportType(1);
  cf.setQueueManager(region.getQueueManager());
  cf.setChannel(region.getChannel());
  cf.setClientId(region.getClientId());
 }
}

Tuesday, October 8, 2013

Nano seconds in Java

  1. Get backport-util-concurrent.jar from nexus
<dependency>
<groupid>backport-util-concurrent</groupid>
<artifactid>backport-util-concurrent</artifactid>
<version>3.1</version>
</dependency>
  • code snippet
   import java.util.concurrent.TimeUnit;
long timeInMillis = System.currentTimeMillis();
  • You can use query to get the DB time
select extract(day from(systimestamp - to_timestamp('1970-01-01', 'YYYY-MM-DD'))) * 86400000 + to_number(to_char(sys_extract_utc(systimestamp), 'SSSSSFF3')) current_time_milliseconds
    from dual;
  • Timestamp dbTimeStamp = result of above quey...
long nanos = TimeUnit.SECONDS.toNanos(System.currentTimeMillis());
dbTimeStamp.setNanos((int) (nanos % 1000000000));