Search in sources :

Example 1 with Employee

use of org.apache.ignite.console.demo.model.Employee in project ignite by apache.

the class DemoCachesLoadService method cacheEmployee.

/**
 * Configure cacheEmployee.
 */
private static CacheConfiguration cacheEmployee() {
    CacheConfiguration ccfg = cacheConfiguration(EMPLOYEE_CACHE_NAME);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setBackups(1);
    // Configure cacheEmployee types.
    Collection<QueryEntity> qryEntities = new ArrayList<>();
    // EMPLOYEE.
    QueryEntity type = new QueryEntity();
    qryEntities.add(type);
    type.setKeyType(Integer.class.getName());
    type.setValueType(Employee.class.getName());
    // Query fields for EMPLOYEE.
    LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>();
    qryFlds.put("id", "java.lang.Integer");
    qryFlds.put("departmentId", "java.lang.Integer");
    qryFlds.put("managerId", "java.lang.Integer");
    qryFlds.put("firstName", "java.lang.String");
    qryFlds.put("lastName", "java.lang.String");
    qryFlds.put("email", "java.lang.String");
    qryFlds.put("phoneNumber", "java.lang.String");
    qryFlds.put("hireDate", "java.sql.Date");
    qryFlds.put("job", "java.lang.String");
    qryFlds.put("salary", "java.lang.Double");
    type.setFields(qryFlds);
    // Indexes for EMPLOYEE.
    QueryIndex idx = new QueryIndex();
    idx.setName("EMP_NAMES");
    idx.setIndexType(QueryIndexType.SORTED);
    LinkedHashMap<String, Boolean> indFlds = new LinkedHashMap<>();
    indFlds.put("firstName", Boolean.FALSE);
    indFlds.put("lastName", Boolean.FALSE);
    idx.setFields(indFlds);
    Collection<QueryIndex> indexes = new ArrayList<>();
    indexes.add(idx);
    indexes.add(new QueryIndex("salary", QueryIndexType.SORTED, false, "EMP_SALARY"));
    type.setIndexes(indexes);
    ccfg.setQueryEntities(qryEntities);
    return ccfg;
}
Also used : ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) Employee(org.apache.ignite.console.demo.model.Employee) QueryIndex(org.apache.ignite.cache.QueryIndex) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 2 with Employee

use of org.apache.ignite.console.demo.model.Employee in project ignite by apache.

the class DemoCachesLoadService method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(ServiceContext ctx) throws Exception {
    cachePool.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            try {
                IgniteCache<Integer, Employee> cacheEmployee = ignite.cache(EMPLOYEE_CACHE_NAME);
                if (cacheEmployee != null)
                    try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                        for (int i = 0, n = 1; i < cnt; i++, n++) {
                            Integer id = rnd.nextInt(EMPL_CNT);
                            Integer depId = rnd.nextInt(DEP_CNT);
                            double r = rnd.nextDouble();
                            cacheEmployee.put(id, new Employee(id, depId, depId, "First name employee #" + n, "Last name employee #" + n, "Email employee #" + n, "Phone number employee #" + n, new java.sql.Date((long) (r * range)), "Job employee #" + n, 500 + AgentDemoUtils.round(r * 2000, 2)));
                            if (rnd.nextBoolean())
                                cacheEmployee.remove(rnd.nextInt(EMPL_CNT));
                            cacheEmployee.get(rnd.nextInt(EMPL_CNT));
                        }
                        if (rnd.nextInt(100) > 20)
                            tx.commit();
                    }
            } catch (Throwable e) {
                if (!e.getMessage().contains("cache is stopped"))
                    ignite.log().error("Cache write task execution error", e);
            }
        }
    }, 10, 3, TimeUnit.SECONDS);
    cachePool.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            try {
                IgniteCache<Integer, Car> cache = ignite.cache(CAR_CACHE_NAME);
                if (cache != null)
                    for (int i = 0; i < cnt; i++) {
                        Integer carId = rnd.nextInt(CAR_CNT);
                        cache.put(carId, new Car(carId, rnd.nextInt(PARK_CNT), "Car #" + (i + 1)));
                        if (rnd.nextBoolean())
                            cache.remove(rnd.nextInt(CAR_CNT));
                    }
            } catch (IllegalStateException ignored) {
            // No-op.
            } catch (Throwable e) {
                if (!e.getMessage().contains("cache is stopped"))
                    ignite.log().error("Cache write task execution error", e);
            }
        }
    }, 10, 3, TimeUnit.SECONDS);
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) Employee(org.apache.ignite.console.demo.model.Employee) Transaction(org.apache.ignite.transactions.Transaction) Car(org.apache.ignite.console.demo.model.Car)

Example 3 with Employee

use of org.apache.ignite.console.demo.model.Employee in project ignite by apache.

the class DemoCachesLoadService method populateCacheEmployee.

/**
 */
private void populateCacheEmployee() {
    if (ignite.log().isDebugEnabled())
        ignite.log().debug("DEMO: Start employees population with data...");
    IgniteCache<Integer, Country> cacheCountry = ignite.cache(COUNTRY_CACHE_NAME);
    for (int i = 0, n = 1; i < CNTR_CNT; i++, n++) cacheCountry.put(i, new Country(i, "Country #" + n, n * 10000000));
    IgniteCache<Integer, Department> cacheDepartment = ignite.cache(DEPARTMENT_CACHE_NAME);
    IgniteCache<Integer, Employee> cacheEmployee = ignite.cache(EMPLOYEE_CACHE_NAME);
    for (int i = 0, n = 1; i < DEP_CNT; i++, n++) {
        cacheDepartment.put(i, new Department(n, rnd.nextInt(CNTR_CNT), "Department #" + n));
        double r = rnd.nextDouble();
        cacheEmployee.put(i, new Employee(i, rnd.nextInt(DEP_CNT), null, "First name manager #" + n, "Last name manager #" + n, "Email manager #" + n, "Phone number manager #" + n, new java.sql.Date((long) (r * range)), "Job manager #" + n, 1000 + AgentDemoUtils.round(r * 4000, 2)));
    }
    for (int i = 0, n = 1; i < EMPL_CNT; i++, n++) {
        Integer depId = rnd.nextInt(DEP_CNT);
        double r = rnd.nextDouble();
        cacheEmployee.put(i, new Employee(i, depId, depId, "First name employee #" + n, "Last name employee #" + n, "Email employee #" + n, "Phone number employee #" + n, new java.sql.Date((long) (r * range)), "Job employee #" + n, 500 + AgentDemoUtils.round(r * 2000, 2)));
    }
    if (ignite.log().isDebugEnabled())
        ignite.log().debug("DEMO: Finished employees population.");
}
Also used : Department(org.apache.ignite.console.demo.model.Department) Employee(org.apache.ignite.console.demo.model.Employee) Country(org.apache.ignite.console.demo.model.Country)

Aggregations

Employee (org.apache.ignite.console.demo.model.Employee)3 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 IgniteCache (org.apache.ignite.IgniteCache)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 QueryIndex (org.apache.ignite.cache.QueryIndex)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 Car (org.apache.ignite.console.demo.model.Car)1 Country (org.apache.ignite.console.demo.model.Country)1 Department (org.apache.ignite.console.demo.model.Department)1 Transaction (org.apache.ignite.transactions.Transaction)1