code: public Layout readLayoutFrom(InputStream in) throws IOException, RepositoryException {
          Transaction txn = mRepository.enterTransaction();
          try {
              txn.setForUpdate(true);
  
              StoredLayout storedLayout = mLayoutStorage.prepare();
              storedLayout.readFrom(in);
              try {
                  storedLayout.insert();
              } catch (UniqueConstraintException e) {
                  StoredLayout existing = mLayoutStorage.prepare();
                  storedLayout.copyPrimaryKeyProperties(existing);
                  if (existing.tryLoad()) {
                      // Only check subset of primary and alternate keys. The check
                      // of layout properties is more important.
                      if (!existing.getStorableTypeName().equals(storedLayout.getStorableTypeName()))
                      {
                          throw e;
                      }
                      storedLayout = existing;
                  } else {
                      // Assume alternate key constraint, so increment the generation.
                      storedLayout.setGeneration
                          (nextGeneration(mRepository, storedLayout.getStorableTypeName()));
                      storedLayout.insert();
                  }
              }
  
              int op;
              while ((op = in.read()) != 0) {
                  StoredLayoutProperty storedProperty = mPropertyStorage.prepare();
                  storedProperty.readFrom(in);
                  try {
                      storedProperty.insert();
                  } catch (UniqueConstraintException e) {
                      StoredLayoutProperty existing = mPropertyStorage.prepare();
                      storedProperty.copyPrimaryKeyProperties(existing);
                      if (!existing.tryLoad()) {
                          throw e;
                      }
                      storedProperty.copyVersionProperty(existing);
                      if (!existing.equalProperties(storedProperty)) {
                          throw e;
                      }
                  }
              }
  
              txn.commit();
  
              return new Layout(this, storedLayout);
          } finally {
              txn.exit();
          }
      }
docs: Read a layout as written by {@link Layout#writeTo}.
  
  @since 1.2.2