Labels

.NET Job Questions About Java Absract class Abstract class Abstract Class and Interface Aggregation ajax aop apache ofbiz Apache ofbiz tutrial Association authentication autocad basics batch Binary Tree bootstrap loader in java build Builder design pattern C++ Job Questions caching CallableStatement in java certifications Chain of responsibility Design pattern charts check parentheses in a string Classes classloader in java classloading concept code quality collage level java program Composition concurrency Concurrency Tutorial Converting InputStream to String Core Java core java concept core java interview questions Core Java Interview Questions Core Java Questions core java tutorial CyclicBarrier in Java data structures database Database Job Questions datetime in c# DB Db2 SQL Replication deserialization in java Design Patterns designpatterns Downloads dtd Eclipse ejb example/sample code exception handling in core java file handling injava File I/O vs Memory-Mapped Filter first program in spring flex Garbage Collection Generics concept in java grails groovy and grails Guice Heap hibernate Hibernate Interview Questions how-to IBM DB2 IBM DB2 Tutorial ide immutable Interceptor Interface interview Interview Questions for Advanced JAVA investment bank j2ee java JAVA Code Examples Java 7 java changes java class loading JAVA Classes and Objects Java Classloader concept Java classloading concept java cloning concept java collection Java collection interview questions Java Collections java concurrency Java CountDownLatch java definiton Java design pattern Java EE 5 Java EE 6 Java Exceptions Java file Java Garbage Collection Java generics Java Glossary java hot concept java immutable concept Java Interface Java interview Question java interview question 2012 java interview question answer Java Interview Questions Java Interview Questions and Answers java interview topic java investment bank Java Job Questions java multithreading java multithreading concept java new features Java Packages java proxy object java questions Java Serialization Java serialization concept java serialization interview question java session concept java string Java Swings Questions java synchronization java threading Java Threads Questions java tutorial java util; java collections; java questions java volatile java volatile interview question Java Wrapper Classes java.java1.5 java.lang.ClassCastException JavaNotes javascript JAX-WS jdbc JDBC JDBC Database connection jdk 1.5 features JDK 1.5 new features Concurrent HashMap JMS interview question JMS tutorial job JSESSIONID concept JSESSIONID interview Question JSF jsp JSP Interview Question JSP taglib JSTL with JSP Junit Junit Concept Junit interview question.Best Practices to write JUnit test cases in Java JVM Linux - Unix tutorial Marker Interfaces MD5 encryption and decryption messaging MNC software java interview question musix NCR java interview question Networking Job Questions news Object Serialization Objects ojdbc14.jar OOP Oracle Oracle SQL Query for two timestamp difference orm own JavaScript function call in Apache ofbiz Packages Palm Apps patterns pdf persistence Portal Portlet Spring Integration Prime number test in java programs Rails Reboot remote computers REST Ruby Sample application schema SCJP security Senior java developer interviews servlet3 servlets session tracking singleton design pattern Spring Spring 2.5 Framework spring ebook Spring framework concept spring MVC spring pdf Spring Security Spring Security interview questions SQL SQL performance SQL Query to create xml file Sql Query tuning ssis and ssrs StAX and XML string concept string immutable string in java strings struts Struts2 Struts2 integration synchronization works in java Technical Interview testing tips Tomcat top Tutorial Volatile in deep Volatile working concept web Web Developer Job Questions web services weblogic Weblogic Application Server websphere what is JSESSIONID xml XML parsing in java XML with Java xslt


Friday, 5 July 2013

Learning Curve

  Mybatis

Mybatis Poc
Advandages found in Poc Mybatis
1)      Compare other ORM tools (Hibernate ,Toplinks)  learning curve is easy
2)      In compare to Hibernate we are writing one xml file for one POJO but in Mybatsis we configure morethan 1 pojo in the single mappefile
3)      In MyBatis only one Mabatis. jar files are enough CRUD Operation
4)      All the crud operation are done on the same mapper XML
5)      We can to the Association (one to Many,Manyto one ,Many to Many)are done on the same mapper.xml
6)      We can also do the Store Procedure
7)      Development Time is very less when compare to other ORM and JDBC
8)      In is compatible with spring for integration we use Mybatis-spring.jar
9)      Developers can Quickly learn and implement  in limited Time
10)    The one of the advantage  of ORM is result s are mapped  into Objects compare to JDBC
11)   All the SQL Queries are come inside the XML so our code is  good to see
12)   Simple API to do our data
13)   My batis join with Spring we handle transaction. So we avoid transaction kind of worries

Using Mybatis CRUD Operation
IN POJO
Single Row
           Brand brand = ( Brand) session.selectOne("selectBrand", 10053);
IN XML
<select id="selectBrand" parameterType="int" resultMap="brandResultMap">
                select * from BRAND where BRAND_SYSID = #{brandSysid}
            </select>
Muitiple Row
IN POJO

ArrayList < Brand> brands = (ArrayList<Brand>) session.selectList("selectMutipleBrand");

IN XML

<select id="selectMutipleBrand"   resultMap="brandResultMap">
                        select * from BRAND 
                    </select>


