豆沙包

…… …… 所学 所写 所想 所做 所悟…… ……

GSQL

GSQL使用户能非常简单地访问/修改关系型数据库。
举例:
/**
 * Test to verify valid construction of default DDL
 * 
 * @author <a href="mailto:jeremy.rayner@bigfoot.com">Jeremy Rayner</a>
 * @version $Revision: 1.2 $
 
*/

package org.javanicus.gsql

import java.io.
*

class SqlGeneratorTest extends GroovyTestCase {
    property database
    property sqlGenerator
              
    
void setUp() {
        typeMap 
= new TypeMap()          
        build 
= new RelationalBuilder(typeMap)
        sqlGenerator 
= new SqlGenerator(typeMap,System.getProperty( "line.separator""\n" ))
                  
        database 
= build.database(name:'genealogy'{
          table(name:
'event'{
              column(name:
'event_id', type:'integer', size:10, primaryKey:true, required:true)
              column(name:
'description', type:'varchar', size:30)          
          }

          table(name:
'individual'{
            column(name:
'individual_id', type:'integer', size:10, required:true, primaryKey:true, autoIncrement:true)
            column(name:
'surname', type:'varchar', size:15, required:true)
            column(name:
'event_id', type:'integer', size:10)
            foreignKey(foreignTable:
'event'{
                reference(local:
'event_id',foreign:'event_id')
            }

            index(name:
'surname_index'{
                indexColumn(name:
'surname')
            }

          }

        }

    }

    
    
void testGenerateDDL() {
        testWriter 
= new PrintWriter(new FileOutputStream("SqlGeneratorTest.sql"))
        sqlGenerator.writer 
= testWriter
        sqlGenerator.createDatabase(database,
true)
        testWriter.flush()
   }


}

posted on 2005-02-28 10:26 carob 阅读(863) 评论(0)  编辑  收藏 所属分类: Groovy


只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问