Exemplo n.º 1
0
 public static void releaseContent(int contentId) {
   try {
     getContentStorage().releaseRecord(contentId);
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   }
 }
Exemplo n.º 2
0
  public static Pair<String[], int[]> listAll(int parentId) {
    try {
      r.lock();
      try {
        final DataInputStream input = readAttribute(parentId, CHILDREN_ATT);
        if (input == null)
          return Pair.create(ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.EMPTY_INT_ARRAY);

        final int count = DataInputOutputUtil.readINT(input);
        final int[] ids = ArrayUtil.newIntArray(count);
        final String[] names = ArrayUtil.newStringArray(count);
        for (int i = 0; i < count; i++) {
          int id = DataInputOutputUtil.readINT(input);
          id = id >= 0 ? id + parentId : -id;
          ids[i] = id;
          names[i] = getName(id);
        }
        input.close();
        return Pair.create(names, ids);
      } finally {
        r.unlock();
      }
    } catch (Throwable e) {
      throw DbConnection.handleError(e);
    }
  }
Exemplo n.º 3
0
 @Nullable
 public static DataInputStream readContentById(int contentId) {
   try {
     return getContentStorage().readStream(contentId);
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   }
 }
Exemplo n.º 4
0
    @Override
    public void close() throws IOException {
      super.close();

      try {
        doFlush();
      } catch (Throwable e) {
        throw DbConnection.handleError(e);
      }
    }
Exemplo n.º 5
0
 public static int storeUnlinkedContent(byte[] bytes) {
   try {
     int recordId = getContentStorage().acquireNewRecord();
     AbstractStorage.StorageDataOutput output = getContentStorage().writeStream(recordId, true);
     output.write(bytes);
     output.close();
     return recordId;
   } catch (IOException e) {
     throw DbConnection.handleError(e);
   }
 }
Exemplo n.º 6
0
 public static void deleteRecordRecursively(int id) {
   try {
     w.lock();
     incModCount(id);
     doDeleteRecursively(id);
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   } finally {
     w.unlock();
   }
 }
Exemplo n.º 7
0
 public static void setTimestamp(int id, long value) {
   try {
     w.lock();
     incModCount(id);
     getRecords().putLong(getOffset(id, TIMESTAMP_OFFSET), value);
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   } finally {
     w.unlock();
   }
 }
Exemplo n.º 8
0
 public static void setName(int id, String name) {
   try {
     w.lock();
     incModCount(id);
     putRecordInt(id, NAME_OFFSET, getNames().enumerate(name));
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   } finally {
     w.unlock();
   }
 }
Exemplo n.º 9
0
 public static void setLength(int id, long len) {
   try {
     w.lock();
     incModCount(id);
     getRecords().putLong(getOffset(id, LENGTH_OFFSET), len);
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   } finally {
     w.unlock();
   }
 }
Exemplo n.º 10
0
 public static boolean wereChildrenAccessed(int id) {
   try {
     r.lock();
     try {
       return findAttributePage(id, CHILDREN_ATT, false) != 0;
     } finally {
       r.unlock();
     }
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   }
 }
Exemplo n.º 11
0
 public static int getContentId(int fileId) {
   try {
     r.lock();
     try {
       return getContentRecordId(fileId);
     } finally {
       r.unlock();
     }
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   }
 }
Exemplo n.º 12
0
 public static void dispose() {
   try {
     w.lock();
     DbConnection.force();
     DbConnection.closeFiles();
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   } finally {
     ourIsDisposed = true;
     w.unlock();
   }
 }
Exemplo n.º 13
0
 public static int acquireFileContent(int fileId) {
   try {
     w.lock();
     int record = getContentRecordId(fileId);
     if (record > 0) getContentStorage().acquireRecord(record);
     return record;
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   } finally {
     w.unlock();
   }
 }
Exemplo n.º 14
0
  private static void checkAttributesStorageSanity(
      int id, IntArrayList usedAttributeRecordIds, IntArrayList validAttributeIds) {
    int attributeRecordId = getAttributeRecordId(id);

    assert attributeRecordId >= 0;
    if (attributeRecordId > 0) {
      try {
        checkAttributesSanity(attributeRecordId, usedAttributeRecordIds, validAttributeIds);
      } catch (IOException ex) {
        throw DbConnection.handleError(ex);
      }
    }
  }
Exemplo n.º 15
0
 public static void setFlags(int id, int flags, final boolean markAsChange) {
   try {
     w.lock();
     if (markAsChange) {
       incModCount(id);
     }
     putRecordInt(id, FLAGS_OFFSET, flags);
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   } finally {
     w.unlock();
   }
 }
