/** * * Metodo que sincroniza os bancos de dados * * @throws RemoteException */ public void sincronizar() throws RemoteException { List<TeacherTO> endidadesInseridas = new ArrayList<>(); List<TeacherTO> endidadesAtualizadas = new ArrayList<>(); List<TeacherTO> a = postgre.list(); List<TeacherTO> b = mysql.list(); List<TeacherTO> c = datastore.list(); try { tx.prepareAll(); if (mustChanges(a)) { for (TeacherTO teacherTO : a) { if (!b.contains(teacherTO) || !c.contains(teacherTO)) { endidadesInseridas.add(teacherTO); } else { endidadesAtualizadas.add(teacherTO); } } add(endidadesInseridas, mysql); add(endidadesInseridas, datastore); update(endidadesAtualizadas, mysql); update(endidadesAtualizadas, datastore); } else if (mustChanges(b)) { for (TeacherTO teacherTO : b) { endidadesAtualizadas.add(teacherTO); } update(endidadesAtualizadas, postgre); update(endidadesAtualizadas, datastore); } else if (mustChanges(c)) { for (TeacherTO teacherTO : c) { endidadesAtualizadas.add(teacherTO); } update(endidadesAtualizadas, mysql); update(endidadesAtualizadas, postgre); } else { throw new RemoteException("Erro ao sincronizar bancos"); } tx.commitAll(); mrm.setPropBancoHash("bancoHash", gh.hashBanco(c)); } catch (RemoteException e) { e.printStackTrace(); tx.rollbackAll(); } }
public Sincronizador(TransCoord t, StoreLocal a, StoreLocal b, StoreLocal c) throws RemoteException { this.tx = t; this.postgre = a; this.mysql = b; this.datastore = c; this.gh = new GenerateHash(); this.mrm = new MirrorManager(); init(postgre.list()); }
/** * * Método que atualiza as entidades no banco * * @param list * @param sl * @throws RemoteException */ public void update(List<TeacherTO> list, StoreLocal sl) throws RemoteException { for (TeacherTO teacherTO : list) { sl.update(teacherTO); } }