mercredi 17 février 2016

How to correct use "Strategy" pattern for selecting which database to use?

I have 2 databases, first - MySQL, and for working with this db, I use hibernate(have Entity, DAO, services); second - HBase, and working with their API, so I create new Entity and other services for working with HBase db. The main task is to use Strategy pattern, how to correct implements this pattern for choose what db we should use? Thanks.

Example for configuration HibernateUtil:

package com.studentbase.app;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

private static final SessionFactory sessionFactory = buildSessionFactory();

private static SessionFactory buildSessionFactory() {
    try {
        Configuration configuration = new Configuration();
        configuration.configure();
        return configuration
                .buildSessionFactory(new StandardServiceRegistryBuilder()
                        .applySettings(configuration.getProperties())
                        .build());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(
                "There was an error building the factory");
    }
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}
}

Aucun commentaire:

Enregistrer un commentaire