Skip to content

Commit

Permalink
DERBY-6213: Deprecate support for Java 5 and CDC
Browse files Browse the repository at this point in the history
- Remove checks for the JVMInfo.J2ME constant

- Move functionality from DirStorageFactory4 to the base class

git-svn-id: https://svn.apache.org/repos/asf/db/derby/code/trunk@1492111 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kahatlen committed Jun 12, 2013
1 parent 29435de commit 38c638d
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 561 deletions.
103 changes: 35 additions & 68 deletions java/engine/org/apache/derby/iapi/services/info/JVMInfo.java
Expand Up @@ -61,8 +61,6 @@ public abstract class JVMInfo
public static final int J2SE_17 = 8; // Java SE 7
public static final int J2SE_18 = 9;

public static final boolean J2ME;

static
{
int id;
Expand All @@ -79,16 +77,6 @@ public abstract class JVMInfo
// version 1.4.
//
String javaVersion;
String javaSpec;
boolean isJ2ME;

try {
javaSpec = System.getProperty("java.specification.name");
} catch (SecurityException se) {
// some vms do not know about this property so they
// throw a security exception when access is restricted.
javaSpec = null;
}

try {
javaVersion = System.getProperty("java.specification.version", "1.4");
Expand All @@ -99,66 +87,45 @@ public abstract class JVMInfo
javaVersion = "1.4";
}

if (javaSpec != null &&
(
javaSpec.startsWith("J2ME") || // recognize IBM WCTME
javaSpec.startsWith("CDC") || // Oracle Java ME Embedded Client
(
(javaSpec.indexOf( "Profile" ) > -1) && // recognize phoneME
(javaSpec.indexOf( "Specification" ) > -1)
)
)
)
{
id = J2SE_14;
isJ2ME = true;
}
else
{
// J2SE/J2EE
isJ2ME = false;

if (javaVersion.equals("1.4"))
{
String vmVersion = System.getProperty("java.version", "1.4.0");
if (javaVersion.equals("1.4"))
{
String vmVersion = System.getProperty("java.version", "1.4.0");

if (JVMInfo.vmCheck(vmVersion, "1.4.0") || JVMInfo.vmCheck(vmVersion, "1.4.1"))
id = J2SE_14;
else
id = J2SE_142;
}
else if (javaVersion.equals("1.5"))
{
id = J2SE_15;
}
else if (javaVersion.equals("1.6"))
{
id = J2SE_16;
}
else if (javaVersion.equals("1.7"))
{
id = J2SE_17;
}
else if (javaVersion.equals("1.8")) {
id = J2SE_18;
}
else
{
// aussme our lowest support unless the java spec
// is greater than our highest level.
id = J2SE_14;
if (JVMInfo.vmCheck(vmVersion, "1.4.0") || JVMInfo.vmCheck(vmVersion, "1.4.1"))
id = J2SE_14;
else
id = J2SE_142;
}
else if (javaVersion.equals("1.5"))
{
id = J2SE_15;
}
else if (javaVersion.equals("1.6"))
{
id = J2SE_16;
}
else if (javaVersion.equals("1.7"))
{
id = J2SE_17;
}
else if (javaVersion.equals("1.8")) {
id = J2SE_18;
}
else
{
// aussme our lowest support unless the java spec
// is greater than our highest level.
id = J2SE_14;

try {
try {

if (Float.parseFloat(javaVersion) > 1.8f)
id = J2SE_18;
} catch (NumberFormatException nfe) {
}
}
}
if (Float.parseFloat(javaVersion) > 1.8f)
id = J2SE_18;
} catch (NumberFormatException nfe) {
}
}

JDK_ID = id;
J2ME = isJ2ME;
}

