summaryrefslogtreecommitdiff
path: root/java/demo/Manual/map_filesystem/FileI.java
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2014-11-07 21:28:00 +0100
committerJose <jose@zeroc.com>2014-11-07 21:28:00 +0100
commitf99742d525f519996a6d321afb323a67fd9be4f9 (patch)
treef7b4454611d64d1a28bf9609aa64234fe78d3f53 /java/demo/Manual/map_filesystem/FileI.java
parentSome IceJS linting fixes (diff)
downloadice-f99742d525f519996a6d321afb323a67fd9be4f9.tar.bz2
ice-f99742d525f519996a6d321afb323a67fd9be4f9.tar.xz
ice-f99742d525f519996a6d321afb323a67fd9be4f9.zip
Fix for (ICE-5832) Versioning of Jar files
Renaming JAR files
Diffstat (limited to 'java/demo/Manual/map_filesystem/FileI.java')
-rw-r--r--java/demo/Manual/map_filesystem/FileI.java221
1 files changed, 221 insertions, 0 deletions
diff --git a/java/demo/Manual/map_filesystem/FileI.java b/java/demo/Manual/map_filesystem/FileI.java
new file mode 100644
index 00000000000..33b8ece4e85
--- /dev/null
+++ b/java/demo/Manual/map_filesystem/FileI.java
@@ -0,0 +1,221 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+import Filesystem.*;
+import FilesystemDB.*;
+
+public class FileI extends _FileDisp
+{
+ public
+ FileI(Ice.Communicator communicator, String envName)
+ {
+ _communicator = communicator;
+ _envName = envName;
+ }
+
+ @Override
+ public String
+ name(Ice.Current c)
+ {
+ Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName);
+ try
+ {
+ IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, filesDB());
+
+ for(;;)
+ {
+ try
+ {
+ FileEntry entry = fileDB.get(c.id);
+ if(entry == null)
+ {
+ throw new Ice.ObjectNotExistException();
+ }
+ return entry.name;
+ }
+ catch(Freeze.DeadlockException ex)
+ {
+ continue;
+ }
+ catch(Freeze.DatabaseException ex)
+ {
+ halt(ex);
+ }
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ @Override
+ public String[]
+ read(Ice.Current c)
+ {
+ Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName);
+ try
+ {
+ IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, filesDB());
+
+ for(;;)
+ {
+ try
+ {
+ FileEntry entry = fileDB.get(c.id);
+ if(entry == null)
+ {
+ throw new Ice.ObjectNotExistException();
+ }
+ return entry.text;
+ }
+ catch(Freeze.DeadlockException ex)
+ {
+ continue;
+ }
+ catch(Freeze.DatabaseException ex)
+ {
+ halt(ex);
+ }
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ @Override
+ public void
+ write(String[] text, Ice.Current c)
+ throws GenericError
+ {
+ Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName);
+ try
+ {
+ IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, filesDB());
+
+ for(;;)
+ {
+ try
+ {
+ FileEntry entry = fileDB.get(c.id);
+ if(entry == null)
+ {
+ throw new Ice.ObjectNotExistException();
+ }
+ entry.text = text;
+ fileDB.put(c.id, entry);
+ break;
+ }
+ catch(Freeze.DeadlockException ex)
+ {
+ continue;
+ }
+ catch(Freeze.DatabaseException ex)
+ {
+ halt(ex);
+ }
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ @Override
+ public void
+ destroy(Ice.Current c)
+ throws PermissionDenied
+ {
+ Freeze.Connection connection = Freeze.Util.createConnection(_communicator, _envName);
+ try
+ {
+ IdentityFileEntryMap fileDB = new IdentityFileEntryMap(connection, filesDB());
+ IdentityDirectoryEntryMap dirDB = new IdentityDirectoryEntryMap(connection, DirectoryI.directoriesDB());
+
+ for(;;)
+ {
+ Freeze.Transaction txn = null;
+ try
+ {
+ //
+ // The transaction is necessary since we are
+ // altering two records in one atomic action.
+ //
+ txn = connection.beginTransaction();
+ FileEntry entry = fileDB.get(c.id);
+ if(entry == null)
+ {
+ throw new Ice.ObjectNotExistException();
+ }
+
+ DirectoryEntry dirEntry = dirDB.get(entry.parent);
+ if(dirEntry == null)
+ {
+ halt(new Freeze.DatabaseException("consistency error: file without parent"));
+ }
+
+ dirEntry.nodes.remove(entry.name);
+ dirDB.put(entry.parent, dirEntry);
+
+ fileDB.remove(c.id);
+
+ txn.commit();
+ txn = null;
+ break;
+ }
+ catch(Freeze.DeadlockException ex)
+ {
+ continue;
+ }
+ catch(Freeze.DatabaseException ex)
+ {
+ halt(ex);
+ }
+ finally
+ {
+ if(txn != null)
+ {
+ txn.rollback();
+ }
+ }
+ }
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ public static String
+ filesDB()
+ {
+ return "files";
+ }
+
+ private void
+ halt(Freeze.DatabaseException e)
+ {
+ //
+ // If this is called it's very bad news. We log the error and
+ // then kill the server.
+ //
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ e.printStackTrace(pw);
+ pw.flush();
+ _communicator.getLogger().error("fatal database error\n" + sw.toString() + "\n*** Halting JVM ***");
+ Runtime.getRuntime().halt(1);
+ }
+
+ private Ice.Communicator _communicator;
+ private String _envName;
+}