Prepared Sun Certification Exam

Having prepared for two months, Sun Certification Exam for Business Component Developer, last for three days, 25 November, I will going to enter the exam location, in Landmark, Johor Bahru, Malaysia.

Holiday, now, next month started, will be my final year. Finally, I will begin my Final Project soon. However what topic to choose I have not any ideas yet in my mind. By pursuing final project in order to get honour degree, it is important for the topic. I wiil choose something suit my interest (sure), and able to be confident (really sure) to complete. Still I confused something for example what platform should my development to use, and other problems. Largely percentage I would using web to show my project.

Do not know can it be, I have one idea, I would like to develop something on Cloud Computing Service, such as Google Appengine, something that would be the most thing required by public, or building new concept?

After this exam, I will take my time to study some past year final project, and think about it! I will read some latest technical news to learn more.

Doing orm.xml Joincolumn and Cascade

When doing orm.xml, I found that the order of Joincolumn and Cascade should be in order, otherwise it will encountered some problem.

Here is my definition of some classes, Customer and CreditCard.

package com.titan.domain;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name=”CUSTOMER_TABLE”)
public class Customer implements java.io.Serializable {
    private int id;
    private String firstName;
    private String lastName;
    private Address address;
    private CreditCard creditCard;
    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    @OneToOne(cascade={CascadeType.ALL})
    @JoinColumn(name=”ADDRESS_ID”)
    public Address getAddress() {
        return address;
    }
    public void setAddress(Address address) {
        this.address = address;
    }
    @OneToOne(cascade={CascadeType.ALL})
    @JoinColumn(name=”CREDIT_CARD_ID”)
    public CreditCard getCreditCard() {
        return creditCard;
    }
    public void setCreditCard(CreditCard creditCard) {
        this.creditCard = creditCard;
    }
}

 

package com.titan.domain;

import java.util.Date;

import javax.persistence.Id;
import javax.persistence.OneToOne;

public class CreditCard implements java.io.Serializable {

    private int id;
    private Date expiration;
    private String number;
    private String name;
    private String organization;
    private Customer customer;
    @Id
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public Date getExpiration() {
        return expiration;
    }
    public void setExpiration(Date expiration) {
        this.expiration = expiration;
    }
    public String getNumber() {
        return number;
    }
    public void setNumber(String number) {
        this.number = number;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getOrganization() {
        return organization;
    }
    public void setOrganization(String organization) {
        this.organization = organization;
    }
    @OneToOne(mappedBy=”creditCard”)
    public Customer getCustomer() {
        return customer;
    }
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }
}

 

Here is my orm.xml, placed below META-INF

<entity-mappings   
   xmlns=”http://java.sun.com/xml/ns/persistence/orm”
   xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
   xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd” 
   version=”1.0″> 
<entity class=”com.titan.domain.Customer” access=”PROPERTY”>
      <attributes>
         <id name=”id”>
            <generated-value/>
         </id>
      <one-to-one name=”creditCard”
                     target-entity=”com.titan.domain.CreditCard”
                     fetch=”LAZY”>
            <join-column name=”CREDIT_CARD_ID”/>
            <cascade>
                <cascade-all />
            </cascade>
         </one-to-one>
      </attributes>
   </entity>
   <entity class=”com.titan.domain.CreditCard” access=”PROPERTY”>
      <attributes>
         <id name=”id”>
            <generated-value/>
         </id>
      <one-to-one name=”customer”
                     target-entity=”com.titan.domain.Customer”
                     mapped-by=”creditCard”/>
      </attributes>
   </entity>

</entity-mappings> 

 

To note that, cascade element should be below of join-column element, and inside cascade element it contains cascade-all, cascade-persist, cascade-merge, cascade-remove, cascade-refresh

Reference Site: http://markmail.org/message/73xeygrwcslyekwn

考试前的生活(回Joe)

回复:http://joeblueland.blogspot.com/2009/10/blog-post.html

你的考试前的生活看来蛮丰富的,而我现在也是等待大考,我的大考在下个星期五,最后一天。现在感觉有点轻松,也不算轻松,就多一点时间来做其他的事情。我的考试只有一天,不像你连续考一堆考试,哈哈。加油考试吧!

Completed Project, Preparing Test

