congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
AutoPartitionByLong
Code IndexAdd Tabnine to your IDE (free)

How to use
AutoPartitionByLong
in
com.actiontech.dble.route.function

Best Java code snippets using com.actiontech.dble.route.function.AutoPartitionByLong (Showing top 6 results out of 315)

origin: actiontech/dble

@Override
public Integer[] calculateRange(String beginValue, String endValue) {
  Integer begin = 0, end = 0;
  if (isUseDefaultNode(beginValue) || isUseDefaultNode(endValue)) {
    begin = 0;
    end = longRanges.length - 1;
  } else {
    begin = calculate(beginValue);
    end = calculate(endValue);
  }
  if (begin == null || end == null) {
    return new Integer[0];
  }
  if (end >= begin) {
    int len = end - begin + 1;
    Integer[] re = new Integer[len];
    for (int i = 0; i < len; i++) {
      re[i] = begin + i;
    }
    return re;
  } else {
    return new Integer[0];
  }
}
origin: actiontech/dble

@Override
public void init() {
  initialize();
  initHashCode();
}
origin: actiontech/dble

@Test
public void test2() {
  AutoPartitionByLong autoPartition = new AutoPartitionByLong();
  autoPartition.setMapFile("autopartition-long.txt");
  autoPartition.setDefaultNode(0);
  autoPartition.init();
  String idVal = "6000001";
  Assert.assertEquals(true, 0 == autoPartition.calculate(idVal));
}
origin: actiontech/dble

@Test
public void test1() {
  AutoPartitionByLong autoPartition = new AutoPartitionByLong();
  autoPartition.setMapFile("autopartition-long.txt");
  autoPartition.init();
  String idVal = "0";
  Assert.assertEquals(true, 0 == autoPartition.calculate(idVal));
  idVal = "2000000";
  Assert.assertEquals(true, 0 == autoPartition.calculate(idVal));
  idVal = "2000001";
  Assert.assertEquals(true, 1 == autoPartition.calculate(idVal));
  idVal = "4000000";
  Assert.assertEquals(true, 1 == autoPartition.calculate(idVal));
  idVal = "4000001";
  Assert.assertEquals(true, 2 == autoPartition.calculate(idVal));
  idVal = "6000000";
  Assert.assertEquals(true, 2 == autoPartition.calculate(idVal));
  idVal = "6000001";
  Assert.assertEquals(true, null == autoPartition.calculate(idVal));
  Map<String, String> map = autoPartition.getAllProperties();
  Assert.assertEquals(true, map.get("mapFile").equals("{\"0-200M\":\"0\"," +
      "\"200M1-400M\":\"1\","+
      "\"400M1-600M\":\"2\"}") );
}
origin: actiontech/dble

@Test
public void test3() {
  AutoPartitionByLong autoPartition = new AutoPartitionByLong();
  autoPartition.setMapFile("autopartition-long.txt");
  autoPartition.setDefaultNode(0);
  autoPartition.init();
  Integer[] res = autoPartition.calculateRange("-1", "9999999999");
  Assert.assertEquals(3, res.length);
  res = autoPartition.calculateRange("-1", "10000000");
  Assert.assertEquals(3, res.length);
  res = autoPartition.calculateRange("-1", "100");
  Assert.assertEquals(3, res.length);
  res = autoPartition.calculateRange("0", "100");
  Assert.assertEquals(1, res.length);
  res = autoPartition.calculateRange("0", "100000");
  Assert.assertEquals(1, res.length);
  res = autoPartition.calculateRange("2000009", "3999999");
  Assert.assertEquals(1, res.length);
  res = autoPartition.calculateRange("2000009", "5999999");
  Assert.assertEquals(2, res.length);
  res = autoPartition.calculateRange("2000009", "59999999");
  Assert.assertEquals(3, res.length);
}
origin: actiontech/dble

private AbstractPartitionAlgorithm createFunction(String name, String clazz)
    throws ClassNotFoundException, InstantiationException,
    IllegalAccessException, InvocationTargetException {
  String lowerClass = clazz.toLowerCase();
  switch (lowerClass) {
    case "hash":
      return new PartitionByLong();
    case "stringhash":
      return new PartitionByString();
    case "enum":
      return new PartitionByFileMap();
    case "jumpstringhash":
      return new PartitionByJumpConsistentHash();
    case "numberrange":
      return new AutoPartitionByLong();
    case "patternrange":
      return new PartitionByPattern();
    case "date":
      return new PartitionByDate();
    default:
      Class<?> clz = Class.forName(clazz);
      //all function must be extend from AbstractPartitionAlgorithm
      if (!AbstractPartitionAlgorithm.class.isAssignableFrom(clz)) {
        throw new IllegalArgumentException("rule function must implements " +
            AbstractPartitionAlgorithm.class.getName() + ", name=" + name);
      }
      return (AbstractPartitionAlgorithm) clz.newInstance();
  }
}
com.actiontech.dble.route.functionAutoPartitionByLong

Javadoc

auto partition by Long ,can be used in auto increment primary key partition

Most used methods

  • <init>
  • calculate
  • calculateRange
  • getAllProperties
  • init
  • initHashCode
  • initialize
  • isUseDefaultNode
  • setDefaultNode
  • setMapFile

Popular in Java

  • Making http requests using okhttp
  • getSharedPreferences (Context)
  • getExternalFilesDir (Context)
  • setScale (BigDecimal)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top 17 PhpStorm Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now