Spring Liquibase – DB Creation/Changes

Steps to Configure Spring Liquibase
– Dependency – pom.xml

<dependency>
        <groupId>org.liquibase</groupId>
	<artifactId>liquibase-maven-plugin</artifactId>
	<version>3.4.1</version>
</dependency>

– In ApplicationContext.xml Create bean of SpringLiquibase

<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
		<property name="dataSource" ref="dataSource" /><!--DataSource cofigs refs related to DB-->
		<property name="defaultSchema" value="${jdbc.schema.name}" /><!--DB schema name-->
		<property name="changeLog" value="classpath:dbchanges/db-changelog.xml" /><!--Configuration file for liquibase-->
	</bean>

– db-changelog.xml

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
	<changeSet author="taher.tinwala" id="1" context="pre-process-db-changes" >
         <sqlFile dbms="postgresql" encoding="utf8" endDelimiter="\nGO" path="/sql-files/project_v1/sqlchanges_1.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true"/>
    </changeSet>
    <changeSet author="java.hunter" id="2" context="pre-process-db-changes">
        <sqlFile dbms="postgresql" encoding="utf8" endDelimiter="\nGO" path="/sql-files/project_v1/sqlchanges_2.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true"/>
    </changeSet>      
</databaseChangeLog>

– We have to place sql files in project for above mentioned location(path attribute)

Posted in Hibernate, Liquibase, Spring | Tagged , , , , | Leave a comment

OCJP/1Z0-851 Preparation Tips www.exampit.com

Best site for Learning and Dumps for OCJP.
You will get set of 11 tests which ensures 100% marks in OCJP. All the best
http://www.exampit.com(OCJP Dumps)

ExamPit is a platform for Student and Teacher, where Student can give Free/Paid Test as per the subject of interest and Teacher can earn by creating Test. Also there are Free test on OCJP/SCJP/1Z0-851 for 100% success

Posted in 1Z0-851, OCJP, SCJP | Tagged , , , , , , , | Leave a comment

Get Attributes of HTML component

(function($) {
                $.fn.attrs = function() {
                    var attributes = {};
                    if (this.length) {
                        $.each(this[0].attributes, function(index, attr) {
                            attributes[ attr.name ] = attr.value;
                        });
                    }

                    return attributes;
                };
            })(jQuery);

            function makeTest(){
                var btnAttr = $('#xyz').attrs();
                for(var tt in btnAttr){
                    console.log(tt+' : '+btnAttr[tt]);
                }
            }
<input id="xyz" type="button" onclick="makePDF()" value="Test BTN"/>
Posted in Javascript, JQuery | Tagged , , , , | Leave a comment

Hibernate Session Object Method brief

save
-Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.)
merge
-Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy of and return it as a newly persistent instance. The given instance does not become associated with the session.
flush
-Force this session to flush. Must be called at the end of a unit of work, before committing the transaction and closing the session.Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
close
-End the session by releasing the JDBC connection and cleaning up. It is not strictly necessary to close the session but you must at least disconnect() it.
evict
-Remove this instance from the session cache. Changes to the instance will not be synchronized with the database.
clear
-Completely clear the session. Evict all loaded instances and cancel all pending saves, updates and deletions. Do not close open iterators or instances of ScrollableResults.
disconnect
-Disconnect the Session from the current JDBC connection. If the connection was obtained by Hibernate close it and return it to the connection pool; otherwise, return it to the application.
persist
-Make a transient instance persistent.
refresh
-Re-read the state of the given instance from the underlying database. It is inadvisable to use this to implement long-running sessions that span many business tasks. This method is, however, useful in certain special circumstances. For example
where a database trigger alters the object state upon insert or update
after executing direct SQL (eg. a mass update) in the same session
after inserting a Blob or Clob
get
-Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. (If the instance is already associated with the session, return that instance. This method never returns an uninitialized instance.)
load
-Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed.
update
-Update the persistent instance with the identifier of the given detached instance. If there is a persistent instance with the same identifier, an exception is thrown.

