Tuesday, May 5, 2009
Tuesday, April 28, 2009
DAO Links
p4j very useful link
DataAccessObject
The DataAccessObject is the primary object of this pattern. The DataAccessObject abstracts the underlying data access implementation for the BusinessObject to enable transparent access to the data source. The BusinessObject also delegates data load and store operations to the DataAccessObject.
DataSource
This represents a data source implementation. A data source could be a database such as an RDBMS, OODBMS, XML repository, flat file system, and so forth. A data source can also be another system (legacy/mainframe), service (B2B service or credit card bureau), or some kind of repository (LDAP).
TransferObject
This represents a Transfer Object used as a data carrier. The DataAccessObject may use a Transfer Object to return data to the client. The DataAccessObject may also receive the data from the client in a Transfer Object to update the data in the data source.
Here we go for some useful links....
Issues in calling DAO from Sateless session bean
Core J2EE Patterns - Session Facade
Don't repeat the DAO!
jpa-ejb killed daoJPA/EJB3 killed the DAO
Regarding to the abstract of the DAO-Pattern: "Access to data varies depending on the source of the data. Access to persistent storage, such as to a database, varies greatly depending on the type of storage (relational databases, object-oriented databases, flat files, and so forth) and the vendor implementation." the DAO tries to decouple the business logic from the proprietary resource. The solution to the problem is the following: "...The DataAccessObject is the primary object of this pattern. The DataAccessObject abstracts the underlying data access implementation for the BusinessObject to enable transparent access to the data source. The BusinessObject also delegates data load and store operations to the DataAccessObject..." [Core J2EE Patterns].
In the practise the DAO-Pattern was often realized by the following items:
- DAO-Interface (provided a datasource-neutral interface)
- DAO-Implementation (=access to the datasource implementation)
- DAO-Factory (the creation of the implementation)
- Optional: ServiceLocator (location of resources in JNDI)
In EJB 3/Java EE 5 environment there is no need to use the low level JDBC to access the database any more. Actually you can use generic, but powerful Query Lanaguae, as well as Native SQL to fetch not only the persistent objects, but also data transfer objects and even primitive data types as well. It is even possible to execute update and delete statements. The JPA comes already with the EntityManager which provides already generic data access functionality. The usage cannot be simpler. The EntityManager will be just injected to the bean-class:
@Stateless
public class CustomerMgrBean implements CustomerMgr{
@PersistenceContext
private EntityManager em;
It's just one liner. The DAO pattern is actually no more interesting for general data access, but is still needed to access data from stored procedures, flat files etc. However the bean above can be considered as a "DAO", but very streamlined one...
You will find some examples in p4j5 - feel free to participate.
Faking css position: fixed in Internet Explorer 6
Try at last
Another How to fix div position using javascript in IE 6.0
This is a trick that I have been doing for some time, but now that Internet Explorer 7 is out and it supports position fixed in css; I think this trick will been even more useful now that it will allow web developers to take better advantage of css and at the same time not leave out the Internet Explorer 6 user base. I am posting this here because I sent this to a friend a couple days ago and thought others might be able to use it as well.
The trick is really quite basic. For simplicity I am just putting this example inline, but you can put it where you want.
First your declare your intended style for IE7 (and basically every other browser):
<style type="text/css">
#fixed_div {
position: fixed;
top: 0px; /* tweak this according to placement */
left: 0px; /* tweak this according to placement */
/* add additional styling, etc. */
}
</style>
Second add in your Javascript function which is going to be doing your movement for IE6:
<script type="text/javascript">
function move_box() {
var offset = 0; // set offset (likely equal to your css top)
var element = document.getElementById('fixed_div');
element.style.top = (document.documentElement.scrollTop + offset) + 'px';
}
</script>
Then declare the element itself:
<div id="fixed_div">I am fixed, even in IE6</div>
Lastly, implement your fix for IE6 only:
<!--[if lt IE 7]>
<style type="text/css">
#fixed_div {
position: absolute;
top: 0px; /* tweak this according to placement */
left: 0px; /* tweak this according to placement */
}
</style>
<script type="text/javascript">
window.setInterval(move_box, 100);
</script>
<![endif]-->
I usually put this last part right before the end of the body (I guess you could just put the whole script there). This is because you don't want the window.setInterval to fire before your fixed div is declared. You could use the body onload but I try to stay away from that because I know it is popular for other uses on more advanced pages and I don't want to run the risk of interfering.
Here is the whole script put together:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
. . .
<style type="text/css">
#fixed_div {
position: fixed;
top: 0px; /* tweak this according to placement */
left: 0px; /* tweak this according to placement */
/* add additional styling, etc. */
}
</style>
<script type="text/javascript">
function move_box() {
var offset = 0; // set offset (likely equal to your css top)
var element = document.getElementById('fixed_div');
element.style.top = (document.documentElement.scrollTop + offset) + 'px';
}
</script>
. . .
</head>
<body>
. . .
<div id="fixed_div">I am fixed, even in IE6</div>
. . .
<!--[if lt IE 7]>
<style type="text/css">
#fixed_div {
position: absolute;
top: 0px; /* tweak this according to placement */
left: 0px; /* tweak this according to placement */
}
</style>
<script type="text/javascript">
window.setInterval(move_box, 100);
</script>
<![endif]-->
</body>
</html>
NOTE: This will only work properly on pages that have a valid doctype definition. If you don't use one [you should start or] you need to change document.documentElement.scrollTop to document.body.scrollTop in the move_box function.
You can also modify this script to apply to multiple elements by passing arguments to the function or something similar. If you are doing multiple elements on a single page, you may want to consider setting up some kind of Javascript array that tracks what elements need to be corrected, this could save you from having multiple window.setInterval instances running.
http://www.finefrog.com/_code/59.htmlhttp://www.howtocreate.co.uk/fixedPosition.html
Friday, April 24, 2009
Wednesday, April 22, 2009
Fluid Layout Template - Fixed Buttons Div
Reference : http://www.howtocreate.co.uk/fixedPosition.html
http://en.allexperts.com/q/Javascript-1520/position-fixed.htm
http://www.jtricks.com/javascript/navigation/fixed_menu.html
Put in head tag:
Within body tag:
Friday, April 17, 2009
Send mail using javamail and gmail
This is my fully tested code. You need javamail 1.4 api to run this. If u find any kind of exception check ur system firewall that is blocking to send mail.
Add mail.jar and activation.jar in ur buildpath and run the code:
import java.io.File;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class SimpleSSLMail {
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final int SMTP_HOST_PORT = 465;
private static final String SMTP_AUTH_USER = "xxxxx@gmail.com";
private static final String SMTP_AUTH_PWD = "xxxx";
public static void main(String[] args) throws Exception{
new SimpleSSLMail().test();
}
public void test() throws Exception{
Properties props = new Properties();
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.host", SMTP_HOST_NAME);
props.put("mail.smtps.auth", "true");
// props.put("mail.smtps.quitwait", "false");
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("Hello Attatched world");
//message.setContent("This is a test", "text/plain");
// content
MimeBodyPart mimeBodyPart = new MimeBodyPart();
//mimeBodyPart.setText("Link goes here:");
String strLink = " Link goes here : http://www.google.com";
mimeBodyPart.setText(strLink);
// multipart is the main content holder
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);
// Part two is attachment
File f = new File("F:\\angel.JPG");
if(f.exists() && f.isFile())
{
System.out.println("attatching file......."+f.getName());
mimeBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(f);
DataHandler handler = new DataHandler(source);
mimeBodyPart.setDataHandler(handler);
mimeBodyPart.setFileName(f.getName());
multipart.addBodyPart(mimeBodyPart);
}
// add multipart data to message
message.setContent(multipart);
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("xxxx@yahoo.com"));
transport.connect
(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}
}