หน้าเว็บ

วันพุธที่ 30 ตุลาคม พ.ศ. 2556

INNER JOIN jpa spring data

โจทย์ คือหาโรงพยาบาล (Hospital) ภายใต้จังหวัดที่กำหนด
 และต้องเป็นโรงพยาบาลที่อยู่ในโครงการ (InHospital) เท่านั้น
package com.blogspot.na5cent.api.repository;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import com.blogspot.na5cent.basicmodel.readonly.Hospital;
import com.blogspot.na5cent.basicmodel.readonly.Province;

/**
 *
 * @author redcrow
 */
public interface HospitalRepository extends JpaRepository<Hospital, String>{
    
        @Query("SELECT hp FROM InHospital inHp INNER JOIN inHp.hospital hp WHERE hp.province = ?1")
        public List<Hospital> findByProvince(Province province);
} 
Hospital.java
...
...
...

@Entity
@Table(name = "hospital")
@ReadOnly
public class Hospital implements Serializable {
    @Id
    @Column(nullable = false, length = 5)
    private String hcode;
    @Column(nullable = false, length = 250)
    private String hname;
    @ManyToOne
    @JoinColumn(name = "province_id", nullable = false)
    private Province province;

    ...
    ...
    ...
}
InHospital.java
...
...
...

@Entity
@Table(name = "in_hospital")
public class InHospital implements Serializable {

    @Id
    @Column(name = "hcode", length = 9)
    private String hcode;
    @Version
    private Integer version;
    @OneToOne
    @JoinColumn(name = "hcode", insertable = false, updatable = false)
    private Hospital hospital; 

    ....
    ....
    ....
}

วันอังคารที่ 29 ตุลาคม พ.ศ. 2556

SQL Oracle random value

random ระหว่าง 0 - 1
select dbms_random.value
from dual

การประยุกต์ใช้งาน

วันจันทร์ที่ 28 ตุลาคม พ.ศ. 2556

spring data jpa repository SQL IN statement

ส่ง List<Type> เข้าไป 
ตรง IN ไม่ต้องมี ( ) ให้ใส่เป็น IN ?1 ได้เลย
package com.blogspot.na5cent.web.repository;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import com.blogspot.na5cent.api.model.RecordItem;

/**
 *
 * @author redcrow
 */
public interface RecordItemRepository extends JpaRepository<RecordItem, Integer> {

    @Query(value = "SELECT item FROM RecordItem item WHERE item.recoredId IN ?1") //*****
    public List<RecordItem> findInRecordIds(List<Integer> recordIds);
}

merge table (resolve update join column) SQL Oracle

ต้องการ update ข้อมูลใน TABLE_A.columnA2 ให้เป็นค่าเดียวกันกับ TABLE_B.column2
โดยมีเงื่อนไข TABLE_A.columnA1 = TABLE_B.column1


merge into TABLE_A
using (
      select  b.column1 columnB1,
              b.column2 columnB2
             
      from TABLE_B b
) on (TABLE_A.columnA1 = columnB1)
when matched 
then update
set TABLE_A.columnA2 = columnB2;

วันพุธที่ 16 ตุลาคม พ.ศ. 2556

webkit css slim scroll

.enable-slimscroll {
    overflow: auto;
}

.enable-slimscroll::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.enable-slimscroll::-webkit-scrollbar-track {
    background-color: #ddd;
}

.enable-slimscroll::-webkit-scrollbar-thumb:vertical,
.enable-slimscroll::-webkit-scrollbar-thumb:horizontal {
    background-color: #999;
}

.enable-slimscroll::-webkit-scrollbar-thumb:vertical:hover,
.enable-slimscroll::-webkit-scrollbar-thumb:horizontal:hover {
    background: #3297fd;
} 


วันอังคารที่ 15 ตุลาคม พ.ศ. 2556

Spring autowire all implementations which implements an interface

interface
สร้าง interface ขึ้นมา ในที่นี้ชื่อว่า Worker

Worker.java
package com.blogspot.na5cent.app.service;

/**
 *
 * @author redcrow
 */
public interface Worker {
    
    public void working();
}
implementations 
สร้าง Worker[n] implementation ซึ่ง implements an interface Worker
ในที่นี้ประกอบไปด้วย Worker1, Worker2, Worker3
การทำงานแต่ละตัวคือให้ log class name ของตัวเองออกมา

วันจันทร์ที่ 14 ตุลาคม พ.ศ. 2556

html meta tag no cache

<head>
    ....
    ....

    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />

    ....
    ....
</head>
thank you : http://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers

วันอังคารที่ 8 ตุลาคม พ.ศ. 2556

jQuery keypress delay

var $input = $('.input-form');
var timeoutReference;

$input.keypress(function(){
  if(timeoutReference){
    window.clearTimeout(timeoutReference);
  }
 
  timeoutReference = setTimeout(function(){
    window.clearTimeout(timeoutReference);
  
    //your code ...
  
  }, 300);
});

วันอาทิตย์ที่ 6 ตุลาคม พ.ศ. 2556

jsf timezone

in view
....
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" locale="en" timeZone="GTM+7" />
....
timeZone="GTM+7" is Bangkok, Hanoi, Jakarta

OR

set Locale timezone  (web.xml)
...
...
...
    <context-param>
        <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
        <param-value>true</param-value>
    </context-param>
...
...
...

วันพุธที่ 2 ตุลาคม พ.ศ. 2556

Lazy load attribute Entity class JPA

Staff.java
...
import javax.persistence.Basic;
...
...
...

@Entity
@Table(name = "Staff")
public class Staff implements Serializable{
    ....
    ....
    ....
    @Lob
    @Basic(fetch = FetchType.LAZY) //****
    private byte[] image;
}