Wednesday, May 26, 2010

Hibernate call store procedure

Hibernate call store procedure

In Hibernate, there are three approaches to call a database store procedure.

1. Native SQL – createSQLQuery

You can use createSQLQuery() to call a store procedure directly.
Query query = session.createSQLQuery(
 "CALL GetStocks(:stockCode)")
 .addEntity(Stock.class)
 .setParameter("stockCode", "7277");
 
List result = query.list();
for(int i=0; i<result.size(); i++){
 Stock stock = (Stock)result.get(i);
 System.out.println(stock.getStockCode());
}

2. NamedNativeQuery in annotation

Declare your store procedure inside the @NamedNativeQueries annotation.
//Stock.java
...
@NamedNativeQueries({
 @NamedNativeQuery(
 name = "callStockStoreProcedure",
 query = "CALL GetStocks(:stockCode)",
 resultClass = Stock.class
 )
})
@Entity
@Table(name = "stock")
public class Stock implements java.io.Serializable {
...
Call it with getNamedQuery().
Query query = session.getNamedQuery("callStockStoreProcedure")
 .setParameter("stockCode", "7277");
List result = query.list();
for(int i=0; i<result.size(); i++){
 Stock stock = (Stock)result.get(i);
 System.out.println(stock.getStockCode());
}

3. sql-query in XML mapping file

Declare your store procedure inside the “sql-query” tag.

...
>
     name="com.mkyong.common.Stock" table="stock" ...>
         name="stockId" type="java.lang.Integer">
             name="STOCK_ID" />
            <generator class="identity" />
        >
         name="stockCode" type="string">
             name="STOCK_CODE" length="10" not-null="true" unique="true" />
        >
        ...
    >
 
     name="callStockStoreProcedure">
  alias="stock" class="com.mkyong.common.Stock"/>
 
    >
 
>
Call it with getNamedQuery().
Query query = session.getNamedQuery("callStockStoreProcedure")
 .setParameter("stockCode", "7277");
List result = query.list();
for(int i=0; i<result.size(); i++){
 Stock stock = (Stock)result.get(i);
 System.out.println(stock.getStockCode());
}

Conclusion

The above three approaches are doing the same thing, call a store procedure in database. There are not much big different between the three approaches, which method you choose is depend on your personal prefer.

Monday, May 24, 2010

Hibernate ant link

http://www.redhat.com/docs/en-US/JBoss_Developer_Studio/en/hibernatetools/html/ant.html

Sunday, April 11, 2010

Apache test config syntax

/usr/sbin/apache2ctl -t
add +Includes for directory required SSI

CSS

http://www.alistapart.com/

http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/

Wednesday, April 7, 2010

date 31 for setDate javascript

Date.setDate(day) day:1-31
When use setDate, setMonth and setYear in javascript.
Must be in order setYear, setMonth, setDate
 otherwise setDate(31) will create wrong date

actually not like this, always do a hack setDate first with hard code value is one

echo "dspStartDate.setDate(1);\n";
echo "dspStartDate.setFullYear(" . date("Y", $startstamp) . ");\n";
echo "dspStartDate.setMonth(" . (date("m", $startstamp) - 1) . ");\n";

//down here the the date that you would like to set

echo "dspStartDate.setDate(" . date("d", $startstamp) . ");\n";

Wednesday, March 17, 2010

Monday, March 15, 2010

Checkbox value not changes when submit form to server

Checkboxes

The status of a checkbox is reflected in the boolean attribute .checked:

var ischecked = obj.checked;  // Retrieve value
obj.checked = true; // Force checked state

When the form is submitted to the web server, the .checked attribute is sent when the checkbox is in the checked state, and it isn't sent when the checkbox is in the unchecked state. You can retrieve or change this value with the .value attribute, as with text fields.

An onclick event is triggered when the checkbox is clicked. If your event handler returns false, the state of the checkbox will not change on Internet Explorer or Mozilla (and other Gecko-based browsers). On Safari, however, the event handler's return value is ignored.

E2C
http://depfind.sourceforge.net/

Thursday, March 11, 2010

What to Do with "The requested operation requires elevation" in Vista

What to Do with "The requested operation requires elevation" in Vista

Somehow you get the prompt The requested operation requires elevation sometimes when you try to execute some Windows network programs or run some network commands in command prompt, and you might wonder what is this and not too sure what to do next.

This is actually part of the User Account Control (UAC) feature of Windows Vista that controls the program execution as normal user, administrator or other user types with different access control. You will get this prompt because that program will need to be run as administrator, so the quick way to fix it is re-run by right clicking the program and select Run as administrator.

Run-as-Administrator

This alert message will come out sometimes even you run that program with administrator user id, this is because the Vista won’t tell you sometimes when that program needs to be run as administrator.


DISABLE UAC feature

If you don’t like this UAC feature, you can actually disable it, you can follow the following ways to disable it. For a better security, next time only log on as normal user to do routine works and use administrator access if you need to run Windows operation or program with admin privilege.

1) Go to Start -> Control Panel, then click on User Accounts and Family Safety.

