@Override
 public void onLoad() {
   // if not in dev mode and in google mode, disables classic dbplugin
   if (Play.mode.isProd() && SienaPlugin.dbType().contains("google")) {
     // FIRST DISABLES DBPlugin
     Play.pluginCollection.disablePlugin(play.db.DBPlugin.class);
   }
 }
  @Override
  public void onApplicationStart() {
    if (Play.mode.isProd() && SienaPlugin.dbType().contains("google")) {
      try {

        Properties p = Play.configuration;

        if (DB.datasource != null) {
          DB.destroy();
        }

        if (p.getProperty("db", "").startsWith("java:")) {

          Context ctx = new InitialContext();
          DB.datasource = (DataSource) ctx.lookup(p.getProperty("db"));

        } else {

          // Try the driver
          String driver = p.getProperty("db.driver");

          try {
            Driver d = (Driver) Class.forName(driver, true, Play.classloader).newInstance();
            DriverManager.registerDriver(new ProxyDriver(d));
          } catch (Exception e) {
            throw new Exception("Driver not found (" + driver + ")");
          }

          // Try the connection
          Connection fake = null;
          try {
            if (p.getProperty("db.user") == null) {
              fake = DriverManager.getConnection(p.getProperty("db.url"));
            } else {
              fake =
                  DriverManager.getConnection(
                      p.getProperty("db.url"), p.getProperty("db.user"), p.getProperty("db.pass"));
            }
          } finally {
            if (fake != null) {
              fake.close();
            }
          }

          // apache basic DS
          BasicDataSource ds = new BasicDataSource();
          ds.setDriverClassName(p.getProperty("db.driver"));
          ds.setUsername(p.getProperty("db.user"));
          ds.setPassword(p.getProperty("db.pass"));
          ds.setUrl(p.getProperty("db.url"));

          DB.datasource = ds;
          url = ds.getUrl();
          Connection c = null;
          try {
            c = ds.getConnection();
          } finally {
            if (c != null) {
              c.close();
            }
          }
          // Logger.info("Connected to %s", ds.getJdbcUrl());
          Logger.info("Connected to %s", url);
        }

        DB.destroyMethod = p.getProperty("db.destroyMethod", "");

      } catch (Exception e) {
        DB.datasource = null;
        Logger.error(e, "Cannot connected to the database : %s", e.getMessage());
        if (e.getCause() instanceof InterruptedException) {
          throw new DatabaseException(
              "Cannot connected to the database. Check the configuration.", e);
        }
        throw new DatabaseException("Cannot connected to the database, " + e.getMessage(), e);
      }
    }
  }