public static Set<Field> getInjectableFields(Class<?> clazz) { Set<Field> fields = U.set(); for (Class<? extends Annotation> annotation : INJECTION_ANNOTATIONS) { fields.addAll(Cls.getFieldsAnnotated(clazz, annotation)); } if (MscOpts.hasJPA()) { Class<Annotation> javaxPersistenceContext = Cls.get("javax.persistence.PersistenceContext"); List<Field> emFields = Cls.getFieldsAnnotated(clazz, javaxPersistenceContext); for (Field emField : emFields) { U.must(emField.getType().getName().equals("javax.persistence.EntityManager"), "Expected EntityManager type!"); } fields.addAll(emFields); } return fields; }
private static Object getIdentifier(Object bean) { return MscOpts.hasRapidoidJPA() ? GuiJpaUtil.getIdentifier(bean) : null; }
@Override public synchronized Resp mvc(boolean mvc) { if (mvc) { U.must(MscOpts.hasRapidoidGUI(), "The rapidoid-gui module must be included for the MVC feature!"); } this.mvc = mvc; return this; }
private static synchronized void restartApp() { if (!MscOpts.hasRapidoidWatch()) { Log.warn("Cannot reload/restart the application, module rapidoid-watch is missing!"); } if (mainClassName == null) { Log.warn("Cannot reload/restart the application, the main app class couldn't be detected!"); } Msc.logSection("!Restarting the web application..."); restarted = true; notifyListenersBeforeRestart(); resetAppStateBeforeRestart(); if (MscOpts.hasRapidoidJPA()) { loader = ReloadUtil.reloader(); ClasspathUtil.setDefaultClassLoader(loader); } reloadAndRunMainClass(); restarted = true; notifyListenersAfterRestart(); Log.info("!Successfully restarted the application!"); }
public static String http() { return MscOpts.isTLSEnabled() ? "https" : "http"; }
private synchronized void listen() { if (!listening && !reloaded) { App.inferCallers(); listening = true; HttpProcessor proc = processor != null ? processor : http(); if (Env.dev() && !On.changes().isIgnored() && MscOpts.hasRapidoidWatch()) { proc = new AppRestartProcessor(this, proc); On.changes().byDefaultRestart(); } if (server == null) { int targetPort = port(); server = proc.listen(address(), targetPort); Log.info("!Server has started", "setup", name(), "!home", "http://localhost:" + targetPort); Log.info("!Static resources will be served from the following locations", "setup", name(), "!locations", custom().staticFilesPath()); } } }
private DataSource createPool() { String provider = U.safe(poolProvider); switch (provider) { case "hikari": U.must(MscOpts.hasHikari(), "Couldn't find Hikari!"); Log.info("Initializing JDBC connection pool with Hikari", "!url", url, "!driver", driver, "!username", username, "!password", maskedPassword()); return HikariFactory.createDataSourceFor(this); case "c3p0": U.must(MscOpts.hasC3P0(), "Couldn't find C3P0!"); Log.info("Initializing JDBC connection pool with C3P0", "!url", url, "!driver", driver, "!username", username, "!password", maskedPassword()); return C3P0Factory.createDataSourceFor(this); default: throw U.rte("Unknown pool provider: '%s'!", provider); } }
public static void bootstrap(String[] packages, DataSource dataSource, Class<?>... providedEntities) { if (MscOpts.hasHibernate()) { if (emf() == null) { bootstrapJPA(packages, dataSource, providedEntities); } else { Log.info("JPA has already been bootstrapped"); } } else { Log.warn("Couldn't find Hibernate, cannot bootstrap JPA!"); } }
private static synchronized void restartApp() { if (!MscOpts.hasRapidoidWatch()) { Log.warn("Cannot reload/restart the application, module rapidoid-watch is missing!"); } if (mainClassName == null) { Log.warn("Cannot reload/restart the application, the main app class couldn't be detected!"); } Msc.logSection("!Restarting the web application..."); restarted = true; notifyListenersBeforeRestart(); resetAppStateBeforeRestart(); if (MscOpts.hasRapidoidJPA()) { loader = ReloadUtil.reloader(); ClasspathUtil.setDefaultClassLoader(loader); } reloadAndRunMainClass(); restarted = true; notifyListenersAfterRestart(); Log.info("!Successfully restarted the application!"); }
public static <T> T connect(String address, int port, int timeout, F3<T, InputStream, BufferedReader, DataOutputStream> protocol) { return MscOpts.isTLSEnabled() ? connectSSL(address, port, timeout, protocol) : connectNoSSL(address, port, timeout, protocol); }
private synchronized void listen() { if (!listening && !reloaded) { App.inferCallers(); listening = true; HttpProcessor proc = processor != null ? processor : http(); if (Env.dev() && !On.changes().isIgnored() && MscOpts.hasRapidoidWatch()) { proc = new AppRestartProcessor(this, proc); On.changes().byDefaultRestart(); } if (delegateAdminToApp()) { server = on().server(); } else if (delegateAppToAdmin()) { server = admin().server(); } if (server == null) { int targetPort; if (isAppOrAdminOnSameServer()) { targetPort = on().port(); server = proc.listen(on().address(), targetPort); } else { targetPort = port(); server = proc.listen(address(), targetPort); } Log.info("!Server has started", "setup", name(), "!home", "http://localhost:" + targetPort); Log.info("!Static resources will be served from the following locations", "setup", name(), "!locations", custom().staticFilesPath()); } } }
private DataSource createPool() { String provider = U.safe(poolProvider); switch (provider) { case "hikari": U.must(MscOpts.hasHikari(), "Couldn't find Hikari!"); Log.info("Initializing JDBC connection pool with Hikari", "!url", url, "!driver", driver, "!username", username, "!password", maskedPassword()); return HikariFactory.createDataSourceFor(this); case "c3p0": U.must(MscOpts.hasC3P0(), "Couldn't find C3P0!"); Log.info("Initializing JDBC connection pool with C3P0", "!url", url, "!driver", driver, "!username", username, "!password", maskedPassword()); return C3P0Factory.createDataSourceFor(this); default: throw U.rte("Unknown pool provider: '%s'!", provider); } }
@PostConstruct public void postConstructInitialization() { U.notNull(ctx, "ConfigurableApplicationContext ctx"); if (useProfiles()) { initProfiles(); } if (useEmf() && JPA.getEmf() == null && MscOpts.hasJPA()) { initJPA(); } if (useBeans()) { initBeans(); } run(); }
private static boolean isEntity(Object item) { return MscOpts.hasRapidoidJPA() && GuiJpaUtil.isEntity(item); }
public ActionsProp() { U.must(MscOpts.hasRapidoidGUI(), "This special property requires the rapidoid-gui module!"); }
public Booter entities() { setup.page(uri("entities")) .internal(true) .roles(Role.ADMINISTRATOR) .zone(CENTER) .menu(50, "Application", 30, "Entities") .mvc(new EntitiesHandler()); if (MscOpts.hasJPA()) { for (Class<?> type : JPA.getEntityJavaTypes()) { String uri = GUI.typeUri(type); BasicConfig zone = HttpUtils.zone(setup.custom(), setup.zone()); String contextPath = zone.entry("home").or(uri("")); X.scaffold(type) .internal(true) .baseUri(Msc.uri(contextPath, uri)) .roles(Role.ADMINISTRATOR) .on(setup); } } return this; }
private Object provideSpecialInstance(Class<?> type, String name) { String cls = type.getName(); if (type.equals(IoCContext.class)) { return U.or(wrapper, this); } if (cls.equals("javax.persistence.EntityManager") && MscOpts.hasRapidoidJPA()) { return OptionalJPAUtil.getSharedContextAwareEntityManagerProxy(); } if (cls.equals("javax.persistence.EntityManagerFactory") && MscOpts.hasRapidoidJPA()) { return OptionalJPAUtil.getSharedEntityManagerFactoryProxy(); } return null; }
private static Object wrapGuiContent(Object content) { if (MscOpts.hasRapidoidGUI()) { Object[] items = null; if (content instanceof Collection<?>) { items = U.array((Collection<?>) content); } else if (content instanceof Object[]) { items = (Object[]) content; } if (items != null) { return Cls.newInstance(Cls.get("org.rapidoid.html.ElementGroup"), new Object[]{items}); } } return content; }
@Override protected void bootstrap() { if (MscOpts.hasJPA()) { JPA.bootstrap(App.path()); } } };
private Object provideSpecialInstance(Class<?> type, String name) { String cls = type.getName(); if (type.equals(IoCContext.class)) { return U.or(wrapper, this); } if (cls.equals("javax.persistence.EntityManager") && MscOpts.hasRapidoidJPA()) { return OptionalJPAUtil.getSharedContextAwareEntityManagerProxy(); } if (cls.equals("javax.persistence.EntityManagerFactory") && MscOpts.hasRapidoidJPA()) { return OptionalJPAUtil.getSharedEntityManagerFactoryProxy(); } return null; }