Package org.hsqldb.lib

Examples of org.hsqldb.lib.Storage


        HsqlArrayList allTables = database.schemaManager.getAllTables();

        rootsList = new int[allTables.size()][];

        Storage dest = null;

        try {
            OutputStream fos =
                database.logger.getFileAccess().openOutputStreamElement(
                    dataFileName + ".new");

            fileStreamOut = new BufferedOutputStream(fos, 1 << 12);

            for (int i = 0; i < cache.initialFreePos; i++) {
                fileStreamOut.write(0);
            }

            fileOffset = cache.initialFreePos;

            for (int i = 0, tSize = allTables.size(); i < tSize; i++) {
                Table t = (Table) allTables.get(i);

                if (t.getTableType() == TableBase.CACHED_TABLE) {
                    int[] rootsArray = writeTableToDataFile(t);

                    rootsList[i] = rootsArray;
                } else {
                    rootsList[i] = null;
                }

                Error.printSystemOut("table: " + t.getName().name
                                     + " complete");
            }

            fileStreamOut.flush();
            fileStreamOut.close();

            fileStreamOut = null;

            // write out the end of file position
            int type = database.logger.isStoredFileAccess()
                       ? ScaledRAFile.DATA_FILE_STORED
                       : ScaledRAFile.DATA_FILE_RAF;

            dest = ScaledRAFile.newScaledRAFile(database,
                                                dataFileName + ".new", false,
                                                type);

            dest.seek(DataFileCache.LONG_FREE_POS_POS);
            dest.writeLong(fileOffset);

            // set shadowed flag;
            int flags = 0;

            if (database.logger.propIncrementBackup) {
                flags = BitMap.set(flags, DataFileCache.FLAG_ISSHADOWED);
            }

            flags = BitMap.set(flags, DataFileCache.FLAG_190);
            flags = BitMap.set(flags, DataFileCache.FLAG_ISSAVED);

            dest.seek(DataFileCache.FLAGS_POS);
            dest.writeInt(flags);
            dest.close();

            dest = null;

            for (int i = 0, size = rootsList.length; i < size; i++) {
                int[] roots = rootsList[i];

                if (roots != null) {
                    Error.printSystemOut(
                        "roots: "
                        + org.hsqldb.lib.StringUtil.getList(roots, ",", ""));
                }
            }

            complete = true;
        } catch (IOException e) {
            throw Error.error(ErrorCode.FILE_IO_ERROR, e);
        } catch (OutOfMemoryError e) {
            throw Error.error(ErrorCode.OUT_OF_MEMORY, e);
        } catch (Throwable t) {
            throw Error.error(ErrorCode.GENERAL_ERROR, t);
        } finally {
            try {
                if (fileStreamOut != null) {
                    fileStreamOut.close();
                }

                if (dest != null) {
                    dest.close();
                }
            } catch (Throwable t) {
                database.logger.logSevereEvent("backupFile failed", t);
            }
View Full Code Here


    // buggy database files had size == position == 0 at the end
    public static void restoreFile(Database database, String sourceName,
                                   String destName) throws IOException {

        Storage source = getStorage(database, sourceName, "r");
        Storage dest   = getStorage(database, destName, "rw");

        while (source.getFilePointer() != source.length()) {
            int    size     = source.readInt();
            long   position = source.readLong();
            byte[] buffer   = new byte[size];

            source.read(buffer, 0, buffer.length);
            dest.seek(position);
            dest.write(buffer, 0, buffer.length);
        }

        source.close();
        dest.close();
    }
View Full Code Here

        HsqlArrayList allTables = database.schemaManager.getAllTables();

        rootsList = new int[allTables.size()][];

        Storage dest = null;

        try {
            OutputStream fos =
                database.getFileAccess().openOutputStreamElement(filename
                    + ".new");

            fileStreamOut = new BufferedOutputStream(fos, 1 << 12);

            for (int i = 0; i < DataFileCache.INITIAL_FREE_POS; i++) {
                fileStreamOut.write(0);
            }

            fileOffset = DataFileCache.INITIAL_FREE_POS;

            for (int i = 0, tSize = allTables.size(); i < tSize; i++) {
                Table t = (Table) allTables.get(i);

                if (t.getTableType() == Table.CACHED_TABLE) {
                    int[] rootsArray = writeTableToDataFile(t);

                    rootsList[i] = rootsArray;
                } else {
                    rootsList[i] = null;
                }

                Trace.printSystemOut(t.getName().name + " complete");
            }

            writeTransactionRows();
            fileStreamOut.flush();
            fileStreamOut.close();

            fileStreamOut = null;

            // write out the end of file position
            dest = ScaledRAFile.newScaledRAFile(
                database, filename
                + ".new", false, ScaledRAFile.DATA_FILE_RAF, database
                    .getURLProperties().getProperty(
                        "storage_class_name"), database.getURLProperties()
                            .getProperty("storage_key"));

            dest.seek(DataFileCache.LONG_FREE_POS_POS);
            dest.writeLong(fileOffset);
            dest.close();

            dest = null;

            for (int i = 0, size = rootsList.length; i < size; i++) {
                int[] roots = rootsList[i];

                if (roots != null) {
                    Trace.printSystemOut(
                        org.hsqldb.lib.StringUtil.getList(roots, ",", ""));
                }
            }

            complete = true;
        } catch (IOException e) {
            throw Trace.error(Trace.FILE_IO_ERROR, filename + ".new");
        } catch (OutOfMemoryError e) {
            throw Trace.error(Trace.OUT_OF_MEMORY);
        } finally {
            if (fileStreamOut != null) {
                fileStreamOut.close();
            }

            if (dest != null) {
                dest.close();
            }

            if (!complete) {
                database.getFileAccess().removeElement(filename + ".new");
            }
View Full Code Here

        HsqlArrayList allTables = database.schemaManager.getAllTables();

        rootsList = new int[allTables.size()][];

        Storage dest = null;

        try {
            OutputStream fos =
                database.getFileAccess().openOutputStreamElement(filename
                    + ".new");

            fileStreamOut = new BufferedOutputStream(fos, 1 << 12);

            for (int i = 0; i < DataFileCache.INITIAL_FREE_POS; i++) {
                fileStreamOut.write(0);
            }

            fileOffset = DataFileCache.INITIAL_FREE_POS;

            for (int i = 0, tSize = allTables.size(); i < tSize; i++) {
                Table t = (Table) allTables.get(i);

                if (t.getTableType() == TableBase.CACHED_TABLE) {
                    int[] rootsArray = writeTableToDataFile(t);

                    rootsList[i] = rootsArray;
                } else {
                    rootsList[i] = null;
                }

                Error.printSystemOut(t.getName().name + " complete");
            }

            writeTransactionRows();
            fileStreamOut.flush();
            fileStreamOut.close();

            fileStreamOut = null;

            // write out the end of file position
            dest = ScaledRAFile.newScaledRAFile(
                database, filename + ".new", false,
                ScaledRAFile.DATA_FILE_RAF,
                database.getURLProperties().getProperty("storage_class_name"),
                database.getURLProperties().getProperty("storage_key"));

            dest.seek(DataFileCache.LONG_FREE_POS_POS);
            dest.writeLong(fileOffset);
            dest.close();

            dest = null;

            for (int i = 0, size = rootsList.length; i < size; i++) {
                int[] roots = rootsList[i];

                if (roots != null) {
                    Error.printSystemOut(
                        org.hsqldb.lib.StringUtil.getList(roots, ",", ""));
                }
            }

            complete = true;
        } catch (IOException e) {
            throw Error.error(ErrorCode.FILE_IO_ERROR, filename + ".new");
        } catch (OutOfMemoryError e) {
            throw Error.error(ErrorCode.OUT_OF_MEMORY);
        } finally {
            if (fileStreamOut != null) {
                fileStreamOut.close();
            }

            if (dest != null) {
                dest.close();
            }

            if (!complete) {
                database.getFileAccess().removeElement(filename + ".new");
            }
View Full Code Here

        HsqlArrayList allTables = database.schemaManager.getAllTables();

        rootsList = new int[allTables.size()][];

        Storage dest = null;

        try {
            OutputStream fos =
                database.getFileAccess().openOutputStreamElement(filename
                    + ".new");

            fileStreamOut = new BufferedOutputStream(fos, 1 << 12);

            for (int i = 0; i < DataFileCache.INITIAL_FREE_POS; i++) {
                fileStreamOut.write(0);
            }

            fileOffset = DataFileCache.INITIAL_FREE_POS;

            for (int i = 0, tSize = allTables.size(); i < tSize; i++) {
                Table t = (Table) allTables.get(i);

                if (t.getTableType() == Table.CACHED_TABLE) {
                    int[] rootsArray = writeTableToDataFile(t);

                    rootsList[i] = rootsArray;
                } else {
                    rootsList[i] = null;
                }

                Trace.printSystemOut(t.getName().name + " complete");
            }

            writeTransactionRows();
            fileStreamOut.close();

            fileStreamOut = null;

            // write out the end of file position
            dest = ScaledRAFile.newScaledRAFile(
                database, filename
                + ".new", false, ScaledRAFile.DATA_FILE_RAF, database
                    .getURLProperties().getProperty(
                        "storage_class_name"), database.getURLProperties()
                            .getProperty("storage_key"));

            dest.seek(DataFileCache.LONG_FREE_POS_POS);
            dest.writeLong(fileOffset);
            dest.close();

            dest = null;

            for (int i = 0, size = rootsList.length; i < size; i++) {
                int[] roots = rootsList[i];

                if (roots != null) {
                    Trace.printSystemOut(
                        org.hsqldb.lib.StringUtil.getList(roots, ",", ""));
                }
            }

            complete = true;
        } catch (IOException e) {
            throw Trace.error(Trace.FILE_IO_ERROR, filename + ".new");
        } catch (OutOfMemoryError e) {
            throw Trace.error(Trace.OUT_OF_MEMORY);
        } finally {
            if (fileStreamOut != null) {
                fileStreamOut.close();
            }

            if (dest != null) {
                dest.close();
            }

            if (!complete) {
                database.getFileAccess().removeElement(filename + ".new");
            }
View Full Code Here

    int i = 0;
    Trace.printSystemOut("Defrag Transfer begins");
    this.transactionRowLookup = this.database.txManager.getTransactionIDList();
    HsqlArrayList localHsqlArrayList = this.database.schemaManager.getAllTables();
    this.rootsList = new int[localHsqlArrayList.size()][];
    Storage localStorage = null;
    try
    {
      OutputStream localOutputStream = this.database.getFileAccess().openOutputStreamElement(this.filename + ".new");
      this.fileStreamOut = new BufferedOutputStream(localOutputStream, 4096);
      for (int j = 0; j < 32; j++)
        this.fileStreamOut.write(0);
      this.fileOffset = 32L;
      j = 0;
      int k = localHsqlArrayList.size();
      Object localObject1;
      while (j < k)
      {
        localObject1 = (Table)localHsqlArrayList.get(j);
        if (((Table)localObject1).getTableType() == 4)
        {
          int[] arrayOfInt = writeTableToDataFile((Table)localObject1);
          this.rootsList[j] = arrayOfInt;
        }
        else
        {
          this.rootsList[j] = null;
        }
        Trace.printSystemOut(((Table)localObject1).getName().name + " complete");
        j++;
      }
      writeTransactionRows();
      this.fileStreamOut.close();
      this.fileStreamOut = null;
      localStorage = ScaledRAFile.newScaledRAFile(this.database, this.filename + ".new", false, 0, this.database.getURLProperties().getProperty("storage_class_name"), this.database.getURLProperties().getProperty("storage_key"));
      localStorage.seek(12L);
      localStorage.writeLong(this.fileOffset);
      localStorage.close();
      localStorage = null;
      j = 0;
      k = this.rootsList.length;
      while (j < k)
      {
        localObject1 = this.rootsList[j];
        if (localObject1 != null)
          Trace.printSystemOut(StringUtil.getList(localObject1, ",", ""));
        j++;
      }
      i = 1;
    }
    catch (IOException localIOException)
    {
      throw Trace.error(29, this.filename + ".new");
    }
    catch (OutOfMemoryError localOutOfMemoryError)
    {
      throw Trace.error(72);
    }
    finally
    {
      if (this.fileStreamOut != null)
        this.fileStreamOut.close();
      if (localStorage != null)
        localStorage.close();
      if (i == 0)
        this.database.getFileAccess().removeElement(this.filename + ".new");
    }
  }
View Full Code Here

TOP

Related Classes of org.hsqldb.lib.Storage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.