Exemplo n.º 1
0
  private EntityResource() {
    try {
      if (log.isDebugEnabled()) log.debug("Loading EMF.");

      DataSource ds = DataSourceUtil.lookupDatasource();

      Map<String, Object> map = new HashMap<String, Object>();
      map.put(TopLinkProperties.NON_JTA_DATASOURCE, ds);

      emf = Persistence.createEntityManagerFactory("validations", map);

      if (log.isDebugEnabled()) log.debug("EMF Loaded.");
    } catch (Exception e) {
      log.error("Error creating entity manager factory.", e);
      throw new PersistenceException(e);
    }
  }
  public static boolean isValid(DatasourceConnection dc, Boolean autoCommit) {
    try {
      if (dc.getConnection().isClosed()) return false;
    } catch (Throwable t) {
      return false;
    }

    try {
      if (dc.getDatasource().validate() && !DataSourceUtil.isValid(dc, 10)) return false;
    } catch (Throwable t) {
    } // not all driver support this, because of that we ignore a error here, also protect from java
      // 5

    try {
      if (autoCommit != null) dc.getConnection().setAutoCommit(autoCommit.booleanValue());
    } catch (Throwable t) {
      return false;
    }

    return true;
  }