001: package org.jsqltool.replication;
002:
003: import java.io.*;
004: import javax.swing.*;
005: import java.util.*;
006: import org.jsqltool.utils.Options;
007:
008: /**
009: * <p>Title: JSqlTool Project</p>
010: * <p>Description: This Value Object contains replication settings used in a Data Replication process.
011: * </p>
012: * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
013: *
014: * <p> This file is part of JSqlTool project.
015: * This library is free software; you can redistribute it and/or
016: * modify it under the terms of the (LGPL) Lesser General Public
017: * License as published by the Free Software Foundation;
018: *
019: * GNU LESSER GENERAL PUBLIC LICENSE
020: * Version 2.1, February 1999
021: *
022: * This library is distributed in the hope that it will be useful,
023: * but WITHOUT ANY WARRANTY; without even the implied warranty of
024: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
025: * Library General Public License for more details.
026: *
027: * You should have received a copy of the GNU Library General Public
028: * License along with this library; if not, write to the Free
029: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
030: *
031: * The author may be contacted at:
032: * maurocarniel@tin.it</p>
033: *
034: * @author Mauro Carniel
035: * @version 1.0
036: */
037: public class ReplicationProfile {
038:
039: private String name;
040: private String sourceDatabase;
041: private String destDatabase;
042: private java.util.ArrayList tablesList;
043: private boolean recreateTablesContent;
044:
045: public ReplicationProfile() {
046: }
047:
048: public String getName() {
049: return name;
050: }
051:
052: public void setName(String name) {
053: this .name = name;
054: }
055:
056: public String getSourceDatabase() {
057: return sourceDatabase;
058: }
059:
060: public void setSourceDatabase(String sourceDatabase) {
061: this .sourceDatabase = sourceDatabase;
062: }
063:
064: public String getDestDatabase() {
065: return destDatabase;
066: }
067:
068: public void setDestDatabase(String destDatabase) {
069: this .destDatabase = destDatabase;
070: }
071:
072: public java.util.ArrayList getTablesList() {
073: return tablesList;
074: }
075:
076: public void setTablesList(java.util.ArrayList tablesList) {
077: this .tablesList = tablesList;
078: }
079:
080: public boolean isRecreateTablesContent() {
081: return recreateTablesContent;
082: }
083:
084: public void setRecreateTablesContent(boolean recreateTablesContent) {
085: this .recreateTablesContent = recreateTablesContent;
086: }
087:
088: /**
089: * Load replication profile file (profile/filename.rep)
090: */
091: public void loadProfile(JInternalFrame parent, File file,
092: ArrayList profiles, Vector profileNames) {
093: try {
094: BufferedReader br = new BufferedReader(
095: new InputStreamReader(new FileInputStream(file)));
096: br.readLine(); // version...
097: this .setName(br.readLine());
098: this .setSourceDatabase(br.readLine());
099: this .setDestDatabase(br.readLine());
100: this .setRecreateTablesContent(br.readLine().toLowerCase()
101: .equals("true"));
102:
103: String line = null;
104: ArrayList tables = new ArrayList();
105: while ((line = br.readLine()) != null) {
106: tables.add(line);
107: }
108: this .setTablesList(tables);
109:
110: br.close();
111:
112: profiles.add(this );
113: profileNames.add(name);
114:
115: } catch (Exception ex) {
116: ex.printStackTrace();
117: JOptionPane
118: .showMessageDialog(
119: parent,
120: Options
121: .getInstance()
122: .getResource(
123: "error on loading replication profile file.")
124: + ":\n" + ex.getMessage(),
125: Options.getInstance().getResource("error"),
126: JOptionPane.ERROR_MESSAGE);
127: }
128: }
129:
130: public void saveProfile(JFrame parent, boolean isEdit) {
131: try {
132: PrintWriter pw = new PrintWriter(new FileOutputStream(
133: new File("profile/" + name.replace(' ', '_')
134: + ".rep")));
135:
136: // save replicaton properties...
137: pw.println("VERSION 1.0.4");
138: pw.println(this .getName());
139: pw.println(this .getSourceDatabase());
140: pw.println(this .getDestDatabase());
141: pw.println(this .isRecreateTablesContent() ? "true"
142: : "false");
143: for (int i = 0; i < this .tablesList.size(); i++)
144: pw.println(this .tablesList.get(i).toString());
145:
146: pw.close();
147:
148: } catch (Exception ex) {
149: ex.printStackTrace();
150: JOptionPane
151: .showMessageDialog(
152: parent,
153: Options
154: .getInstance()
155: .getResource(
156: "error on saving replication profile file.")
157: + ":\n" + ex.getMessage(),
158: Options.getInstance().getResource("error"),
159: JOptionPane.ERROR_MESSAGE);
160: }
161: }
162:
163: }
|