示例#1
0
  /** Configure cacheEmployee. */
  private static <K, V> CacheConfiguration<K, V> cacheCar() {
    CacheConfiguration<K, V> ccfg = cacheConfiguration(CAR_CACHE_NAME);

    // Configure cacheCar types.
    Collection<QueryEntity> qryEntities = new ArrayList<>();

    // CAR.
    QueryEntity type = new QueryEntity();

    qryEntities.add(type);

    type.setKeyType(Integer.class.getName());
    type.setValueType(Car.class.getName());

    // Query fields for CAR.
    LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>();

    qryFlds.put("id", "java.lang.Integer");
    qryFlds.put("parkingId", "java.lang.Integer");
    qryFlds.put("name", "java.lang.String");

    type.setFields(qryFlds);

    ccfg.setQueryEntities(qryEntities);

    return ccfg;
  }
示例#2
0
  /** Configure cacheEmployee. */
  private static <K, V> CacheConfiguration<K, V> cacheEmployee() {
    CacheConfiguration<K, V> 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.
    Collection<QueryIndex> indexes = new ArrayList<>();

    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);

    indexes.add(idx);
    indexes.add(new QueryIndex("salary", QueryIndexType.SORTED, false, "EMP_SALARY"));

    type.setIndexes(indexes);

    ccfg.setQueryEntities(qryEntities);

    return ccfg;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);

    CacheConfiguration ccfg = new CacheConfiguration();
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    QueryEntity person = new QueryEntity();
    person.setKeyType(TestKey.class.getName());
    person.setValueType(Person.class.getName());
    person.addQueryField("name", String.class.getName(), null);

    ccfg.setQueryEntities(Arrays.asList(person));

    cfg.setCacheConfiguration(ccfg);

    cfg.setMarshaller(null);

    return cfg;
  }
  final void createBinaryCaches() {
    {
      CacheConfiguration s2pCcfg = cacheConfig("S2P", true, false);

      QueryEntity s2p = new QueryEntity(String.class.getName(), "Person");

      LinkedHashMap<String, String> flds = new LinkedHashMap<>();

      flds.put("id", Integer.class.getName());
      flds.put("name", String.class.getName());

      s2p.setFields(flds);

      s2p.setIndexes(Collections.<QueryIndex>emptyList());

      QueryEntity s2s = new QueryEntity(String.class.getName(), String.class.getName());

      s2pCcfg.setQueryEntities(Arrays.asList(s2p, s2s));

      ignite(0).createCache(s2pCcfg);
    }

    {
      CacheConfiguration i2pCcfg = cacheConfig("I2P", true, false);

      QueryEntity i2p = new QueryEntity(Integer.class.getName(), "Person");

      LinkedHashMap<String, String> flds = new LinkedHashMap<>();

      flds.put("id", Integer.class.getName());
      flds.put("name", String.class.getName());

      i2p.setFields(flds);

      i2p.setIndexes(Collections.<QueryIndex>emptyList());

      i2pCcfg.setQueryEntities(Collections.singletonList(i2p));

      ignite(0).createCache(i2pCcfg);
    }

    {
      CacheConfiguration k2pCcfg = cacheConfig("K2P", true, false);

      QueryEntity k2p = new QueryEntity(Key.class.getName(), "Person");

      k2p.setKeyFields(Collections.singleton("key"));

      LinkedHashMap<String, String> flds = new LinkedHashMap<>();

      flds.put("key", Integer.class.getName());
      flds.put("id", Integer.class.getName());
      flds.put("name", String.class.getName());

      k2p.setFields(flds);

      k2p.setIndexes(Collections.<QueryIndex>emptyList());

      k2pCcfg.setQueryEntities(Collections.singletonList(k2p));

      ignite(0).createCache(k2pCcfg);
    }

    {
      CacheConfiguration k22pCcfg = cacheConfig("K22P", true, true);

      QueryEntity k22p = new QueryEntity(Key2.class.getName(), "Person2");

      k22p.setKeyFields(Collections.singleton("Id"));

      LinkedHashMap<String, String> flds = new LinkedHashMap<>();

      flds.put("Id", Integer.class.getName());
      flds.put("id", Integer.class.getName());
      flds.put("name", String.class.getName());
      flds.put("IntVal", Integer.class.getName());

      k22p.setFields(flds);

      k22p.setIndexes(Collections.<QueryIndex>emptyList());

      k22pCcfg.setQueryEntities(Collections.singletonList(k22p));

      ignite(0).createCache(k22pCcfg);
    }

    {
      CacheConfiguration k32pCcfg = cacheConfig("K32P", true, false);

      QueryEntity k32p = new QueryEntity(Key3.class.getName(), "Person");

      k32p.setKeyFields(new HashSet<>(Arrays.asList("key", "strKey")));

      LinkedHashMap<String, String> flds = new LinkedHashMap<>();

      flds.put("key", Integer.class.getName());
      flds.put("strKey", String.class.getName());
      flds.put("id", Integer.class.getName());
      flds.put("name", String.class.getName());

      k32p.setFields(flds);

      k32p.setIndexes(Collections.<QueryIndex>emptyList());

      k32pCcfg.setQueryEntities(Collections.singletonList(k32p));

      ignite(0).createCache(k32pCcfg);
    }

    {
      CacheConfiguration k42pCcfg = cacheConfig("K42P", true, false);

      QueryEntity k42p = new QueryEntity(Key4.class.getName(), "Person");

      k42p.setKeyFields(new HashSet<>(Arrays.asList("key", "strKey")));

      LinkedHashMap<String, String> flds = new LinkedHashMap<>();

      flds.put("key", Integer.class.getName());
      flds.put("strKey", String.class.getName());
      flds.put("id", Integer.class.getName());
      flds.put("name", String.class.getName());

      k42p.setFields(flds);

      k42p.setIndexes(Collections.<QueryIndex>emptyList());

      k42pCcfg.setQueryEntities(Collections.singletonList(k42p));

      ignite(0).createCache(k42pCcfg);
    }

    {
      CacheConfiguration i2iCcfg = cacheConfig("I2I", true, false);

      QueryEntity i2i = new QueryEntity(Integer.class.getName(), Integer.class.getName());

      i2i.setFields(new LinkedHashMap<String, String>());

      i2i.setIndexes(Collections.<QueryIndex>emptyList());

      i2iCcfg.setQueryEntities(Collections.singletonList(i2i));

      ignite(0).createCache(i2iCcfg);
    }
  }