Insert Row
IN POO
Try{
session.insert("insertbrand", brand);
}catch(Exception e){}
session.commit;
IN XML

                                 <insert id="insertbrand" parameterType="com.exmple.Brand">
                                 INSERT INTO BRAND (BRAND_SYSID, BRAND_DESCRIPTION, UPDATE_USER_ID,UPDATE_DATE,UPDATE_SYSTEM)


                                VALUES (#{brandSysid}, #{brandDescription}, #{updateUserId}, #{updateDate}, #{updateSystem})
                                </insert>
IN POJO
Try{
session.update("updatebrand", brand);
}catch(Exception e){}
session.commit;

IN XML

                    <update  id="updatebrand" parameterType="com.exmple.Brand">
                                                 UPDATE   BRAND SET
                                                 BRAND_DESCRIPTION=#{brandDescription},
                                                 UPDATE_USER_ID=#{updateUserId},
                                                 UPDATE_DATE=#{updateDate},
                                                 UPDATE_SYSTEM=#{updateSystem}
                                                 where BRAND_SYSID=#{brandSysid}
                 
                    </update>


IN POJO

session.delete("deletebran", id);
IN XML

                    <delete  id="deletebran"  parameterType="int">
                                                 DELETE   FROM BRAND where
                                                 BRAND_SYSID = #{brandSysid}
                    </delete>
Relations  or Association
INPOJO
 MorSaveReport morsavereport = (MorSaveReport) session.selectOne("selectMorsave", "reportBame6");
                                                                                                
ArrayList<MORSsveDetails>savedetails= morsavereport.getMorSaveDetailsCollection(); 
IN XML
<mapper namespace="onetomanymap">
        <resultMap id="MorsaveResultMap" type="onetomanymap.MorSaveReport">
                        <id property="reportName" column="REPORT_NAME" />                          
                        <result property="reportType" column="REPORT_TYPE" />       
                         ……………            
                         <collection property="morSaveDetailsCollection"   ofType="MorSaveDetailsMap" javaType="ArrayList" resultMap="MorSaveDetailsMap"/>            
PROCEDURE CALL
 INPOJO
 
 
   Brand e = (Brand)smc.queryForObject
                ("Brand.getBrnadInfo ", id);
 


XML

<procedure id="getBrnadInfo" resultClass="Employee"
              parameterMap="getBrandInfoCall">
   { call getBrand( #acctID# ) }
</procedure>
<parameterMap id=" getBrandInfoCall " class="map">
   <parameter property="acctID" jdbcType="INT"
   javaType="java.lang.Integer" mode="IN"/>
</parameterMap>
  for Details and source code goto Mybatis Details goto



  Spring Jdbc Template


Data access using spring JDBC template

Spring JDBC Template advantages compare to Standard JDBC
1. Jdbc Template class is the central class in the JDBC core package.
2. Jdbc Templates handles the creation, release the resources and clean-up the resources automatically.
3. Helps to avoid common errors such as forgetting the close connection and etc.
4. The Spring JDBC template offers several ways to query the database.
·         returns a list of HashMaps
·         allows to translates the SQL result direct into an object
·         return list of objects
·         Populate the objects in a list via matching the bean property names to the column names.
5. Spring JDBC provides exception translation. This allows the programmer to react more flexible to the errors. Well defined API for database exceptions.
6. Using Jdbc templates API packages do
·         CRUD operation
·         Bulk batch updated
·         Stored procedures and SQL function call
·         Named parameter call
·         Convert result into user custom ways.
7. Understanding APIs and learning curves easy.




Using JDBC Templates - CRUD Operation
1.Updating (INSERT/UPDATE/DELETE)
jdbcTemplate.update("insert into t_actor (first_name, surname) values (?, ?)", new Object[] {"Leonor", "Watling"});
jdbcTemplate.update("update t_actor set weapon = ? where id = ?", new Object[] {"Banjo", new Long(5276)});
jdbcTemplate.update("delete from orders"); // :)

2. Query single row
Customer customer = (Customer)getJdbcTemplate().queryForObject(sql, new Object[] { custId }, new CustomerRowMapper());
3. Query single row with BeanPropertyRowMapper
Customer customer = (Customer)getJdbcTemplate().queryForObject(sql, new Object[] { custId },new BeanPropertyRowMapper(Customer.class));
5. Query multiple rows with manual mapping
List<Map<String, Object>> rows = getJdbcTemplate().queryForList(sql);
6. Query multiple rows with BeanPropertyRowMapper
List<Customer> customers  = getJdbcTemplate().query(sql, new BeanPropertyRowMapper(Customer.class));
7. Named Parameter Query
namedParameterJdbcTemplate.queryForObject(query,namedParameters, new RowMapper()  {
              public Object mapRow(ResultSet resultSet, int rowNum) throws SQLException {
                          return new Forum(resultSet.getInt("FORUM_ID"),resultSet.getString("FORUM_NAME"),
resultSet.getString("FORUM_DESC"));
              }
  });

8. Batch Update Query
jdbcTemplate.batchUpdate("insert into z_customer1 (id, first_name, last_name, last_login, comments) values (?, ?, ?, ?, ?)",new BatchPreparedStatementSetter() {
              public void setValues(PreparedStatement ps, int i) throws SQLException {
                          ps.setLong(1, i + 1);
                          ps.setString(2, firstNames.get(i));
                          ps.setString(3, lastNames.get(i));
              }
              public int getBatchSize() { return count; }
  });

9. Stored procedures call
countryProcedure = new SimpleJdbcCall(dataSource)
              .withoutProcedureColumnMetaDataAccess()
              .withProcedureName(procedureName)
              .declareParameters(new SqlOutParameter("RETURNCODE", Types.INTEGER))
              .declareParameters(new SqlOutParameter("RETURNMSG", Types.VARCHAR))
              .returningResultSet("countries", new ParameterizedRowMapper<Country>() {
            public Country mapRow(ResultSet rs, int rowNum)
                    throws SQLException {
                Country country = new Country();
                country.setId(rs.getInt(1));
                country.setName(rs.getString(2));
                return country;
            }
        });

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...