All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.zalando.sprocwrapper.sharding.VirtualShardMurmur2HashStrategy Maven / Gradle / Ivy

Go to download

Library to make PostgreSQL stored procedures available through simple Java "*SProcService" interfaces including automatic object serialization and deserialization (using typemapper and convention-over-configuration). Supports sharding, advisory locking, statement timeouts and PostgreSQL types such as enums and hstore.

There is a newer version: 2.0.0
Show newest version
package de.zalando.sprocwrapper.sharding;

import java.util.List;

public class VirtualShardMurmur2HashStrategy extends VirtualShardKeyStrategy {

    /**
     * @param   objs  Key Objects
     *
     * @return  virtual shard id
     */
    @Override
    public int getShardId(final Object[] objs) {
        if (objs == null || objs.length == 0) {
            return 0;
        }

        Object input = null;

        if (objs[0] == null) {
            return 0;
        }

        if (objs[0] instanceof List) {
            List list = (List) objs[0];
            if (list.isEmpty()) {
                return 0;
            }

            input = list.get(0);
        } else {
            input = objs[0];
        }
/*
 *      if (input instanceof Long) {
 *          hasher.putLong((Long) input);
 *      } else if (input instanceof Integer) {
 *          hasher.putInt((Integer) input);
 *      } else {
 *          hasher.putString((String) input);
 *      }*/

        return Murmur2Hash.hash(((String) input).getBytes(), 0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy