Friday, October 31, 2014

Encription App

 



String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int key;
        public Form1()
        {
            InitializeComponent();
        }

        private void InverseA(int a)
        {

            for (int i = 0; i < 26; i++)
            {
                if ((a * i) % 26 == 1)
                {
                    key = i;
                    break;
                }
            }
        }

        private String indexToChar(int index)
        {

            String indexToC = alphabet[index].ToString();
            return indexToC;
        }

        private int charToIndex(String character)
        {
            int cToindex = alphabet.IndexOf(character);
            return cToindex;
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            String plain = txtOrigin.Text;
            String encrypt = "";
            for (int i = 0; i < plain.Length; i++)
            {
                encrypt += indexToChar(Encrypt(charToIndex(plain[i].ToString())));
            }
            txtEncrypt1.Text = encrypt;
        }

        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            InverseA(Convert.ToInt32(txtDKey.Text));
            String encrypted = txtEncrypt2.Text;
            String decypted = "";
            for (int i = 0; i < encrypted.Length; i++)
            {
                decypted += indexToChar(Decrypt(charToIndex(encrypted[i].ToString())));
            }
            txtDecrypt.Text = decypted;
        }

        private int Decrypt(int value)
        {
            int upper = key * (value - 3);
            int decrypt;
            if (upper < 0)
            {
                if (upper < -26)
                    upper = 26 + upper;
                decrypt = -26 % 26 + (26 + upper) % 26;
            }else{
                decrypt = (key * (value - 3)) % 26;
            }
            return decrypt;
        }

        private int Encrypt(int value)
        {
            int encrypt = (Convert.ToInt32(txtEKey.Text) * value + 3) % 26;
            return encrypt;
        }

currency converter

Event
        private void button1_Click(object sender, EventArgs e)
        {
            ServiceReference.CurrencyConvertorSoapClient oServiceReference = new ServiceReference.CurrencyConvertorSoapClient("CurrencyConvertorSoap12");
            ServiceReference.Currency from = (ServiceReference.Currency) comboBox1.SelectedValue;
            ServiceReference.Currency to = (ServiceReference.Currency)comboBox2.SelectedValue;

            label1.Text = (oServiceReference.ConversionRate(from, to)*Convert.ToInt32(textBox1.Text)).ToString();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = Enum.GetValues(typeof(ServiceReference.Currency));
            comboBox2.DataSource = Enum.GetValues(typeof(ServiceReference.Currency));
        }


WSDL 

http://www.webservicex.com/CurrencyConvertor.asmx?wsdl

Message driven bean

List  Items

@WebServlet(name = "listWord", urlPatterns = {"/listWord"})
public class listWord extends HttpServlet {
    @EJB
    private DicWordEntryFacade dicWordEntryFacade;
    @EJB
    private SessionmManagerBean sessionmManagerBean;

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.getSession(true);
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet listWord</title>");          
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet listWord at " + request.getContextPath() + "</h1>");
            List word= dicWordEntryFacade.findAll();
            for (Iterator it= word.iterator(); it.hasNext();) {
                DicWordEntry elem= (DicWordEntry) it.next();
                out.println("<b>"+elem.getWord()+"</b><br/>");
                out.println("<b>"+elem.getDiscription()+"</b><br/>");
            }
           
            out.println("<a href='AddWord'>Add New Word</a>");
            out.println("</body>");
            out.println("</html>");
        } finally {          
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}

--------------------------------------------------------------------------------------------------------------------------
Add Item


@WebServlet(name = "AddWord", urlPatterns = {"/AddWord"})
public class AddWord extends HttpServlet {

    @Resource(mappedName="jms/NewMessageFactory")
    private ConnectionFactory connectionFactory;
   
    @Resource(mappedName="jms/NewMessageBean")
    private Queue queue;
    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
       
            String word = request.getParameter("word");
            String discription = request.getParameter("discription");

