public WrapImpl(WrapType type, boolean wrapFirstElement) {
    Type myType;

    switch (type) {
      case NORMAL:
        myType = Type.WRAP_AS_NEEDED;
        break;
      case NONE:
        myType = Type.DO_NOT_WRAP;
        break;
      case ALWAYS:
        myType = Type.WRAP_ALWAYS;
        break;
      case CHOP_DOWN_IF_LONG:
      default:
        myType = Type.CHOP_IF_NEEDED;
    }

    int myId = ourId++;
    assert myId < ID_MAX;
    myFlags |=
        (wrapFirstElement ? WRAP_FIRST_ELEMENT_MASK : 0)
            | (myType.ordinal() << TYPE_SHIFT)
            | (myId << ID_SHIFT);
  }
Exemple #2
0
 public void writeTo(DataOutput out) throws Exception {
   out.writeByte(type.ordinal());
   Util.writeString(lock_name, out);
   Util.writeStreamable(owner, out);
   out.writeLong(timeout);
   out.writeBoolean(is_trylock);
 }
Exemple #3
0
 public void writeTo(DataOutput out) throws Exception {
   out.writeByte(type.ordinal());
   // We can't use Util.writeObject since it's size is limited to 2^15-1
   try {
     if (object instanceof Streamable) {
       out.writeShort(-1);
       Util.writeGenericStreamable((Streamable) object, out);
     } else {
       byte[] bytes = Util.objectToByteBuffer(object);
       out.writeInt(bytes.length);
       out.write(bytes);
     }
   } catch (IOException e) {
     throw e;
   } catch (Exception e) {
     throw new IOException("Exception encountered while serializing execution request", e);
   }
   out.writeLong(request);
 }
Exemple #4
0
  public static Set<String> getEntitiesNames(SQLConnection sql, Type type, boolean defaultOnly) {
    try {
      Set<String> entities = new HashSet<String>();

      ResultSet result =
          sql.prepAndBind(
                  "SELECT name FROM `{permissions_entity}` WHERE `type` = ? "
                      + (defaultOnly ? " AND `default` = 1" : ""),
                  type.ordinal())
              .executeQuery();

      while (result.next()) {
        entities.add(result.getString("name"));
      }

      result.close();

      return Collections.unmodifiableSet(entities);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
Exemple #5
0
 public AlignmentImpl(final Type type) {
   myFlags = ((ourId++) >> ID_SHIFT) | type.ordinal();
 }