Exemplo n.º 16
0
 public static String getName(int id) {
   try {
     r.lock();
     try {
       final int nameId = getRecordInt(id, NAME_OFFSET);
       return nameId != 0 ? getNames().valueOf(nameId) : "";
     } finally {
       r.unlock();
     }
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   }
 }
Exemplo n.º 17
0
  private static void deleteRecord(final int id) {
    try {
      w.lock();
      DbConnection.markDirty();
      deleteContentAndAttributes(id);

      DbConnection.cleanRecord(id);
      addToFreeRecordsList(id);
    } catch (Throwable e) {
      throw DbConnection.handleError(e);
    } finally {
      w.unlock();
    }
  }
Exemplo n.º 18
0
 @Nullable
 public static DataInputStream readContent(int fileId) {
   try {
     int page;
     try {
       r.lock();
       page = findContentPage(fileId, false);
       if (page == 0) return null;
     } finally {
       r.unlock();
     }
     return getContentStorage().readStream(page);
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   }
 }
Exemplo n.º 19
0
  public static void setParent(int id, int parent) {
    if (id == parent) {
      LOG.error("Cyclic parent/child relations");
      return;
    }

    try {
      w.lock();
      incModCount(id);
      putRecordInt(id, PARENT_OFFSET, parent);
    } catch (Throwable e) {
      throw DbConnection.handleError(e);
    } finally {
      w.unlock();
    }
  }
Exemplo n.º 20
0
  public static int getParent(int id) {
    try {
      r.lock();
      try {
        final int parentId = getRecordInt(id, PARENT_OFFSET);
        if (parentId == id) {
          LOG.error("Cyclic parent child relations in the database. id = " + id);
          return 0;
        }

        return parentId;
      } finally {
        r.unlock();
      }
    } catch (Throwable e) {
      throw DbConnection.handleError(e);
    }
  }
Exemplo n.º 21
0
 @Nullable
 public static DataInputStream readAttribute(int fileId, String attId) {
   try {
     synchronized (attId) {
       int page;
       try {
         r.lock();
         page = findAttributePage(fileId, attId, false);
         if (page == 0) return null;
       } finally {
         r.unlock();
       }
       return getAttributesStorage().readStream(page);
     }
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   }
 }
Exemplo n.º 22
0
 public static void updateList(int id, @NotNull int[] children) {
   try {
     w.lock();
     DbConnection.markDirty();
     final DataOutputStream record = writeAttribute(id, CHILDREN_ATT, false);
     DataInputOutputUtil.writeINT(record, children.length);
     for (int child : children) {
       if (child == id) {
         LOG.error("Cyclic parent child relations");
       } else {
         child = child > id ? child - id : -child;
         DataInputOutputUtil.writeINT(record, child);
       }
     }
     record.close();
   } catch (Throwable e) {
     throw DbConnection.handleError(e);
   } finally {
     w.unlock();
   }
 }
Exemplo n.º 23
0
  public static int[] list(int id) {
    try {
      r.lock();
      try {
        final DataInputStream input = readAttribute(id, CHILDREN_ATT);
        if (input == null) return ArrayUtil.EMPTY_INT_ARRAY;

        final int count = DataInputOutputUtil.readINT(input);
        final int[] result = ArrayUtil.newIntArray(count);
        for (int i = 0; i < count; i++) {
          int childId = DataInputOutputUtil.readINT(input);
          childId = childId >= 0 ? childId + id : -childId;
          result[i] = childId;
        }
        input.close();
        return result;
      } finally {
        r.unlock();
      }
    } catch (Throwable e) {
      throw DbConnection.handleError(e);
    }
  }
Exemplo n.º 24
0
  public static int createRecord() {
    try {
      w.lock();
      DbConnection.markDirty();

      final int free = DbConnection.getFreeRecord();
      if (free == 0) {
        final int filelength = (int) getRecords().length();
        LOG.assertTrue(filelength % RECORD_SIZE == 0);
        int newrecord = filelength / RECORD_SIZE;
        DbConnection.cleanRecord(newrecord);
        assert filelength + RECORD_SIZE == getRecords().length();
        return newrecord;
      } else {
        DbConnection.cleanRecord(free);
        return free;
      }
    } catch (Throwable e) {
      throw DbConnection.handleError(e);
    } finally {
      w.unlock();
    }
  }
Exemplo n.º 25
0
 public static RuntimeException handleError(Throwable e) {
   return DbConnection.handleError(e);
 }