H2 and rename file extension

1,123 views
Skip to first unread message

Paluee

unread,
May 6, 2010, 6:43:01 PM5/6/10
to H2 Database
Hi there,

I read on the website that one can rename the file extension of H2, no
problem.
But I ran into a problem.

I created a CRUD database.
When I issued a statement to create file on disk, H2 appends to the
file name: ".h2db",
how to I override this. Is there a method I am missing.

Also, I said to myself fine, I will create the file and then
physically rename its file extension.
So i created : firstFile.h2db ---> re-named it to : firstFile.ppyt.

When I tried to read the file with my java app, it would not read it.
It will only read it if its file extension is : firstFile.h2db.

Hope somebody can help me with this.

Palmer

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Christian Peter

unread,
May 7, 2010, 2:31:14 AM5/7/10
to H2 Database
Hi,

the extension must not be changed.

See http://www.h2database.com/html/features.html#database_file_layout
and there the topic "Moving and Renaming Database Files".

I'll change the documentation to:

While a database is closed, the files can be moved to another
directory, and they can be renamed
as well (as long as all files start with the same name and the
respective extensions are unchanged).

The only way to change it would be to edit org.h2.engine.Constants.
There are constants defined for the file extensions.

Regards

Christian

Thomas Mueller

unread,
May 7, 2010, 2:37:47 AM5/7/10
to h2-da...@googlegroups.com
Hi,

> the extension must not be changed.

That's true.

> as long as all files start with the same name

That's not required. Only the suffix needs to stay.

Regards,
Thomas

Thomas Mueller

unread,
May 7, 2010, 2:39:00 AM5/7/10
to h2-da...@googlegroups.com
Hi,

>> as long as all files start with the same name
> That's not required. Only the suffix needs to stay.

Ah, I understand... All files of the same database need to start with
the same name... What about:

"
While a database is closed, the files can be moved to another
directory, and they can be renamed
as well (as long as all files of the same database start with the same
name and the
respective extensions are unchanged).
"

Christian Peter

unread,
May 7, 2010, 2:47:11 AM5/7/10
to H2 Database
Thats even better :)

I committed it.

Regards

Christian

On May 7, 8:39 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Paluee

unread,
May 7, 2010, 12:09:13 PM5/7/10
to H2 Database
Hi,

OK then how would I be able to edit this:
"The only way to change it would be to edit org.h2.engine.Constants.
There are constants defined for the file extensions. "

Is there some method I can access called:
"ChangeExt(".h2.db",".ppyt").

Is there something like this.
Or do I have to somehow edit a java file and change the hardcoded
value manually.

Please let me know.

P


On May 7, 2:39 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Christian Peter

unread,
May 7, 2010, 2:13:25 PM5/7/10
to H2 Database
Hi,

currently you have to compile H2 yourself. There is no way to change
the extension at runtime.

Patches are welcome :)

Regards

Christian

Thomas Mueller

unread,
May 7, 2010, 2:51:28 PM5/7/10
to h2-da...@googlegroups.com
Hi,

Why do you want to rename the file?

Paluee

unread,
May 7, 2010, 3:30:41 PM5/7/10
to H2 Database
Hi there,

The reason why I would want to change it is for esthethic reasons, and
"Human Interaction/Usability" reasons.
For example, people who use windows expect certain things like
extensions being
only three letters ".txt", ".xls", ".doc", etc .
This current extension of "*.h2.db", is very alien to a windows user.

Also in this way one can customize the meaning of the database file
based on the business logic of the application.
For example, the application may be about utility
information(Electric, Natural gas, Water), so hence you can call it
".udb" for utility database or ".edb" for energy database.
This gives more meaning to a person, when you are using h2 and going
to make an application with say two database files, sure they have
names but to customize it further
via the extension makes it even more meaningful.

So that is the reason.

P



On May 7, 2:51 pm, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Sylvain Pointeau

unread,
May 7, 2010, 4:55:21 PM5/7/10
to h2-da...@googlegroups.com
what about "electric.h2db" "NaturalGas.h2db" etc?

Ryan How

unread,
May 7, 2010, 8:56:59 PM5/7/10
to h2-da...@googlegroups.com
You could set up a file extension association with your application.
Because with the page store it is just the single file you could just
use it as the document format for your application. I reckon it would be
nifty :). I've seen it done with Access databases quite a bit.

Thomas Mueller

unread,
May 8, 2010, 1:33:28 AM5/8/10
to h2-da...@googlegroups.com
Hi,

