Пример #1
0
 public List<String> getUnsynchronizedTablesList()
     throws ReplicatorConnectionException, ReplicatorException {
   List<String> tables = new ArrayList<String>();
   try {
     Connection remoteConnection = remoteConnector.getNewConnection();
     Connection localConnection = null;
     try {
       localConnection = localConnector.getNewConnection();
       int localCount = getTableRecordsCount(localConnection, localSis.getStudentsTable());
       int remoteCount = getTableRecordsCount(remoteConnection, remoteSis.getStudentsTable());
       if (localCount != remoteCount) {
         tables.add(remoteSis.getStudentsTable());
       }
       int staffLocalCount = getTableRecordsCount(localConnection, "users");
       int staffRemoteCount = getTableRecordsCount(remoteConnection, "users");
       if (staffLocalCount != staffRemoteCount) {
         tables.add("users");
       }
       return tables;
     } catch (JdbcConnectorException e) {
       throw new ReplicatorException("Couldn't connect to local SIS");
     } finally {
       JdbcUtils.closeIfNeededSilently(remoteConnection);
       JdbcUtils.closeIfNeededSilently(localConnection);
     }
   } catch (JdbcConnectorException e) {
     throw new ReplicatorConnectionException("Couldn't connect to remote SIS");
   }
 }
Пример #2
0
  public void replicate(List<String> tables) throws ReplicatorException {
    Connection remoteConnection = null;
    try {
      remoteConnection = remoteConnector.getNewConnection();
      Connection localConnection = null;
      try {
        localConnection = localConnector.getNewConnection();
        localConnection.setAutoCommit(false);
        clean(localConnection, localSis.getStudentsTable());
        replicateStudentDataFromRemoteSis(remoteConnection, localConnection);

        clean(localConnection, "users");
        replicateStaffDataFromRemoteSis(remoteConnection, localConnection);

        localConnection.commit();
      } catch (SQLException e) {
        JdbcUtils.rollbackSilently(localConnection);
        throw new ReplicatorException("Couldn't transfer data from remote to local SIS", e);
      } catch (JdbcConnectorException e) {
        throw new ReplicatorException("Couldn't connect to local SIS");
      } finally {
        JdbcUtils.closeIfNeededSilently(localConnection);
      }
    } catch (JdbcConnectorException ex) {
      throw new ReplicatorConnectionException("Couldn't connect to remote SIS", ex);
    } finally {
      JdbcUtils.closeIfNeededSilently(remoteConnection);
    }
  }
Пример #3
0
 private void fillStatement(PreparedStatement insertStatement, ResultSet resultSet)
     throws SQLException {
   insertStatement.setString(1, resultSet.getString(1));
   insertStatement.setString(2, resultSet.getString(2));
   insertStatement.setString(3, resultSet.getString(3));
   int resultSetCoulmnPosition = 4;
   if (isNotEmpty(remoteSis.activeFieldName())) {
     insertStatement.setString(
         resultSetCoulmnPosition, resultSet.getString(resultSetCoulmnPosition));
     resultSetCoulmnPosition++;
   }
   if (isNotEmpty(remoteSis.getLastNameField())) {
     insertStatement.setString(
         resultSetCoulmnPosition, resultSet.getString(resultSetCoulmnPosition++));
     insertStatement.setString(
         resultSetCoulmnPosition, resultSet.getString(resultSetCoulmnPosition));
   }
 }
Пример #4
0
 private String generateSelectSQL(SisSettings sisSettings) {
   String activeField =
       isNotEmpty(sisSettings.activeFieldName()) ? ", " + sisSettings.activeFieldName() : "";
   String nameFields =
       isNotEmpty(sisSettings.getLastNameField())
           ? ", " + sisSettings.getFirstNameField() + ", " + sisSettings.getLastNameField() + " "
           : "";
   return "select "
       + sisSettings.studentIDFieldName()
       + ","
       + sisSettings.freeFieldName()
       + ", "
       + sisSettings.reducedFieldName()
       + activeField
       + nameFields
       + " from "
       + sisSettings.getStudentsTable();
 }
Пример #5
0
 private String generateInsertSQL(SisSettings sisSettings) {
   return "insert into "
       + sisSettings.getStudentsTable()
       + " ("
       + sisSettings.studentIDFieldName()
       + ", "
       + sisSettings.freeFieldName()
       + ", "
       + sisSettings.reducedFieldName()
       + (isNotEmpty(sisSettings.activeFieldName()) ? "," + sisSettings.activeFieldName() : "")
       + (isNotEmpty(sisSettings.getFirstNameField()) ? "," + sisSettings.getFirstNameField() : "")
       + (isNotEmpty(sisSettings.getLastNameField()) ? "," + sisSettings.getLastNameField() : "")
       + ") values ( ?, ?, ?"
       + (isNotEmpty(sisSettings.activeFieldName()) ? ", ?" : "")
       + (isNotEmpty(sisSettings.getFirstNameField()) ? ", ?" : "")
       + (isNotEmpty(sisSettings.getLastNameField()) ? ", ?" : "")
       + ")";
 }