Follow by Email

Sunday, December 29, 2013

$.each($('#uploader').pluploadQueue().files, function(){this.name = this.name.replace(/\'/g,' ')})
add in:
preinit: attachCallbacks,
below all the bits like
unique_names : false,
then after the whole initilisation bit add in:
function attachCallbacks(Uploader) {
Uploader.bind('FileUploaded', function(Up, File, Response) {
  if( (Uploader.total.uploaded + 1) == Uploader.files.length)
  {
    window.location = 'http://www';
  }
});

Wednesday, December 18, 2013

Row Expander example in ext4.2.1

Ext.Loader.setConfig({
    enabled: true
});
Ext.require([
    'Ext.grid.*',
    'Ext.data.*'
]);
Ext.onReady(function(){
    Ext.define('outerGridModel', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'company'},
            {name:'id'}
         ]
    });   
    Ext.define('innerGridModel', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'company'},
            {name: 'desig'}
            ]
        });
    // Array data for the grids
    Ext.grid.dummyOuterData = [
        ['MA1','id1'],
        ['MA2','id2'],
        ['Ma3','id3']
    ];


    Ext.QuickTips.init();

    var getOuterStore = Ext.create('Ext.data.ArrayStore', {
            model: 'outerGridModel',
            data: Ext.grid.dummyOuterData
        });
   
     var storeID;
    var outerGrid = Ext.create('Ext.grid.Panel', {
        store: getOuterStore,
        columns: [
            {text: "Root Cause Analysis", flex: 1, dataIndex: 'company'}
        ],
        columnLines: true,
       // enableLocking: true,
        width: 600,
        height: 600,
        plugins: [{
            ptype: 'rowexpander',
            rowBodyTpl : ["
"]
        }],
       
        collapsible: true,
        animCollapse: false,
        title: 'Sample',
        iconCls: 'icon-grid',
        margin: '0 0 20 0',
        renderTo: Ext.getBody()
        //loadPopup(sm1[0].get("id")); } } 
    });
    Ext.grid.dummyInnerData = [
            ['AAAAAAAA', 'dasda'],
            ['BBBBBBBB', 'dasda'],
            ['CCCCCCCC', 'dasda']
        ];
        var getInnerStore = function() {
            return Ext.create('Ext.data.ArrayStore', {
                model: 'innerGridModel',
                data: Ext.grid.dummyInnerData
            });
        };
        var innrerGrid = Ext.create('Ext.grid.Panel', {
            title:'RCA'    ,
             width: 100,
            height: 100,
            store: getInnerStore(),
            columns: [
                {text: "Company", flex: 1, dataIndex: 'company'},
                {text: "Desig", flex: 1, dataIndex: 'desig'}
            ],
            frame : false,
            border : true,
            width: 200,
            height: 120,
            animCollapse: false,
            margin: '0 0 20 0',
            //renderTo: storeID
        });
    outerGrid.view.on('expandbody', function(rowNode, record){
    storeID = record.get("id");        
    innrerGrid.render(storeID);
       
    });
});

Saturday, October 12, 2013

Hibernate with MS Access

Here is the sample to link hibernate with ms access

First create a new datasource in Control Panel -> Administrative tools -> Data Sources

Add New Data source - > MS Access Driver (*mdb, *.accdb)

Provide a data source name, and click select and select the data base access file (*mdb, *.accdb)

and click apply....

The data source name which we entered will be the data source

Most important thing.... Add the following jars

antlr-2.7.7.jar
commons-collections-3.2.1.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.0.1.Final.jar
hibernate-entitymanager-4.0.1.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate.jar
javassist-3.12.1.GA.jar
jboss-logging-3.1.0.CR2.jar
jta-1.1.jar
slf4j-api-1.6.1.jar
validation-api-1.0.0.GA.jar

bean class

package bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity(name="Users")
public class Users {
 @Id
int id;
String userName;
String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}


}

config file



Main class

package main;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

import bean.Users;

