Search in sources :

Example 21 with PostConstruct

use of jakarta.annotation.PostConstruct in project tomee by apache.

the class Movies method construct.

@PostConstruct
private void construct() throws Exception {
    Connection connection = movieDatabase.getConnection();
    try {
        PreparedStatement stmt = connection.prepareStatement("CREATE TABLE movie ( director VARCHAR(255), title VARCHAR(255), year integer)");
        stmt.execute();
    } finally {
        connection.close();
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) PostConstruct(jakarta.annotation.PostConstruct)

Example 22 with PostConstruct

use of jakarta.annotation.PostConstruct in project tomee by apache.

the class Alternative method postConstruct.

@PostConstruct
public <T> void postConstruct() throws MBeanRegistrationException {
    final String name = properties.remove("name").toString();
    final String iface = properties.remove("interface").toString();
    final String prefix = properties.remove("prefix").toString();
    requireNotNull(name);
    requireNotNull(iface);
    try {
        final Class<T> ifaceCls = (Class<T>) Class.forName(iface, true, Thread.currentThread().getContextClassLoader());
        final StandardMBean mBean = new StandardMBean((T) this, ifaceCls);
        for (String attributeName : properties.stringPropertyNames()) {
            final Object value = properties.remove(attributeName);
            if (prefix != null) {
                if (!attributeName.startsWith(prefix + ".")) {
                    continue;
                } else {
                    attributeName = attributeName.substring(prefix.length() + 1);
                }
            }
            final Class<?> targetType = findAttributeType(mBean.getMBeanInfo(), attributeName);
            final Object targetValue = Converter.convert(value, targetType, null);
            final Attribute attribute = new Attribute(attributeName, targetValue);
            mBean.setAttribute(attribute);
        }
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final ObjectName objectName = new ObjectName(name);
        mbs.registerMBean(this, objectName);
    } catch (final Exception e) {
        LOGGER.severe("Unable to register mbean " + e.getMessage());
        throw new MBeanRegistrationException(e);
    }
}
Also used : StandardMBean(javax.management.StandardMBean) Attribute(javax.management.Attribute) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanRegistrationException(org.superbiz.resource.jmx.factory.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(org.superbiz.resource.jmx.factory.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) PostConstruct(jakarta.annotation.PostConstruct)

Example 23 with PostConstruct

use of jakarta.annotation.PostConstruct in project tomee by apache.

the class SampleDataManager method createSomeData.

@PostConstruct
public void createSomeData() {
    final User tomee = users.create("tomee", "tomee", "tomee@apache.org");
    final User openejb = users.create("openejb", "openejb", "openejb@apache.org");
    final Post tomeePost = posts.create("TomEE", "TomEE is a cool JEE App Server", tomee.getId());
    posts.create("OpenEJB", "OpenEJB is a cool embedded container", openejb.getId());
    comments.create("visitor", "nice post!", tomeePost.getId());
}
Also used : User(org.superbiz.rest.model.User) Post(org.superbiz.rest.model.Post) PostConstruct(jakarta.annotation.PostConstruct)

Example 24 with PostConstruct

use of jakarta.annotation.PostConstruct in project tomee by apache.

the class FarmerBrown method construct.

@PostConstruct
private void construct() {
    final TimerConfig plantTheCorn = new TimerConfig("plantTheCorn", false);
    timerService.createCalendarTimer(new ScheduleExpression().month(5).dayOfMonth("20-Last").minute(0).hour(8), plantTheCorn);
    timerService.createCalendarTimer(new ScheduleExpression().month(6).dayOfMonth("1-10").minute(0).hour(8), plantTheCorn);
    final TimerConfig harvestTheCorn = new TimerConfig("harvestTheCorn", false);
    timerService.createCalendarTimer(new ScheduleExpression().month(9).dayOfMonth("20-Last").minute(0).hour(8), harvestTheCorn);
    timerService.createCalendarTimer(new ScheduleExpression().month(10).dayOfMonth("1-10").minute(0).hour(8), harvestTheCorn);
    final TimerConfig checkOnTheDaughters = new TimerConfig("checkOnTheDaughters", false);
    timerService.createCalendarTimer(new ScheduleExpression().second("*").minute("*").hour("*"), checkOnTheDaughters);
}
Also used : ScheduleExpression(jakarta.ejb.ScheduleExpression) TimerConfig(jakarta.ejb.TimerConfig) PostConstruct(jakarta.annotation.PostConstruct)

Example 25 with PostConstruct

use of jakarta.annotation.PostConstruct in project cdi-tck by jakartaee.

the class Farm method postConstruct.

@PostConstruct
protected void postConstruct() {
    founded = new Date();
    initialStaff = farmOffice.noOfStaff;
}
Also used : Date(java.util.Date) PostConstruct(jakarta.annotation.PostConstruct)

Aggregations

PostConstruct (jakarta.annotation.PostConstruct)76 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 IOException (java.io.IOException)6 Date (java.util.Date)6 PostBean (it.vige.rubia.dto.PostBean)4 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)4 ArrayList (java.util.ArrayList)4 ForumBean (it.vige.rubia.dto.ForumBean)3 FacesContext (jakarta.faces.context.FacesContext)3 Method (java.lang.reflect.Method)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)2 HTTPServer (io.prometheus.client.exporter.HTTPServer)2 ModuleException (it.vige.rubia.ModuleException)2 CategoryBean (it.vige.rubia.dto.CategoryBean)2 TopicBean (it.vige.rubia.dto.TopicBean)2 SessionScoped (jakarta.enterprise.context.SessionScoped)2 Typed (jakarta.enterprise.inject.Typed)2 ClientWindow (jakarta.faces.lifecycle.ClientWindow)2 Serializable (java.io.Serializable)2