            if (word != null && discription != null) {
                try {
                    Connection connection = connectionFactory.createConnection();
                    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                    MessageProducer messageProducer= session.createProducer(queue);
                   
                    ObjectMessage message= session.createObjectMessage();
                    DicWordEntry Dicword = new DicWordEntry();
                Dicword.setWord(word);
                Dicword.setDiscription(discription);
                message.setObject(Dicword);
                messageProducer.send(message);
                messageProducer.close();
                connection.close();
                response.sendRedirect("listWord");
                } catch (Exception e) {
                }

             
            }
       
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet AddWord</title>");          
            out.println("</head>");
            out.println("<body>");
            out.println("<form>");
            out.println("<h1>Servlet AddWord at " + request.getContextPath() + "</h1>");
             out.println("Word :<input type='text' name='word'><br/>");
             out.println("Discription :<input type='text' name='discription'><br/>");
             out.println("<input type='submit'><br/>");
            out.println("</form>");
            out.println("</body>");
            out.println("</html>");
        } finally {          
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}

Monday, October 13, 2014

Hibernate many to many mapping

Person Class

public class Person {

    private int personid;
    private String name;
    private int age;
   
    private Set copanys;

    @Override
    public String toString() {
        return "Person: " + getPersonid()
                + " Name: " + getName()
                + " Age: " + getAge();
    }

    public int getPersonid() {
        return personid;
    }

    public void setPersonid(int personid) {
        this.personid = personid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Set getCopanys() {
        return copanys;
    }

    public void setCopanys(Set copanys) {
        this.copanys = copanys;
    }
   
    public void AddCom(Company c){
        if(copanys==null){
            copanys=new HashSet();
        }
        copanys.add(c);
    }
}
--------------------------------------------------------------------------------------------------------------------------
Company  Class

public class Company {
    private int id;
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
   
   
}
--------------------------------------------------------------------------------------------------------------------------
Mapping file

<hibernate-mapping>
    <class name="hibernate3.Person" table="PRESON">
        <id name="personid" column="personid">
            <generator class="increment"/>
        </id>
        <property column="personname" name="name"/>
        <property column="personage" name="age"/>
     
        <set cascade="all" name="copanys" table="PERSON_COM">
            <key column="pid"/>
            <many-to-many class="hibernate3.Company" column="cid"/>
        </set>
    </class>
    <class name="hibernate3.Company" table="COMPANY">
        <id name="id" column="id">
            <generator class="increment"/>
        </id>
        <property name="name" column="name"/>
       
    </class>
</hibernate-mapping>

--------------------------------------------------------------------------------------------------------------------------
Main file

  public static void main(String[] args) {
     
        Company c1=new Company();
        c1.setName("xxxxx");
       
          Company c2=new Company();
        c2.setName("vvvvvvvv");
       
          Company c3=new Company();
        c3.setName("bbbbb");

       
        Person p=new Person();
        p.setName("pppppppppppp");
        p.setAge(12);
        p.AddCom(c1);
        p.AddCom(c2);
        p.AddCom(c3);
       
        Session s=SessionFac.getSee();
        Transaction t=s.beginTransaction();
       
        s.save(p);
       
     
        t.commit();
      // s.close();
       
    }

Chat App

Service.cs

[WebMethod]
    public List<ClassObj> Chat( int _id ,String _Msg)
    {
        ClassObj obj = new ClassObj();
        obj.ID =_id;
        obj.Message = _Msg;

        ListObj._listObj.Add(obj);
        return ListObj._listObj;
    }
[WebMethod]
public  void ChatClear()
{
    ListObj._listObj.Clear();
}
----------------------------------------------------------------------------------------------------------------------

public static class ListObj
{
    public static List<ClassObj> _listObj = new List<ClassObj>();
}

-----------------------------------------------------------------------------------------------------------------------
public class ClassObj
{
    public int ID { get; set; }
    public String Message { get; set; }
}
-----------------------------------------------------------------------------------------------------------------------

Client App

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Enter User ID');", true);          
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ServiceReference1.ServiceSoapClient client = new ServiceSoapClient();
        ServiceReference1.ClassObj[] _classObj = client.Chat(Convert.ToInt32(TextBox2.Text), TextBox1.Text);
        String ss="";
        ListBox1.Items.Clear();
        for (int i = 0; i < _classObj.Count(); i++)
        {
            ListBox1.Items.Add(_classObj[i].ID.ToString());
            ListBox1.Items.Add(_classObj[i].Message.ToString());
        }
       
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ServiceReference1.ServiceSoapClient client = new ServiceSoapClient();
        client.ChatClear();
        ListBox1.Items.Clear();

    }





Encryption

