Ejemplo n.º 1
0
 /**
  * Shutdown the hsqldb database
  *
  * @throws SQLException
  * @throws HibernateException
  */
 public static void shutdown() throws HibernateException, SQLException {
   if (sessionFactory != null) {
     if (selectedDB.getDialect().equals(HSQLDB)) {
       HibernateUtil.currentSession().connection().createStatement().execute("SHUTDOWN");
     }
     sessionFactory.close();
   }
   HibernateUtil.closeSession();
   sessionFactory = null;
 }
Ejemplo n.º 2
0
  public static void loadSessionFactory(Database db) throws HibernateException, SQLException {
    Configuration cfg = new Configuration();
    cfg.addResource("net/sf/royal/datamodel/Editor.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Collection.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Author.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Work.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Album.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Serie.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/CommentedImage.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Type.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Borrower.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Loan.hbm.xml");
    cfg.addResource("net/sf/royal/datamodel/Location_Emprunt.hbm.xml");
    cfg.setProperty("hbm2ddl.auto", "update");
    cfg.setProperty("hibernate.connection.driver_class", db.getDriver());

    // MySQL ou PostgreSQL
    if (db.getPassword() != null) {
      cfg.setProperty("hibernate.connection.password", db.getPassword());
      // HSQLDB
    } else {
      cfg.setProperty("hibernate.connection.password", "");
      cfg.setProperty("hibernate.connection.shutdown", "true");
    }
    cfg.setProperty("hibernate.connection.url", db.getUrl());
    cfg.setProperty("hibernate.connection.username", db.getUsername());
    cfg.setProperty("hibernate.dialect", db.getDialect());

    if (sessionFactory != null) {
      HibernateUtil.shutdown();
    }

    SchemaUpdate update = new SchemaUpdate(cfg);
    update.execute(false, true);
    sessionFactory = cfg.buildSessionFactory();
  }
Ejemplo n.º 3
0
 /**
  * Create a PreparedStatement for SELECT requests with scrolling of results row by row (only one
  * row in memory at a time)
  */
 public PreparedStatement newScrollingSingleRowSelectStatement(DbSession session, String sql) {
   int fetchSize = database.getDialect().getScrollSingleRowFetchSize();
   return newScrollingSelectStatement(session, sql, fetchSize);
 }
