public DefaultTransactionFactory(@Inject RuntimeProperties properties, @Inject JdbcEventLogger jdbcEventLogger) { this.externalTransactions = properties.getBoolean(Constants.SERVER_EXTERNAL_TX_PROPERTY, false); this.jdbcEventLogger = jdbcEventLogger; }
public Slf4jJdbcEventLogger(@Inject RuntimeProperties runtimeProperties) { this.queryExecutionTimeLoggingThreshold = runtimeProperties.getLong( Constants.QUERY_EXECUTION_TIME_LOGGING_THRESHOLD_PROPERTY, 0); }
protected JettyHttpROPConnector createJettyHttpRopConnector() { String url = runtimeProperties.get(ClientConstants.ROP_SERVICE_URL_PROPERTY); if (url == null) { throw new ConfigurationException( "No property defined for '%s', can't initialize connection", ClientConstants.ROP_SERVICE_URL_PROPERTY); } String username = runtimeProperties.get(ClientConstants.ROP_SERVICE_USERNAME_PROPERTY); long readTimeout = runtimeProperties.getLong( ClientConstants.ROP_SERVICE_TIMEOUT_PROPERTY, -1L); HttpClient httpClient = initJettyHttpClient(); addBasicAuthentication(httpClient, url, username); JettyHttpROPConnector result = new JettyHttpROPConnector(httpClient, url, username); if (readTimeout > 0) { result.setReadTimeout(readTimeout); } return result; }
public QueryCache get() throws ConfigurationException { int size = properties.getInt( Constants.QUERY_CACHE_SIZE_PROPERTY, MapQueryCache.DEFAULT_CACHE_SIZE); return new MapQueryCache(size); } }
@Override public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Exception { String suffix = "." + nodeDescriptor.getDataChannelDescriptor().getName() + "." + nodeDescriptor.getName(); String driverClass = getProperty(Constants.JDBC_DRIVER_PROPERTY, suffix); String url = getProperty(Constants.JDBC_URL_PROPERTY, suffix); String username = getProperty(Constants.JDBC_USERNAME_PROPERTY, suffix); String password = getProperty(Constants.JDBC_PASSWORD_PROPERTY, suffix); int minConnections = getIntProperty(Constants.JDBC_MIN_CONNECTIONS_PROPERTY, suffix, 1); int maxConnections = getIntProperty(Constants.JDBC_MAX_CONNECTIONS_PROPERTY, suffix, 1); long maxQueueWaitTime = properties.getLong(Constants.JDBC_MAX_QUEUE_WAIT_TIME, UnmanagedPoolingDataSource.MAX_QUEUE_WAIT_DEFAULT); String validationQuery = properties.get(Constants.JDBC_VALIDATION_QUERY_PROPERTY); Driver driver = objectFactory.newInstance(Driver.class, driverClass); return DataSourceBuilder.url(url).driver(driver).userName(username).password(password) .pool(minConnections, maxConnections).maxQueueWaitTime(maxQueueWaitTime) .validationQuery(validationQuery).build(); }
protected void initWithProperties(RuntimeProperties properties) { // expiration time is never used actually maxSize = properties.getInt(Constants.SNAPSHOT_CACHE_SIZE_PROPERTY, SNAPSHOT_CACHE_SIZE_DEFAULT); if (logger.isDebugEnabled()) { logger.debug("DataRowStore property " + Constants.SNAPSHOT_CACHE_SIZE_PROPERTY + " = " + maxSize); } this.snapshots = new ConcurrentLinkedHashMap.Builder<ObjectId, DataRow>() .maximumWeightedCapacity(maxSize) .build(); }
private URI getConfig() { String config = properties.get(JCacheConstants.JCACHE_PROVIDER_CONFIG); if(config == null) { return null; } else { try { return new URI(config); } catch (URISyntaxException ex) { throw new RuntimeException("Wrong value for JCache provider config property", ex); } } } }
public ObjectStore createObjectStore(DataRowStore dataRowCache) { boolean sync = runtimeProperties.getBoolean(Constants.SERVER_CONTEXTS_SYNC_PROPERTY, true); return sync ? new ObjectStore(dataRowCache, retainStrategy.createObjectMap()) : new NoSyncObjectStore(dataRowCache, retainStrategy.createObjectMap()); } }
@Override public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Exception { DataSourceInfo descriptor = nodeDescriptor.getDataSourceDescriptor(); if (descriptor == null) { String message = "Null dataSourceDescriptor for nodeDescriptor '" + nodeDescriptor.getName() + "'"; logger.info(message); throw new ConfigurationException(message); } long maxQueueWaitTime = properties.getLong(Constants.JDBC_MAX_QUEUE_WAIT_TIME, UnmanagedPoolingDataSource.MAX_QUEUE_WAIT_DEFAULT); Driver driver = objectFactory.newInstance(Driver.class, descriptor.getJdbcDriver()); return DataSourceBuilder.url(descriptor.getDataSourceUrl()).driver(driver).userName(descriptor.getUserName()) .password(descriptor.getPassword()) .pool(descriptor.getMinConnections(), descriptor.getMaxConnections()) .maxQueueWaitTime(maxQueueWaitTime).build(); }
dataDomain.setMaxIdQualifierSize(runtimeProperties.getInt(Constants.SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY, -1));
protected void addBasicAuthentication(HttpClient httpClient, String url, String username) { String password = runtimeProperties.get(ClientConstants.ROP_SERVICE_PASSWORD_PROPERTY); String realm = runtimeProperties.get(ClientConstants.ROP_SERVICE_REALM_PROPERTY); if (username != null && password != null) { if (realm == null && logger.isWarnEnabled()) { logger.warn("In order to use JettyClient with BASIC Authentication " + "you should provide Constants.ROP_SERVICE_REALM_PROPERTY."); return; } if (logger.isInfoEnabled()) { logger.info( "Adding authentication" + "\nUser: " + username + "\nRealm: " + realm); } AuthenticationStore auth = httpClient.getAuthenticationStore(); auth.addAuthentication(new BasicAuthentication(URI.create(url), realm, username, password)); } }
@Override protected HttpClient initJettyHttpClient() { try { HttpClientTransportOverHTTP2 http2 = new HttpClientTransportOverHTTP2(new HTTP2Client()); boolean useALPN = runtimeProperties.getBoolean(ClientConstants.ROP_SERVICE_USE_ALPN_PROPERTY, false); http2.setUseALPN(useALPN); HttpClient httpClient = new HttpClient(http2, new SslContextFactory()); httpClient.start(); return httpClient; } catch (Exception e) { throw new CayenneRuntimeException("Exception while starting Jetty HttpClient over HTTP/2.", e); } }
/** * @since 4.0 */ protected DataChannelDescriptor loadDescriptor() { DataChannelDescriptor descriptor = locations.isEmpty() ? new DataChannelDescriptor() : loadDescriptorFromConfigs(); String nameOverride = runtimeProperties.get(Constants.SERVER_DOMAIN_NAME_PROPERTY); if (nameOverride != null) { descriptor.setName(nameOverride); } return descriptor; }
/** * Creates new JdbcAdapter with a set of default parameters. */ public JdbcAdapter(@Inject RuntimeProperties runtimeProperties, @Inject(Constants.SERVER_DEFAULT_TYPES_LIST) List<ExtendedType> defaultExtendedTypes, @Inject(Constants.SERVER_USER_TYPES_LIST) List<ExtendedType> userExtendedTypes, @Inject(Constants.SERVER_TYPE_FACTORIES_LIST) List<ExtendedTypeFactory> extendedTypeFactories, @Inject(Constants.SERVER_RESOURCE_LOCATOR) ResourceLocator resourceLocator, @Inject ValueObjectTypeRegistry valueObjectTypeRegistry) { // init defaults this.setSupportsBatchUpdates(false); this.setSupportsUniqueConstraints(true); this.caseInsensitiveCollations = runtimeProperties.getBoolean(Constants.CI_PROPERTY, false); this.resourceLocator = resourceLocator; this.pkGenerator = createPkGenerator(); this.quotingStrategy = createQuotingStrategy(); this.ejbqlTranslatorFactory = createEJBQLTranslatorFactory(); this.typesHandler = TypesHandler.getHandler(findResource("/types.xml")); this.extendedTypes = new ExtendedTypeMap(); initExtendedTypes(defaultExtendedTypes, userExtendedTypes, extendedTypeFactories, valueObjectTypeRegistry); }
@SuppressWarnings("unchecked") public Map<Object, Persistent> createObjectMap() { String strategy = runtimeProperties .get(Constants.SERVER_OBJECT_RETAIN_STRATEGY_PROPERTY); if (strategy == null || WEAK_RETAIN_STRATEGY.equals(strategy)) { return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK); } else if (SOFT_RETAIN_STRATEGY.equals(strategy)) { return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); } else if (HARD_RETAIN_STRATEGY.equals(strategy)) { return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.HARD); } else { throw new CayenneRuntimeException("Unsupported retain strategy %s", strategy); } } }
}; for (String propertyConstant : verifiableProperties) { String property = properties.get(getDataNodePropertyName(nodeDescriptor, propertyConstant)); if (property != null) { logResult.append(getDataNodePropertyName(nodeDescriptor, propertyConstant)).append(", "); found = true; property = properties.get(propertyConstant); if (property != null) { logResult.append(propertyConstant).append(", ");
protected boolean shouldConfigureDataSourceFromProperties( DataNodeDescriptor nodeDescriptor) { String channelName = nodeDescriptor.getDataChannelDescriptor() != null ? nodeDescriptor.getDataChannelDescriptor().getName() : null; String driver = properties.get(Constants.JDBC_DRIVER_PROPERTY); if (driver == null && channelName != null) { driver = properties.get(getDataNodePropertyName(nodeDescriptor, Constants.JDBC_DRIVER_PROPERTY)); } if (driver == null) { findUnusedProperties(nodeDescriptor); return false; } String url = properties.get(Constants.JDBC_URL_PROPERTY); if (url == null && channelName != null) { url = properties.get(getDataNodePropertyName(nodeDescriptor, Constants.JDBC_URL_PROPERTY)); } if (url == null) { findUnusedProperties(nodeDescriptor); return false; } logger .info(String .format( "Found DataSourceFactory system property overrides for URL and Driver " + "of '%s.%s' node. Will ignore project DataSource configuration.", channelName, nodeDescriptor.getName())); return true; }
@Override public ClientConnection get() throws DIRuntimeException { String sharedSession = runtimeProperties .get(ClientConstants.ROP_SERVICE_SHARED_SESSION_PROPERTY); JettyHttpROPConnector ropConnector = createJettyHttpRopConnector(); ProxyRemoteService remoteService = new ProxyRemoteService(serializationService, ropConnector); HttpClientConnection clientConnection = new HttpClientConnection(remoteService, sharedSession); ropConnector.setClientConnection(clientConnection); return clientConnection; }