For the project week I have completed for IS215, and for the project part completed for CS230, but wait for its test, and presentation. And now I have a lot of time to study the Sun Certification for Business Component Developer, and preparing for the CS230 final exam on next Friday. After that, it is holiday. After holiday, continue preparing Sun Exam until the end of November and will be relax later.

Doing Persistence under JBOSS

Just learnt EJB for half month. Just learnt how to create Entity class. When deploys, JBOSS always give me error. Now I found a solution, The problem is sometimes persistence.xml lost the XML Schema, the full persistence.xml can be like this:

<?xml version=”1.0″ encoding=”UTF-8″?>

<persistence
    xmlns=”http://java.sun.com/xml/ns/persistence”
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
    xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd”
    version=”1.0″>
    <persistence-unit name=”calculator”>
    <jta-data-source>java:/DefaultDS</jta-data-source>
    <properties>
        <property name=”hibernate.hbm2ddl.auto” value=”create-drop” />
    </properties>
    </persistence-unit>
</persistence>

Hope anyone who faced this problem can solve your problem.

SNS coding Tip in ASP.NET

During my university small project doing Internet Technology, having opportunities doing Social Networking Service Website with using ASP.NET. I have done some coding that might help you and me. The coding below will accomplish some tasks, such as getting list of friend, list of friend of friend, and getting friendly times string.

List of Friend

First of all, we need a Friend Table and User Table, I have created like this

  1. create table Users (
  2. uid int constraint ctUser_pk primary key(uid) identity,
  3. username char(100) not null default ”,
  4. password char(32) not null default ”,
  5. gender int default ‘0’,
  6. email char(100) default ”,
  7. address char(255) default ”,
  8. avatar char(255) default ”
  9. );
  10. create table Friend (
  11. uid int not null,
  12. fuid int not null,
  13. fusername char(30) not null,
  14. status int,
  15. dateline datetime
  16. );

Then I have created a Friend Class with the method implementation below/

  1. public DataTable getFriendList(int uid, int limit)
  2.     {
  3.         SqlConnection sqlConn = Util.openDB();
  4.         SqlCommand sqlCommand = new SqlCommand(“Select Top(@limit) f.*,u.* From Friend f Left Join Users u On u.Uid = f.Uid Where f.uid = @uid”, sqlConn);
  5.         sqlCommand.Parameters.Add(“uid”, uid);
  6.         sqlCommand.Parameters.Add(“limit”, limit);
  7.         SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCommand);
  8.         DataTable dt = new DataTable();
  9.         sqlAdapter.Fill(dt);
  10.         Util.closeDB();
  11.         return dt;
  12.     }

List of Friend of Friend

Method implementation of getting friend of friend:

  1. public DataTable gerFriendOfFriend(int uid, int limit)
      {
  2.         SqlConnection sqlConn = Util.openDB();
  3.         SqlCommand sqlCommand = new SqlCommand(“select  distinct Top(@limit) f.fuid, f.fusername, u.avatar from friend f left join users u on u.uid = f.fuid where f.uid in (select fuid from friend where uid = @uid) and f.fuid != @uid”, sqlConn);
  4.         sqlCommand.Parameters.Add(“uid”, uid);
  5.         sqlCommand.Parameters.Add(“limit”, limit);
  6.         SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCommand);
  7.         DataTable dt = new DataTable();
  8.         sqlAdapter.Fill(dt);
  9.         Util.closeDB();
  10.         return dt;
  11.     }

Friendly Time String