User Accounts and Family Safety

2) After that click on User Accounts.

User Accounts

3) Click Turn User Account Control on or off in User Accounts window.

Note: If you are using Control Panel in classic view mode, you can come to this page by going to Start ->Control Panel -> User Accounts.

Turn User Account Control On or Off

4) Uncheck Use User Account Control (UAC) to help protect your computer and click OK at last.

Note: You need to to restart the computer in order to disable the UAC feature successfully.

Use User Account Control UAC

Monday, March 8, 2010

Smart Client Lib for GWT

www.smartclient.com

http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html

http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html

Wednesday, February 17, 2010

Search Engine Friendly URL

Search Engine Friendly urls


This tutorial will guide you through setting up the SEF - Search Engine Friendly Urls for the latest version of Joomla 1.5

By default Joomla will produce URLs which look like this

Joomla Search engine friendly url

As you can see the default URL includes the PHP sting, component name plus a number of parameters which don't look to good to search engines or your visitors.

Enabling the SEF functionality built into Joomla! offers the following advantages

  • It will make it easier for other web sites to link directly to the SEF article rather than to the default URL generated by Joomla!
  • Visitors are more likely to remember the short easy to read SEF URL
  • Provides the visitor and search engines with useful information about the article title and the section, category the article is associated with.
  • You can include targeted keywords in the URL which reference the section, category and article title which may help improve your search engine position
  • Can resolve the issue where your template is displayed on the front page but not on other pages

The above are just some of the benifits of using SEF Urls.

We will now explain how you can setup your Joomla! site to use this functionality.

What will you need to setup the search engine friendly urls

  • Access to the Joomla Administrator area
  • FTP Access to rename and update the htaccess.txt file included with the default installation of Joomla!
  • Your web site is hosted on a Linix platform, this tutorial does not cover setting up SEF urls for IIS

Step 1 : Rename Htaccess.txt file

The first step is to rename the htaccess.txt file located in the root of the public_html directory where you have installed Joomla!. To do this log into the web site using your FTP client and rename the htaccess.txt file to .htaccess

Please note you must add the dot . before the htaccess file when renaming it from htaccess.txt to .htaccess

Step 2 : Configuration.php file permissions

In order to change the SEO settings you will need to ensure the Joomla! configuration.php file is writable.

To make the configuration.php file writable complete the following

  1. Log into the web site using your FTP client and browse to the Joomla installation
  2. Select the configuration.php file and change the file permissions from CHMOD 644 to CHMOD 777
After you have updated the SEO settings ALWAYS change the file permissions for the configuration.php file back to CHMOD 644

STEP 3 : Setup Joomla SEO settings

  1. Log into the Joomla! administrator area
  2. Select the Global Configuration icon
  3. You will now see the following SEO setting
  4. To save the SEO settings select the APPLY button

