Handling clob variables in plsql

If you are storing more than 4K characters in the database or more than 32K characters in pl/sql, then you are advised to use clob datatype instead of varchar2.

These functions will be very helpful in handling clob variables:

create or replace function CLOB_TO_BLOB (p_clob CLOB) return BLOB
as
l_blob blob;
l_dest_offset integer := 1;
l_source_offset integer := 1;
l_lang_context integer := DBMS_LOB.DEFAULT_LANG_CTX;
l_warning integer := DBMS_LOB.WARN_INCONVERTIBLE_CHAR;
BEGIN

DBMS_LOB.CREATETEMPORARY(l_blob, TRUE);
DBMS_LOB.CONVERTTOBLOB
(
dest_lob =>l_blob,
src_clob =>p_clob,
amount =>DBMS_LOB.LOBMAXSIZE,
dest_offset =>l_dest_offset,
src_offset =>l_source_offset,
blob_csid =>DBMS_LOB.DEFAULT_CSID,
lang_context=>l_lang_context,
warning =>l_warning
);
return l_blob;
END;

create or replace function blob_to_clob(p_blob blob) return CLOB as
l_clob clob;
l_dest_offsset integer := 1;
l_src_offsset integer := 1;
l_lang_context integer := dbms_lob.default_lang_ctx;
l_warning integer;

BEGIN

if p_blob is null then
return null;
end if;

dbms_lob.createTemporary(lob_loc => l_clob
,cache => false);

dbms_lob.converttoclob(dest_lob => l_clob
,src_blob => p_blob
,amount => dbms_lob.lobmaxsize
,dest_offset => l_dest_offsset
,src_offset => l_src_offsset
,blob_csid => dbms_lob.default_csid
,lang_context => l_lang_context
,warning => l_warning);

return l_clob;

END;

Posted in Database | Leave a comment

Rendering a flex widget in Extjs

In the head section include the following:

    extjs/ext-all.js in the script tag with type=”text/javascript” attribute

    swfobject/swfobject.js in the script tag with type=”text/javascript” attribute

    extjs/resources/css/ext-all.css in the link tag with rel=”stylesheet” type=”text/css” attributes

Ext.onReady(function () {
var win = Ext.widget(‘window’, {
title: “Inspections Widget!”,
layout: ‘fit’,
width: 700,
height: 500,
resizable: true,
items: {
xtype: ‘flash’,
url: ‘http://somedomain.com/someflashfile.swf’,
flashVars: {locale:’en’,dealerCode:’XTIMEMOTORS’,webKey:’xtimemotors’,make:’HYUNDAI’,vin:’5NPEU46FX6H146379′,day:’01/20/2015′,customerName:’DABROWSKI, AMY’,model:’SONATA’,year:’2006′}
}
});
win.show();
});

Note: You can download swfobject.js from

References:

Posted in Extjs, Flex | Leave a comment

Search for files containing a text on linux

I found this command to be very useful. Often we would like to search for a file containing a text.

$ find /path-here -type f -exec fgrep -l ‘text-to-find-here’ {} \;

Eg.

$ find /home/venkat -type f -exec fgrep -l ‘foo’ {} \;

Posted in Linux | Leave a comment

Handling non-english characters in .java files

You should save the .java file as “Encode in UTF-8 without BOM” using an editor like Notepad++.
Do not use Notepad. Notepad introduces some special characters because of which the jvm will throw compiling error because of the special characters.

This applies to .properties files also, which will have non-english characters.

Posted in Java | Leave a comment

Handling OutOfMemory problems in Java

I am now dealing with “big data” applications.
I built applications which process large volumes of data and store them in different data stores like Database, Solr etc.

One of the ways to handle OutOfMemory problem would be to specify the min. and max memory that the JVM can use in your program.

By default a jvm of a Java application uses only 64 MB. We can specify the min and max memory that the JVM can use by using following command line options:
1. -Xms specifies the minimum memory
2. -Xmx specifies the maximum memory

You have to specify the memory values in terms of Megabytes as shown in the following Example:

$ java -Xms1024m -Xmx2048m HelloWorld

You can check the total memory available for the JVM in your program by using the following statement:
Runtime.getRuntime().totalMemory()
This will return the total memory in terms of bytes.

You can check the free memory available for the JVM in your program by using the following statement:
Runtime.getRuntime().freeMemory()

Posted in Java | Leave a comment

Couchbase as properties repository

Couchbase is a NOSQL persistent data store. You can store Serializable Java objects in couchbase.
I have used Couchbase extensively to save all the configurations properties. I have saved all the properties as JSON objects. These objects can be created and edited directly using the admin console provided by Couchbase.

You can perform asynchronous get/set operations with couchbase.

I have observed that the get/set operations fail at certain times. Hence, I have also implemented retrying mechanism. In the retry mechanism I add the the failed tasks to a List of pending tasks. I perform the get/set operations of these pending tasks by means of a separate Timer task which is scheduled at a regular interval.

Posted in Java | Leave a comment

Logging to Loggly – Cloud based logging

Loggly is a platform which acts as a store house of log messages. The advantage of using Loggly is that we will be able to view the logs simply by using a browser. There is an ability to filter the log messages based on the time, category etc.

There is a multi-threaded java implementation of logging messages to Loggly which I customized and used in my project.
You can download the java code from the url – https://github.com/webmetrics/loggly-java/tree/master/src/main/java/biz/neustar/loggly

Posted in Java | Leave a comment