Using inbuilt algorithm

 public static void main(String[] args) {
        // TODO code application logic here
        try
        {
            String plainData = "Hukahan", cipherText, decryptedText;
            KeyGenerator keyGen = KeyGenerator.getInstance("AES");
            keyGen.init(128);
            SecretKey secretKey = keyGen.generateKey();
            cipherText = encrypt(plainData, secretKey);
            System.out.println("Plain Text :"+plainData);
            System.out.println("cypher text : "+cipherText);
            decryptedText = decrypt(cipherText, secretKey);
            System.out.println("decrypted text : "+decryptedText);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }
   
    public static String encrypt(String plainData, SecretKey secretKey) throws Exception
    {
        Cipher aesCipher = Cipher.getInstance("AES");
        aesCipher.init(Cipher.ENCRYPT_MODE, secretKey);
        byte[] byteDataToEncrypt = plainData.getBytes();
        byte[] byteCipherText = aesCipher.doFinal(byteDataToEncrypt);
        return new BASE64Encoder().encode(byteCipherText);
    }

    public static String decrypt(String cipherData, SecretKey secretKey) throws Exception
    {
        byte[] data = new BASE64Decoder().decodeBuffer(cipherData);
        Cipher aesCipher = Cipher.getInstance("AES");
        aesCipher.init(Cipher.DECRYPT_MODE, secretKey);
        byte[] plainData = aesCipher.doFinal(data);
        return new String(plainData);
    }

--------------------------------------------------------------------------------------------------------------------------
Use define algorithm

private final String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-gfuifyuvfyifrghvhyifyutcyi";

    public String encriptText(String text, int key) {

        String EncriptText = "";
        int Charactorposition;
        int keyVal;
        char replaceValue;
        for (int i = 0; i < text.length(); i++) {
            Charactorposition = chars.indexOf(text.charAt(i));
            keyVal = (Charactorposition + key) % chars.length();
            replaceValue = chars.charAt(keyVal);

            EncriptText += replaceValue;
        }

        return EncriptText;
    }

    public String decript(String text, int key) {
        String EncriptText = "";
        int Charactorposition;
        int keyVal;
        char replaceValue;

        for (int i = 0; i < text.length(); i++) {
            Charactorposition = chars.indexOf(text.charAt(i));
            keyVal = (Charactorposition - key);
            if (keyVal < 0) {
                keyVal = this.chars.length() + keyVal;
            }

            replaceValue = this.chars.charAt(keyVal);
            EncriptText += replaceValue;

        }

        return EncriptText;

    }

Mongodb tutorial

DBManager Class

public class DBManager {
    public static DB database;
   
    public static DB getDatabase()
    {
        if(database==null)
        {
            MongoClient mongo;
            try {
                mongo = new MongoClient("localhost", 27017);
                database = mongo.getDB("Test");
            } catch (Exception e) {
            }
        }
            return database;
    }
}
--------------------------------------------------------------------------------------------------------------------------
Insert Button Click event

   private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        

        try {
            User user = new User();
            user.setId(Integer.parseInt(jTextField1.getText().toString()));
            user.setName(jTextField2.getText().toString());
            user.setEmail(jTextField3.getText().toString());
            DBObject obj = createDBObject(user);
            DB userDb = DBManager.getDatabase();
            DBCollection col = userDb.getCollection("user");
            col.insert(obj);
            JOptionPane.showMessageDialog(this, "Ok");
           
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }

        // TODO add your handling code here:
    }                                      

    private DBObject createDBObject(User user) {
        BasicDBObjectBuilder ob = BasicDBObjectBuilder.start();

        ob.append("id", user.getId());
        ob.append("name", user.getName());
        ob.append("email", user.getEmail());
        return ob.get();
    }
--------------------------------------------------------------------------------------------------------------------------
Update event

 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
try{
   
       BasicDBObject updateFelds = new BasicDBObject();
       updateFelds.append("name", jTextField2.getText().toString());
       updateFelds.append("email", jTextField3.getText().toString());
     
      BasicDBObject update = new BasicDBObject();
       update.append("$set", updateFelds);
        BasicDBObject where  = new BasicDBObject();
        where.append("id", Integer.parseInt(jTextField1.getText()));
       
        col.update(where, update);
        JOptionPane.showMessageDialog(this,"ok");
}catch(Exception e){
    JOptionPane.showMessageDialog(this,e.getMessage().toString());}
        // TODO add your handling code here:
    }    

