congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
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

  • Finding current android device location
  • setContentView (Activity)
  • scheduleAtFixedRate (Timer)
  • getExternalFilesDir (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Runner (org.openjdk.jmh.runner)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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