Package org.makersoft.shards.id

Examples of org.makersoft.shards.id.IdGenerator


      return null;
    } else if (shard.getShardIds().size() == 1) {
      return shard.getShardIds().iterator().next();
    } else {
      //TODO(fengkuok) 似乎从来不会走到这个逻辑
      IdGenerator idGenerator = shardedSqlSessionFactory.getIdGenerator();
      if (idGenerator != null) {
        return idGenerator.extractShardId(this.extractId(parameter));
      } else {
        // TODO(tomislav): also use shard resolution strategy if it returns only 1 shard;
        // throw this error in config instead of here
        throw new RuntimeException(
            "Can not use virtual sharding with non-shard resolving id gen");
View Full Code Here


        .getName()));
    return shardId;
  }

  List<ShardId> selectShardIdsFromShardResolutionStrategyData(ShardResolutionStrategyData srsd) {
    IdGenerator idGenerator = shardedSqlSessionFactory.getIdGenerator();
    if ((idGenerator != null) && (srsd.getId() != null)) {
      //
      return Collections.singletonList(idGenerator.extractShardId(srsd.getId()));
    }
    return shardStrategy.getShardResolutionStrategy()
        .selectShardIdsFromShardResolutionStrategyData(srsd);
  }
View Full Code Here

    log.debug(String.format("Inserting object of type %s to shard %s", parameter.getClass(),
        shardId));

    SqlSession session = shardIdsToShards.get(shardId).establishSqlSession();

    IdGenerator idGenerator = shardedSqlSessionFactory.getIdGenerator();
    if (idGenerator != null) {
      //TODO(fengkuok) 生成主键 DB生成主键是用专有session?
      Serializable id = idGenerator.generate(session, parameter);

      log.debug(String
          .format("Generating id for object %s ,the type of IdGenerator is %s and generated Id is %s.",
              parameter.getClass(), idGenerator.getClass(), id));

      ParameterUtil.generatePrimaryKey(parameter, id);
    }

    return session.insert(statement, ParameterUtil.resolve(parameter, shardId));
View Full Code Here

  }

  public static void main(String[] args) throws Exception {
    ShardedSqlSessionImpl.setCurrentSubgraphShardId(new ShardId(0));

    IdGenerator gen = new ShardedUUIDGenerator();
    IdGenerator gen2 = new ShardedUUIDGenerator();

    for (int i = 0; i < Integer.MAX_VALUE; i++) {
      String id = (String) gen.generate(null, null);
      System.out.println(id);
      String id2 = (String) gen2.generate(null, null);
      System.out.println(id2);
    }

  }
View Full Code Here

TOP

Related Classes of org.makersoft.shards.id.IdGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.