Monday, June 6, 2016

Ghost Constraints in Oracle

When you drop/update constraints in Oracle, specially as I had to update a unique constraint in a table, First I updated the constraint and tried to insert a raw in to the table with the updated unique constraints. Then I noticed, it is throwing an error by applying the old constraint. I was wondering and dropped the constraint and tried again to insert the raw. Then also it was the same error.

As it was strange, I tried to find a solution. Then I got to know that Oracle has an index created with the same name of the unique constraint dropped/updated.

select index_name 
from user_indexes
where table_name = '--insert the table name here--'
and  uniqueness='UNIQUE' 
/

You can verify it using the above query. Then I dropped the index using the below query and re applied the unique constraint as I wanted, Now the raw is successfully inserted in to the table.

DROP INDEX --insert the constraint name here--
/
Thanks for the below link on the solution

http://stackoverflow.com/questions/2372163/finding-ghost-constraint-from-oracle-db

Tuesday, April 19, 2016

How to swap changes on tracking branch to another remote and reset previous tracking branch

I was working in GIT remote tracking branch without pushing the changes to it's origin. A requirement came to share those changes with another developer with a separate remote branch. That means I need to create another remote branch with my changes. Following are the commands I used to do it.

git checkout current_origin_branch

git pull

git checkout -b new_feature_branch

git push -u origin new_feature_branch

git checkout current_origin_branch

git reset --hard origin/current_origin_branch

Above requirement will not be raised, if you are always creating local branches from the tracking branches for your feature developments.

Friday, February 12, 2016

Resolve issue of IntelliJ IDEA 14 Keyboard not working in Ubuntu

I have been working with IntelliJ IDEA 14 in Ubuntu for a long time. Some times I experienced a sudden failure of keyboard not working for IDEA and you can't type anything in editor and any of the shortcuts are not working at all.

Initially I restarted the IDEA and worked again, but that's a big hassle as I have to always restart the Wildfly and this may kill time as when this issue happens frequently. But executing below command in terminal is working for this issue and you don't need to restart the IDEA.

ibus-daemon -rd

Tuesday, February 9, 2016

Resolve Video Playing Issue in VLC Player on Ubuntu

Recently when I was trying to play a video file using VLC in my ubuntu OS, it only showed a black screen with background sounds. Tried few ways and following worked to resolve the issue.

1. Open VLC player

2. Click Tools

3. Select Preferences

4. Select Video

5. Click drop down in output and select "OpenGL GLX Video output(XCB)"
(default, it was "Automatic").



6.Click Save and Then play the video 

Monday, February 1, 2016

SFTP File Uploading/Downloading Using Java

 Recently I got a requirement to upload a file to host using a java program. I used Jsch library and below is the maven dependency required

 <dependency>  
       <groupId>com.jcraft</groupId>  
       <artifactId>jsch</artifactId>  
       <version>0.1.53</version>  
  </dependency>  


Using above library, below is a simple util class which you can use with SFTP on java.

 import com.jcraft.jsch.Channel;  
 import com.jcraft.jsch.ChannelSftp;  
 import com.jcraft.jsch.JSch;  
 import com.jcraft.jsch.JSchException;  
 import com.jcraft.jsch.ProxyHTTP;  
 import com.jcraft.jsch.Session;  
 import com.jcraft.jsch.SftpException;  
 /**  
  * Utility class to upload or download files via SFTP  
  *  
  * @author : chamara  
  */  
 public class SFTPFileUtil {  
      private Session session = null;  
      private ChannelSftp sftpChannel = null;  
      private String host = null;  
      private int port = 22;  
      private String username = null;  
      private String password = null;  
      private String strictHostChk = "no";  
      private final String SFTP_PROTOCOL = "sftp";  
      private boolean useHttpProxy = false;  
      private String httpProxyHost = null;  
      private int httpProxyPort;  
      public SFTPFileUtil(String host, String username, String password) {  
           this.host = host;  
           this.username = username;  
           this.password = password;  
      }  
      public SFTPFileUtil(String host, int port, String username, String password) {  
           this.host = host;  
           this.port = port;  
           this.username = username;  
           this.password = password;  
      }  
      public void connectAndLogin() throws JSchException {  
           if (session == null || !session.isConnected()) {  
                JSch jsch = new JSch();  
                session = jsch.getSession(username, host, port);  
                session.setConfig("StrictHostKeyChecking", strictHostChk);  
                session.setPassword(password);  
                if (isUseHttpProxy()) {  
                     session.setProxy(new ProxyHTTP(getHttpProxyHost(), getHttpProxyPort()));  
                }  
                session.connect();  
           }  
           if (sftpChannel == null || sftpChannel.isClosed()) {  
                Channel channel = session.openChannel(SFTP_PROTOCOL);  
                channel.connect();  
                sftpChannel = (ChannelSftp) channel;  
           }  
      }  
      public void closeAndLogout() {  
           if (sftpChannel != null) {  
                sftpChannel.exit();  
           }  
           if (session != null) {  
                session.disconnect();  
           }  
      }  
      @Override  
      protected void finalize() throws Throwable {  
           closeAndLogout();  
           super.finalize();  
      }  
      private boolean isUseHttpProxy() {  
           return useHttpProxy;  
      }  
      public void setHttpProxy(String httpHost, Integer httpPort) {  
           if (httpHost != null && !"".equals(httpHost.trim()) && httpPort != null && httpPort > 0) {  
                this.useHttpProxy = true;  
                this.httpProxyHost = httpHost;  
                this.httpProxyPort = httpPort;  
           } else {  
                this.useHttpProxy = false;  
           }  
      }  
      private String getHttpProxyHost() {  
           return httpProxyHost;  
      }  
      private int getHttpProxyPort() {  
           return httpProxyPort;  
      }  
      public void changeDirectory(String path) throws SftpException, JSchException {  
           connectAndLogin();  
           sftpChannel.cd(path);  
      }  
      public void uploadFile(String localPath) throws SftpException, JSchException {  
           connectAndLogin();  
           sftpChannel.put(localPath);  
      }  
      public void uploadFile(String localPath, String remotePath) throws SftpException, JSchException {  
           connectAndLogin();  
           sftpChannel.put(localPath, remotePath);  
      }  
      public void downloadFile(String localPath, String remotePath) throws SftpException, JSchException {  
           connectAndLogin();  
           sftpChannel.get(remotePath,localPath );  
      }  
      public static void main(String[] args){  
           SFTPFileUtil fileUtil = new SFTPFileUtil("[host name]","[user name]","[password]");  
           try {  
                fileUtil.uploadFile("[local file path]","[remote directory path]");  
           } catch (SftpException e) {  
                e.printStackTrace();  
           } catch (JSchException e) {  
                e.printStackTrace();  
           }  
           fileUtil.closeAndLogout();  
      }  
 }