Monday, September 21, 2009

Lazy initilasation in Hibernate

Hibernate supports the feature of lazy initilasation for both entities and collections. What this actually means is, the Hibernate engine loads only those objects that we are querying for and doesnt try to fetch other entities(that are associated with the entity we are querying) or collections.

An attribute 'lazy' can be used to let Hibernate know if the associated entity or collection has to be lazily loaded or prefetched.


This causes the collection to be eagerly fetched rather than doing a lazy fetch. If on the other hand , the attribute value of lazy is set to true, then hibernate will not make an attempt to fire the query for fetching the collection object until the request is made by the user.

Wednesday, September 2, 2009

delete user from LDAP

public boolean deleteUser(LDAPConnection ld, String ou, String username) throws LDAPException {
String dn = String.valueOf(String.valueOf((new StringBuffer("uid=")).append(username).append(", ou=").append(ou).append(", o=").append(organization)));
ld.delete(dn);
System.out.println("Entry deleted");
return true;
}

Tuesday, September 1, 2009

Send sms using Gammu 1.18

1.install gammu
2.setup configuration file
3.add system path to gammu bin directory
4.open command prompt and type below code

c:\>gammu identify

then your phone details should be display otherwise gammu not configured

after that you can send massage using this

c:\>echo Test_Massage_body | gammu nothing --sendsms TEXT +94777123456

Gammu 1.18 Configuration file

[gammu]
port = com8:
;model = 6110
connection = irdaphonet
name=
model=
;synchronizetime = yes
;logfile = gammulog
;logformat = textall
;use_locking = yes
;gammuloc = locfile
;startinfo = yes
;gammucoding = utf8
;usephonedb = yes


I have working example for gammu 1.8 if you having any problem using gammu please contact me somehow I can help you

Java Mail

public boolean sendEMail(String from, String to, String cc, String bcc, String subject, String mail) {
boolean sucess = false;
Properties props = new Properties();
props.put("mail.smtp.host", "XXX.XXX.XXX.XXX");//SMTP Host
Session sessions = Session.getInstance(props, null);
sessions.setDebug(false);
Message msg = new MimeMessage(sessions);
try {
msg.setFrom(new InternetAddress(from));
msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(to, false));
msg.setRecipients(javax.mail.Message.RecipientType.CC, InternetAddress.parse(cc, false));
msg.setRecipients(javax.mail.Message.RecipientType.BCC, InternetAddress.parse(bcc, false));
msg.setSubject(subject);
MimeMultipart mp = new MimeMultipart();
mp.setSubType("related");
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(mail, "text/html");
mbp1.setHeader("X-Mailer", "Details");
MimeBodyPart mbp2 = new MimeBodyPart();
MimeBodyPart mbp3 = new MimeBodyPart();
mp.addBodyPart(mbp1);
msg.setContent(mp);
msg.setSentDate(new Date());
sucess = true;
}
catch (MessagingException e) {
e.printStackTrace();
sucess = false;
}
try {
Transport.send(msg);
sucess = true;
}
catch (MessagingException e) {
e.printStackTrace();
sucess = false;
}
return sucess;
}