Posted in Hibernate | Leave a comment

Understanding Propagation value for @Transactional in Spring

MANDATORY
Support a current transaction, throw an exception if none exists.
NESTED
Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else.
NEVER
Execute non-transactionally, throw an exception if a transaction exists.
NOT_SUPPORTED
Execute non-transactionally, suspend the current transaction if one exists.
REQUIRED
Support a current transaction, create a new one if none exists.
REQUIRES_NEW
Create a new transaction, suspend the current transaction if one exists.
SUPPORTS
Support a current transaction, execute non-transactionally if none exists.

Posted in Hibernate, Spring | Leave a comment

Creating custom function on JavaScript String startsWith and endsWith


if (typeof String.prototype.startsWith != 'function') {
                String.prototype.startsWith = function(str) {
                    return this.slice(0, str.length) == str;
                };
}

if (typeof String.prototype.endsWith != 'function') {
                String.prototype.endsWith = function(str) {
                    return this.slice(-str.length) == str;
                };
}
alert('mankind'.startsWith('man'));
alert('mankind'.endsWith('kind'));

Posted in Javascript, JQuery | Leave a comment

Hibernate Inheritance: Table Per Concrete Class

package taher.javahunter.hibernate;
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
 
 
@Entity
@Table(name = "PERSON")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Person {
 
    @Id
    @Column(name = "PERSON_ID")
    private Long personId;
     
    @Column(name = "FIRSTNAME")
    private String firstname;
     
    @Column(name = "LASTNAME")
    private String lastname;
     
    public Person() {
     
    }
    public Person(String firstname, String lastname) {
        this.firstname = firstname;
        this.lastname = lastname;
    }
    // Getter and Setter methods, 
}
package taher.javahunter.hibernate;
 
import java.util.Date;
 
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
 
@Entity
@Table(name="EMPLOYEE")
@AttributeOverrides({
    @AttributeOverride(name="firstname", column=@Column(name="FIRSTNAME")),
    @AttributeOverride(name="lastname", column=@Column(name="LASTNAME"))
})
public class Employee extends Person {
 
    @Column(name="joining_date")
    private Date joiningDate;
     
    @Column(name="department_name")
    private String departmentName;
 
    public Employee() {
    }
     
    public Employee(String firstname, String lastname, String departmentName, Date joiningDate) {
         
        super(firstname, lastname);
         
        this.departmentName = departmentName;
        this.joiningDate = joiningDate;
    }
     
    // Getter and Setter methods, 
}
package taher.javahunter.hibernate;
 
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
 
@Entity
@Table(name="OWNER")
@AttributeOverrides({
    @AttributeOverride(name="firstname", column=@Column(name="FIRSTNAME")),
    @AttributeOverride(name="lastname", column=@Column(name="LASTNAME"))
})
public class Owner extends Person {
 
    @Column(name="stocks")
    private Long stocks;
     
    @Column(name="partnership_stake")
    private Long partnershipStake;
 
    public Owner() {
    }
     
    public Owner(String firstname, String lastname, Long stocks, Long partnershipStake) {
         
        super(firstname, lastname);
         
        this.stocks = stocks;
        this.partnershipStake = partnershipStake;
    }
 
    // Getter and Setter methods, 
}
Output :

Hibernate: insert into PERSON (FIRSTNAME, LASTNAME, PERSON_ID) values (?, ?, ?)
Hibernate: insert into EMPLOYEE (FIRSTNAME, LASTNAME, department_name, joining_date, PERSON_ID) values (?, ?, ?, ?, ?)
Hibernate: insert into OWNER (FIRSTNAME, LASTNAME, partnership_stake, stocks, PERSON_ID) values (?, ?, ?, ?, ?)

Posted in Hibernate | Leave a comment