Monday, January 25, 2010
SQL Best Practise
Isolating indexed field
//Bad Idea.
Where TO_DAYS(order_created) - TO_DAYS(CURRENT_DATE())>= 7
//Better Idea. CURRENT_DATE() not working for query cache
Where order_created >= CURRENT_DATE() - INTERVAL 7 DAY
//Best Idea
Where order_created >= '11/11/2009' - INTERVAL 7 DAY
Using calculated field
//Bad idea
WHERE email_address LIKE '%.com';
//Better idea
ALTER TABLE CUSTOMERS
ADD COLUMN rv_email_address VARCHAR(80) NOT NULL;
UPDATE customers SET rv_email_address = REVERSE(email_address);
CREATE INDEX ix_rv_email ON customer (rv_email_address(20));
DELIMITER ;;
CREATE TRIGGER trg_bi_cust BEFORE INSERT ON customers
FOR EACH ROW BEGIN
SET NEW.rv_email_address=REVERSE(NEW.email_address);
END;;
//same trigger for BEFORE UPDATE...
//Then SELECT on the new field...
WHERE r_email_address LIKE CONCAT(REVERSE('.com'),'%');
Saturday, January 2, 2010
J2ME HttpConnection issue
J2ME HttpConnection issue when testing with Digi telco and Sony Ericsson W810i
I am wondering why Lwuit-Makeover is able to connect but my own application can not. Then i found out that my application need to run in Internet setting but Lwuit-Makeover just need WAP setting.
If request connection setting from telco, they will send you the following setting.
Lwuit-Makeover
My own application
Reference
Avoid Connection Problems with Your Java Applications
I am wondering why Lwuit-Makeover is able to connect but my own application can not. Then i found out that my application need to run in Internet setting but Lwuit-Makeover just need WAP setting.
If request connection setting from telco, they will send you the following setting.
- Digi Streaming
- Digi Internet
- Digi MMS
- Digi WAP
Lwuit-Makeover
- "Setting for java" can be WAP setting.
- Internally this application use com.sun.me.web.request api and Get method to make connection.
My own application
- "Setting for java" does not work with WAP setting. It need internet setting.
- I use (HttpConnection) Connector.open("http://.."); and writebyte method to make connection.
Reference
Avoid Connection Problems with Your Java Applications
Friday, December 18, 2009
SSO : JOSSO VS CAS
JOSSO, CAS and openSSO are famous Java Single Sign-On in the open source world. The following are some comments on JOSSO and CAS.
CAS
JOSSO
Architecture is hard to deploy. It consists of gateway and agent. Gateway is the project of SSO/login module. Agent need to be installed in all servers for security filtering. Thus, it tights the configuration to server and bunch of xml files in lib folder of tomcat. The security is configure in the server and not within the project. Even thought installation script is provided but it is just for all(agent, gateway,project) in one server. I got no idea how the configuration should be if more than one server is using...
JOSSO + Acegi integration
Look like outdated because have not upgraded to spring security.
CAS
- Architecture is simple to install. Security filtering is inside war file.
- Only work with SSL.
- Easily integrate in Spring security.
JOSSO
Architecture is hard to deploy. It consists of gateway and agent. Gateway is the project of SSO/login module. Agent need to be installed in all servers for security filtering. Thus, it tights the configuration to server and bunch of xml files in lib folder of tomcat. The security is configure in the server and not within the project. Even thought installation script is provided but it is just for all(agent, gateway,project) in one server. I got no idea how the configuration should be if more than one server is using...
JOSSO + Acegi integration
Look like outdated because have not upgraded to spring security.
Sunday, October 4, 2009
Cross Platform Hibernate @Id Sequence setting
Cross platform @Id setting
@SequenceGenerator(name = "SEQ_HRMS_EMP", sequenceName = "SEQ_HRMS_EMP", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_HRMS_EMP")
@Id
@Column(name = "user_id")
private Integer userId;
Schema export from hibernate
@SequenceGenerator(name = "SEQ_HRMS_EMP", sequenceName = "SEQ_HRMS_EMP", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_HRMS_EMP")
@Id
@Column(name = "user_id")
private Integer userId;
Schema export from hibernate
- MySql
create table HRMS_EMP (
user_id integer not null auto_increment,
MySql will ignore the generator = "SEQ_HRMS_EMP" setting because MySql does not have sequence. - Postgres
create sequence SEQ_HRMS_EMP; - Oracle
create sequence SEQ_HRMS_EMP;
Monday, September 7, 2009
Fluent Interface Design Pattern in IBatis3
I found the following coding style in ibatis3 tutorial. Look interesting about the coding.
private String selectPersonSql() {
BEGIN(); // Clears ThreadLocal variable
SELECT("P.ID, P.USERNAME, P.PASSWORD, P.FULL_NAME");
SELECT("P.LAST_NAME, P.CREATED_ON, P.UPDATED_ON");
FROM("PERSON P");
FROM("ACCOUNT A");
INNER_JOIN("DEPARTMENT D on D.ID = P.DEPARTMENT_ID");
INNER_JOIN("COMPANY C on D.COMPANY_ID = C.ID");
WHERE("P.ID = A.ID");
WHERE("P.FIRST_NAME like ?");
OR();
WHERE("P.LAST_NAME like ?");
GROUP_BY("P.ID");
HAVING("P.LAST_NAME like ?");
OR();
HAVING("P.FIRST_NAME like ?");
ORDER_BY("P.ID");
ORDER_BY("P.FULL_NAME");
return SQL();
}
private String selectPersonSql() {
BEGIN(); // Clears ThreadLocal variable
SELECT("P.ID, P.USERNAME, P.PASSWORD, P.FULL_NAME");
SELECT("P.LAST_NAME, P.CREATED_ON, P.UPDATED_ON");
FROM("PERSON P");
FROM("ACCOUNT A");
INNER_JOIN("DEPARTMENT D on D.ID = P.DEPARTMENT_ID");
INNER_JOIN("COMPANY C on D.COMPANY_ID = C.ID");
WHERE("P.ID = A.ID");
WHERE("P.FIRST_NAME like ?");
OR();
WHERE("P.LAST_NAME like ?");
GROUP_BY("P.ID");
HAVING("P.LAST_NAME like ?");
OR();
HAVING("P.FIRST_NAME like ?");
ORDER_BY("P.ID");
ORDER_BY("P.FULL_NAME");
return SQL();
}
Tuesday, September 1, 2009
Tuesday, August 11, 2009
Load Balance by using mod_jk + apache server2.0
1)Add following code to C:/Program Files/Apache Group/Apache2/conf/httpd.conf
# Include mod_jk configuration file
Include "C:/Program Files/Apache Group/Apache2/mod_jk/mod_jk.conf"
2)Create mod_jk.conf to C:/Program Files/Apache Group/Apache2/mod_jk/mod_jk.conf
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module "C:/Program Files/Apache Group/Apache2/mod_jk/mod_jk-1.2.28-httpd-2.0.52.so"
# Where to find workers.properties
JkWorkersFile "C:/Program Files/Apache Group/Apache2/mod_jk/workers.properties"
# Where to put jk logs
JkLogFile "C:\Program Files\Apache Group\Apache2\mod_jk/mod_jk.log"
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
#Mount your webapps eg WebApplication1 using JkMount
# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile /var/log/apache2/jk.shm
JkMount /* router
<Location /router/>
JkMount router
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
3) Create worker.properties on C:\Program Files\Apache Group\Apache2\mod_jk\worker.properties
# The advanced router LB worker
worker.list=router
# Define a worker using ajp13
worker.worker1.port=8009
worker.worker1.host=127.0.0.1
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
# Define preferred failover node for worker1
worker.worker1.redirect=worker2
# Define another worker using ajp13
worker.worker2.port=8009
worker.worker2.host=127.0.0.1
worker.worker2.type=ajp13
worker.worker2.lbfactor=1
# Disable worker2 for all requests except failover
worker.worker2.activation=disabled
# Define the LB worker
worker.router.type=lb
worker.router.balance_workers=worker1,worker2
4) Download iso mod_jk-1.2.28-httpd-2.0.52.so from http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/
to C:\Program Files\Apache Group\Apache2\mod_jk\
5) For sticky session
Edit tomcat's server.xml for all tomcat
Comment <!-- <Engine name="Catalina" defaultHost="localhost"> -->
Uncomment <Engine name="Standalone" defaultHost="localhost" jvmRoute="worker1">
References
Step by step - http://www.devside.net/guides/windows/tomcat
Help for worker.properties
http://tomcat.apache.org/connectors-doc/reference/workers.html
http://tomcat.apache.org/connectors-doc/generic_howto/loadbalancers.html
Subscribe to:
Posts (Atom)




