Tuesday, 22 May 2012

How to index data in solr from database automatically?

As most of the application store the data in relational databases and once the data size gets larger the option comes to solr. Index the data of database using solr DIH. It requires you to configure the data-config.xml. All the required info about setting up solr and data-config.xml is available at
http://abhijitbashetti.blogspot.in/2011/09/apache-solr-set-up-for-tomcat-on-linux.html and

the other useful link is http://abhijitbashetti.blogspot.in/2011/09/indexing-database-with-solr-34-from.html

Now the question comes how to automize the same. I have used the JBoss for scheduling the same.

In the data-config.xml use the last_index_time as the variable resolver. Or add a new column to the table from where you are fetching the data for indexing e.g last_modification_date.

For the next scheduling which will be invoked for updating the index for the updated data in your database. It will check the last_modification_date with last_index_time and update the index accordingly.

Here you can use the jboss scheduling mechanism by firing different url to your solr server.

i.e. Add the variable resolver in your query and send those data in the http URL to solr.

Your database query would be like ...



select  doc.document_id as id,
        doc.name as name,
        doc.author as author,
        from   ds_document_c doc
        where doc.last_modification_date >= to_date(${dataimporter.request.last_index_time}, 'DD/MM/YYYY HH24:MI:SS');


and the http url for the solr would like

http://localhost:8080/solr/select?qt=/dataimport&command=full-import&clean=false&commit=true&verbose=true&last_index_time='12/05/2012'


This will help you to automate your database indexing ....











Friday, 4 May 2012

modify an existing check constraint in oracle?

Drop and Recreate it.



Oracle "alter table" syntax to drop constraints.


ALTER TABLE TEST_TABLE DROP constraint TEST_TABLE_CC1;


Oracle "alter table" syntax to add a check constraint.


ALTER TABLE TEST_TABLE ADD CONSTRAINT TEST_TABLE_CC1 CHECK ( PAYMENT_MODE IN ( 'CASH' , 'NET_BANKING' , 'CHEQUE' ) );

Tuesday, 17 April 2012

IFRAME Example


The <iframe> tag specifies an inline frame.
An inline frame is used to embed another document within the current HTML document.

I wanted to have the "src" to be changed dynamically. 

Here is the example of IFRAME where in source can be changed though TextField. 
Whatever you enter into the text box will be given to the Iframe and iframe window will render that page.


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TEST Page</title>
</head>
<script type="text/javascript" >
function iframeMethod() {
var srcValue =  document.getElementById("text");
var iframe   =  document.getElementById("frame");
iframe.setAttribute('src', srcValue.value);
}
</script>
<body>
<iframe src="http://www.google.com" name="frame" id="frame"
frameborder=0 style="overflow:visible; width:100%; height:600; scrolling="no">
</iframe>
<input type="text" name="text" id="text" target="frame"/>
<input type="submit" name="submit" id="submit" value="Submit" onclick="javascript:iframeMethod();"/>
</body>
</html>

Monday, 9 April 2012

How to set JAVA_HOME environment variable in Ubuntu


    Open /etc/bash.bashrc using sudo command
    e.g. sudo gedit /etc/bash.bashrc.
   
   go to the end of the file and add following lines:

    JAVA_HOME=/usr/lib/jvm/name_of_your_java_folder(e.g. java,open-6-jdk etc.)
    export JAVA_HOME
   
    PATH=$PATH:$JAVA_HOME/bin
    export PATH

   Done. Just reboot your computer.


    echo $JAVA_HOME
    it shows something like this:/usr/lib/jvm/name_of_your_java_folder(e.g. java,open-6-jdk etc.)
 
    echo $PATH
    it shows something like this::/usr/lib/jvm/name_of_your_java_folder(e.g. java,open-6-jdk etc.)/bin 

Thursday, 22 March 2012

Unique constraint and index relationship in Oracle

Dropping Unique Key does not drop the index created for it in Oracle.

I am not very sure for which all versions it happens.

But when I explicitly run the

Drop Index <indexName>;

After execution the same , my unique constraint violation exception issue is fixed.


Tuesday, 7 February 2012

Updating the Cookie for specific time interval


If you want to update the cookies after some time interval using the time then call the below function.
Timer should run with the interval of less than 11 minutes.

updateCookieValue  :  function () {
    var cookies = document.cookie.split(";");
if (cookies.length > 0) {
var nTime = new Date();
//add 11 mins to current time so that the recursive call to update cookie
             (with interval 10 mins)
//gets executed before the cookie gets expired ( 11 * 1000 * 60)
             // time added in millisecond
nTime.setTime(nTime.getTime()+660000);
for (var i = 0; i < cookies.length; i++){
var name = cookies[i].split("=")[0];
name = name.trim();
var value = cookies[i].split("=")[1];
if((name == " cookie_0") || (name == " cookie_1")){
document.cookie = name + "=" +escape( value ) +";expires="
                      + nTime.toGMTString()+";path=/;domain=";
}
        }
}
}

Sunday, 5 February 2012

Encryption and Decryption Technique


import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class EncryptDecryptUtil {

    private static final String UNICODE_FORMAT = "UTF8";
    public static final String DESEDE_ENCRYPTION_SCHEME = "DESede";
    private KeySpec keySpec;
    private SecretKeyFactory secretKeyFactory;
    private Cipher cipher;
    byte[] keyAsBytes;
    private String encryptionKey;
    private String encryptionScheme;
    private SecretKey secretKey;

    public EncryptDecryptUtil() throws Exception
    {
        encryptionKey = "EncryptionKeyForEncryption";
        encryptionScheme = DESEDE_ENCRYPTION_SCHEME;
        keyAsBytes = encryptionKey.getBytes(UNICODE_FORMAT);
        keySpec = new DESedeKeySpec(keyAsBytes);
        secretKeyFactory = SecretKeyFactory.getInstance(encryptionScheme);
        cipher = Cipher.getInstance(encryptionScheme);
        secretKey = secretKeyFactory.generateSecret(keySpec);
    }

    public String encrypt(String unencryptedString) {
        String encryptedString = null;
        try {
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
            byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT);
            byte[] encryptedText = cipher.doFinal(plainText);
            BASE64Encoder base64encoder = new BASE64Encoder();
            encryptedString = base64encoder.encode(encryptedText);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encryptedString;
    }
 
    public String decrypt(String encryptedString) {
        String decryptedText=null;
        try {
            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            BASE64Decoder base64decoder = new BASE64Decoder();
            byte[] encryptedText = base64decoder.decodeBuffer(encryptedString);
            byte[] plainText = cipher.doFinal(encryptedText);
            decryptedText= bytes2String(plainText);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return decryptedText;
    }
 
    private static String bytes2String(byte[] bytes) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < bytes.length; i++) {
            stringBuffer.append((char) bytes[i]);
        }
        return stringBuffer.toString();
    }
 
     /**
     * Testing The Encryption And Decryption Technique
     */
    public static void main(String args []) throws Exception
    {
    EncryptDecryptUtil myEncryptor = new EncryptDecryptUtil();
    String stringToEncrypt= "theherald";
        String encrypted=myEncryptor.encrypt(stringToEncrypt);
        String decrypted=myEncryptor.decrypt(encrypted);

        System.out.println("The String To be Encrypted : "+stringToEncrypt);
        System.out.println("Encrypted Value of the String : " + encrypted);
        System.out.println("Decrypted Value of the String : "+decrypted);

    }
}  


The output is ::::::

The String To be Encrypted : theherald
Encrypted Value of the String :b6WaWLvUO7XznWLKxDzGXw==
Decrypted Value of the String :theherald