KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > mapper > rdb > lib > RdbScriptPMSM


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  */

25
26 package org.objectweb.jorm.mapper.rdb.lib;
27
28 import java.io.FileWriter JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 import org.objectweb.jorm.api.PException;
32 import org.objectweb.jorm.api.PExceptionIO;
33
34 /**
35  * This class is used to define a dummy PMappingStructuresManager
36  * to generate the database creation script.
37  * @author Y.Bersihand
38  */

39 public class RdbScriptPMSM extends RdbPMappingStructuresManager implements
40         RdbScriptWriter {
41
42     private boolean writeScript = false;
43     private String JavaDoc fileName;
44     
45     public RdbScriptPMSM(String JavaDoc fileName, boolean writeScript) {
46         this.fileName = fileName;
47         this.writeScript = writeScript;
48     }
49     
50     /**
51      * Creates the file.
52      * The file name MUST be specified before calling this method.
53      */

54     public void init() throws PException {
55         if (fileName == null) {
56             throw new PException("A file name must be specified before calling the init method.");
57         }
58         if (writeScript) {
59             try {
60                 //create the file
61
FileWriter JavaDoc writer = new FileWriter JavaDoc(fileName, false);
62                 writer.write("");
63                 writer.close();
64             } catch (IOException JavaDoc ioe) {
65                 throw new PExceptionIO(ioe, "Problem while creating the database creation script file.");
66             }
67         }
68     }
69     
70     public String JavaDoc getFileName() {
71         return fileName;
72     }
73     public void setFileName(String JavaDoc fileName) {
74         this.fileName = fileName;
75     }
76     
77     public boolean isWriteScript() {
78         return writeScript;
79     }
80     public void setWriteScript(boolean writeScript) {
81         this.writeScript = writeScript;
82     }
83
84 }
85
Popular Tags