Seedo Scala Framework (Bean generation)

Posted 2011年1月1日 by

データ・ディクショナリ

データベースに接続してデータ・ディクショナリを参照してScala Beanを生成するObjectを作りました。

Oracleのデータ・ディクショナリとは、データベースに関する情報を提供する読取り専用の表の集合です。データ・ディクショナリには次のものが含まれます。

    • データベース内のすべてのスキーマ・オブジェクト(表、ビュー、索引、クラスタ、シノニム、順序、プロシージャ、ファンクション、パッケージ、トリガーなど)の定義
      スキーマ・オブジェクトに割り当てられている領域と、現在使用されている領域の容量
      ・列のデフォルト値
      ・整合性制約に関する情報
      ・Oracleユーザーの名前
      ・それぞれのユーザーに付与されている権限とロール
      ・各種スキーマ・オブジェクトにアクセスまたは更新したユーザーなどの監査情報
      ・その他の一般的なデータベース情報
  • Scala Bean の生成は、seedo.jar を使います。
    環境変数のPPPを jarファイルを置いたディレクトリを指定します。

    jpa.jar は、旧Sunのjavax.persistence です。
    ojdbc6.jar は、OracleJDBCドライバです。

    以下のBatファイル(Windows環境)を実行します。
    OracleDBに接続する設定値のDNS(-d) や UserID(-u)、Password(p)は生成したいスキーマを指定します。

    rem SeeDo
    rem  eWave Solutions Inc.(c) 2000-2011, LAMP/EPFL
    rem
    set JAVA_OPT=-Xmx512M -Xms128M
    set PPP=C:\eclipse\workspace\SeeDo\lib\
    set CLASSPATH=%PPP%jpa.jar;%PPP%ojdbc6.jar;
    
    call scala -classpath %CLASSPATH%;%PPP%seedo.jar seedo.database.GenerateBeanClass -j oracle.jdbc.driver.OracleDriver -d jdbc:oracle:thin:@127.0.0.1:1521:ORCL -u scott -p tiger
    
    echo -- end --
    pause
    



    カレントフォルダーのsrc/scott/bean/ フォルダーの下に scala ファイルが生成されます。

    BONUS.scala
    DEPT.scala
    EMP.scala
    SALGRADE.scala

    生成されたEmp表のBeanは、

    /* 
     * SeeDo
     *  eWave Solutions Inc.(c) 2000-2011, LAMP/EPFL
    */
    package scott.bean
    
    import scala.xml._
    import java.math.BigDecimal
    import java.sql.Blob
    import java.sql.Date
    import java.sql.Timestamp
    import javax.persistence.{Column,Entity,Id,Table,Lob,UniqueConstraint,SequenceGenerator}
    
    import seedo.Util
    
    @Entity
    @Table(name="EMP")
    class EMP{
    	// Type = TABLE
    	// Index = 
    	// Commect = -
    	def clear :Unit= {
    		EMPNO = null
    		ENAME = null
    		JOB = null
    		MGR = null
    		HIREDATE = null
    		SAL = null
    		COMM = null
    		DEPTNO = null
    		for (i <- 0 to modifiedProperty.length - 1) {
    			modifiedProperty(i) = false
    		}
    	}
    	def toJson :String = {
    		"{\"EMP\" : {\"EMPNO\" : \""+EMPNO+"\",\"ENAME\" : \""+ENAME+"\",\"JOB\" : \""+JOB+"\",\"MGR\" : \""+MGR+"\",\"HIREDATE\" : \""+HIREDATE+"\",\"SAL\" : \""+SAL+"\",\"COMM\" : \""+COMM+"\",\"DEPTNO\" : \""+DEPTNO+"\"}}"
    	}
    	override def clone :EMP = {
    		var base = new EMP
    		if (EMPNO != null) {
    			base.EMPNO = new BigDecimal(EMPNO.toString)
    		}
    		if (ENAME != null) {
    			base.ENAME = new String(ENAME)
    		}
    		if (JOB != null) {
    			base.JOB = new String(JOB)
    		}
    		if (MGR != null) {
    			base.MGR = new BigDecimal(MGR.toString)
    		}
    		if (HIREDATE != null) {
    			base.HIREDATE = new Timestamp(HIREDATE.getTime)
    		}
    		if (SAL != null) {
    			base.SAL = new BigDecimal(SAL.toString)
    		}
    		if (COMM != null) {
    			base.COMM = new BigDecimal(COMM.toString)
    		}
    		if (DEPTNO != null) {
    			base.DEPTNO = new BigDecimal(DEPTNO.toString)
    		}
    		for (i <- 0 to modifiedProperty.length - 1) {
    			base.modifiedProperty(i) = modifiedProperty(i)
    		}
    		base
    	}
    	def isModified  :Boolean = {
    		modifiedProperty.foreach (i => {
    			if (i) {
    				return true
    			}
    		})
    		return false
    	}
    	def isPrimaryKey(columnName:String) :Boolean = {
    		if (columnName.equals("EMPNO")) {return true}
    		false
    	}
    	def isColumn(columnName:String):Int= {
    		return 0
    	}
    	/**
    	 * Getter
    	 * @return the EMPNO
    	 */
    	def getEMPNO:BigDecimal = EMPNO
    	/**
    	 * Setter
    	 * @param Empno the EMPNO to set
    	 */
    	def setEMPNO( Empno:BigDecimal) :Unit = {
    		this.EMPNO = Empno
    		modifiedProperty(0) = true
    	}
    	/**
    	 * Setter
    	 * @param Empno the EMPNO to set
    	 */
    	def setEMPNO(Empno:Int) :Unit = {
    		this.EMPNO = new BigDecimal(Empno)
    		modifiedProperty(0) = true
    	}
    	/**
    	 * Setter
    	 * @param Empno the EMPNO to set
    	 */
    	def setEMPNO(Empno:Long) :Unit = {
    		this.EMPNO = new BigDecimal(Empno)
    		modifiedProperty(0) = true
    	}
    	/**
    	 * Setter
    	 * @param Empno the EMPNO to set
    	 */
    	def setEMPNO(Empno:Double) :Unit = {
    		this.EMPNO = new BigDecimal(String.valueOf(Empno))
    		modifiedProperty(0) = true
    	}
    	/**
    	 * Getter
    	 * @return the ENAME
    	 */
    	def getENAME:String = ENAME
    	/**
    	 * Setter
    	 * @param Ename the ENAME to set
    	 */
    	def setENAME( Ename:String) :Unit = {
    		this.ENAME = Ename
    		modifiedProperty(1) = true
    	}
    	/**
    	 * Getter
    	 * @return the JOB
    	 */
    	def getJOB:String = JOB
    	/**
    	 * Setter
    	 * @param Job the JOB to set
    	 */
    	def setJOB( Job:String) :Unit = {
    		this.JOB = Job
    		modifiedProperty(2) = true
    	}
    	/**
    	 * Getter
    	 * @return the MGR
    	 */
    	def getMGR:BigDecimal = MGR
    	/**
    	 * Setter
    	 * @param Mgr the MGR to set
    	 */
    	def setMGR( Mgr:BigDecimal) :Unit = {
    		this.MGR = Mgr
    		modifiedProperty(3) = true
    	}
    	/**
    	 * Setter
    	 * @param Mgr the MGR to set
    	 */
    	def setMGR(Mgr:Int) :Unit = {
    		this.MGR = new BigDecimal(Mgr)
    		modifiedProperty(3) = true
    	}
    	/**
    	 * Setter
    	 * @param Mgr the MGR to set
    	 */
    	def setMGR(Mgr:Long) :Unit = {
    		this.MGR = new BigDecimal(Mgr)
    		modifiedProperty(3) = true
    	}
    	/**
    	 * Setter
    	 * @param Mgr the MGR to set
    	 */
    	def setMGR(Mgr:Double) :Unit = {
    		this.MGR = new BigDecimal(String.valueOf(Mgr))
    		modifiedProperty(3) = true
    	}
    	/**
    	 * Getter
    	 * @return the HIREDATE
    	 */
    	def getHIREDATE:Timestamp = HIREDATE
    	/**
    	 * Setter
    	 * @param Hiredate the HIREDATE to set
    	 */
    	def setHIREDATE( Hiredate:Timestamp) :Unit = {
    		this.HIREDATE = Hiredate
    		modifiedProperty(4) = true
    	}
    	/**
    	 * Setter
    	 * @param Hiredate the HIREDATE to set
    	 */
    	def setHIREDATE(Hiredate:String) {
    		this.HIREDATE = Util.toTimestamp(Hiredate)
    		modifiedProperty(4) = true
    	}
    	/**
    	 * Getter
    	 * @return the SAL
    	 */
    	def getSAL:BigDecimal = SAL
    	/**
    	 * Setter
    	 * @param Sal the SAL to set
    	 */
    	def setSAL( Sal:BigDecimal) :Unit = {
    		this.SAL = Sal
    		modifiedProperty(5) = true
    	}
    	/**
    	 * Setter
    	 * @param Sal the SAL to set
    	 */
    	def setSAL(Sal:Int) :Unit = {
    		this.SAL = new BigDecimal(Sal)
    		modifiedProperty(5) = true
    	}
    	/**
    	 * Setter
    	 * @param Sal the SAL to set
    	 */
    	def setSAL(Sal:Long) :Unit = {
    		this.SAL = new BigDecimal(Sal)
    		modifiedProperty(5) = true
    	}
    	/**
    	 * Setter
    	 * @param Sal the SAL to set
    	 */
    	def setSAL(Sal:Double) :Unit = {
    		this.SAL = new BigDecimal(String.valueOf(Sal))
    		modifiedProperty(5) = true
    	}
    	/**
    	 * Getter
    	 * @return the COMM
    	 */
    	def getCOMM:BigDecimal = COMM
    	/**
    	 * Setter
    	 * @param Comm the COMM to set
    	 */
    	def setCOMM( Comm:BigDecimal) :Unit = {
    		this.COMM = Comm
    		modifiedProperty(6) = true
    	}
    	/**
    	 * Setter
    	 * @param Comm the COMM to set
    	 */
    	def setCOMM(Comm:Int) :Unit = {
    		this.COMM = new BigDecimal(Comm)
    		modifiedProperty(6) = true
    	}
    	/**
    	 * Setter
    	 * @param Comm the COMM to set
    	 */
    	def setCOMM(Comm:Long) :Unit = {
    		this.COMM = new BigDecimal(Comm)
    		modifiedProperty(6) = true
    	}
    	/**
    	 * Setter
    	 * @param Comm the COMM to set
    	 */
    	def setCOMM(Comm:Double) :Unit = {
    		this.COMM = new BigDecimal(String.valueOf(Comm))
    		modifiedProperty(6) = true
    	}
    	/**
    	 * Getter
    	 * @return the DEPTNO
    	 */
    	def getDEPTNO:BigDecimal = DEPTNO
    	/**
    	 * Setter
    	 * @param Deptno the DEPTNO to set
    	 */
    	def setDEPTNO( Deptno:BigDecimal) :Unit = {
    		this.DEPTNO = Deptno
    		modifiedProperty(7) = true
    	}
    	/**
    	 * Setter
    	 * @param Deptno the DEPTNO to set
    	 */
    	def setDEPTNO(Deptno:Int) :Unit = {
    		this.DEPTNO = new BigDecimal(Deptno)
    		modifiedProperty(7) = true
    	}
    	/**
    	 * Setter
    	 * @param Deptno the DEPTNO to set
    	 */
    	def setDEPTNO(Deptno:Long) :Unit = {
    		this.DEPTNO = new BigDecimal(Deptno)
    		modifiedProperty(7) = true
    	}
    	/**
    	 * Setter
    	 * @param Deptno the DEPTNO to set
    	 */
    	def setDEPTNO(Deptno:Double) :Unit = {
    		this.DEPTNO = new BigDecimal(String.valueOf(Deptno))
    		modifiedProperty(7) = true
    	}
    	override def toString :String= {
    		var buf = new StringBuffer
    		buf.append(EMPNO).append(",")
    		buf.append(ENAME).append(",")
    		buf.append(JOB).append(",")
    		buf.append(MGR).append(",")
    		buf.append(HIREDATE).append(",")
    		buf.append(SAL).append(",")
    		buf.append(COMM).append(",")
    		buf.append(DEPTNO);
    		buf.toString
    	}
    	def toXml :Node = {
    {EMPNO}{if(ENAME != null)seedo.Util.rpxml(ENAME)}{if(JOB != null)seedo.Util.rpxml(JOB)}{MGR}{if(HIREDATE != null)seedo.Util.getFormatDate(HIREDATE)}{SAL}{COMM}{DEPTNO}	}
    	def toXmlModified :Node = {
    {if(modifiedProperty(0)){{EMPNO}}}{if(modifiedProperty(1)){{if(ENAME != null)seedo.Util.rpxml(ENAME)}}}{if(modifiedProperty(2)){{if(JOB != null)seedo.Util.rpxml(JOB)}}}{if(modifiedProperty(3)){{MGR}}}{if(modifiedProperty(4)){{if(HIREDATE != null)seedo.Util.getFormatDate(HIREDATE)}}}{if(modifiedProperty(5)){{SAL}}}{if(modifiedProperty(6)){{COMM}}}{if(modifiedProperty(7)){{DEPTNO}}}
    	}
    	override def hashCode :Int = {
    		return (EMPNO).hashCode
    	}
    	@Id
    	@Column(name="EMPNO",precision=4,nullable=false,unique=true,columnDefinition="NUMBER(4)")
    	@SequenceGenerator(name="List(KU$_LIST_FILTER_TEMP, WWV_FLOW_LOV_TEMP, WWV_FLOW_LOV_TEMP, PK_EMP)", sequenceName="List(KU$_LIST_FILTER_TEMP, WWV_FLOW_LOV_TEMP, WWV_FLOW_LOV_TEMP, PK_EMP)")
    	var EMPNO:BigDecimal = null
    	@Column(name="ENAME",length=10,nullable=true,unique=false,columnDefinition="VARCHAR2(10)")
    	var ENAME:String = null
    	@Column(name="JOB",length=9,nullable=true,unique=false,columnDefinition="VARCHAR2(9)")
    	var JOB:String = null
    	@Column(name="MGR",precision=4,nullable=true,unique=false,columnDefinition="NUMBER(4)")
    	var MGR:BigDecimal = null
    	@Column(name="HIREDATE",nullable=true,unique=false,columnDefinition="DATE")
    	var HIREDATE:Timestamp = null
    	@Column(name="SAL",precision=7,scale=2,nullable=true,unique=false,columnDefinition="NUMBER(7)")
    	var SAL:BigDecimal = null
    	@Column(name="COMM",precision=7,scale=2,nullable=true,unique=false,columnDefinition="NUMBER(7)")
    	var COMM:BigDecimal = null
    	@Column(name="DEPTNO",precision=2,nullable=true,unique=false,columnDefinition="NUMBER(2)")
    	var DEPTNO:BigDecimal = null
    	var modifiedProperty:Array[Boolean] = Array(false,false,false,false,false,false,false,false,false)
    }
    

    Post Details

    • Post Title: Seedo Scala Framework (Bean generation)
    • 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.

    コメントを残す