Ejemplo n.º 4
0
  public MyBatis start() {
    LogFactory.useSlf4jLogging();

    Configuration conf = new Configuration();
    conf.setEnvironment(
        new Environment("production", createTransactionFactory(), database.getDataSource()));
    conf.setUseGeneratedKeys(true);
    conf.setLazyLoadingEnabled(false);
    conf.setJdbcTypeForNull(JdbcType.NULL);
    Dialect dialect = database.getDialect();
    conf.setDatabaseId(dialect.getId());
    conf.getVariables().setProperty("_true", dialect.getTrueSqlValue());
    conf.getVariables().setProperty("_false", dialect.getFalseSqlValue());
    conf.getVariables()
        .setProperty("_scrollFetchSize", String.valueOf(dialect.getScrollDefaultFetchSize()));

    loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class);
    loadAlias(conf, "Author", AuthorDto.class);
    loadAlias(conf, "Component", ComponentDto.class);
    loadAlias(conf, "Dashboard", DashboardDto.class);
    loadAlias(conf, "Dependency", DependencyDto.class);
    loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
    loadAlias(conf, "Graph", GraphDto.class);
    loadAlias(conf, "Group", GroupDto.class);
    loadAlias(conf, "GroupRole", GroupRoleDto.class);
    loadAlias(conf, "GroupMembership", GroupMembershipDto.class);
    loadAlias(conf, "LoadedTemplate", LoadedTemplateDto.class);
    loadAlias(conf, "MeasureFilter", MeasureFilterDto.class);
    loadAlias(conf, "NotificationQueue", NotificationQueueDto.class);
    loadAlias(conf, "Property", PropertyDto.class);
    loadAlias(conf, "PurgeableSnapshot", PurgeableSnapshotDto.class);
    loadAlias(conf, "QualityGate", QualityGateDto.class);
    loadAlias(conf, "QualityGateCondition", QualityGateConditionDto.class);
    loadAlias(conf, "ProjectQgateAssociation", ProjectQgateAssociationDto.class);
    loadAlias(conf, "Resource", ResourceDto.class);
    loadAlias(conf, "ResourceIndex", ResourceIndexDto.class);
    loadAlias(conf, "ResourceSnapshot", ResourceSnapshotDto.class);
    loadAlias(conf, "Rule", RuleDto.class);
    loadAlias(conf, "RuleParam", RuleParamDto.class);
    loadAlias(conf, "Snapshot", SnapshotDto.class);
    loadAlias(conf, "Semaphore", SemaphoreDto.class);
    loadAlias(conf, "SchemaMigration", SchemaMigrationDto.class);
    loadAlias(conf, "User", UserDto.class);
    loadAlias(conf, "UserRole", UserRoleDto.class);
    loadAlias(conf, "UserGroup", UserGroupDto.class);
    loadAlias(conf, "Widget", WidgetDto.class);
    loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class);
    loadAlias(conf, "MeasureModel", MeasureModel.class);
    loadAlias(conf, "Measure", MeasureDto.class);
    loadAlias(conf, "Metric", MetricDto.class);
    loadAlias(conf, "Issue", IssueDto.class);
    loadAlias(conf, "IssueChange", IssueChangeDto.class);
    loadAlias(conf, "IssueFilter", IssueFilterDto.class);
    loadAlias(conf, "IssueFilterFavourite", IssueFilterFavouriteDto.class);
    loadAlias(conf, "ActionPlanIssue", ActionPlanDto.class);
    loadAlias(conf, "ActionPlanStats", ActionPlanStatsDto.class);
    loadAlias(conf, "PermissionTemplate", PermissionTemplateDto.class);
    loadAlias(conf, "PermissionTemplateUser", PermissionTemplateUserDto.class);
    loadAlias(conf, "PermissionTemplateGroup", PermissionTemplateGroupDto.class);
    loadAlias(conf, "Characteristic", CharacteristicDto.class);
    loadAlias(conf, "UserWithPermission", UserWithPermissionDto.class);
    loadAlias(conf, "GroupWithPermission", GroupWithPermissionDto.class);
    loadAlias(conf, "QualityProfile", QualityProfileDto.class);
    loadAlias(conf, "ActiveRule", ActiveRuleDto.class);
    loadAlias(conf, "ActiveRuleParam", ActiveRuleParamDto.class);
    loadAlias(conf, "RequirementMigration", RequirementMigrationDto.class);
    loadAlias(conf, "Activity", ActivityDto.class);
    loadAlias(conf, "AnalysisReport", AnalysisReportDto.class);
    loadAlias(conf, "IdUuidPair", IdUuidPair.class);
    loadAlias(conf, "FilePathWithHash", FilePathWithHashDto.class);
    loadAlias(conf, "UuidWithProjectUuid", UuidWithProjectUuidDto.class);

    // AuthorizationMapper has to be loaded before IssueMapper because this last one used it
    loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
    // ResourceMapper has to be loaded before IssueMapper because this last one used it
    loadMapper(conf, ResourceMapper.class);

    loadMapper(conf, "org.sonar.core.permission.PermissionMapper");
    Class<?>[] mappers = {
      ActivityMapper.class,
      ActiveDashboardMapper.class,
      AuthorMapper.class,
      DashboardMapper.class,
      DependencyMapper.class,
      DuplicationMapper.class,
      GraphDtoMapper.class,
      IssueMapper.class,
      IssueChangeMapper.class,
      IssueFilterMapper.class,
      IssueFilterFavouriteMapper.class,
      LoadedTemplateMapper.class,
      MeasureFilterMapper.class,
      Migration44Mapper.class,
      PermissionTemplateMapper.class,
      PropertiesMapper.class,
      PurgeMapper.class,
      ResourceKeyUpdaterMapper.class,
      ResourceIndexerMapper.class,
      ResourceSnapshotMapper.class,
      RoleMapper.class,
      RuleMapper.class,
      SchemaMigrationMapper.class,
      SemaphoreMapper.class,
      UserMapper.class,
      GroupMapper.class,
      UserGroupMapper.class,
      WidgetMapper.class,
      WidgetPropertyMapper.class,
      org.sonar.api.database.model.MeasureMapper.class,
      FileSourceMapper.class,
      ActionPlanMapper.class,
      ActionPlanStatsMapper.class,
      NotificationQueueMapper.class,
      CharacteristicMapper.class,
      GroupMembershipMapper.class,
      QualityProfileMapper.class,
      ActiveRuleMapper.class,
      MeasureMapper.class,
      MetricMapper.class,
      QualityGateMapper.class,
      QualityGateConditionMapper.class,
      ComponentMapper.class,
      SnapshotMapper.class,
      ProjectQgateAssociationMapper.class,
      AnalysisReportMapper.class,
      ComponentIndexMapper.class,
      Migration45Mapper.class,
      Migration50Mapper.class
    };
    loadMappers(conf, mappers);

    sessionFactory = new SqlSessionFactoryBuilder().build(conf);
    return this;
  }