▼
2015年1月26日 星期一
[Software Development] Terminology: Boilerplate
http://en.wikipedia.org/wiki/Boilerplate_%28text%29
http://en.wikipedia.org/wiki/Boilerplate_code
Differences between boilerplate and template?
From : http://www.webopedia.com/TERM/B/boilerplate.html
Template: describes the layout & style information
Boilerplate: actual text & graphics
http://whatis.techtarget.com/definition/boilerplate
boilerplate : actual text / code
template: fill-in-the-blanks boilerplate
http://en.wikipedia.org/wiki/Boilerplate_code
Differences between boilerplate and template?
From : http://www.webopedia.com/TERM/B/boilerplate.html
Template: describes the layout & style information
Boilerplate: actual text & graphics
http://whatis.techtarget.com/definition/boilerplate
boilerplate : actual text / code
template: fill-in-the-blanks boilerplate
[MongoDB] When name goes wrong
db.collectionName.find()
> work
db.collectionName.renameCollection("1")
> operation ok
db.1.find()
> error, illegal collection name
How to rollback?
db.getCollection("1").find()
> work
db.getCollection("1").renameCollection("properCollectionName")
> done
http://blog.onetechnical.com/2013/05/22/how-to-drop-a-mongodb-collection-with-an-illegal-name/
> work
db.collectionName.renameCollection("1")
> operation ok
db.1.find()
> error, illegal collection name
How to rollback?
db.getCollection("1").find()
> work
db.getCollection("1").renameCollection("properCollectionName")
> done
http://blog.onetechnical.com/2013/05/22/how-to-drop-a-mongodb-collection-with-an-illegal-name/
2015年1月22日 星期四
[Java Groovy] Convert Array or Object to String
def numbers = [0, 1, 2, 3, 4, 5] as Integer[]
assert '0 x 1 x 2 x 3 x 4 x 5' == numbers.join(' x ')
def objects = [new URL('http://www.mrhaki.com'), 'mrhaki', new Expando(name: 'mrhaki'), new Date(109, 10, 10)]
assert 'http://www.mrhaki.com,mrhaki,{name=mrhaki},Tue Nov 10 00:00:00 UTC 2009' == objects.join(',')
http://mrhaki.blogspot.hk/2009/10/groovy-goodness-join-elements-to-string.html
2015年1月15日 星期四
2015年1月14日 星期三
[Spring] [MongoDB] MongoDB Collection Event Listener
Event Listeners:
How to Use:
http://www.27programs.com/2013/10/27/mongodb-collection-event-listeners-spring-data/
http://maciejwalkowiak.pl/blog/2012/05/09/sorting-spring-data-mongodb-collections-using-orderby/
http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.html
- onBeforeConvert(E document)
- onAfterConvert(DbObject dbo, E document)
- onBeforeSave(E document)
- onAfterSave( E collection, DbObject dbo)
- ...
How to Use:
Step 1: Write Java class
package com.tsp.event;
import javax.annotation.Resource;
import org.springframework.data.mongodb.core.mapping.event.
AbstractMongoEventListener; // line broken for rendering
import com.mongodb.DBObject;
/**
* @author siva mondi
*
*/
public class UserEventListener extends AbstractMongoEventListener<User> {
@Override
public void onBeforeConvert(User user) {
}
@Override
public void onBeforeSave(User user, DBObject dbo) {
}
@Override
public void onAfterSave(User user, DBObject dbo) {
}
@Override
public void onAfterLoad(DBObject dbo) {
}
@Override
public void onAfterConvert(DBObject dbo, User user) {
}
}
|
Step 2: Register Event Listener in Spring XML
<!-- All The Event Listeners -->
<bean class="com.tsp.event.UserEventListener" />
|
http://www.27programs.com/2013/10/27/mongodb-collection-event-listeners-spring-data/
http://maciejwalkowiak.pl/blog/2012/05/09/sorting-spring-data-mongodb-collections-using-orderby/
http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.html
[MongoDB] ObjectId to Timestamp Converter
Test data (ObjectId): 54b37110f441a40ce4239497
Return (ISO Timestamp): 2015-01-12T07:00:32.000Z
* Note that _id stores the timestamp to second only, no millisecond value stored :(
http://steveridout.github.io/mongo-object-time/
Return (ISO Timestamp): 2015-01-12T07:00:32.000Z
* Note that _id stores the timestamp to second only, no millisecond value stored :(
http://steveridout.github.io/mongo-object-time/
[JPA] @transient
transient : passing with time; remaining in a place only a brief of time
http://www.thefreedictionary.com/transient
@transient : a field not to be persisted in database
http://stackoverflow.com/questions/2154622/why-does-jpa-have-a-transient-annotation
http://www.thefreedictionary.com/transient
@transient : a field not to be persisted in database
http://stackoverflow.com/questions/2154622/why-does-jpa-have-a-transient-annotation
2015年1月13日 星期二
[Java] HashMap, TreeMap and LinkedHashMap
HashMap - random ordering, after each new insertion
TreeMap - natural ordering by key
LinkedHashMap - ordering by insertion order
http://stackoverflow.com/questions/2889777/difference-between-hashmap-linkedhashmap-and-treemap
TreeMap - natural ordering by key
LinkedHashMap - ordering by insertion order
http://stackoverflow.com/questions/2889777/difference-between-hashmap-linkedhashmap-and-treemap
2015年1月8日 星期四
[Spring Security] Get Current User
To get the current authentication:
Method 1
http://www.mkyong.com/spring-security/get-current-logged-in-username-in-spring-security/
Method 1
Authentication auth = SecurityContextHolder.getContext().getAuthentication();Method 2
String name = auth.getName(); //get logged in username
User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();String name = user.getUsername(); //get logged in username
http://www.mkyong.com/spring-security/get-current-logged-in-username-in-spring-security/
2015年1月6日 星期二
[Spring Security] About CSRF
What is CSRF?
Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF (sometimes pronounced sea-surf[1]) or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts.
http://en.wikipedia.org/wiki/Cross-site_request_forgery
Some descriptions are at the bottom of the page:
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/helloworld.html
You can also read (before conclusion):
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/hellomvc.html#security-config-java
Some descriptions are at the bottom of the page:
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/helloworld.html
You can also read (before conclusion):
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/hellomvc.html#security-config-java
For Spring Security, notice that one description says:
" If you were not using Spring MVC taglibs or Thymeleaf, you can access the CsrfToken on the ServletRequest using the attribute _csrf. "
2015年1月2日 星期五
[Spring MVC] Some references for using Spring Security / MVC for web app
Spring Security
http://pro.ctlok.com/2010/02/spring-security-3.html
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/hellomvc.html#security-config-java
Spring Web MVC
http://krams915.blogspot.hk/2010/12/spring-3-mvc-using-modelattribute-in.html
http://www.javacodegeeks.com/2013/04/spring-mvc-hibernate-maven-crud-operations-example.html
http://examples.javacodegeeks.com/enterprise-java/spring/mvc/spring-mvc-form-handling-example/#code
Hindrance of using jsp:
Some of the related .jar files (more precisely .tld files with those jars) have to put into "/WEB-INF/lib", though they are included in the main application's "dist"(or "target") folder.
http://pro.ctlok.com/2010/02/spring-security-3.html
http://docs.spring.io/autorepo/docs/spring-security/3.2.x/guides/hellomvc.html#security-config-java
Spring Web MVC
http://krams915.blogspot.hk/2010/12/spring-3-mvc-using-modelattribute-in.html
http://www.javacodegeeks.com/2013/04/spring-mvc-hibernate-maven-crud-operations-example.html
http://examples.javacodegeeks.com/enterprise-java/spring/mvc/spring-mvc-form-handling-example/#code
Hindrance of using jsp:
Some of the related .jar files (more precisely .tld files with those jars) have to put into "/WEB-INF/lib", though they are included in the main application's "dist"(or "target") folder.