Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Sunday, October 19, 2014

How to read auto generated key in Java

Database : SQL Server 2008

insertSuccessFileObj = new ();
insertSuccessFileObj.setFILE_CODE("DASHBOARD");
insertSuccessFileObj.setFILE_TYPE("MARS_DASHBOARD_DETAILS");
insertSuccessFileObj.setFILE_NAME(fileName);
insertSuccessFileObj.setFILE_PATH(filePath + "\\" + YEAR + "\\" + MONTH + "\\"+ fileName);
insertSuccessFileObj.setUPLOADED_DATE(new Date());
insertSuccessFileObj.setMONTH(MONTH);
insertSuccessFileObj.setYEAR(Double.valueOf(YEAR));
insertSuccessFileObj.setCREATED_ON(new Date());
insertSuccessFileObj.setCREATED_BY(BSF.getUser().substring(BSF.getUser().indexOf("=") + 1, BSF.getUser().indexOf(",")));
insertSuccessFileObj.insert();
double fileID = insertSuccessFileObj.getFD_ID(); //fileID returned would be 0.0

The above is a small sample of code which inserts record in a table called MARS_FILE_DETAILS in which FD_ID is a column which is auto generated in database which is of type Double. 

Requirement is, we want to insert record through program and read the FD_ID (auto generated field) and return it as response. This is not achievable using the above sample piece of code because the java layer will know about the whereabouts of primary key only after committing the transaction. Hence we need to commit through program and get the FD_ID. This is done using below line

BSF.getObjectManager()._commitTransactionDirect(true); 

Hence the above sample would be modified as below

MARS_FILE_DETAILS insertSuccessFileObj = new MARS_FILE_DETAILS();
insertSuccessFileObj.setFILE_CODE("DASHBOARD");
insertSuccessFileObj.setFILE_TYPE("MARS_DASHBOARD_DETAILS");
insertSuccessFileObj.setFILE_NAME(fileName);
insertSuccessFileObj.setFILE_PATH(filePath + "\\" + YEAR + "\\" + MONTH + "\\"+ fileName);
insertSuccessFileObj.setUPLOADED_DATE(new Date());
insertSuccessFileObj.setMONTH(MONTH);
insertSuccessFileObj.setYEAR(Double.valueOf(YEAR));
insertSuccessFileObj.setCREATED_ON(new Date());
insertSuccessFileObj.setCREATED_BY(BSF.getUser().substring(BSF.getUser().indexOf("=") + 1, BSF.getUser().indexOf(",")));
insertSuccessFileObj.insert();
BSF.getObjectManager()._commitTransactionDirect(true);
double fileID = insertSuccessFileObj.getFD_ID();

Wednesday, October 8, 2014

How to use STUFF keyword in Microsoft SQL Server

Usage of STUFF in Microsoft SQL Server 

General syntax of STUFF in SQL Server is 

STUFF ( character_expression , start , length , replaceWith_expression )

You can refer the details from below link
http://msdn.microsoft.com/en-IN/library/ms188043.aspx

SELECT DISTINCT COMMISION_NUMBERS = 
STUFF((Select ','+COMMISION_NUMBER from MARS_ALLOCATION_DATA where MONTH='JUN' and YEAR=2014
 FOR XML PATH('')),1,1,'') FROM MARS_ALLOCATION_DATA


Wednesday, August 27, 2014

Change Folder to ControlPanel

There are situations where you want to have your data secured. Hiding folder is typical way one would go for but everyone would be aware of un-hiding them. Here is one way of encrypting the data.

With this one can change the folder to control panel, technically you will use a bat file and change the folder to control panel. On double click of this folder, it would take you to control panel instead of taking to the folder contents.

Control panel will be identified using the keystring "21EC2020-3AEA-1069-A2DD-08002B30309D" in Windows XP and "ED7BA470-8E54-465E-825C-99712043E01C" in Windows 7. Do the below steps to change the folder to control panel.


  • Lets say you have a folder named "Example" in which you have some confidential information.
  • Open text pad and write the contents as given below
    ren Example ControlPanel.{ED7BA470-8E54-465E-825C-99712043E01C} 
  • Rename this file to <SomeFileName>.bat 
  • When you double click the file you can see that your folder "Example" will be converted to "ControlPanel"
Do the below steps to revert back to Example folder
  • Lets say you have a folder named "Example" in which you have some confidential information.
  • Open text pad and write the contents as given below
    ren ControlPanel.{ED7BA470-8E54-465E-825C-99712043E01C} Example
  • Rename this file to <SomeFileName>.bat
  • On double click this file you can see that your control pane will be converted back to "Example" folder.
Note : This post is only for those who are new to the computers and not meant to the people with average skills on internet browsing. 

Monday, May 26, 2014

Log from Java method in WSO2 Framework

Pre-Requisites :

  Ø 
Application server should be up and running.
   Ø  Should be able to write a simple java method using eclipse.
   Ø  One should have knowledge on how to deploy the service from java methods.
   Ø  Should be able to test the service after deployment.

Steps :

    Ø Write a simple Custom Java method by following syntax.


  import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;

 private static Log eventLogger = LogFactory.getLog(HelloDH.class);

   Ø  Create a jar and deploy it in the application server (Or Any other way of deploying the java methods onto application server).

   Ø  Test and check for the logs.

o   Test the service by searching for the web service and once tested,You can check for the log as shown in the below screenshot.


You can even find the logs in file system. For ex., "
E:\Kiran\Softwares DH\WSO2\WSO2\wso2as-5.2.1\wso2as-5.2.1\repository\logs"

Friday, May 23, 2014

Learnings from WSO2 Framework : Application Server

Tuesday, December 17, 2013

Custom Gateway : Get Server Variables

req.getServerVariable("HTTPS")
req.getServerVariable("SERVER_NAME")
req.getServerVariable("SERVER_PORT")