Search in sources :

Example 1 with OptionRepository

use of org.b3log.solo.repository.OptionRepository in project solo by b3log.

the class SoloServletListener method contextInitialized.

@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
    // For Latke IoC        
    Latkes.setScanPath("org.b3log.solo");
    super.contextInitialized(servletContextEvent);
    Stopwatchs.start("Context Initialized");
    beanManager = Lifecycle.getBeanManager();
    // Upgrade check (https://github.com/b3log/solo/issues/12040)
    final UpgradeService upgradeService = beanManager.getReference(UpgradeService.class);
    upgradeService.upgrade();
    JdbcRepository.dispose();
    // Set default skin, loads from preference later
    Skins.setDirectoryForTemplateLoading(Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME);
    final OptionRepository optionRepository = beanManager.getReference(OptionRepositoryImpl.class);
    final Transaction transaction = optionRepository.beginTransaction();
    try {
        loadPreference();
        if (transaction.isActive()) {
            transaction.commit();
        }
    } catch (final Exception e) {
        if (transaction.isActive()) {
            transaction.rollback();
        }
    }
    registerEventProcessor();
    final PluginManager pluginManager = beanManager.getReference(PluginManager.class);
    pluginManager.load();
    LOGGER.info("Solo is running [" + Latkes.getServePath() + "]");
    Stopwatchs.end();
    LOGGER.log(Level.DEBUG, "Stopwatch: {0}{1}", Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat());
}
Also used : PluginManager(org.b3log.latke.plugin.PluginManager) UpgradeService(org.b3log.solo.service.UpgradeService) Transaction(org.b3log.latke.repository.Transaction) OptionRepository(org.b3log.solo.repository.OptionRepository)

Example 2 with OptionRepository

use of org.b3log.solo.repository.OptionRepository in project solo by b3log.

the class OptionRepositoryImplTestCase method test.

/**
     * Tests.
     * 
     * @throws Exception exception
     */
@Test
public void test() throws Exception {
    final OptionRepository optionRepository = getOptionRepository();
    final JSONObject option = new JSONObject();
    option.put(Keys.OBJECT_ID, Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
    option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_BROADCAST);
    option.put(Option.OPTION_VALUE, 0L);
    Transaction transaction = optionRepository.beginTransaction();
    optionRepository.add(option);
    transaction.commit();
    Assert.assertEquals(optionRepository.count(), 1);
    Assert.assertNotNull(optionRepository.get(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME));
}
Also used : JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) OptionRepository(org.b3log.solo.repository.OptionRepository) Test(org.testng.annotations.Test)

Aggregations

Transaction (org.b3log.latke.repository.Transaction)2 OptionRepository (org.b3log.solo.repository.OptionRepository)2 PluginManager (org.b3log.latke.plugin.PluginManager)1 UpgradeService (org.b3log.solo.service.UpgradeService)1 JSONObject (org.json.JSONObject)1 Test (org.testng.annotations.Test)1