I understand. I think by default databases should have a suffix
(currently it's .h2.db). I understand in some cases this should be a
different suffix. What about an escape mechanism? For example, if the
database ends with a slash, then the regular suffix is not used.
Examples:

jdbc:h2:~/data (will create a file named "data.h2.db")
jdbc:h2:~/data.db/ (will create a file named "data.db")
jdbc:h2:~/data/ (will create a file named "data")

Other ideas are welcome.

Currently the default suffix is ".h2.db". It would be better if the
suffix has only one dot by default. What about .h2db? I will add a
feature request. However, for backward compatibility, I don't plan to
change it in the near future.

So I will add two feature requests:

- Database file name suffix: a way to use no or a different suffix
(for example using a slash).
- Database file name suffix: should only have one dot by default. Example: .h2db

For me this is low priority. If you want to provide a patch you are welcome.

Paluee

unread,
May 8, 2010, 2:19:34 AM5/8/10
to H2 Database
Hi Thomas,
Yes I like your ideas.
I like your idea about the JDBC url with slashes.
For example:
jdbc:h2:~/data.db/ (will create a file named "data.db")

Does this mean thru the url one would be able to customize like this:
jdbc:h2:~/data.epdb/ (will create a file named "data.epdb")
If that is the case, that is exactly what I am looking for, you got
it!!!!!!

And yes, currently the "data.h2.db" is unpleasant to Windows users,
and changing it to "data.h2db" is much, much better.
The two dots is too much. One dot should be the way.

I see that you say it is low-priority, I can understand that there are
more important issues,
but I hope you will due this in some future release.

Thanks for your response, I really appreciate it Thomas !!!

P.



On May 8, 1:33 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Dario Fassi

unread,
May 8, 2010, 12:32:02 PM5/8/10
to h2-da...@googlegroups.com
Hi,
The historic extension for a data file containing an unspecified (or non
standard) data format is: .DAT or .BIN

For many admin reasons I like the way several well known databases use
to organize storage in a very predictable directory hierarchy.
I think it's much better that storage of a database that involve more
than a single file should be a directory with a name that contain a
prefix/suffix that express the vendor and the database name.

Like: /h2db-databaname/ ...
or: /h2dbdir/databasename/ ...

Inside database data directory any file it's considered belonging to
database and files extensions become less relevant.
Anyway .h2db is very expressive as extension. Or .h2.dat , .h2.log ,
.h2.trace , etc.
The main benefit of these conventions is to facilitate searches in the
file system, to express the file type, database and dbm vendor to which
they belong.

I know that next words are out of scope in this thread - but it's
related to.
A usefull concept to organize physical database storage it's the
TABLESPACE database object , that specify an storage URI and type. This
concept support partitioning and physical organization,
where any database has a default TABLESPACE in witch all tables are
stored, except that they specify a tablespace at creation time.
This make possible the use of different tablespaces (RO/RW , Fast/Slow ,
Local/Remote) for different tables and indexes on the same database.

regards,
Dario

El 08/05/10 02:33, Thomas Mueller escribió:
> I understand. I think by default databases should have a suffix
> (currently it's .h2.db). I understand in some cases this should be a
> different suffix. What about an escape mechanism? For example, if the
> database ends with a slash, then the regular suffix is not used.
> Examples:
>
> jdbc:h2:~/data (will create a file named "data.h2.db")
> jdbc:h2:~/data.db/ (will create a file named "data.db")
> jdbc:h2:~/data/ (will create a file named "data")
>
> Other ideas are welcome.
>
> Currently the default suffix is ".h2.db". It would be better if the
> suffix has only one dot by default. What about .h2db? I will add a
> feature request. However, for backward compatibility, I don't plan to
> change it in the near future.
>
> So I will add two feature requests:
>
> - Database file name suffix: a way to use no or a different suffix
> (for example using a slash).
> - Database file name suffix: should only have one dot by default. Example: .h2db
>


Thomas Mueller

unread,
Jul 20, 2010, 3:52:24 PM7/20/10
to H2 Google Group
Hi,

Please use the Google Group and don't send mails to me directly.
Others may also want to participate in the discussion. The original
mail is below.

> I'd like to implement this feature as you specified (database file
> name suffix) and then provide a patch.
> Could you please tell me in which class the file name is assigned?

Check for Constants.SUFFIX_PAGE_FILE. Usually the code is written like this:

String fn = db.getName() + Constants.SUFFIX_PAGE_FILE;

Currently there are other suffixes as well (trace file, lock file,
temp files, lob files; see Constants.SUFFIX_*). What about if the
suffix is still used in those cases? Therefore, I suggest to use a new
method in Database.java, similar to the following (untested):

public static String getDatabaseFileName(String databaseName, String suffix) {
if (databaseName.endsWith(".")) {
String fileName = databaseName.substring(0, databaseName.length() - 1)
if (suffix.equals(Constants.SUFFIX_PAGE_FILE)) {
return fileName;
}
return fileName + suffix;
}
return databaseName + suffix;
}

Regards,
Thomas


On Sun, Jul 18, 2010 at 8:47 PM, Costantino ... wrote:
> Hi Thomas,
>
> I'd like to implement this feature as you specified (database file
> name suffix) and then provide a patch.
> Could you please tell me in which class the file name is assigned?
>
> Regards,
> Costantino

Reply all
Reply to author
Forward
0 new messages