use of fr.xephi.authme.datasource.CacheDataSource in project AuthMeReloaded by AuthMe.
the class MySqlDefaultChangerTest method shouldLeaveMySqlFieldToNullOnInitialization.
@Test
public void shouldLeaveMySqlFieldToNullOnInitialization() {
// given
DataSource dataSource = mock(DataSource.class);
PlayerCache playerCache = mock(PlayerCache.class);
CacheDataSource cacheDataSource = new CacheDataSource(dataSource, playerCache);
MySqlDefaultChanger defaultChanger = createDefaultChanger(cacheDataSource);
// when
defaultChanger.setMySqlField();
// then
assertThat(ReflectionTestUtils.getFieldValue(MySqlDefaultChanger.class, defaultChanger, "mySql"), nullValue());
}
use of fr.xephi.authme.datasource.CacheDataSource in project AuthMeReloaded by AuthMe.
the class DataSourceProvider method createDataSource.
/**
* Sets up the data source.
*
* @return the constructed data source
* @throws SQLException when initialization of a SQL data source failed
*/
private DataSource createDataSource() throws SQLException {
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
DataSource dataSource;
switch(dataSourceType) {
case MYSQL:
dataSource = new MySQL(settings, mySqlExtensionsFactory);
break;
case POSTGRESQL:
dataSource = new PostgreSqlDataSource(settings, mySqlExtensionsFactory);
break;
case SQLITE:
dataSource = new SQLite(settings, dataFolder);
break;
default:
throw new UnsupportedOperationException("Unknown data source type '" + dataSourceType + "'");
}
if (settings.getProperty(DatabaseSettings.USE_CACHING)) {
dataSource = new CacheDataSource(dataSource, playerCache);
}
if (DataSourceType.SQLITE.equals(dataSourceType)) {
checkDataSourceSize(dataSource);
}
return dataSource;
}
use of fr.xephi.authme.datasource.CacheDataSource in project AuthMeReloaded by AuthMe.
the class DebugSectionUtilsTest method shouldUnwrapCacheDataSource.
@Test
public void shouldUnwrapCacheDataSource() {
// given
DataSource source = mock(DataSource.class);
PlayerCache playerCache = mock(PlayerCache.class);
CacheDataSource cacheDataSource = new CacheDataSource(source, playerCache);
// when
DataSource result = DebugSectionUtils.unwrapSourceFromCacheDataSource(cacheDataSource);
// then
assertThat(result, equalTo(source));
}
use of fr.xephi.authme.datasource.CacheDataSource in project AuthMeReloaded by AuthMe.
the class DataStatistics method outputDatabaseStats.
private void outputDatabaseStats(CommandSender sender) {
sender.sendMessage("Total players in DB: " + dataSource.getAccountsRegistered());
if (dataSource instanceof CacheDataSource) {
CacheDataSource cacheDataSource = (CacheDataSource) this.dataSource;
sender.sendMessage("Cached PlayerAuth objects: " + cacheDataSource.getCachedAuths().size());
}
}
use of fr.xephi.authme.datasource.CacheDataSource in project AuthMeReloaded by AuthMe.
the class DebugSectionUtils method unwrapSourceFromCacheDataSource.
/**
* Unwraps the "cache data source" and returns the underlying source. Returns the
* same as the input argument otherwise.
*
* @param dataSource the data source to unwrap if applicable
* @return the non-cache data source
*/
static DataSource unwrapSourceFromCacheDataSource(DataSource dataSource) {
if (dataSource instanceof CacheDataSource) {
try {
Field source = CacheDataSource.class.getDeclaredField("source");
source.setAccessible(true);
return (DataSource) source.get(dataSource);
} catch (NoSuchFieldException | IllegalAccessException e) {
logger.logException("Could not get source of CacheDataSource:", e);
return null;
}
}
return dataSource;
}
Aggregations