Sunday, July 6, 2014

David Luis Fan Club ++


Early days with REST

For last 7 years I have been following Roy Fielding's master piece, REST. I remember it was Rick Cobb who introduced this style of modelling services. Further Rajesh's musings helped me a lot in unleashing this style better. These days were very early days when REST trend has just started in industry. With no standards for styling, every other person has its own flavor of REST the way they want. If I remember the right names Restlet, RestEasy were some framework which emerged and they too had their beta version out.

We started writing REST services in a scripting language called TCL which was played on AOLServer. As such there was no support for REST but the choice was driven by application hosting platform. I remember those long discussion which I had with Rajesh understanding how to design URLs and responses. What resources are and how HTTP method maps to it and what it means then. I too remember the discussion on data interchange styles; XML was already popular, JSON was blooming, UL LI, XOXO :) etc. Deep diving microformat was our part time hobby.

Rick later introduced concept of POD (point of  something), with concept of PODs I realized the actual benefits of REST; importance of statelessness and how can that solve the Scalability & Availability needs of the service.

Thursday, June 26, 2014

MyBatis & Managed Transaction

How to work with Managed transaction in MyBatis?

MyBatis+Managed Transaction

public class BizService {
private SqlSessionFactory sqlSessionFactory;
/**
* Initalize the
*
* @param config the config
*/
private void init(QueryEngineConfiguration config) {
InputStream inputStream;
Properties properties= new Properties();
properties.setProperty("driver", config.getDriverClassName());
properties.setProperty("url", config.getDbUrl());
properties.setProperty("username", config.getDbUsername());
properties.setProperty("password", config.getDbPassword());
try(
inputStream = Resources.getResourceAsStream(config.getSqlMapConfigPath());
) {
this.sqlSessionFactory= new SqlSessionFactoryBuilder().build(inputStream, properties);
}
}
public void bizFunction(SomeValueObject valueObject){
try (
SqlSession session = factory.openSession(false);
){
Entity1 entity1 = valueObject.getEntity1();
sqlSession.insert("insertQueryName1", entity1);
Entity2 entity = valueObject.getEntity2();
sqlSession.insert("insertQueryName2", entity);
session.commit();
}
}
}
view raw BizService.java hosted with ❤ by GitHub
<environments default="development">
<environment id="development">
<transactionManager type="MANAGED" />
<dataSource type="POOLED">
<property name="driver" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
...
</dataSource>
</environment>
</environments>
view raw sqlconfig.xml hosted with ❤ by GitHub

Mybatis & returning auto-generated IDs with inserts

How do I return auto-generated IDs inserted in table within the same insert API?

PostgreSQL+MyBatis+Insert+Autogenerated ID

CREATE TABLE BOOK (
ID SERIAL PRIMARY KEY,
NAME VARCHAR (50) UNIQUE NOT NULL,
TITLE VARCHAR (100),
DESCRIPTION VARCHAR (200)
);
view raw book.sql hosted with ❤ by GitHub
<mapper>
<select id="add_book" parameterType="map" resultType="map">
INSERT
INTO BOOK(NAME,TITLE,DESCRIPTION)
VALUES
(#{name},#{title},#{description})
RETURNING *;
</select>
<select id="add_book" parameterType="list" resultType="map">
INSERT
INTO BOOK(NAME,TITLE,DESCRIPTION)
VALUES
<foreach collection="list" item="item" index="index" open="" separator="," close="">
(#{item.name},#{item.title},#{item.description})
</foreach>
RETURNING *;
</select>
</mapper>
view raw sqlmap.xml hosted with ❤ by GitHub

Wednesday, April 16, 2014

noname001 :)

Useful note from Shaun Anchor talk on 'The happy secret to better work'

Saturday, February 22, 2014

Flowers @ Jinendram

Lantana (Yellow), Lantana (Red/Yellow), Sevanti AKA Chrysanthemum, Nastritium(Yellow), Rose(Red/Pink/Orange),

Tuesday, February 11, 2014

Badminton @ MKM

Malhar Krida Mandal (MKM)
Many thanks to Bargal sir for getting this club integrated, one of the finest one in Indore & being an inspiration. 
Your commitment towards fitness and making others aware of its importance is really valuable.


Statcounter