Example #1
0
 @Override
 public void storeProperties(Map properties) {
   super.storeProperties(properties);
   properties.put("projectId", this.projectId);
   properties.put("name", this.name);
   properties.put("text", this.text);
 }
Example #2
0
 public void ensureIntegrity() {
   super.ensureIntegrity();
   if (!isProjectSet()) {
     repairMissingMaster();
     return;
   }
   try {
     getProject();
   } catch (EntityDoesNotExistException ex) {
     LOG.info("Repairing dead project reference");
     repairDeadProjectReference(this.projectId);
   }
 }
Example #3
0
  private boolean loadObject(File file, Map<String, AEntity> entities, Class type, String alias) {
    String name = file.getName();
    if (!name.endsWith(".xml")) {
      LOG.warn("Unsupported file. Skipping:", name);
      return false;
    }

    if (entityfilePreparator != null) entityfilePreparator.prepareEntityfile(file, type, alias);

    BufferedInputStream in;
    try {
      in = new BufferedInputStream(new FileInputStream(file));
    } catch (FileNotFoundException ex) {
      throw new RuntimeException(ex);
    }
    AEntity entity = (AEntity) beanSerializer.deserialize(in);
    entities.put(entity.getId(), entity);
    try {
      in.close();
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
    return true;
  }
Example #4
0
  @Override
  public synchronized void delete(AEntity entity) {
    String alias = aliases.get(entity.getClass());
    File file = new File(dir + "/" + alias + "/" + entity.getId() + ".xml");

    // backup
    if (file.exists() && !(entity instanceof BackupHostile)) {
      backup(file, entity.getDao().getEntityName());
    }

    // delete
    if (!file.delete() && file.exists())
      throw new RuntimeException("Deleting entity file failed: " + file.getAbsolutePath());

    getDao(entity.getClass()).remove(entity.getId());

    LOG.debug("Entity deleted:", file.getPath(), entity.getClass().getSimpleName(), entity);
  }
Example #5
0
  @Override
  public synchronized void save(AEntity entity) {
    if (!versionSaved) saveVersion();

    String alias = aliases.get(entity.getClass());
    File tmpFile = new File(dir + "/tmp/" + entity.getId() + ".xml");

    if (!tmpFile.getParentFile().exists()) {
      tmpFile.getParentFile().mkdirs();
    }

    // save
    BufferedOutputStream out;
    try {
      out = new BufferedOutputStream(new FileOutputStream(tmpFile));
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
    beanSerializer.serialize(entity, out);
    try {
      out.close();
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }

    File file = new File(dir + "/" + alias + "/" + entity.getId() + ".xml");

    // backup
    if (file.exists() && !(entity instanceof BackupHostile)) {
      backup(file, entity.getDao().getEntityName());
    }

    IO.move(tmpFile, file, true);

    getDao(entity.getClass()).put(entity.getId(), entity);

    LOG.debug("Entity saved:", entity, "->", file.getPath());
  }
Example #6
0
 protected void repairDeadReferences(String entityId) {
   super.repairDeadReferences(entityId);
   repairDeadProjectReference(entityId);
 }