--------------------------------------------------------------------------------------------------------------------------
Search event

 try{
          jTextField2.setText("");
        jTextField3.setText("");
        BasicDBObject where  = new BasicDBObject();
        where.put("id", Integer.parseInt(jTextField1.getText()));
        BasicDBObject obj= (BasicDBObject) col.findOne(where);
     //  User user = (User) obj;
        jTextField2.setText(obj.get("name").toString());
        jTextField3.setText(obj.get("email").toString());
       
       
        System.out.println(obj);
       }
       catch(Exception e){JOptionPane.showMessageDialog(this, "no recod found");}
     
--------------------------------------------------------------------------------------------------------------------------

Delete event


      BasicDBObject select =  (BasicDBObject) col.findOne( new BasicDBObject().append("id", Integer.parseInt(jTextField1.getText())));
     
      col.remove(select);
         jTextField1.setText("");
        jTextField2.setText("");
        jTextField3.setText("");
        JOptionPane.showMessageDialog(this,"ok");

Java Hibernate One-To-Many

Person Entity

public class Person {
 
    private int PersonId;
    private String Name;
    private int Age;
    private Set Hats;

    public Person()
    {
        Hats= new HashSet();
    }
 
    public Set getHats() {
        return Hats;
    }

    public void setHats(Set Hats) {
        this.Hats = Hats;
    }

    public void addHat(Hat hat)
    {
        this.Hats.add(hat);
    }
 
    public void removeHat(Hat hat)
    {
        this.Hats.remove(hat);
    }
 
    public int getPersonId() {
        return PersonId;
    }

