Bean と scala.reflect.{BeanProperty,BeanInfo}

Posted 2010年12月2日 by

ScalaにはBeanクラスを定義する便利なライブリがあります

@BeanPropertyを使えば、getter setter は書かなくてもOKです。

import scala.reflect.{BeanProperty,BeanInfo}
import java.math.BigDecimal
import java.sql.{Date,Timestamp}
import java.text.{DateFormat,SimpleDateFormat}

@BeanInfo
class MASTER(
	@BeanProperty var RENTALODRID:BigDecimal
        , @BeanProperty var CUSTOMERID:Integer
        , @BeanProperty var SALESPRICE:BigDecimal
        , @BeanProperty var DLVFEETAX:BigDecimal
        , @BeanProperty var DLVFEE:BigDecimal
        , @BeanProperty var RNTODRDATE:java.sql.Date
        , @BeanProperty var LASTUPDATE:Timestamp
        , @BeanProperty var RATE:java.lang.Double
        , @BeanProperty var RATE1:Double
        , @BeanProperty var RATE2:Float
        , @BeanProperty var RATE3:Int
        , @BeanProperty var OTHER:String

) {
	def this() = this(null,0,null,null,null,null,null,0,0,0,0,null) 
	override def toString :String  = {
                var buf = "["
                buf += RENTALODRID
                buf += "," + CUSTOMERID
                buf += "," + SALESPRICE
                buf += "," + DLVFEETAX
                buf += "," + DLVFEE
                buf += "," + RNTODRDATE
                buf += "," + LASTUPDATE
                buf += "," + OTHER
                buf += "]"
                buf
        }
        override def hashCode:Int = RENTALODRID.hashCode
}

新しく定義したMASTER Class を動かしてみるために書いたプログラムです

import java.math.BigDecimal
import java.sql.{Date,Timestamp}
import java.text.{DateFormat,SimpleDateFormat}

object master {
  def main(args : Array[String]) : Unit = {
		var m = new MASTER
		m.setRENTALODRID(new BigDecimal(1))
		m.setSALESPRICE(new BigDecimal("320.34"))
		println(m)
    }
}

実行結果です。

[1,0,320.34,null,null,null,null,null]

Post Details

  • Post Title: Bean と scala.reflect.{BeanProperty,BeanInfo}
  • Author: admin
  • Filed As: Scala
  • Tags:
  • You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

コメントを残す