I have created another class called Util. The method implementation of getting friendly time string as below:

  1. public static string gmtime(DateTime t)
      {
  2.         string timeString = “”;
  3.         // show x seconds ago, 1-59 minutes 1-23 hours 1-7 days ago, otherwise original
  4.         DateTime now = DateTime.Now;
  5.         // convert into 1970 time format (this called unix timestamp)
  6.         long nowtime = Util.ConvertToTimestamp(now);
  7.         long time = Util.ConvertToTimestamp(t);
  8.         long diff = nowtime – time;
  9.         if (diff < 0)
  10.         {
  11.             timeString = “Invalid Time”;
  12.         }
  13.         else if (diff < 60)
  14.         {
  15.             timeString = diff + ” seconds ago”;
  16.         }
  17.         else if (diff < 3600)
  18.         {
  19.             decimal minute = Math.Round((decimal) diff / 60, 0);
  20.             timeString = minute + ” minutes ago”;
  21.         }
  22.         else if (diff < 86400)
  23.         {
  24.             decimal hour = Math.Round((decimal) diff / 60 / 60, 0);
  25.             timeString = hour + ” hours ago”;
  26.         }
  27.         else if (diff < 604800) // 7 days before
  28.         {
  29.             decimal day = Math.Round((decimal) diff / 60 / 60 / 24, 0);
  30.             timeString = day + ” days ago”;
  31.         }
  32.         else
  33.         {
  34.             timeString = t.ToString(); // show original after 7 days
  35.         }
  36.         return timeString;
  37.     }
  38.     // reference: http://www.dreamincode.net/code/snippet2094.htm
  39.     // convert datetime to unix timestamp
  40.     public static long ConvertToTimestamp(DateTime value)
  41.     {
  42.         //create Timespan by subtracting the value provided from
  43.         //the Unix Epoch
  44.         TimeSpan span = (value – new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
  45.         //return the total seconds (which is a UNIX timestamp)
  46.         return (long)span.TotalSeconds;
  47.     }

Academic Award

If not my friend mention, I already forgot today got academic award ceremony held in MPH. Since last time I got the letter from one lecturer talked me that I got this award but I already decided to not going attend at all. For some reason, first, I not like going. Second, I think that is nothing special for me, maybe this is only small achievement. Third, my family need not specially drive up to Inti Nilai. Year 2 become harder and harder beyond my knowledge, what can I do is trying to continue study well to repay my family, that is enough. I should take the final year graduation ceremony to be my only one opportunities to go up to the stage to accept the award.

Now I am going to prepare my third Sun Certification Exam, Business Component Developer. This is a same level with the previous web component developer one, but with a new topic, and technically back-end and harder than previous one. A lot of concept involved inside. Having no previous knowledge will be harder. Need a lot of effort to understand some concept.

Now I also need to rush many projects, all projects involve using ASP.NET to develop the website. I am first time learn ASP.NET this semester, and personally learn myself. Maybe I got PHP and JSP experience, when I first touched ASP.NET, I not feel that it is a new monster in front of me. But I think ASP.NET is great. The ASP.NET framework provided developer a new broad sense of concept, convenience way to construct the web application. Powerful I can say. JSP one now having JSF (Java Server Faces), heard that it similar to ASP.NET event driven model concept however I not tried before but I saw some books regarding JSF. In JSF, some concept will different. But the last time I saw that book, based on my first view and not very cleared and detailed view, I thought that ASP.NET will be better than JSF. Take example for their event-driven model. You just put your ASP.NET button code like this: <asp:button ID=”button1″ onclick=”button1_onclick” /> in your code-behind part you can just call button1 to do your own work. You not need explicitly defined that. But in JSF, you need explicitly define that you are using button1 and it is bind to button1_onclick in other aspect. Since I have forgotten something I not going to talk again. But I will continue to learn JSF later to see their difference I choose the best one for me.

Thanks sincerely,
fyhao

9月中的某个日记

好久没到这里发表任何文字了。最近都在忙着做功课还有写程序的。最近,精神好像也不大好,熬夜是熬夜,一直想睡觉,很多东西都被我拖延了。一个简单的段落我可以花超过1个小时才来完成,在时间管理上,我要加倍努力了啦。

现在东西能不能做的好,就是体现在时间管理上,还有精神管理,有精神才是比较重要的。清心精神最近都很累的样子。我觉得我今天,严格来说,9月17日早上起来就要严格遵守清心精神,给我一天下来一个规划,去遵守这个规划,完成我今天要做的东西。

好的,今天我要做的事情有:

  • Internet Technology Assignment 至少写完 database support 然后做一点 performance 或者 security features。。。尽量

今天我也跟了 vampcheah 聊天,开始只是想问他一些PHP framework使用的问题,以为他是一个大忙人,但是他很好,算是从大忙的生活解脱出来跟我聊了很多,也跟我分享了很多人生经验的问题。给我的感觉是,他有着与常人非凡的想法,可以从另外一个角度来看一个东西,拥有批判的精神且不受任何风吹影响而有自己独立的看法。希望可以继续和他交流。

写完到这里了,等下我就会看看新闻及一些文章吧,功课暂时停在这里。