org.apache.cayenne.configuration.server.ServerModule Maven / Gradle / Ivy
/*****************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
****************************************************************/
package org.apache.cayenne.configuration.server;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.apache.cayenne.DataChannel;
import org.apache.cayenne.access.DataDomain;
import org.apache.cayenne.access.DefaultObjectMapRetainStrategy;
import org.apache.cayenne.access.ObjectMapRetainStrategy;
import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
import org.apache.cayenne.access.jdbc.BatchQueryBuilderFactory;
import org.apache.cayenne.access.jdbc.DefaultBatchQueryBuilderFactory;
import org.apache.cayenne.access.types.BigDecimalType;
import org.apache.cayenne.access.types.BigIntegerType;
import org.apache.cayenne.access.types.BooleanType;
import org.apache.cayenne.access.types.ByteArrayType;
import org.apache.cayenne.access.types.ByteType;
import org.apache.cayenne.access.types.CalendarType;
import org.apache.cayenne.access.types.CharType;
import org.apache.cayenne.access.types.DateType;
import org.apache.cayenne.access.types.DoubleType;
import org.apache.cayenne.access.types.FloatType;
import org.apache.cayenne.access.types.IntegerType;
import org.apache.cayenne.access.types.LongType;
import org.apache.cayenne.access.types.ShortType;
import org.apache.cayenne.access.types.TimeType;
import org.apache.cayenne.access.types.TimestampType;
import org.apache.cayenne.access.types.UUIDType;
import org.apache.cayenne.access.types.UtilDateType;
import org.apache.cayenne.access.types.VoidType;
import org.apache.cayenne.ashwood.AshwoodEntitySorter;
import org.apache.cayenne.cache.MapQueryCacheProvider;
import org.apache.cayenne.cache.QueryCache;
import org.apache.cayenne.configuration.ConfigurationNameMapper;
import org.apache.cayenne.configuration.Constants;
import org.apache.cayenne.configuration.DataChannelDescriptorLoader;
import org.apache.cayenne.configuration.DataChannelDescriptorMerger;
import org.apache.cayenne.configuration.DataMapLoader;
import org.apache.cayenne.configuration.DefaultConfigurationNameMapper;
import org.apache.cayenne.configuration.DefaultDataChannelDescriptorMerger;
import org.apache.cayenne.configuration.DefaultObjectStoreFactory;
import org.apache.cayenne.configuration.DefaultRuntimeProperties;
import org.apache.cayenne.configuration.ObjectContextFactory;
import org.apache.cayenne.configuration.ObjectStoreFactory;
import org.apache.cayenne.configuration.RuntimeProperties;
import org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader;
import org.apache.cayenne.configuration.XMLDataMapLoader;
import org.apache.cayenne.dba.db2.DB2Sniffer;
import org.apache.cayenne.dba.derby.DerbySniffer;
import org.apache.cayenne.dba.frontbase.FrontBaseSniffer;
import org.apache.cayenne.dba.h2.H2Sniffer;
import org.apache.cayenne.dba.hsqldb.HSQLDBSniffer;
import org.apache.cayenne.dba.ingres.IngresSniffer;
import org.apache.cayenne.dba.mysql.MySQLSniffer;
import org.apache.cayenne.dba.openbase.OpenBaseSniffer;
import org.apache.cayenne.dba.oracle.OracleSniffer;
import org.apache.cayenne.dba.postgres.PostgresSniffer;
import org.apache.cayenne.dba.sqlite.SQLiteSniffer;
import org.apache.cayenne.dba.sqlserver.SQLServerSniffer;
import org.apache.cayenne.dba.sybase.SybaseSniffer;
import org.apache.cayenne.di.AdhocObjectFactory;
import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.ListBuilder;
import org.apache.cayenne.di.Module;
import org.apache.cayenne.di.spi.DefaultAdhocObjectFactory;
import org.apache.cayenne.event.DefaultEventManager;
import org.apache.cayenne.event.EventManager;
import org.apache.cayenne.log.CommonsJdbcEventLogger;
import org.apache.cayenne.log.JdbcEventLogger;
import org.apache.cayenne.map.EntitySorter;
import org.apache.cayenne.resource.ClassLoaderResourceLocator;
import org.apache.cayenne.resource.ResourceLocator;
/**
* A DI module containing all Cayenne server runtime configuration.
*
* @since 3.1
*/
public class ServerModule implements Module {
private static final int DEFAULT_MAX_ID_QUALIFIER_SIZE = 10000;
protected String[] configurationLocations;
/**
* Creates a ServerModule with at least one configuration location. For multi-module
* projects additional locations can be specified as well.
*/
public ServerModule(String... configurationLocations) {
if (configurationLocations == null) {
throw new NullPointerException("Null configurationLocations");
}
if (configurationLocations.length < 1) {
throw new IllegalArgumentException("Empty configurationLocations");
}
this.configurationLocations = configurationLocations;
}
public void configure(Binder binder) {
// configure global stack properties
binder.bindMap(Constants.PROPERTIES_MAP)
.put(Constants.SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY, String.valueOf(DEFAULT_MAX_ID_QUALIFIER_SIZE));
binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
AdhocObjectFactory objectFactory = new DefaultAdhocObjectFactory();
binder.bind(AdhocObjectFactory.class).toInstance(objectFactory);
// configure known DbAdapter detectors in reverse order of popularity. Users can
// add their own to install custom adapters automatically
binder
.bindList(Constants.SERVER_ADAPTER_DETECTORS_LIST)
.add(new OpenBaseSniffer(objectFactory))
.add(new FrontBaseSniffer(objectFactory))
.add(new IngresSniffer(objectFactory))
.add(new SQLiteSniffer(objectFactory))
.add(new DB2Sniffer(objectFactory))
.add(new H2Sniffer(objectFactory))
.add(new HSQLDBSniffer(objectFactory))
.add(new SybaseSniffer(objectFactory))
.add(new DerbySniffer(objectFactory))
.add(new SQLServerSniffer(objectFactory))
.add(new OracleSniffer(objectFactory))
.add(new PostgresSniffer(objectFactory))
.add(new MySQLSniffer(objectFactory));
// configure an empty filter chain
binder.bindList(Constants.SERVER_DOMAIN_FILTERS_LIST);
// configure extended types
binder
.bindList(Constants.SERVER_DEFAULT_TYPES_LIST)
.add(new VoidType())
.add(new BigDecimalType())
.add(new BigIntegerType())
.add(new BooleanType())
.add(new ByteArrayType(false, true))
.add(new ByteType(false))
.add(new CharType(false, true))
.add(new DateType())
.add(new DoubleType())
.add(new FloatType())
.add(new IntegerType())
.add(new LongType())
.add(new ShortType(false))
.add(new TimeType())
.add(new TimestampType())
.add(new UtilDateType())
.add(new CalendarType(GregorianCalendar.class))
.add(new CalendarType(Calendar.class))
.add(new UUIDType());
binder.bindList(Constants.SERVER_USER_TYPES_LIST);
binder.bindList(Constants.SERVER_TYPE_FACTORIES_LIST);
// configure explicit configurations
ListBuilder
© 2015 - 2025 Weber Informatics LLC | Privacy Policy