littlecowk35 / eic-quan-ly-cong-van

Automatically exported from code.google.com/p/eic-quan-ly-cong-van
0 stars 0 forks source link

How to use p6spy to show the real SQL statement in Liferay #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The real statement is the SQL which is fulled the parameters value

Original issue reported on code.google.com by ntanh...@gmail.com on 22 Jan 2015 at 9:08

GoogleCodeExporter commented 9 years ago
1. Copy p6spy.jar and spy.propertioes to folder tomcat-7.0.42/lib/ext
2. Add this value to:tomcat-7.0.42/bin/setenv.sh
JAVA_OPTS="$JAVA_OPTS 
-Dp6.home=/opt/liferay-qlcv/liferay-9080/tomcat-7.0.42/lib/ext 
-Dfile.encoding=UTF8"
3. Set these value in file spy.properties:
realdriver=oracle.jdbc.driver.OracleDriver
logfile     = /opt/liferay-qlcv/liferay-9080/tomcat-7.0.42/lib/ext/spy.log

4. Change the driver class by modify this 
file:tomcat-7.0.42/webapps/ROOT/WEB-INF/classes/portal-ext.properties
jdbc.default.driverClassName=com.p6spy.engine.spy.P6SpyDriver
jdbc.default.username=htqlcv1
jdbc.default.url=jdbc:oracle:thin:@localhost:1521:xe

Original comment by ntanh...@gmail.com on 22 Jan 2015 at 9:12

GoogleCodeExporter commented 9 years ago
 Liferay sử dụng hibernate, do vậy  việc tích hợp p6spy là khá tương đồng. 

1. download file p6spy-install.jar từ http://sourceforge.net/projects/p6spy/
--> thực hiện giải nén và lấy hai file : p6spy.jar và spy.properties 
sử dụng lastest version  1.3 ( modified 2003-12-01)

2. copy p6spy.jar  vào thư mục lib của server,
ví dụ với tomcat  tôi copy vào : 
liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\lib\ext
Note : trong thư mục giải nén có chứa cả guide --> có thể tham 
khảo cho các server khác nhau.

3. Đưa file spy.properties vào ClassPath.
file spy.properties chứa các thông tin cấu hình cho p6spy. để p6spy 
có thể đọc được thì ta cần đưa nó vào classpath. 
ta có hai cách: 
-- các đơn gian là đặt nó vào root folder của project: với liferay 
tôi copy nó vào 
:\liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\webapps\ROOT\WEB-INF\classes
==> nó được load tương tự các file portal-*.properties  hay 
service-*.properties.
-- các hai là thiết lập   -Dp6.home   vào JAVA_OPTS  để chỉ ra 
folder chứa file spy.properties. 
ví dụ với tomcat trên window  --> tìm vào thêm dòng in đậm với 
đường dẫn thích hợp trên máy của bạn 
  .....\liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\bin\setenv.bat

set "JAVA_OPTS=%JAVA_OPTS%  
-Dp6.home=D:/apps/liferay/liferay-portal-tomcat-6.1/liferay-portal-6.1.1-ce-ga2/
tomcat-7.0.27/lib/ext 
 -Dfile.encoding=UTF8 -Djava.net.preferIPv4Stack=true -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m"

4. edit spy.properties 
- Có một property bắt buộc cần edit đó là : realdriver  --> tương 
ứng với driver của db bạn đang connect tới
ví dụ  với MYSQL: 
# mysql Connector/J driver
 realdriver=com.mysql.jdbc.Driver
- thuộc tính thứ hai cần lưu ý  là  chỉ ra vị trí của  file log
ví dụ  : 
logfile     = 
D:/apps/liferay/liferay-portal-tomcat-6.1/liferay-portal-6.1.1-ce-ga2/tomcat-7.0
.27/logs/spy.log

-  thuộc tính khác là : log4j.logger.p6spy  chỉ ra Level được log 
ví dụ log4j.logger.p6spy=INFO,STDOUT

5. Cầu hình JDBC trong portal-ext.properties với driver class là 
P6SpyDriver class của p6spy.

    jdbc.default.driverClassName=com.p6spy.engine.spy.P6SpyDriver
    jdbc.default.username=root
    jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false

    #
    # Set other miscellaneous Hibernate properties.
    #
    hibernate.show_sql=true

final : Run server và tay sẽ thấy file  spy.log tương ứng ở vị 
trí đã config khi thực hiện các query thì chúng sẽ được log 
tại đây. Điều chính Log Level cho phù hợp với mục địch.

Lưu ý : việc tích hợp p6spy giảm thiểu tối đa thời gian cho 
việc debug, và sử dụng nó trong môi develop, khi ứng dụng được 
triển khai trên môi trường product thì cần loại bỏ  p6spy.

Original comment by ntanh...@gmail.com on 22 Jan 2015 at 9:12

GoogleCodeExporter commented 9 years ago
http://loilog.blogspot.com/2013/04/p6spy-log-sql-statements-along-with.html
http://scalsys-liferay.blogspot.com/2012/12/p6spy-installation-in-liferay-1-edit
.html
http://www.mkyong.com/hibernate/how-to-display-hibernate-sql-parameter-values-so
lution/

Original comment by ntanh...@gmail.com on 22 Jan 2015 at 9:13

GoogleCodeExporter commented 9 years ago
http://www.liferay.com/web/miguel.pastor/blog/-/blogs/10243286

Original comment by ntanh...@gmail.com on 22 Jan 2015 at 9:13