コード例 #1
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test(expected = IllegalArgumentException.class)
 public void shouldFailOverToMostApplicableSimpleName() {
   Configuration c = new Configuration();
   final String fullName = "com.mycache.MyCache";
   final String invalidName = "unknown.namespace.MyCache";
   final PerpetualCache cache = new PerpetualCache(fullName);
   c.addCache(cache);
   assertEquals(cache, c.getCache(fullName));
   assertEquals(cache, c.getCache(invalidName));
 }
コード例 #2
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @Test
 public void shouldResolveBothSimpleNameAndFullyQualifiedName() {
   Configuration c = new Configuration();
   final String fullName = "com.mycache.MyCache";
   final String shortName = "MyCache";
   final PerpetualCache cache = new PerpetualCache(fullName);
   c.addCache(cache);
   assertEquals(cache, c.getCache(fullName));
   assertEquals(cache, c.getCache(shortName));
 }
コード例 #3
0
ファイル: EntityDataStore.java プロジェクト: requery/requery
  /**
   * Creates a new {@link EntityDataStore} with the given configuration.
   *
   * @param configuration to use
   */
  public EntityDataStore(Configuration configuration) {
    closed = new AtomicBoolean();
    readers = new ClassMap<>();
    writers = new ClassMap<>();
    entityModel = Objects.requireNotNull(configuration.getModel());
    connectionProvider = Objects.requireNotNull(configuration.getConnectionProvider());
    mapping = configuration.getMapping();
    platform = configuration.getPlatform();
    transactionMode = configuration.getTransactionMode();
    this.configuration = configuration;
    statementListeners = new CompositeStatementListener(configuration.getStatementListeners());
    stateListeners = new CompositeEntityListener<>();

    entityCache =
        configuration.getCache() == null ? new EmptyEntityCache() : configuration.getCache();
    int statementCacheSize = configuration.getStatementCacheSize();
    if (statementCacheSize > 0) {
      statementCache = new PreparedStatementCache(statementCacheSize);
    }
    // set default mapping (otherwise deferred to getConnection()
    if (platform != null && mapping == null) {
      mapping = new GenericMapping(platform);
    }
    context = new DataContext();
    transactionProvider = new TransactionProvider(context);
    updateOperation = new UpdateOperation(context);
    countOperation = new SelectCountOperation(context);
    Set<EntityStateListener<T>> entityListeners = new LinkedHashSet<>();
    if (configuration.getUseDefaultLogging()) {
      LoggingListener<T> logListener = new LoggingListener<>();
      entityListeners.add(logListener);
      statementListeners.add(logListener);
    }
    if (!configuration.getEntityStateListeners().isEmpty()) {
      for (@SuppressWarnings("unchecked")
      EntityStateListener<T> listener : configuration.getEntityStateListeners()) {
        entityListeners.add(listener);
      }
    }
    if (!entityListeners.isEmpty()) {
      stateListeners.enableStateListeners(true);
      for (EntityStateListener<T> listener : entityListeners) {
        stateListeners.addPostLoadListener(listener);
        stateListeners.addPostInsertListener(listener);
        stateListeners.addPostDeleteListener(listener);
        stateListeners.addPostUpdateListener(listener);
        stateListeners.addPreInsertListener(listener);
        stateListeners.addPreDeleteListener(listener);
        stateListeners.addPreUpdateListener(listener);
      }
    }
  }
コード例 #4
0
  @Test(expectedExceptions = AluminumException.class)
  public void tryingToObtainConfigurationElementAfterClosingConfigurationShouldCauseException() {
    Configuration configuration = new DefaultConfiguration();
    configuration.close();

    configuration.getCache();
  }
コード例 #5
0
  public void configurationShouldInitialiseCache() {
    ConfigurationParameters parameters = new ConfigurationParameters();
    parameters.addParameter(CACHE_CLASS, TestCache.class.getName());

    configuration = new DefaultConfiguration(parameters);

    assert ((TestCache) configuration.getCache()).getConfiguration() == configuration;
  }
コード例 #6
0
  public void cacheShouldBeConfigurable() {
    ConfigurationParameters parameters = new ConfigurationParameters();
    parameters.addParameter(CACHE_CLASS, TestCache.class.getName());

    configuration = new DefaultConfiguration(parameters);

    assert configuration.getCache() instanceof TestCache;
  }
コード例 #7
0
  @Test(dependsOnMethods = "configurationShouldInitialiseCache")
  public void configurationShouldDisableCacheWhenItIsClosed() {
    ConfigurationParameters parameters = new ConfigurationParameters();
    parameters.addParameter(CACHE_CLASS, TestCache.class.getName());

    Configuration configuration = new DefaultConfiguration(parameters);

    TestCache cache = (TestCache) configuration.getCache();

    configuration.close();

    assert cache.getConfiguration() == null;
  }
コード例 #8
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
  @Test
  public void shouldSucceedWhenFullyQualifiedButFailDueToAmbiguity() {
    Configuration c = new Configuration();

    final String name1 = "com.mycache.MyCache";
    final PerpetualCache cache1 = new PerpetualCache(name1);
    c.addCache(cache1);

    final String name2 = "com.other.MyCache";
    final PerpetualCache cache2 = new PerpetualCache(name2);
    c.addCache(cache2);

    final String shortName = "MyCache";

    assertEquals(cache1, c.getCache(name1));
    assertEquals(cache2, c.getCache(name2));

    try {
      c.getCache(shortName);
      fail("Exception expected.");
    } catch (Exception e) {
      assertTrue(e.getMessage().contains("ambiguous"));
    }
  }
コード例 #9
0
  public void cacheShouldDefaultToNull() {
    configuration = new DefaultConfiguration();

    assert configuration.getCache() == null;
  }