RSS

Play Framework: Data Model

27 Jan



За жаахан үргэлжлүүлчье. Зарим хүмүүс прожект үүсгэж туршиж үзсэн байх гэж бодож байна.
/conf хавтас дотор байгаа application.conf файлд өгөгдлийн сантайгаа холбогдох тохиргоогоо хиие.

Ерөнхийдөө энэ файлд бичигдсэн зүйлсийн өмнө “#” ийм тэмдэг байвал тайлбар гэж ойлгоорой.

1. db=mem – өгөгдлийн түр санах ойд хадгална.
2. db=fs – өгөгдлийн файлд хадгална.
3. db=mysql:user:pwd@database_name – MySQL – ийг ашиглаж байгаа үед энэ тохиргоог хийнэ.
4. db.url=jdbc:postgresql:translator
db.driver=org.postgresql.Driver
db.user=root
db.pass=password
Энэ харин PostgreSql – ийг ашиглаж байгаа үед хийх тохиргоо.

Энэ харин өгөгдлийн сантай үүссэн холбоосын тохиргоо.
db.pool.timeout=1000
db.pool.maxSize=30
db.pool.minSize=10


Ер нь ихэнхи нь Entity framework гэж сонсож байсан байх. Тэгвэл үүнийг ашиглан Play framework дээр хүснэгт үүсгэх, өгөгдөл хайх, нэмэх, хасах гэх мэт үндсэн үйлдэлүүийг маш хялбарчилаж өгсөн.

Жишээ: Доор нэг класс файлыг эх кодыг харуулая. энэ нь бидний сайн мэдэх MediaWiki – ийн mw_user хүснэгтийн бүтцийг үүсгэж байгаа жишээ юм.

package models;

import javax.persistence.*;
import play.data.validation.*;
import play.db.jpa.*;

/**
*
* @author MongolCoder
*/

@Entity
public class Mw_user extends Model {

@Required
@Column(length = 255)
public String user_name;

@Required
@Column(length = 255)
public String user_real_name;

@Required
@Lob
@Password
public String user_passsword;

@Required
@Lob
@Password
public String user_newpassword;

@Column(length = 14)
public Number user_newpass_time;

@Email
@Column(length = 50)
@Required
public String user_email;

@Required
public String user_options;

@Required
public String user_touched;

public String user_email_authenticated;

@Password
public String user_email_token;

public String user_email_token_expires;

public String user_registration;

public int user_editcount;

public Mw_user(
String user_name,
String user_real_name,
String user_passsword,
String user_newpassword,
byte user_newpass_time,
String user_email,
String user_options,
String user_touched,
String user_email_authenticated,
String user_email_token,
String user_email_token_expires,
String user_registration,int user_editcount){
this.user_name = user_name;
this.user_real_name = user_real_name;
this.user_passsword = user_passsword;
this.user_newpassword = user_newpassword;
this.user_newpass_time = user_newpass_time;
this.user_email = user_email;
this.user_options = user_options;
this.user_touched = user_touched;
this.user_email_authenticated = user_email_authenticated;
this.user_email_token = user_email_token;
this.user_email_token_expires = user_email_token_expires;
this.user_registration = user_registration;
this.user_editcount = user_editcount;

}

@Override
public String toString(){
return user_name;
}
}

Ингээл болоо. Энэ класс нь Play Framework – д тодорхойлогдсон Model Классаас удамшиж байгааг харж байгаа байх.
За одоо үндсэн үйлдэлүүдийг хийж үзье.

Mw_user muser = new Mw_user(“Батаа”,”Батдорж”,”123456″,”1234564″ ….. ).save();
гээд объектоо үүсгээд болоо. Цаанаа Insert хийгдэж байнаа гэж ойлгож болно.
insert into mw_user values (“Батаа”,”Батдорж”,”123456″,”1234564″ ….. );

Одоо өгөгдөл уншвал
Mw_user muser1 = Mw_user.find(“user_name”, “Батаа”).first();
эсвэл
List musers = Mw_user.find(“order by id asc”).fetch();
гэх мэтээр уншина.

Маш энгийн …

Play framework: Install

Play Framework: Админ хуудас

Advertisements
 
4 Comments

Posted by on January 27, 2011 in My, Play Framework

 

Tags: , , ,

4 responses to “Play Framework: Data Model

  1. pornhd

    January 4, 2017 at 6:41 pm

    Hі there, ӏ discovered your web site bү the use of Google at the same time as loоking
    for a ϲomparable topic, your site got here up, it appears good.
    I have bookmarked it in my gߋogⅼe bookmarks.
    Hi there, simply was aware of your Ьlog thru Ԍoogle, and found that it iѕ really informative.
    I am going to watch out for brussels. I’ll appreciate in the event you procеed this in future.
    Numerous other folks might be benefited from your
    writing. Cheeгs!

     
  2. bachelor college degree online

    June 4, 2013 at 6:44 am

    The experience: I had to have someone come in to set up my computer,.
    A study in the British Medical Journal found a significant connection between a person”.
    Earwigs are largely nocturnal creatures that can easily be drawn in at
    night by any lights you have in or around your home.

     
  3. http://tinyurl.com/lazebiern02984

    February 5, 2013 at 10:25 pm

    I blog likewise and I’m creating a little something very
    close to this excellent article, “Play Framework:
    Data Model My notes ”. Do you really mind in cases where Iwork with some of
    your own ideas? Thanks a lot ,Natisha

     
  4. free movie download

    January 28, 2011 at 12:35 pm

    i like it turmoil frame: Data Model « Bokhoo's Problems & Solutions now im your rss reader

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: