Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Hard coded database plattforms...
Hard coded database plattforms... [message #376328] Wed, 09 July 2008 20:49 Go to next message
Michael Seidel is currently offline Michael Seidel
Messages: 12
Registered: July 2009
Junior Member
Hi,

Are there any plans to make the database support more configurable,
extensible? I just wanted to try EclipseLink with
the H2-Database (see: www.h2database.com) and had to use the HSQL Dialect
(no sequence support), because H2
is not supported by EclipseLink.

First thought was to write a support for the H2 database on my own.
Unfortunately all the database plattform identifier
are hard coded into internal classes in EclipseLink! I couldn't believe it,
but there is really one method for each supported
database in the abstract class
org.eclipse.persistence.internal.databaseaccess.Platform

Why don't you use any kind of factory and configure it from a file or let
the user name the plattform used within the
persistence.xml. In Hibernate there is a property for the persistence.xml,
which specifies the database dialect to use and
everybody can extend it, if needed. Of course, I can use the following
property

<property name="eclipselink.target-database" value="HSQL" />

but have no chance, if there is no build-in support for a database.

What about a property with the classified name of a Plattform-Implementation
to be used?

<property name="eclipselink.target-plattform"
value="org.eclipse.persistence.platform.database.HSQLPlatform " />

Regards,
Michael
Re: Hard coded database plattforms... [message #376330 is a reply to message #376328] Thu, 10 July 2008 09:19 Go to previous messageGo to next message
Doug Clarke is currently offline Doug Clarke
Messages: 155
Registered: July 2009
Senior Member
Michael,

In earlier versions of TopLink we always made the developer provide the
fully qualified platform name. We added the TargetDatabase enum with short
values to simplify things. If you do write your own platform you can still
specify it by providing the fully qualified class name in the value of the
property:

<property name="eclipselink.target-database"
value="mypackage.MyH2Platform" />

If you wish to contribute your H2 platform to the project please attach it
to a bug and we'll do our best to get it in the next release.

Doug
Re: Hard coded database plattforms... [message #376343 is a reply to message #376330] Sat, 12 July 2008 19:15 Go to previous message
Michael Seidel is currently offline Michael Seidel
Messages: 12
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C8E464.68B6C490
Content-Type: text/plain;
format=flowed;
charset="iso-8859-15";
reply-type=response
Content-Transfer-Encoding: 7bit

Hi Doug,

thanks for the hint. I extended the HSQLPlatform (see attachment) and tried
it with your Geodata example.
Works fine. ;-)

Michael

"Doug Clarke" <douglas.clarke@oracle.com> schrieb im Newsbeitrag
news:851a1b27a0adf12154655151e107903c$1@www.eclipse.org...
> Michael,
>
> In earlier versions of TopLink we always made the developer provide the
> fully qualified platform name. We added the TargetDatabase enum with short
> values to simplify things. If you do write your own platform you can still
> specify it by providing the fully qualified class name in the value of the
> property:
>
> <property name="eclipselink.target-database"
> value="mypackage.MyH2Platform" />
>
> If you wish to contribute your H2 platform to the project please attach it
> to a bug and we'll do our best to get it in the next release.
>
> Doug
>

------=_NextPart_000_0013_01C8E464.68B6C490
Content-Type: application/octet-stream;
name="H2Platform.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="H2Platform.java"

package org.eclipse.persistence.platform.database;

import java.io.IOException;
import java.io.Writer;
import java.util.Hashtable;

import org.eclipse.persistence.expressions.ExpressionOperator;
import =
org.eclipse.persistence.internal.databaseaccess.FieldTypeDef inition;
import org.eclipse.persistence.queries.ValueReadQuery;
import org.eclipse.persistence.sequencing.NativeSequence;
import org.eclipse.persistence.sequencing.Sequence;

public class H2Platform extends HSQLPlatform {
private static final long serialVersionUID =3D =
-2935483687958482934L;

public H2Platform() {
super();
setPingSQL("CALL 42");
setSupportsAutoCommit(true);
setUsesBatchWriting(true);
}

@Override
public final boolean isHSQL() {
return false;
}

@Override
@SuppressWarnings("unchecked")
protected Hashtable buildFieldTypes() {
Hashtable fieldTypeMapping =3D super.buildFieldTypes();
fieldTypeMapping.put(java.sql.Date.class, new =
FieldTypeDefinition("DATE", false));
fieldTypeMapping.put(java.sql.Time.class, new =
FieldTypeDefinition("TIME", false));
fieldTypeMapping.put(java.sql.Timestamp.class, new =
FieldTypeDefinition("TIMESTAMP", false));
return fieldTypeMapping;
}

@Override
public ValueReadQuery buildSelectQueryForSequenceObject(String =
seqName, Integer size) {
return new ValueReadQuery(new StringBuilder(20 + seqName.length())
.append("CALL NEXT VALUE FOR ").append(seqName).toString());
}

@Override
public Writer buildSequenceObjectAlterIncrementWriter(Writer writer, =
String fullSeqName, int increment) throws IOException {
return writer.append("ALTER SEQUENCE ").append(fullSeqName)
.append(" INCREMENT BY ").append(Integer.toString(increment));
}

@Override
public Writer buildSequenceObjectCreationWriter(Writer writer, =
String fullSeqName, int increment, int start) throws IOException {
return writer.append("CREATE SEQUENCE IF NOT EXISTS =
").append(fullSeqName)
.append(" START WITH ").append(Integer.toString(start)).append(" =
INCREMENT BY ")
.append(Integer.toString(increment));
}

@Override
protected Sequence createPlatformDefaultSequence() {
return new NativeSequence();
}

@Override
public boolean isAlterSequenceObjectSupported() {
return true;
}

@Override
public boolean supportsForeignKeyConstraints() {
return true;
}

@Override
public boolean supportsLocalTempTables() {
return true;
}

@Override
public boolean supportsGlobalTempTables() {
return true;
}

@Override
public boolean supportsNativeSequenceNumbers() {
return true;
}

@Override
public boolean supportsStoredFunctions() {
return true;
}

@Override
public ValueReadQuery getTimestampQuery() {
return new ValueReadQuery("SELECT CURRENT_TIMESTAMP()");
}

@Override
protected void initializePlatformOperators() {
super.initializePlatformOperators();
addOperator(ExpressionOperator.simpleMath(ExpressionOperator .Concat, =
"||"));
}
}

------=_NextPart_000_0013_01C8E464.68B6C490--
Previous Topic:JPA vs. Native
Next Topic:maven2 support?
Goto Forum:
  


Current Time: Tue Sep 16 15:31:05 GMT 2014

Powered by FUDForum. Page generated in 0.13574 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software