/** Save all the VOs related to this core responsibility structure */
  public void save() throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {
        // Save or update the raw responsibility structure
        //				openSession.saveOrUpdate(rawRSVO);

        for (Iterator<ArchEResponsibilityVO> itResps = rawRSVO.getResponsibilities().iterator();
            itResps.hasNext(); ) {
          ArchEResponsibilityVO resp = itResps.next();
          String name = resp.getName();
          openSession.saveOrUpdate(resp);
          this.saveParametersForResponsibility(resp, openSession);
        }

        // Save or update the translation relations
        for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); )
          openSession.saveOrUpdate(it.next());

        // Save or update the refinement relations
        for (Iterator<ArchERefinementRelationVO> it = refVOs.iterator(); it.hasNext(); )
          openSession.saveOrUpdate(it.next());

        // It deletes the list of 'removed' VOs
        for (Iterator it = removedRelationVOs.iterator(); it.hasNext(); )
          openSession.delete(it.next());

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
 @Test
 public void testDialectNotFound() {
   Map properties = Collections.EMPTY_MAP;
   try {
     dialectFactory.buildDialect(properties, Mocks.createConnection("NoSuchDatabase", 666));
     fail();
   } catch (HibernateException e) {
     assertNull(e.getCause());
   }
 }
  @Test
  public void testBuildDialectByProperties() {
    Properties props = new Properties();

    try {
      dialectFactory.buildDialect(props, null);
      fail();
    } catch (HibernateException e) {
      assertNull(e.getCause());
    }

    props.setProperty(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect");
    assertEquals(HSQLDialect.class, dialectFactory.buildDialect(props, null).getClass());
  }
 public static void assertCfgIsInvalid(Configuration configuration, Class[] mapping) {
   try {
     for (Class annotated : mapping) {
       (configuration).addAnnotatedClass(annotated);
     }
     configuration.setProperty("hibernate.search.default.directory_provider", "ram");
     configuration.buildSessionFactory();
     fail();
   } catch (HibernateException e) {
     // thrown exceptions means the test is ok when caused by a SearchException
     Throwable cause = e.getCause();
     assertTrue(cause instanceof SearchException);
   }
 }
Пример #5
0
  @Test
  public void testExplicitlySuppliedDialectClassName() {
    final Map<String, String> configValues = new HashMap<String, String>();

    configValues.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect");
    assertEquals(HSQLDialect.class, dialectFactory.buildDialect(configValues, null).getClass());

    configValues.put(Environment.DIALECT, "org.hibernate.dialect.NoSuchDialect");
    try {
      dialectFactory.buildDialect(configValues, null);
      fail();
    } catch (HibernateException e) {
      assertEquals(
          "unexpected exception type", ClassLoadingException.class, e.getCause().getClass());
    }

    configValues.put(Environment.DIALECT, "java.lang.Object");
    try {
      dialectFactory.buildDialect(configValues, null);
      fail();
    } catch (HibernateException e) {
      assertEquals("unexpected exception type", ClassCastException.class, e.getCause().getClass());
    }
  }
  /** Restore all the VOs related to this core responsibility structure */
  public void restore() throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {
        // Restore a raw responsibility structure
        rawRSVO =
            (ArchEResponsibilityStructureVO)
                (openSession
                    .createQuery("from ArchEResponsibilityStructureVO as v where v.id = ?")
                    .setInteger(0, version.getId())
                    .uniqueResult());

        // Lazy initialization of collections
        Hibernate.initialize(rawRSVO.getResponsibilities());

        for (Iterator<ArchEResponsibilityVO> itResps = rawRSVO.getResponsibilities().iterator();
            itResps.hasNext(); )
          this.restoreParametersForResponsibility(itResps.next(), openSession);

        // Restore the translation relations from requirements to responsibilities
        Query qrels =
            ArchECoreDataProvider.getSessionFactory()
                .getCurrentSession()
                .createQuery(
                    "from ArchETranslationRelationVO as rel where rel.parentType = ? and rel.version = ?");
        qrels.setString(0, "Scenario");
        qrels.setInteger(1, version.getId());
        trVOs = qrels.list();

        // Restore the refinement relations (between responsibilities)
        Query qrefs =
            ArchECoreDataProvider.getSessionFactory()
                .getCurrentSession()
                .createQuery("from ArchERefinementRelationVO as rel where rel.version = ?");
        qrefs.setInteger(0, version.getId());
        refVOs = qrefs.list();

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
Пример #7
0
 @Override
 public void truncateCampaignTable(final String campaignImportEntiry) throws HibernateException {
   // TODO Auto-generated method stub
   Session session = null;
   final String tableName = campaignImportEntiry.substring(0, 14);
   try {
     session = sessionFactory.openSession();
     final int result = hqlTruncate(campaignImportEntiry, session);
     LOGGER.info("Delete all records from [" + tableName + "] table successfully");
   } catch (HibernateException e) {
     final String exceptionMsg =
         "HibernateException occurs while deleting records from ["
             + tableName
             + "] table due to : "
             + e.getCause();
     LOGGER.error(exceptionMsg);
     throw new HibernateException(exceptionMsg);
   } finally {
     session.close();
   }
 }
 public void testFailOnInexistentLockingFactory() {
   FullTextSessionBuilder builder = new FullTextSessionBuilder();
   try {
     builder
         .addAnnotatedClass(SnowStorm.class)
         .setProperty("hibernate.search.default.locking_option", "somethingHere")
         .setProperty(
             "hibernate.search.default.locking_strategy", "org.hibernate.NotExistingFactory")
         .build();
     builder.close();
     fail();
   } catch (org.hibernate.HibernateException e) {
     Throwable causeSearch = e.getCause();
     assertNotNull(causeSearch);
     assertTrue(causeSearch instanceof org.hibernate.search.SearchException);
     Throwable causeLockin = causeSearch.getCause();
     assertNotNull(causeLockin);
     assertEquals(
         "Unable to find locking_strategy implementation class: org.hibernate.NotExistingFactory",
         causeLockin.getMessage());
   }
 }
  /**
   * Save AS all the VOs related to this core responsibility structure
   *
   * @param newVersion The version for the new VOs
   * @throws ArchEException
   */
  public void saveAs(ArchEVersionVO newVersion) throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {

        // Save the newly-created raw responsibility structure
        rawRSVO.setId(newVersion.getId());

        ArchEResponsibilityVO itemResp = null;
        for (Iterator<ArchEResponsibilityVO> it = rawRSVO.getResponsibilities().iterator();
            it.hasNext(); ) {
          itemResp = it.next();
          itemResp.setVersion(newVersion);
          openSession.save(itemResp);
          this.saveParametersForResponsibilityAs(newVersion, itemResp, openSession);
        }

        // Create a copy of the existing translation relations
        ArchETranslationRelationVO itemTr = null;
        for (Iterator<ArchETranslationRelationVO> it = trVOs.iterator(); it.hasNext(); ) {
          itemTr = it.next();
          itemTr.setVersion(newVersion);
          openSession.save(itemTr);
        }

        // Create a copy of the existing refinement relations
        ArchERefinementRelationVO itemRef = null;
        for (Iterator<ArchERefinementRelationVO> it = refVOs.iterator(); it.hasNext(); ) {
          itemRef = it.next();
          itemRef.setVersion(newVersion);
          openSession.save(itemRef);
        }

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }
 @Test
 public void testAuthenticationFailureAtStartUp() throws Exception {
   Properties properties = new Properties();
   // Set by Neo4jTestHelper
   properties.setProperty(
       OgmProperties.HOST, System.getProperties().getProperty(OgmProperties.HOST));
   properties.setProperty(
       OgmProperties.PORT, System.getProperties().getProperty(OgmProperties.PORT));
   properties.setProperty(OgmProperties.USERNAME, "completely wrong");
   properties.setProperty(OgmProperties.PASSWORD, "completely wrong");
   RemoteNeo4jDatastoreProvider remoteDatastoreProvider = new RemoteNeo4jDatastoreProvider();
   remoteDatastoreProvider.configure(properties);
   try {
     remoteDatastoreProvider.start();
     fail("Credentials should be invalid");
   } catch (HibernateException e) {
     // Unable to start datastore provider
     assertThat(e.getMessage()).startsWith("OGM000071");
     assertThat(e.getCause().getMessage()).startsWith("OGM001419");
   } finally {
     remoteDatastoreProvider.stop();
   }
 }
  /**
   * Delete all the VOs related to this core responsibility structure
   *
   * @throws ArchEException
   */
  public void delete() throws ArchEException {
    Session openSession = ArchECoreDataProvider.getSessionFactory().getCurrentSession();
    if (openSession != null && openSession.isConnected() && openSession.isOpen()) {
      try {
        // Delete the raw responsibility structure
        openSession.delete(rawRSVO);

        for (Iterator<ArchEResponsibilityVO> itResps = rawRSVO.getResponsibilities().iterator();
            itResps.hasNext(); )
          this.deleteParametersForResponsibility(itResps.next(), openSession);

        // Delete the translation relations
        for (Iterator<ArchETranslationRelationVO> itTr = trVOs.iterator(); itTr.hasNext(); )
          openSession.delete(itTr.next());

        // Delete the refinement relations
        for (Iterator<ArchERefinementRelationVO> itRef = refVOs.iterator(); itRef.hasNext(); )
          openSession.delete(itRef.next());

      } catch (HibernateException ex) {
        throw new ArchEException(ex.getMessage(), ex.getCause());
      }
    }
  }