JavaDoc


001    /**
002     * Copyright (c) 2003 Daffodil Software Ltd all rights reserved,
003     * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved.
004     * This program is free software; you can redistribute it and/or modify
005     * it under the terms of version 2 of the GNU General Public License as
006     * published by the Free Software Foundation.
007     * There are special exceptions to the terms and conditions of the GPL
008     * as it is applied to this software. See the GNU General Public License for more details.
009     *
010     * This program is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this prog232ram; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018     */
019    
020    package org.dbreplicator.repconsole;
021    
022    import java.sql.*;
023    
024    import java.awt.*;
025    import java.awt.event.*;
026    import javax.swing.*;
027    import javax.swing.border.*;
028    import javax.swing.tree.*;
029    
030    import org.dbreplicator.replication.*;
031    import java.rmi.*;
032    import org.dbreplicator.replication.DBHandler.AbstractDataBaseHandler;
033    import java.util.ArrayList;
034    
035    /**
036     * <p>Title: </p>
037     * <p>Description: </p>
038     * <p>Copyright: Copyright (c) 2003</p>
039     * <p>Company: </p>
040     * @author not attributable
041     * @version 1.0
042     */
043    
044    public class SelectTable
045        extends JDialog
046        implements FocusListener, KeyListener {
047      JPanel panel1 = new JPanel();
048      JButton jButton_Select = new JButton();
049      JButton jButtonDeselect = new JButton();
050    
051      DefaultListModel dlmDatabase = new DefaultListModel();
052      JList jListDatabaseTables = new JList(dlmDatabase);
053    
054      DefaultListModel dlmSelect = new DefaultListModel();
055      JList jListSelectedTables = new JList(dlmSelect);
056    
057      JLabel jLabel1 = new JLabel();
058      String pubName, conflictResolver;
059      _ReplicationServer repServer;
060      _Publication pub;
061      AbstractDataBaseHandler dbh;
062      JButton jButton1 = new JButton();
063      JButton jButton2 = new JButton();
064      JButton jButton3 = new JButton();
065      JButton jButton4 = new JButton();
066      JDialog createPublication;
067      DefaultTreeModel defaultTreeModel;
068      DefaultMutableTreeNode pubRootNode;
069      JLabel jLabel2 = new JLabel();
070      JEditorPane help = new JEditorPane();
071      JScrollPane jscrollpane_td;
072      JScrollPane jscrollpane_st;
073      Border border1;
074      TitledBorder titledBorder1;
075      TitledBorder titledBorder2;
076      Border border2;
077      String operationType;
078    
079      public SelectTable(Frame frame, String title, String operationType0,
080                         boolean modal) {
081        super(frame, title, modal);
082        try {
083          operationType = operationType0;
084          jbInit();
085          pack();
086        }
087        catch (Exception ex) {
088          JOptionPane.showMessageDialog(this, ex, "Error Message",
089                                        JOptionPane.ERROR_MESSAGE);
090          return;
091        }
092      }
093    
094      public SelectTable(DefaultTreeModel defaultTreeModel,
095                         DefaultMutableTreeNode pubRootNode, String pubName,
096                         _ReplicationServer repServer, String conflictResolver,
097                         JDialog createPublication, String operationType0) {
098    
099        this(StartRepServer.getMainFrame(), "Select Table", operationType0, true);
100        this.pubName = pubName;
101        this.repServer = repServer;
102        this.conflictResolver = conflictResolver;
103        this.createPublication = createPublication;
104        this.defaultTreeModel = defaultTreeModel;
105        this.pubRootNode = pubRootNode;
106        if (operationType.equalsIgnoreCase(RepConstants.create_Publication)) {
107          initListWithDatabaseTablesForCreate();
108          jButton4.setEnabled(false);
109        }
110        else if (operationType.equalsIgnoreCase(RepConstants.addTable_Publication)) {
111          initListWithDatabaseTablesForAdd();
112          jButton4.setEnabled(false);
113        }
114        else {
115          initListWithDatabaseTablesForDrop();
116          jButton2.setVisible(false);
117        }
118      }
119    
120      private void jbInit() throws Exception {
121        border1 = BorderFactory.createEmptyBorder();
122        titledBorder1 = new TitledBorder("");
123        titledBorder2 = new TitledBorder("");
124        border2 = new EtchedBorder(EtchedBorder.RAISED, Color.white,
125                                   new Color(148, 145, 140));
126        panel1.setLayout(null);
127    
128        jButton_Select.setBounds(new Rectangle(240, 112, 52, 22));
129        jButton_Select.setEnabled(true);
130        jButton_Select.setFont(new java.awt.Font("Dialog", 1, 15));
131        jButton_Select.setText(">>");
132        jButton_Select.addActionListener(new
133                                         SelectTable_jButton_Select_actionAdapter(this));
134        jButtonDeselect.setBounds(new Rectangle(240, 141, 52, 22));
135        jButtonDeselect.setFont(new java.awt.Font("Dialog", 1, 15));
136        jButtonDeselect.setText("<<");
137        jButtonDeselect.addActionListener(new
138                                          SelectTable_jButtonDeselect_actionAdapter(this));
139        jListDatabaseTables.setFont(new java.awt.Font("Dialog", 0, 12));
140    
141        jListDatabaseTables.addFocusListener(this);
142        jListSelectedTables.addFocusListener(this);
143    
144        jListSelectedTables.setFont(new java.awt.Font("Dialog", 0, 12));
145    
146        jLabel1.setFont(new java.awt.Font("Serif", 3, 25));
147        jLabel1.setForeground(SystemColor.infoText);
148        jLabel1.setText("Select Tables For Publication");
149        jLabel1.setBounds(new Rectangle(100, 4, 324, 27));
150    
151        jButton1.setBounds(new Rectangle(90, 264, 81, 26));
152        jButton1.setEnabled(true);
153        jButton1.setFont(new java.awt.Font("Dialog", 1, 12));
154        jButton1.setFocusPainted(true);
155        jButton1.setText("<Back");
156        if (operationType != RepConstants.create_Publication) {
157          jButton1.setVisible(false);
158        }
159    
160        jButton1.addActionListener(new SelectTable_jButton1_actionAdapter(this));
161        jButton2.setBounds(new Rectangle(178, 264, 81, 26));
162        jButton2.setEnabled(true);
163        jButton2.setFont(new java.awt.Font("Dialog", 1, 12));
164        jButton2.setFocusPainted(true);
165        jButton2.setText("Next>");
166        jButton2.addActionListener(new SelectTable_jButton2_actionAdapter(this));
167    
168        jButton3.setBounds(new Rectangle(354, 263, 81, 26));
169        jButton3.setFont(new java.awt.Font("Dialog", 1, 12));
170        jButton3.setActionCommand("Cancle");
171        jButton3.setFocusPainted(true);
172        jButton3.setText("Cancel");
173        jButton3.addActionListener(new SelectTable_jButton3_actionAdapter(this));
174    
175        jButton4.setBounds(new Rectangle(266, 264, 81, 26));
176        jButton4.setEnabled(true);
177        jButton4.setFont(new java.awt.Font("Dialog", 1, 12));
178        jButton4.setFocusPainted(true);
179        jButton4.setText("Finish");
180        jButton4.addActionListener(new SelectTable_jButton4_actionAdapter(this));
181    
182        jLabel2.setFont(new java.awt.Font("Dialog", 1, 11));
183        jLabel2.setBorder(border2);
184        jLabel2.setText("");
185        jLabel2.setBounds(new Rectangle(10, 55, 510, 165));
186    
187        help.setBackground(UIManager.getColor("Button.background"));
188        help.setEnabled(true);
189        help.setFont(new java.awt.Font("Dialog", 2, 12));
190        help.setDoubleBuffered(false);
191        help.setRequestFocusEnabled(false);
192        help.setDisabledTextColor(Color.black);
193        help.setEditable(false);
194        if (operationType.equalsIgnoreCase(RepConstants.dropTable_Publication))
195          help.setText("Select tables to be dropped from published");
196        else
197          help.setText("Select tables to be published");
198    
199        help.setBounds(new Rectangle(9, 221, 399, 38));
200    
201        jscrollpane_td = new JScrollPane(jListDatabaseTables);
202        jscrollpane_td.setFont(new java.awt.Font("Dialog", 1, 11));
203            //bjt
204        jscrollpane_td.setBounds(new Rectangle(21, 59, 210, 153));
205    
206        jscrollpane_st = new JScrollPane(jListSelectedTables);
207            //bjt
208        jscrollpane_st.setBounds(new Rectangle(301, 59, 210, 153));
209    
210        titledBorder2.setTitleFont(new java.awt.Font("Dialog", 0, 12));
211        titledBorder1.setTitleFont(new java.awt.Font("Dialog", 0, 12));
212        getContentPane().add(panel1);
213    
214        panel1.add(jLabel1, null);
215        panel1.add(jLabel2, null);
216        panel1.add(jscrollpane_td);
217        panel1.add(jscrollpane_st);
218        panel1.add(jButton_Select, null);
219        panel1.add(jButtonDeselect, null);
220        panel1.add(help, null);
221        panel1.add(jButton4, null);
222        panel1.add(jButton3, null);
223        panel1.add(jButton1, null);
224        panel1.add(jButton2, null);
225    
226    //    jListDatabaseTables.grabFocus();
227    
228        jscrollpane_st.setBorder(new TitledBorder("Selected Tables"));
229        jscrollpane_td.setBorder(new TitledBorder("Tables in Database"));
230      }
231    
232      void initListWithDatabaseTablesForCreate() {
233        ResultSet rsTableNames = null;
234        try {
235          jListDatabaseTables.setAutoscrolls(true);
236          Connection connection = repServer.getDefaultConnection();
237          rsTableNames = connection.getMetaData().getTables(null, null,
238              "%", new String[] {"TABLE"});
239          int i = 0;
240          String databaseProductName = connection.getMetaData().
241              getDatabaseProductName();
242    
243          while (rsTableNames.next()) {
244            if (!((databaseProductName.equalsIgnoreCase(Utility.FireBird_ProductName)) || (databaseProductName.equalsIgnoreCase(Utility.MySQL_ProductName)))) {
245              if (!rsTableNames.getString("TABLE_SCHEM").equalsIgnoreCase("SYSTEM")) {
246                if (rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
247                    RepConstants.publication_TableName) ||
248                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
249                    RepConstants.subscription_TableName) ||
250                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
251                    RepConstants.bookmark_TableName) ||
252                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
253                    RepConstants.rep_TableName) ||
254                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
255                    RepConstants.log_Table) ||
256                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
257                    RepConstants.schedule_Table) ||
258                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
259                    RepConstants.ignoredColumns_Table) ||
260                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
261                    RepConstants.trackReplicationTablesUpdation_Table) ||
262                    /////////Here consider Rep_Shadow ... specifically....
263                    rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
264                    "rep_shadow_") ||
265                    rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
266                    "r_s_")) {
267    
268    
269                  continue;
270                }
271    
272                dlmDatabase.addElement(rsTableNames.getString("TABLE_SCHEM") + "." +
273                                       rsTableNames.getString("TABLE_NAME"));
274    
275              }
276            }
277            else {
278              if (rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
279                  RepConstants.publication_TableName) ||
280                  rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
281                  RepConstants.subscription_TableName) ||
282                  rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
283                  RepConstants.bookmark_TableName) ||
284                  rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
285                  RepConstants.rep_TableName) ||
286                  rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
287                  RepConstants.log_Table) ||
288                  rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
289                  RepConstants.schedule_Table) ||
290                  rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
291                  RepConstants.trackReplicationTablesUpdation_Table) ||
292                  rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
293                  RepConstants.ignoredColumns_Table) ||
294                  /////////Here consider Rep_Shadow ... specifically....
295                  rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
296                  "rep_shadow_") ||
297                  rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
298                  "r_s_")) {
299                continue;
300              }
301              dlmDatabase.addElement(rsTableNames.getString("TABLE_NAME"));
302            }
303          }
304        }
305        catch (SQLException ex) {
306          RepConstants.writeERROR_FILE(ex);
307          JOptionPane.showMessageDialog(this, ex, "Error Message",
308                                        JOptionPane.ERROR_MESSAGE);
309          return;
310        }
311        finally {
312          try {
313            if (rsTableNames != null) {
314              rsTableNames.close();
315            }
316          }
317          catch (SQLException ex1) {
318          }
319        }
320      }
321    
322      void initListWithDatabaseTablesForAdd() {
323        ResultSet rsPublishedTable = null;
324        ResultSet rsTableNames = null;
325        Statement stt = null;
326        try {
327          jListDatabaseTables.setAutoscrolls(true);
328          Connection connection = repServer.getDefaultConnection();
329          rsTableNames = connection.getMetaData().getTables(null, null, "%",
330              new String[] {"TABLE"});
331          int i = 0;
332          //select published tables comapre them to show in case of drop and ignoring in case of adding tables
333    
334          stt = connection.createStatement();
335          pub = repServer.getPublication(pubName);
336          dbh = Utility.getDatabaseHandler( ( (Publication) pub).getConnectionPool(),
337                                           pubName);
338          StringBuffer sb = new StringBuffer();
339          sb.append("select ").append(RepConstants.repTable_tableName2).
340              append(
341              " from ").append(dbh.getRepTableName()).append(" where ")
342              .append(RepConstants.repTable_pubsubName1).append(" = '")
343              .append(pubName).append("'");
344    //System.out.println(sb.toString());
345          rsPublishedTable = stt.executeQuery(sb.toString());
346          ArrayList publishedTable = new ArrayList();
347          while (rsPublishedTable.next()) {
348            publishedTable.add(rsPublishedTable.getString(1).substring(
349                rsPublishedTable.getString(1).indexOf(".") + 1,
350                rsPublishedTable.getString(1).length()));
351          }
352          dbh = Utility.getDatabaseHandler( ( (Publication) pub).getConnectionPool(),
353                                           pubName);
354          while (rsTableNames.next()) {
355            boolean flag = false;
356    
357    //System.out.println("publishedTable " +publishedTable.get(j));
358    //System.out.println("rsTableNames.getString(TABLE_NAME) " +rsTableNames.getString("TABLE_NAME"));
359    System.out.println(" dbh.getvendorName() ::  "+dbh.getvendorName());
360            if(!((dbh.getvendorName() == Utility.DataBase_Firebird) || (dbh.getvendorName()== Utility.DataBase_MySQL ))) {
361              for (int j = 0; j < publishedTable.size(); j++) {
362                if (!rsTableNames.getString("TABLE_SCHEM").equalsIgnoreCase(
363                    "SYSTEM")) {
364                  if (rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
365                      RepConstants.publication_TableName) ||
366                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
367                      RepConstants.subscription_TableName) ||
368                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
369                      RepConstants.bookmark_TableName) ||
370                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
371                      RepConstants.rep_TableName) ||
372                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
373                      RepConstants.log_Table) ||
374                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
375                      RepConstants.schedule_Table) ||
376                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
377                      RepConstants.trackReplicationTablesUpdation_Table) ||
378                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
379                      RepConstants.ignoredColumns_Table) ||
380                      /////////Here consider Rep_Shadow ... specifically....
381                      rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
382                      "rep_shadow_") ||
383                      rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
384                      "r_s_") ||
385                      //here already published tables are ignored
386                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase( (
387                      String)
388                      publishedTable.get(j))) {
389                    flag = true;
390                    break;
391                  }
392                }
393              }
394              if (!flag)
395                dlmDatabase.addElement(rsTableNames.getString("TABLE_SCHEM") +
396                                       "." +
397                                       rsTableNames.getString("TABLE_NAME"));
398    
399            }
400            else {
401              for (int j = 0; j < publishedTable.size(); j++) {
402                if (rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
403                    RepConstants.publication_TableName) ||
404                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
405                    RepConstants.subscription_TableName) ||
406                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
407                    RepConstants.bookmark_TableName) ||
408                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
409                    RepConstants.rep_TableName) ||
410                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
411                    RepConstants.log_Table) ||
412                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
413                    RepConstants.schedule_Table) ||
414                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
415                    RepConstants.trackReplicationTablesUpdation_Table) ||
416                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
417                    RepConstants.ignoredColumns_Table) ||
418                    /////////Here consider Rep_Shadow ... specifically....
419                    rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
420                    "rep_shadow_") ||
421                    rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
422                    "r_s_") ||
423                    //here already published tables are ignored
424                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase( (String)
425                    publishedTable.get(j))) {
426                  flag = true;
427                  break;
428                }
429              }
430              if (!flag)
431                dlmDatabase.addElement(rsTableNames.getString("TABLE_NAME"));
432    
433            }
434    
435          }
436        }
437    
438        catch (SQLException ex) {
439          RepConstants.writeERROR_FILE(ex);
440          JOptionPane.showMessageDialog(this, ex, "Error Message",
441                                        JOptionPane.ERROR_MESSAGE);
442          return;
443        }
444        catch (RepException ex) {
445          RepConstants.writeERROR_FILE(ex);
446          JOptionPane.showMessageDialog(this, ex, "Error Message",
447                                        JOptionPane.ERROR_MESSAGE);
448          return;
449        }
450        catch (RemoteException ex) {
451          RepConstants.writeERROR_FILE(ex);
452          JOptionPane.showMessageDialog(this, ex, "Error Message",
453                                        JOptionPane.ERROR_MESSAGE);
454          return;
455        }
456    
457        finally {
458          try {
459            if (rsTableNames != null) {
460              rsTableNames.close();
461            }
462            if (rsPublishedTable != null) {
463              rsPublishedTable.close();
464            }
465            if (stt != null)
466              stt.close();
467          }
468          catch (SQLException ex1) {
469          }
470        }
471      }
472    
473      void initListWithDatabaseTablesForDrop() {
474        ResultSet rsPublishedTable = null;
475        ResultSet rsTableNames = null;
476        Statement stt = null;
477        try {
478          jListDatabaseTables.setAutoscrolls(true);
479          Connection connection = repServer.getDefaultConnection();
480          rsTableNames = connection.getMetaData().getTables(null, null,
481              "%", new String[] {"TABLE"});
482          int i = 0;
483          //select published tables comapre them to show in case of drop and ignoring in case of adding tables
484    
485          stt = connection.createStatement();
486          pub = repServer.getPublication(pubName);
487          dbh = Utility.getDatabaseHandler( ( (Publication) pub).getConnectionPool(),
488                                           pubName);
489    
490          StringBuffer sb = new StringBuffer();
491          sb.append("select ").append(RepConstants.repTable_tableName2).
492              append(
493              " from ").append(dbh.getRepTableName()).append(" where ")
494              .append(RepConstants.repTable_pubsubName1).append(" = '")
495              .append(pubName).append("'");
496    //System.out.println(sb.toString());
497          rsPublishedTable = stt.executeQuery(sb.toString());
498          ArrayList publishedTable = new ArrayList();
499          ArrayList tablesAddedToList = new ArrayList();
500    
501          while (rsPublishedTable.next()) {
502            publishedTable.add(rsPublishedTable.getString(1).substring(
503                rsPublishedTable.getString(1).indexOf(".") + 1,
504                rsPublishedTable.getString(1).length()));
505          }
506    
507          while (rsTableNames.next()) {
508            boolean flag = true;
509            for (int j = 0; j < publishedTable.size(); j++) {
510                if (!((dbh.getvendorName() == Utility.DataBase_Firebird) ||(dbh.getvendorName() == Utility.DataBase_MySQL ))) {
511                if (!rsTableNames.getString("TABLE_SCHEM").equalsIgnoreCase(
512                    "SYSTEM")) {
513    //System.out.println(rsTableNames.getString("TABLE_NAME").equalsIgnoreCase((String)publishedTable.get(j)));
514                  if (rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
515                      RepConstants.publication_TableName) ||
516                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
517                      RepConstants.subscription_TableName) ||
518                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
519                      RepConstants.bookmark_TableName) ||
520                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
521                      RepConstants.rep_TableName) ||
522                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
523                      RepConstants.log_Table) ||
524                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
525                      RepConstants.schedule_Table) ||
526                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
527                      RepConstants.ignoredColumns_Table) ||
528                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
529                      RepConstants.trackReplicationTablesUpdation_Table) ||
530                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
531                      RepConstants.trackReplicationTablesUpdation_Table) ||
532                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
533                      RepConstants.ignoredColumns_Table) ||
534                      /////////Here consider Rep_Shadow ... specifically....
535                      rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
536                      "rep_shadow_") ||
537                      rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
538                      "r_s_") || !
539                      rsTableNames.getString("TABLE_NAME").equalsIgnoreCase( (
540                      String) publishedTable.get(j))) {
541                    flag = false;
542                  }
543                  else
544                    flag = true;
545                  if (flag) {
546                    tablesAddedToList.add(rsTableNames.getString("TABLE_SCHEM") +
547                                          "." +
548                                          rsTableNames.getString("TABLE_NAME"));
549                    continue;
550                  }
551    
552                }
553              }
554              else {
555                if (rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
556                    RepConstants.publication_TableName) ||
557                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
558                    RepConstants.subscription_TableName) ||
559                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
560                    RepConstants.bookmark_TableName) ||
561                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
562                    RepConstants.rep_TableName) ||
563                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
564                    RepConstants.log_Table) ||
565                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
566                    RepConstants.schedule_Table) ||
567                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
568                    RepConstants.trackReplicationTablesUpdation_Table) ||
569                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase(
570                    RepConstants.ignoredColumns_Table) ||
571    
572                    /////////Here consider Rep_Shadow ... specifically....
573                    rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
574                    "rep_shadow_") ||
575                    rsTableNames.getString("TABLE_NAME").toLowerCase().startsWith(
576                    "r_s_") || !
577                    rsTableNames.getString("TABLE_NAME").equalsIgnoreCase( (String)
578                    publishedTable.get(j))) {
579                  flag = false;
580                }
581                else
582                  flag = true;
583                if (flag) {
584                  tablesAddedToList.add(rsTableNames.getString("TABLE_NAME"));
585                  continue;
586                }
587    
588              }
589            }
590          }
591          for (int j = 0; j < tablesAddedToList.size(); j++)
592            dlmDatabase.addElement(tablesAddedToList.get(j));
593        }
594    
595        catch (SQLException ex) {
596          RepConstants.writeERROR_FILE(ex);
597          JOptionPane.showMessageDialog(this, ex, "Error Message",
598                                        JOptionPane.ERROR_MESSAGE);
599          return;
600        }
601        catch (RepException ex) {
602          RepConstants.writeERROR_FILE(ex);
603          JOptionPane.showMessageDialog(this, ex, "Error Message",
604                                        JOptionPane.ERROR_MESSAGE);
605          return;
606        }
607        catch (RemoteException ex) {
608          RepConstants.writeERROR_FILE(ex);
609          JOptionPane.showMessageDialog(this, ex, "Error Message",
610                                        JOptionPane.ERROR_MESSAGE);
611          return;
612        }
613    
614        finally {
615          try {
616            if (rsTableNames != null) {
617              rsTableNames.close();
618            }
619            if (rsPublishedTable != null) {
620              rsPublishedTable.close();
621            }
622            if (stt != null)
623              stt.close();
624          }
625          catch (SQLException ex1) {
626          }
627        }
628      }
629    
630      void jButton_Select_actionPerformed(ActionEvent e) {
631        Object[] tableNames = jListDatabaseTables.getSelectedValues();
632        for (int i = 0; i < tableNames.length; i++) {
633          String tableNameForPublishing = (String) tableNames[i];
634          if (! (tableNameForPublishing == null ||
635                 tableNameForPublishing.equalsIgnoreCase(""))) {
636            dlmDatabase.removeElement(tableNameForPublishing);
637            dlmSelect.addElement(tableNameForPublishing);
638          }
639        }
640      }
641    
642      void jButtonDeselect_actionPerformed(ActionEvent e) {
643        Object[] tableNames = jListSelectedTables.getSelectedValues();
644        for (int i = 0; i < tableNames.length; i++) {
645          String deselectTableNameForPublishing = (String) tableNames[i];
646          if (! (deselectTableNameForPublishing == null ||
647                 deselectTableNameForPublishing.equalsIgnoreCase(""))) {
648            dlmDatabase.addElement(deselectTableNameForPublishing);
649            dlmSelect.removeElement(deselectTableNameForPublishing);
650          }
651        }
652      }
653    
654      void jButton3_actionPerformed(ActionEvent e) {
655        hide();
656      }
657    
658      void jButton2_actionPerformed(ActionEvent e) {
659        int selectedNoOfTables = dlmSelect.getSize();
660        try {
661          if (selectedNoOfTables == 0) {
662            throw new RepException("REP012", new Object[] {pubName});
663          }
664          String[] tables = new String[selectedNoOfTables];
665          for (int i = 0; i < selectedNoOfTables; i++) {
666            tables[i] = ( (String) dlmSelect.get(i));
667          }
668    
669          if (operationType.equalsIgnoreCase(RepConstants.create_Publication)) {
670            try {
671              pub = repServer.createPublication(pubName, tables);
672              pub.setConflictResolver(conflictResolver);
673               setFilterClause(tables);
674            }
675            catch (RepException ex1) {
676              if (ex1.getRepCode().equalsIgnoreCase("REP0205")) {
677    
678                    callSelectTableToBreakCycle(tables, ex1);
679    
680              }
681              else {
682                throw ex1;
683              }
684            }
685          }
686          else {
687            pub = repServer.getPublication(pubName);
688          }
689          if (operationType.equalsIgnoreCase(RepConstants.addTable_Publication)) {
690            setFilterClause(tables);
691          }
692        }
693        catch (RepException ex) {
694          JOptionPane.showMessageDialog(this, ex, "Error Message",
695                                        JOptionPane.ERROR_MESSAGE);
696          return;
697        }
698        catch (RemoteException ex) {
699          JOptionPane.showMessageDialog(this, ex, "Error Message",
700                                        JOptionPane.ERROR_MESSAGE);
701          return;
702        }
703    
704      }
705    
706      void jButton1_actionPerformed(ActionEvent e) {
707        hide();
708        createPublication.show();
709      }
710    
711      void jButton4_actionPerformed(ActionEvent e) {
712        int selectedNoOfTables = dlmSelect.getSize();
713        try {
714          if (selectedNoOfTables == 0) {
715            throw new RepException("REP012", new Object[] {pubName});
716          }
717          String[] tables = new String[selectedNoOfTables];
718          for (int i = 0; i < selectedNoOfTables; i++) {
719            tables[i] = ( (String) dlmSelect.get(i));
720          }
721          _Publication pub = null;
722          pub = repServer.getPublication(pubName);
723    
724          if (operationType.equalsIgnoreCase(RepConstants.dropTable_Publication)) {
725            pub.dropTableFromPublication(tables);
726          }
727          JOptionPane.showMessageDialog(this, "Publication Updated Successfully",
728                                        "Success",
729                                        JOptionPane.INFORMATION_MESSAGE);
730          hide();
731        }
732        catch (RepException ex) {
733          JOptionPane.showMessageDialog(this, ex, "Error Message",
734                                        JOptionPane.ERROR_MESSAGE);
735          return;
736        }
737        catch (RemoteException ex) {
738          JOptionPane.showMessageDialog(this, ex, "Error Message",
739                                        JOptionPane.ERROR_MESSAGE);
740          return;
741        }
742      }
743    
744      public void keyTyped(KeyEvent keyEvent) {
745      }
746    
747      public void keyPressed(KeyEvent keyEvent) {
748      }
749    
750      public void keyReleased(KeyEvent keyEvent) {
751      }
752    
753      public void focusGained(FocusEvent fe) {
754        if ( ( (JList) fe.getSource()).equals(jListDatabaseTables)) {
755          if (operationType.equalsIgnoreCase(RepConstants.dropTable_Publication))
756            help.setText("Select tables to be dropped from published");
757          else
758            help.setText("Select tables to be published");
759        }
760        if ( ( (JList) fe.getSource()).equals(jListSelectedTables)) {
761          help.setText("Your selected tables  are in this list ");
762    
763        }
764    
765      }
766    
767      public void focusLost(FocusEvent fe) {
768        if (operationType == RepConstants.dropTable_Publication) {
769          jButton4.setEnabled(true);
770        }
771        jButton2.setEnabled(true);
772        if (jListDatabaseTables.getSelectedIndices().length < 0) {
773          jButton2.setEnabled(false);
774    
775        }
776    
777      }
778    
779    
780      private void callSelectTableToBreakCycle(String[] tables,RepException exception) throws
781          RepException {
782        boolean cycleInTables=true;
783        ArrayList selectedBreakCycleRelation=new ArrayList();
784        while(cycleInTables){
785        if (exception.getRepCode().equalsIgnoreCase("REP0205")) {
786          int userResponse = JOptionPane.showConfirmDialog(this, exception,
787              "Error Message", JOptionPane.ERROR_MESSAGE);
788          //if pressed OK
789          if (userResponse == 0) {
790            ArrayList tableNamesInCycle = repServer.getTablesInCycle();
791    
792            SelectTableToBreakCycle selectTableToBreakCycle = new
793                SelectTableToBreakCycle(defaultTreeModel, pubRootNode, pubName,
794                                        repServer, conflictResolver,
795                                        createPublication, tableNamesInCycle,selectedBreakCycleRelation);
796    
797            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
798            Dimension frameSize = new Dimension(440, 355);
799            selectTableToBreakCycle.setBounds( (screenSize.width - frameSize.width) /
800                                              2,
801                                              (screenSize.height - frameSize.height) /
802                                              2, 535, 355);
803          if(this instanceof SelectTable){
804            this.hide();
805          }
806           selectTableToBreakCycle.show();
807           //get cycle break list
808          ArrayList tableToBreakCycle = selectTableToBreakCycle.
809                getSelectedRelationToBreakCycle();
810    
811            for (int i = 0; i < tableToBreakCycle.size(); i++) {
812              String relation=(String)tableToBreakCycle.get(i);
813    //          System.out.println("relation:"+relation);
814              if(!selectedBreakCycleRelation.contains(relation)){
815    //            System.out.println("adding relation:"+relation);
816                selectedBreakCycleRelation.add(relation);
817              }
818            }
819    //        call createPublication
820            try {
821              String[] selectedBreakCycleRelation0 = new String[selectedBreakCycleRelation.size()];
822              selectedBreakCycleRelation.toArray(selectedBreakCycleRelation0);
823    //          for (int i = 0; i < selectedBreakCycleRelation0.length; i++) {
824    //            System.out.println("selectedBreakCycleRelation0 ::  "+selectedBreakCycleRelation0[i]);
825    //          }
826              pub = repServer.createPublication(pubName, tables, selectedBreakCycleRelation0);
827              cycleInTables=false;
828              pub.setConflictResolver(conflictResolver);
829              setFilterClause(tables);
830            }
831            catch (RepException ex1) {
832              if (!ex1.getRepCode().equalsIgnoreCase("REP0205")) {
833                throw ex1;
834              }
835            }
836          }
837          else {
838            return;
839          }
840        }
841          else {
842            return;
843          }
844        }
845        }
846    
847        private void setFilterClause(String[] tables){
848          SetFilterClause setFilterClause = new SetFilterClause(repServer,
849               defaultTreeModel, pubRootNode, pubName, pub, tables, this,
850               operationType);
851           Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
852           Dimension frameSize = new Dimension(430, 300);
853           setFilterClause.setBounds( (screenSize.width - frameSize.width) / 2,
854                                     (screenSize.height - frameSize.height) / 2,
855                                     430,
856                                     300);
857           hide();
858           setFilterClause.show();
859        }
860    }
861    
862    class SelectTable_jButton_Select_actionAdapter
863        implements java.awt.event.ActionListener {
864      SelectTable adaptee;
865    
866      SelectTable_jButton_Select_actionAdapter(SelectTable adaptee) {
867        this.adaptee = adaptee;
868      }
869    
870      public void actionPerformed(ActionEvent e) {
871        adaptee.jButton_Select_actionPerformed(e);
872      }
873    }
874    
875    class SelectTable_jButtonDeselect_actionAdapter
876        implements java.awt.event.ActionListener {
877      SelectTable adaptee;
878    
879      SelectTable_jButtonDeselect_actionAdapter(SelectTable adaptee) {
880        this.adaptee = adaptee;
881      }
882    
883      public void actionPerformed(ActionEvent e) {
884        adaptee.jButtonDeselect_actionPerformed(e);
885      }
886    }
887    
888    class SelectTable_jButton3_actionAdapter
889        implements java.awt.event.ActionListener {
890      SelectTable adaptee;
891    
892      SelectTable_jButton3_actionAdapter(SelectTable adaptee) {
893        this.adaptee = adaptee;
894      }
895    
896      public void actionPerformed(ActionEvent e) {
897        adaptee.jButton3_actionPerformed(e);
898      }
899    }
900    
901    class SelectTable_jButton2_actionAdapter
902        implements java.awt.event.ActionListener {
903      SelectTable adaptee;
904    
905      SelectTable_jButton2_actionAdapter(SelectTable adaptee) {
906        this.adaptee = adaptee;
907      }
908    
909      public void actionPerformed(ActionEvent e) {
910        adaptee.jButton2_actionPerformed(e);
911      }
912    }
913    
914    class SelectTable_jButton1_actionAdapter
915        implements java.awt.event.ActionListener {
916      SelectTable adaptee;
917    
918      SelectTable_jButton1_actionAdapter(SelectTable adaptee) {
919        this.adaptee = adaptee;
920      }
921    
922      public void actionPerformed(ActionEvent e) {
923        adaptee.jButton1_actionPerformed(e);
924      }
925    }
926    
927    class SelectTable_jButton4_actionAdapter
928        implements java.awt.event.ActionListener {
929      SelectTable adaptee;
930    
931      SelectTable_jButton4_actionAdapter(SelectTable adaptee) {
932        this.adaptee = adaptee;
933      }
934    
935      public void actionPerformed(ActionEvent e) {
936        adaptee.jButton4_actionPerformed(e);
937      }
938    }





























































Powered by Drupal - Theme by Danger4k