Connecting the Dots
Musing about my interests, hobbies & passions.
Restating what Steve Jobs said long back: You can't connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something, your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life.
Sunday, July 6, 2014
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.
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE BOOK ( | |
ID SERIAL PRIMARY KEY, | |
NAME VARCHAR (50) UNIQUE NOT NULL, | |
TITLE VARCHAR (100), | |
DESCRIPTION VARCHAR (200) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Wednesday, April 16, 2014
Saturday, February 22, 2014
Flowers @ Jinendram
Tuesday, February 11, 2014
Badminton @ MKM
Subscribe to:
Posts (Atom)