/**
Expand All @@ -177,7 +144,7 @@ public static String derbyVMLevel()
{
switch (JDK_ID)
{
case J2SE_14: return J2ME ? "J2ME - JDBC for CDC/FP 1.1" : "J2SE 1.4 - JDBC 3.0";
case J2SE_14: return "J2SE 1.4 - JDBC 3.0";
case J2SE_142: return "J2SE 1.4.2 - JDBC 3.0";
case J2SE_15: return "J2SE 5.0 - JDBC 3.0";
case J2SE_16: return "Java SE 6 - JDBC 4.1";
Expand Down
195 changes: 158 additions & 37 deletions java/engine/org/apache/derby/impl/io/DirFile.java
Expand Up @@ -36,18 +36,23 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import java.io.RandomAccessFile;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessControlException;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import org.apache.derby.iapi.error.StandardException;
import org.apache.derby.iapi.services.io.FileUtil;
import org.apache.derby.iapi.util.InterruptStatus;
import org.apache.derby.shared.common.reference.SQLState;

/**
* This class provides a disk based implementation of the StorageFile interface. It is used by the
* database engine to access persistent data and transaction logs under the directory (default) subsubprotocol.
*/
class DirFile extends File implements StorageFile
{
private RandomAccessFile lockFileOpen;
private FileChannel lockFileChannel;
private FileLock dbLock;

/**
* Construct a DirFile from a path name.
Expand Down Expand Up @@ -132,7 +137,7 @@ public OutputStream getOutputStream( ) throws FileNotFoundException
public OutputStream getOutputStream( final boolean append) throws FileNotFoundException
{
boolean exists = exists();
OutputStream result = new FileOutputStream( getPath(), append);
OutputStream result = new FileOutputStream(this, append);

if (!exists) {
FileUtil.limitAccessToOwner(this);
Expand Down Expand Up @@ -163,44 +168,163 @@ public InputStream getInputStream( ) throws FileNotFoundException
* NO_FILE_LOCK_SUPPORT if the system does not support exclusive locks.<br>
*/
public synchronized int getExclusiveFileLock() throws StandardException
{
if (exists())
{
delete();
}
try
{
boolean validExclusiveLock = false;
int status;

/*
** There can be a scenario where there is some other JVM that is before jkdk1.4
** had booted the system and jdk1.4 trying to boot it, in this case we will get the
** Exclusive Lock even though some other JVM has already booted the database. But
** the lock is not a reliable one , so we should still throw the warning.
** The Way we identify this case is if "dbex.lck" file size is differen
** for pre jdk1.4 jvms and jdk1.4 or above.
** Zero size "dbex.lck" file is created by a jvm i.e before jdk1.4 and
** File created by jdk1.4 or above writes EXCLUSIVE_FILE_LOCK value into the file.
** If we are unable to acquire the lock means other JVM that
** currently booted the system is also JDK1.4 or above;
** In this case we could confidently throw a exception instead of
** of a warning.
**/

try
{
//Just create an empty file
RandomAccessFile lockFileOpen = new RandomAccessFile( (File) this, "rw");
limitAccessToOwner();
lockFileOpen.getFD().sync( );
lockFileOpen.close();
}catch(IOException ioe)
{
// do nothing - it may be read only medium, who knows what the
// problem is
if (SanityManager.DEBUG)
{
SanityManager.THROWASSERT(
"Unable to create Exclusive Lock File " + getPath(), ioe);
}
}

return NO_FILE_LOCK_SUPPORT;
} // end of getExclusiveFileLock
//create the file that us used to acquire exclusive lock if it does not exists.
if (createNewFile())
{
validExclusiveLock = true;
}
else if (length() > 0)
{
validExclusiveLock = true;
}

//If we can acquire a reliable exclusive lock , try to get it.
if (validExclusiveLock)
{
int retries = InterruptStatus.MAX_INTERRUPT_RETRIES;
while (true) {
lockFileOpen = new RandomAccessFile((File) this, "rw");
limitAccessToOwner(); // tamper-proof..
lockFileChannel = lockFileOpen.getChannel();

try {
dbLock =lockFileChannel.tryLock();
if(dbLock == null) {
lockFileChannel.close();
lockFileChannel=null;
lockFileOpen.close();
lockFileOpen = null;
status = EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE;
} else {
lockFileOpen.writeInt(EXCLUSIVE_FILE_LOCK);
lockFileChannel.force(true);
status = EXCLUSIVE_FILE_LOCK;
}
} catch (AsynchronousCloseException e) {
// JDK bug 6979009: use AsynchronousCloseException
// instead of the logically correct
// ClosedByInterruptException

InterruptStatus.setInterrupted();
lockFileOpen.close();

if (retries-- > 0) {
continue;
} else {
throw e;
}
}

break;
}
}
else
{
status = NO_FILE_LOCK_SUPPORT;
}

} catch(IOException ioe)
{
// do nothing - it may be read only medium, who knows what the
// problem is

//release all the possible resource we created in this functions.
releaseExclusiveFileLock();
status = NO_FILE_LOCK_SUPPORT;
if (SanityManager.DEBUG)
{
SanityManager.THROWASSERT("Unable to Acquire Exclusive Lock on "
+ getPath(), ioe);
}
} catch (OverlappingFileLockException ofle)
{
//
// Under Java 6 and later, this exception is raised if the database
// has been opened by another Derby instance in a different
// ClassLoader in this VM. See DERBY-700.
//
// The OverlappingFileLockException is raised by the
// lockFileChannel.tryLock() call above.
//
try {
lockFileChannel.close();
lockFileOpen.close();
} catch (IOException e)
{
if (SanityManager.DEBUG)
{
SanityManager.THROWASSERT("Error closing file channel "
+ getPath(), e);
}
}
lockFileChannel = null;
lockFileOpen = null;
status = EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE;
}

return status;
} // end of getExclusiveFileLock

/**
* Release the resource associated with an earlier acquired exclusive lock
*
* @see #getExclusiveFileLock
*/
public synchronized void releaseExclusiveFileLock()
{
if( exists())
{
delete();
}
} // End of releaseExclusiveFileLock
public synchronized void releaseExclusiveFileLock()
{
try
{
if (dbLock!=null)
{
dbLock.release();
dbLock = null;
}

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

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

// delete the exclusive lock file name.
if (exists())
{
delete();
}
}
catch (IOException ioe)
{
// do nothing - it may be read only medium, who knows what the
// problem is
}
} // End of releaseExclusiveFileLock

/**
* Get a random access (read/write) file.
Expand All @@ -224,9 +348,6 @@ public synchronized void releaseExclusiveFileLock()
*/
public StorageRandomAccessFile getRandomAccessFile( String mode) throws FileNotFoundException
{
// Assume that modes "rws" and "rwd" are not supported.
if( "rws".equals( mode) || "rwd".equals( mode))
mode = "rw";
return new DirRandomAccessFile( (File) this, mode);
} // end of getRandomAccessFile

Expand Down

0 comments on commit 38c638d

Please sign in to comment.