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;
}
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);
}
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.");
}
Aggregations