    public void setPersonId(int PersonId) {
        this.PersonId = PersonId;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public int getAge() {
        return Age;
    }

    public void setAge(int Age) {
        this.Age = Age;
    }

    @Override
    public String toString() {
     
        String personString="PersonId=" + getPersonId()+
                " Name=" + getName() +
                " Age=" + getAge();
        String HatString="";
        for (Iterator itr=Hats.iterator();itr.hasNext();) {
            Hat hat= (Hat) itr.next();
            HatString=HatString +"\t\t"+hat.toString()+"\n";
        }
     
        return personString +"\n"+HatString;
    }

--------------------------------------------------------------------------------------------------------------------------

Hat Entity

public class Hat {
    private int HatId;
    private String Colour;
    private String Size;
    private int PersonId;

    public int getHatId() {
        return HatId;
    }

    public void setHatId(int HatId) {
        this.HatId = HatId;
    }

    public String getColour() {
        return Colour;
    }

    public void setColour(String Colour) {
        this.Colour = Colour;
    }

    public String getSize() {
        return Size;
    }

    public void setSize(String Size) {
        this.Size = Size;
    }

    public int getPersonId() {
        return PersonId;
    }

    public void setPersonId(int PersonId) {
        this.PersonId = PersonId;
    }

    @Override
    public String toString() {
        return "Hat{" + "HatId=" + getHatId() + ", Colour=" + getColour() + ", Size=" + getSize() + '}';
    }
 

    
--------------------------------------------------------------------------------------------------------------------------

SessionFactoryUtil class 


public class SessionFactoryUtil {
 
    private static final SessionFactory sessionFactory;
    private static String ex;
 
    static {
 
        try {
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed."
                    + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
 
    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }
 
    public static  Session getCurrentSession()
    {
        return sessionFactory.getCurrentSession();
    }
 
    public static Session OpenSession()
    {
        return sessionFactory.openSession();
    }
 
    public static void CloseSessionFactory()
    {
        if(sessionFactory != null)
        {
            sessionFactory.close();
        }

    }
--------------------------------------------------------------------------------------------------------------------------

Main Class

   public static void main(String[] args) {

        Person p1 = new Person();
     
        p1.setName("Saman With Hats");
        p1.setAge(30);
        Hat h1 = new Hat();
        h1.setColour("Black");
        h1.setSize("Small");
        Hat h2 = new Hat();
        h2.setColour("White");
        h2.setSize("Large");
        p1.addHat(h1);
        p1.addHat(h2);
        p1.addHat(h2);
        createPerson(p1);
 
     
    }
 
    public static void createPerson(Person person) {
        Transaction tx = null;
        Session session = SessionFactoryUtil.getCurrentSession();
        try {
            tx = session.beginTransaction();
            session.save(person);
            tx.commit();
        } catch (RuntimeException e) {
            if (tx != null && tx.isActive()) {
                try {
               
                    tx.rollback();
                } catch (HibernateException e1) {
                    System.out.println("Error rolling back transaction");
                }
       
                throw e;
            }
        }
     
    }
 
    public static void createHat(Hat hat) {
        Transaction tx = null;
        Session session = SessionFactoryUtil.getCurrentSession();
        try {
            tx = session.beginTransaction();
            session.save(hat);
            tx.commit();
        } catch (Exception e) {
        }
    }
        private static void listPerson() {
        Transaction tx = null;
        Session session = SessionFactoryUtil.getCurrentSession();
        try {
            tx = session.beginTransaction();
//            List persons = session.createQuery(
//                    "select p from Person as p").list();
            Query q = session.createQuery("select p from Person as p where p.age >:age");
            Person fooPerson = new Person();
            fooPerson.setAge(0);
            q.setProperties(fooPerson);
            List persons = q.list();

            System.out.println("*** Content of the Person Table ***");
            System.out.println("*** Start ***");
            for (Iterator iter = persons.iterator(); iter.hasNext();) {
                Person element = (Person) iter.next();
                System.out.println(element);
            }
            System.out.println("*** End ***");
            tx.commit();
        } catch (RuntimeException e) {
            if (tx != null && tx.isActive()) {
                try {
         
                    tx.rollback();
                } catch (HibernateException e1) {
                    System.out.println("Error rolling back transaction");
                }
                throw e;
            }
        }
    }

    private static void deletePerson(Person person) {
        Transaction tx = null;
        Session session = SessionFactoryUtil.getCurrentSession();
        try {
            tx = session.beginTransaction();
            session.delete(person);
            tx.commit();
        } catch (RuntimeException e) {
            if (tx != null && tx.isActive()) {
                try {
               
                    tx.rollback();
                } catch (HibernateException e1) {
                    System.out.println("Error rolling back transaction");
                }
            }
   
            throw e;
        }
    }

    private static void updatePerson(Person person) {
        Transaction tx = null;
        Session session = SessionFactoryUtil.getCurrentSession();
        try {
            tx = session.beginTransaction();
            session.update(person);
            tx.commit();
        } catch (RuntimeException e) {
            if (tx != null && tx.isActive()) {
                try {
           
                    tx.rollback();
                } catch (HibernateException e1) {
                    System.out.println("Error rolling back transaction");
                }
           
                throw e;
            }
        }
    }
--------------------------------------------------------------------------------------------------------------------------

Person Mapping

<hibernate-mapping>
  <class name="hibonateonetomany.Person" table="PERSON">
      <id column="PERSONID" name="PersonId">
          <generator class="increment"/>
      </id>
      <property column="NAME" name="Name"/>
      <property column="AGE" name="Age" />
      <set cascade="all" name="Hats" table="HAT">
          <key column="PERSONID"/>
          <one-to-many class="hibonateonetomany.Hat"/>
      </set>
  </class>
</hibernate-mapping>
--------------------------------------------------------------------------------------------------------------------------

Hat Mapping

<hibernate-mapping>
    <class name="hibonateonetomany.Hat" table="HAT">
        <id column="HATID" name="HatId">
            <generator class="increment"/>
        </id>
        <property column="COLOUR"  name="Colour"/>
        <property column="SIZE" name="Size"/>
    </class>
</hibernate-mapping>







Hibernate Annotations

Java Servlet Without MessageBean



    @EJB

    private NewsEntityFacade newsEntityFacade;
--------------------------------------------------------------------------------------------------------------------------

Add Method

  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */

            String Titel = request.getParameter("title");
            String Body = request.getParameter("body");

            if (Titel != null && Body != null) {
                NewsEntity news = new NewsEntity();
                news.setTitel(Titel);
                news.setBody(Body);
                newsEntityFacade.create(news);
                response.sendRedirect("ListNews");
            }

            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet AddNews</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet AddNews at " + request.getContextPath() + "</h1>");
            out.println("<form>");
            out.println("<input type='text' name='title'></br>");
            out.println("<input type='text' name='body'></br>");
            out.println("<input type='submit'> </br>");
            out.println("</form>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }
--------------------------------------------------------------------------------------------------------------------------
Show Method

  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ListNews</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ListNews at " + request.getContextPath() + "</h1>");

            List newsList = newsEntityFacade.findAll();
            for (int i = 0; i < newsList.size(); i++) {

                NewsEntity n = (NewsEntity) newsList.get(i);
                out.println("Titel :"+n.getTitel() + " Message : " + n.getBody());
                out.println("<a href ='EditNews?id=" + n.getId() + "'>Edit</a>");
                out.println("<a href ='DeleteNews?id=" + n.getId() + "'>Delete</a>  </br>");

            }
            out.println("<a href='AddNews'>Add new Message   </a>");

            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }

--------------------------------------------------------------------------------------------------------------------------

Edit Method


  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        Long id = Long.parseLong(request.getParameter("id"));
        String Titel = request.getParameter("title");
        String Body = request.getParameter("body");

        if (Titel != null && Body != null) {
            NewsEntity news = new NewsEntity();
            news.setId(id);
            news.setTitel(Titel);
            news.setBody(Body);
            newsEntityFacade.edit(news);
            response.sendRedirect("ListNews");
        }
        PrintWriter out = response.getWriter();
        try {

            /* TODO output your page here. You may use following sample code. */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet EditNews</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet EditNews at " + request.getContextPath() + "</h1>");
            out.println("<form>");
            NewsEntity news = newsEntityFacade.find(id);
            out.println("<input type='text' name='title' value='" + news.getTitel() + "'></br>");
            out.println("<input type='text' name='body'value='" + news.getBody() + "'></br>");
            out.println("<input type='hidden' name='id'value='" +id + "'></br>");
            out.println("<input type='submit'> </br>");
            out.println("</form>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }
--------------------------------------------------------------------------------------------------------------------------

Delete Method

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        Long id = Long.parseLong(request.getParameter("id"));
        String Titel = request.getParameter("title");
        String Body = request.getParameter("body");
     
        if(id !=null)
        {
             NewsEntity news = new NewsEntity();
            news.setId(id);
            news.setTitel(Titel);
            news.setBody(Body);
            newsEntityFacade.remove(news);
            response.sendRedirect("ListNews");
        }

        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet DeleteNews</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet DeleteNews at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }

Sunday, April 13, 2014

How to Root Smartphone (Dialog i35,k35,i43)

අපි බලමු මොකක්ද මෙ Root කරනවා කියන්නේ කියලා

ඔයලා දෑකලා ඈති සමහර Application තියෙනව අපිට Uninstall කරන්න බෑ,(Dialog Phone එකක් ගත්තොත් එක හොදට බලා ගන්න පුලුවන්, උදහරනයක් ව්දියට Dialog app එකක්වත් අපිට Uninstall කරන්න බෑ) එ කියන්නේ Phone අපේ උනාට අපිට ඔන දේවල් කරන්න අපිට Permission නෑ කියන එක, කොටින්ම කියනව න්ම් අපිට Kernel Access නෑ, අපි දෑන් බලමු කොහොමද Kernel Access හදගන්නේ කියල...

මේ පෝස්ට් එක අදාල Dialog Phone වලට විතරක් නෙමෙ...
අනිත් Androide Phone වලටත් මෙහෙම Root කරන්න පුලුවන් :)

Step 1:
ඔයලා මුලින්ම ම්න් කියල තියේන Software එක Download කරලා ඔයගේ PC/Lap එකට Install කරගන්න ඔන. තියේන ලෑන්වෙජ් එක ගෑන හිතන්න එපා.
(Click here)
Install උනට පස්සේ මේ වගේ Interface එකක් බලාගන්න පුලුවන්



Step 2:
දෑන් ඔයා ඔයගේ Phone එකේ debugging mode එක on කරලා PC එකට හරි Lap එකට හරි Connect කරන්න. ඉට පස්සේ ඔයා Install කර ගත්ත Software එක Run කරන්න.
අමතක කරන්න එපා ඔය Software එක Run කරන්න කලින් Internet එකට Connect වෙලා ඉන්න.

මේ වගේ Interface එකක් අවට පස්සේ Root කියන Button එක ඔබන්න.
ඊට පස්සෙ ෆෝන් එක Reboot වෙවි....
ඊට පස්සෙ හරි ලකුනක් වැටිල දුරකතනයෙ නම පස්සෙන් Root කියල වැටෙවි.

දෑන් වෑඩේ හරි..
Phone එක Root උනාට පස්සේ ඔයලට Superuser කියල හරි Kinguser කියල හරි Icon එකක් ඔයලගේ Phone එකේ ඈති එකේන් ඔයාලට පුලුවන් ඔන Application එකක් Uninstall කරන්න.


How to Unlock Dongle

කොහොමද යලුවනේ...

ම්න් හිතුව පොඩි Help 1ක් කරන්න හෑමොටම හොයන Dongle ලේසියෙන් අන්ලොක් කරන්න ව්දියක්
හෑමොන කෑමතිනේ තමන්ගේ Dongle 1ක තමන්ම අන්ලොක් කරන්න..

බලන්නකො Try 1ක් දාල, වෑඩේ ලේසි :)

Step 1 :
මුලින්ම බලන්න ඔයගේ Dongle එකේ Model එක මෙතන තියෙනවද කියල

Huawei E155
Huawei E1550
Huawei E1551
Huawei E1552
Huawei E1553
Huawei E155X
Huawei E156
Huawei E156C
Huawei E156G
Huawei E156X
Huawei E158
Huawei E160
Huawei E1609
Huawei E160E
Huawei E160G
Huawei E161
Huawei E1612
Huawei E1615
Huawei E1616
Huawei E1630
Huawei E1632
Huawei E166
Huawei E166G
Huawei E169
Huawei E1690
Huawei E1692
Huawei E169G
Huawei E170
Huawei E170G
Huawei E171
Huawei E172
Huawei E172G
Huawei E173
Huawei E176
Huawei E1762
Huawei E177
Huawei E1780
Huawei E180
Huawei E1800
Huawei E1803
Huawei E180G
Huawei E180S
Huawei E181
Huawei E182
Huawei E1820
Huawei E1823
Huawei E182E
Huawei E1831
Huawei E188
Huawei E196
Huawei E2010
Huawei E216
Huawei E219
Huawei E220
Huawei E226
Huawei E22X
Huawei E230
Huawei E270
Huawei E271
Huawei E272
Huawei E303
Huawei E303s HiLink
Huawei E352
Huawei E353
Huawei E355
Huawei E357
Huawei E367
Huawei E368
Huawei E369
Huawei E372
Huawei E392
Huawei E397
Huawei E398
Huawei E612
Huawei E618
Huawei E620
Huawei E630
Huawei E630+
Huawei E660
Huawei E660A
Huawei E800
Huawei E870
Huawei E880
Huawei E968
Huawei EG162
Huawei EG162G
Huawei EG602
Huawei EG602G
Huawei EM770

Huawei K3517
Huawei K3520
Huawei K3710

Huawei S4011
Huawei UMG181

Huawei E1731
Huawei E3131
Huawei E3131 HiLink

Step 2:
ඔයගේ Dongle එකේ Model එක තියෙනවාන්ම්, දෑන් ඔයට කරන්න තියෙන්නේ ඔයගේ Dongle එකේ IMEI Number එක හොයා ගන්න එක,
එකට විදි දේකක් තියෙනවා
1. ඔයට පුලුවන් මම පේන්නලා තියේන Image එකේ විදියට ගිහින් ගන්න.
2. නෑතිනම් ඔයට පුලුවන් Dongle එකේ SIM එක දාන තෑනින් IMEI එක බලා ගන්න.


Step 3:
දෑන් ඔයලට පුලුවන් මේ Link( Click here ) එකට ගිහින් Dongle එක Unlock කර ගන්න,
Dongle එක Unlock කරන්න කලින් ඔයල G mail එකට Sign In වේලා ඉන්න ඔන, ඉට පස්සේ ඔයා කලින් Copy කර ගත් IMEI Number එක මෙතනට Paste කරලා ඔයගේ Dongle එකේ Unlock Code එක මොකක්ද කියල බලාගන්න.


Step 4:
දෑන් තියෙන 3G තියෙන වෙන සිම් එකක් ඩොංගල් එකට දාන්න.දැම්මම අන්ලොක් කෝඩ් එකක් ඉල්ලනවනෙ. ඉට පස්සේ ඔයලට කරන්න තියෙන්නේ Image එකේ ව්දියට කියලා තියෙන new algo code එක Copy කරල ඔයගේ Unlock Code එකට දෙන්න.




දෑන් වෑඩේ හරි...
ඔයට පුලුවන් දෑන් ඔන SIM එකක් Use කරල net යන්න. :)


අවුලක් තිබ්බොත් කමේන්ට් එකක් දාලා අහන්න...