4. Each setting you select from the above will produce a different result.

5. If you enable the " Search Engine Friendly URLs" option

6. The URL will look like this and include the .index.php name in the URL

7. Using the above method may break the template layout "your design displays ok on the front page but not on other pages"

8 . If you enable both the "search engine friendly URLs" plus "Use Apache mod_rewrite"

9. The URL will look like this and produce a clean easy to read URL.

10. If you enable all 3 of the above settings

11. The URL will display a .html suffix

If you want search engine and human freindly URLs we recommend you choose both the "search engine friendly URLs" plus "Use Apache mod_rewrite" seo options.

From http://www.joomladesigns.co.uk/Tutorials/Joomla/Search-Engine-Friendly-urls.html

Store Procedure and Function

The main different between store procedure and function is that
- Function can return only one value and must return a value
- Store procedure can have many IN or OUT parameters and no return value
- Function can be called in a select statement but store procedure can not be called in a select, it must be executed by 'call storeprocedure name'
Example
create function AddA(p_inparam varchar(30)) returns varchar(30)
return concat('A',p_inparam);

mysql> select AddA(emp_name) from emps;
+----------------+
| AddA(emp_name) |
+----------------+
| ARoger |
| AJohn |
| AAlan |
+----------------+
3 rows in set (0.26 sec)

create procedure AddB(INOUT p_inparam varchar(30))
set p_inparam := concat('B',p_inparam);

mysql> select AddB(emp_name) from emps;
ERROR 1305 (42000): FUNCTION pers.AddB does not exist

mysql> select call AddB(emp_name) from emps;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'call AddB(emp_name) from emps' at line 1

Thursday, January 21, 2010

  • R = runnable
  • S = sleeping
  • D = uninterruptible sleep
  • T = stopped or traced
  • Z = zombie process
  • Second field = W if the process has no resident pages.
  • Third field = N if the process has a positive nice value

How to enable or clean cache in Joomla 1.5?

Enabling cache will increase the overall performance of your Joomla application.

You can enable caching from your Joomla admin area > Site > Global Configuration > System.

At the right side of the System page, under Cache Settings, next to Cache you should select Yes. Then click Save at the top right menu to enable caching for your Joomla :)


Sometimes, when you have made a change in your Joomla application and it does not appear on the front end, the only solution is cleaning the cache.

You can clean your Joomla 1.5 cache from the admin area > Tools > Clean Cache.



Apache, by default, is set up for worker processes to exit after handling a limited number of requests. This is designed to not allow memory leaks to get out of hand.

Usually, the main Apache process will reap any of its workers that exit. However, on a heavily-loaded server like you describe, the main process may not have enough time available to it to do this reaping. Unreaped (“zombie”) processes show up as in top. In this case, the processes are normal and are not of concern, unless there are many, many unreaped processes.

However, an alternative possibility is that your worker processes are dying abnormally. This can happen if your web application (or its engine) has a bug which causes the worker process to crash. You should look in your Apache error log to see if there are any serious error messages in it.

The below explains what means. If you aren't a Unix system administrator, this may not be of interest to you.

Normally, when a process exits (normally or abnormally), it enters a state known as “zombie” (which in top appears as Z). Its process ID stays in the process table until its parent waits on (or “reaps”) it. Under normal circumstances, when the parent process fully expects its child processes to exit, it sets up a signal handler for SIGCHLD so that, when the signal is sent (upon a child process's exit), the parent process then reaps it at its convenience.

If the parent process has hung for some reason, such as if it's suspended, or is too busy, or is deadlocked, then child processes that exit will not be reaped (until the parent process resumes again). This can cause serious problems if there are many child processes, occupying slots in the process table that will not be freed.

In that case, one solution (if the parent process is unrecoverable, say), is to kill the parent process. Then, the child processes will be reparented to the init process (process ID 1), which will reap them. (If the init process is stalled, then you have much, much bigger problems than child processes not being reaped. In fact, a crashed init process will usually cause a kernel panic.)