/** * Return the list of ClassPathScanner services using serverConfig service loader. */ public static List<ClassPathScanner> find(ServerConfig serverConfig) { List<ClassPathScanner> scanners = new ArrayList<>(); ServiceLoader<ClassPathScannerFactory> scannerLoader = serverConfig.serviceLoad(ClassPathScannerFactory.class); for (ClassPathScannerFactory factory : scannerLoader) { ClassPathScanner scanner = factory.createScanner(serverConfig.getClassLoadConfig().getClassLoader()); scanners.add(scanner); } return scanners; } }
private void readXmlMapping() { try { ClassLoader classLoader = serverConfig.getClassLoadConfig().getClassLoader(); Enumeration<URL> resources = classLoader.getResources("ebean.xml"); List<XmEbean> mappings = new ArrayList<>(); while (resources.hasMoreElements()) { URL url = resources.nextElement(); InputStream is = url.openStream(); mappings.add(XmlMappingReader.read(is)); is.close(); } for (XmEbean mapping : mappings) { List<XmEntity> entityDeploy = mapping.getEntity(); for (XmEntity deploy : entityDeploy) { readEntityMapping(classLoader, deploy); } } } catch (IOException e) { throw new RuntimeException("Error reading ebean.xml", e); } }
public GeneratedPropertyFactory(ServerConfig serverConfig, List<IdGenerator> idGenerators) { this.classLoadConfig = serverConfig.getClassLoadConfig(); this.insertFactory = new InsertTimestampFactory(classLoadConfig); this.updateFactory = new UpdateTimestampFactory(classLoadConfig); CurrentUserProvider currentUserProvider = serverConfig.getCurrentUserProvider(); if (currentUserProvider != null) { generatedWhoCreated = new GeneratedWhoCreated(currentUserProvider); generatedWhoModified = new GeneratedWhoModified(currentUserProvider); } else { generatedWhoCreated = null; generatedWhoModified = null; } numberTypes.add(Integer.class.getName()); numberTypes.add(int.class.getName()); numberTypes.add(Long.class.getName()); numberTypes.add(long.class.getName()); numberTypes.add(Short.class.getName()); numberTypes.add(short.class.getName()); numberTypes.add(Double.class.getName()); numberTypes.add(double.class.getName()); numberTypes.add(BigDecimal.class.getName()); if (idGenerators != null) { for (IdGenerator idGenerator : idGenerators) { idGeneratorMap.put(idGenerator.getName(), new CustomIdGenerator(idGenerator)); } } }
/** * Detect if Joda classes are in the classpath and if so register the Joda * data types. */ private void initialiseJodaTypes(JsonConfig.DateTime mode, ServerConfig config) { // detect if Joda classes are in the classpath if (config.getClassLoadConfig().isJodaTimePresent()) { // Joda classes are in the classpath so register the types logger.debug("Registering Joda data types"); typeMap.put(LocalDateTime.class, new ScalarTypeJodaLocalDateTime(mode)); typeMap.put(DateTime.class, new ScalarTypeJodaDateTime(mode)); typeMap.put(LocalDate.class, new ScalarTypeJodaLocalDate()); typeMap.put(DateMidnight.class, new ScalarTypeJodaDateMidnight()); String jodaLocalTimeMode = config.getJodaLocalTimeMode(); if ("normal".equalsIgnoreCase(jodaLocalTimeMode)) { // use the expected/normal local time zone typeMap.put(LocalTime.class, new ScalarTypeJodaLocalTime()); logger.debug("registered ScalarTypeJodaLocalTime"); } else if ("utc".equalsIgnoreCase(jodaLocalTimeMode)) { // use the old UTC based typeMap.put(LocalTime.class, new ScalarTypeJodaLocalTimeUTC()); logger.debug("registered ScalarTypeJodaLocalTimeUTC"); } } }
/** * Run the DB migration against the DataSource. */ public DataSource runDbMigration(DataSource dataSource) { if (migrationConfig.isRunMigration()) { MigrationRunner runner = migrationConfig.createRunner(getClassLoadConfig().getClassLoader()); runner.run(dataSource); } return dataSource; }
/** * Create and attach a DataSourcePoolListener if it has been specified via properties and there is not one already attached. */ private void attachListener(ServerConfig config, DataSourceConfig dsConfig) { if (dsConfig.getListener() == null) { String poolListener = dsConfig.getPoolListener(); if (poolListener != null) { dsConfig.setListener((DataSourcePoolListener) config.getClassLoadConfig().newInstance(poolListener)); } } }
/** * Construct for the owning many property. */ public BeanPropertyAssocManyJsonHelp(BeanPropertyAssocMany<?> many) { this.many = many; boolean objectMapperPresent = many.getBeanDescriptor().getServerConfig().getClassLoadConfig().isJacksonObjectMapperPresent(); this.jsonTransient = !objectMapperPresent ? null : new BeanPropertyAssocManyJsonTransient(); }
private void initialiseJavaTimeTypes(JsonConfig.DateTime mode, ServerConfig config) { if (java7Present) { typeMap.put(java.nio.file.Path.class, new ScalarTypePath()); } if (config.getClassLoadConfig().isJavaTimePresent()) { logger.debug("Registering java.time data types"); typeMap.put(java.time.LocalDate.class, new ScalarTypeLocalDate()); typeMap.put(java.time.LocalDateTime.class, new ScalarTypeLocalDateTime(mode)); typeMap.put(OffsetDateTime.class, new ScalarTypeOffsetDateTime(mode)); typeMap.put(ZonedDateTime.class, new ScalarTypeZonedDateTime(mode)); typeMap.put(Instant.class, new ScalarTypeInstant(mode)); typeMap.put(DayOfWeek.class, new ScalarTypeDayOfWeek()); typeMap.put(Month.class, new ScalarTypeMonth()); typeMap.put(Year.class, new ScalarTypeYear()); typeMap.put(YearMonth.class, new ScalarTypeYearMonthDate()); typeMap.put(MonthDay.class, new ScalarTypeMonthDay()); typeMap.put(OffsetTime.class, new ScalarTypeOffsetTime()); typeMap.put(ZoneId.class, new ScalarTypeZoneId()); typeMap.put(ZoneOffset.class, new ScalarTypeZoneOffset()); boolean localTimeNanos = config.isLocalTimeWithNanos(); typeMap.put(java.time.LocalTime.class, (localTimeNanos) ? new ScalarTypeLocalTimeWithNanos() : new ScalarTypeLocalTime()); boolean durationNanos = config.isDurationWithNanos(); typeMap.put(Duration.class, (durationNanos) ? new ScalarTypeDurationWithNanos() : new ScalarTypeDuration()); } }
private BootupClassPathSearch(ServerConfig serverConfig) { // find packages defined in META-INF/ebean.mf resources Set<String> mfPackages = ManifestReader.readManifests(serverConfig.getClassLoadConfig().getClassLoader(), EBEAN_MF); this.packages = DistillPackages.distill(serverConfig.getPackages(), mfPackages); this.scanners = ClassPathScanners.find(serverConfig); }
/** * Create the DefaultTypeManager. */ public DefaultTypeManager(ServerConfig config, BootupClasses bootupClasses) { this.java7Present = config.getClassLoadConfig().isJava7Present(); this.jsonDateTime = config.getJsonDateTime(); this.typeMap = new ConcurrentHashMap<>(); this.nativeMap = new ConcurrentHashMap<>(); boolean objectMapperPresent = config.getClassLoadConfig().isJacksonObjectMapperPresent(); this.objectMapper = (objectMapperPresent) ? initObjectMapper(config) : null; this.extraTypeFactory = new DefaultTypeFactory(config); this.postgres = isPostgres(config.getDatabasePlatform()); this.arrayTypeFactory = arrayTypeFactory(postgres, config.getDatabasePlatform()); this.offlineMigrationGeneration = DbOffline.isGenerateMigration(); initialiseStandard(jsonDateTime, config); initialiseJavaTimeTypes(jsonDateTime, config); initialiseJodaTypes(jsonDateTime, config); initialiseJacksonTypes(config); loadTypesFromProviders(config, objectMapper); if (bootupClasses != null) { initialiseCustomScalarTypes(jsonDateTime, bootupClasses); initialiseScalarConverters(bootupClasses); initialiseAttributeConverters(bootupClasses); } }