jeudi 12 avril 2018

Advice on a more correct design pattern

I need to change an existing code that access a PostgreSQL database, to include in some operations (basically all the ones involving Inserts), to perform those operations over an Oracle DB too.

So basically the insert functions will need to insert the data in both PostgreSQL and Oracle DBs.

What could be the most suitable design pattern for this situation? Having into account that these changes to write in the Oracle DB will only be there for some months (some project requirements)

So far, I was thinking of using a Wrapper that internally call the respective functions to write the data to each DB. Like

class DBWrapper  {
    private $postgreSQLDB;
    private $oracleDB;

    private static $instance;

    public static function getInstance()
    {
        // --
    }

    public function connect($params)
    {
        // Connect to the two DBs.
    }

    public function insertData($table, $something) {
        $this->postgreSQLDB->insertData($table);
        $this->oracleDB->insertData($table);
    }
}

But, with this I would need to include all the PostgreSQL functions too... even if it just calls the PostgresSQL functions.

Are there better alternatives for this situation?

Aucun commentaire:

Enregistrer un commentaire