Codota Logo
AutoPartitionByLong
Code IndexAdd Codota 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)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
OutputStreamWriter o =
  • Codota IconOutputStream out;new OutputStreamWriter(out)
  • Codota IconOutputStream out;String charsetName;new OutputStreamWriter(out, charsetName)
  • Codota IconHttpURLConnection connection;new OutputStreamWriter(connection.getOutputStream())
  • Smart code suggestions by Codota
}
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

  • Updating database using SQL prepared statement
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • onCreateOptionsMenu (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • IOException (java.io)
    Signals that an I/O exception of some sort has occurred. This class is the general class of exceptio
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Locale (java.util)
    A Locale object represents a specific geographical, political, or cultural region. An operation that
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Runner (org.openjdk.jmh.runner)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now