public class HibernateProcess {

public static void main(String[] args) {

try {
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(
configuration.getProperties()).buildServiceRegistry();
SessionFactory sf = configuration.buildSessionFactory(sr);

Users user1 = new Users();
user1.setUserName("Sriram");
user1.setPassword("sriram");
Session ss = sf.openSession();
ss.beginTransaction();
ss.save(user1);
ss.getTransaction().commit();
ss.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}


Enjoy Hibernate

Friday, October 19, 2012

This reads excel and prints value from the same. Jar used is poi.
The speciality here is that you can read values from the excel sheet using the column name also.


Enjoy !!!


package main.java.excel;

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;

public class ReadExcel {
    public static void main(String args[]) {
        try {
            FileInputStream fis = new FileInputStream("D:\\Path\\template.xls");
            HSSFWorkbook workbook = new HSSFWorkbook(fis);
            HSSFSheet sheet = workbook.getSheet("Sheet1");
            Map excelMap = new HashMap();
            excelMap = selectUsingMap(sheet, excelMap);
            Iterator rows = sheet.rowIterator();
            while (rows.hasNext()) {
                HSSFRow row = (HSSFRow) rows.next();
                    System.out.println(((HSSFCell)row.getCell(excelMap.get("ACTION"))).getStringCellValue());
                    System.out.println(row.getLastCellNum());
                    Iterator cells = row.cellIterator();
                    while (cells.hasNext()) {
                        HSSFCell cell = (HSSFCell) cells.next();
                        System.out.println(cell.getStringCellValue());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static Map selectUsingMap(HSSFSheet sheet, Map excelMap) {
        HSSFRow row = sheet.getRow(0);
        short q;
        for(short i=0;i            q = (short)i;
            excelMap.put(((HSSFCell)row.getCell(q)).getStringCellValue(), i);
        }
        return excelMap;
    }
}

Sunday, October 14, 2012

calling rowtype in oracle stored procedure

Scenario: consider u have a situation in which u want to call a stored procedure that accepts %Rowtype as input. This procedure cannot be called from java, because there no equivalent Oracle.Types which is being provided by JDBC.

Another reason is that u cannot create a TYPE for the ROWTYPE in sql, because ROWTYPE is not sql, its pl/sql. And hence pl/sql cannot be exposed to schema (sql) level. Hence its TYPE cannot be bind with the java object.

 Here's the solution: Create a function inside a package which accepts a java object, there by creating a sql TYPE that accepts java objects as input. Call the same function from java using callable statement, and in that function (package) call another function which internally calls the function whose argument is %ROWTYPE.

 Here is the code snippet.
Java:
OracleDataSource ods;
CallableStatement stmt;
Connection conn; ods = new OracleDataSource();
String url = "jdbc:oracle:thin:@//ip:port/Dbs";
ods.setURL(url); ods.setUser(uname); ods.setPassword(pwd);
conn = ods.getConnection();
Object[] p1obj = { "1", "2", "3", "4" };
 StructDescriptor desc1 = StructDescriptor.createDescriptor("AAA", conn);
STRUCT p1struct = new STRUCT(desc1, conn, p1obj);
stmt = conn .prepareCall("{? = call pack_name.functin1(?)}");
 stmt.setObject(2, p1struct);
 stmt.registerOutParameter(1, Types.INTEGER);
 stmt.registerOutParameter(2, OracleTypes.STRUCT, "AAA");
 stmt.execute();
 String result = stmt.getString(1);
System.out.println("result:" + result);

 Package:
CREATE OR REPLACE PACKAGE BODY pack_name
IS
 FUNCTION functin1 ( aaa IN OUT AAA ) RETURN NUMBER
 IS
 v_lno NUMBER;
 bbb TABLE_NAME%ROWTYPE;
BEGIN
 bbb.id := aaa.id;
 bbb.no := aaa.no;
 bbb.val := aaa.val;
 v_lno := pack_name.function2(bbb);
 return v_lno;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE('Invalid value ' || v_lno);
 RETURN '';
END;
FUNCTION function2 ( ccc IN TABLE_NAME%ROWTYPE )
 RETURN NUMBER
 IS
 v_lno NUMBER;
 BEGIN
 --Logic for ccc variable---
 EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE('Invalid ' || v_lno);
 RETURN '';
 END;
END;


Enjoy !!!

Noof Visitors