Skip to content
Snippets Groups Projects
Commit b5e4c83c authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Bugfix

parent 678ffebe
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets" >
<ui:define name="title">TapSchema Manager - Credentials insertion page</ui:define>
<ui:define name="title">TapSchema Manager - Session Expired</ui:define>
<ui:define name="content">
<br/>
<div class="container">
......
package it.inaf.oats.ia2.tapschemamanager.datalayer;
import java.io.Closeable;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
......@@ -67,10 +69,10 @@ class ColumnsInfo implements Serializable {
}
/**
* This class manage load of TAP_SCHEMA entities and other database schemas informations.
* IMPORTANT: If you use this class inside another object remember to call the
* close method to release the occupied resources.
*
* This class manage load of TAP_SCHEMA entities and other database schemas
* informations. IMPORTANT: If you use this class inside another object remember
* to call the close method to release the occupied resources.
*
* @author Sonia Zorba <zorba at oats.inaf.it>
*/
public class TapSchemaHandler implements Serializable, Closeable {
......@@ -317,7 +319,7 @@ public class TapSchemaHandler implements Serializable, Closeable {
public void save() throws SQLException {
if (exists) {
loadEntityManager();
entityManager.getTransaction().begin();
for (SchemaEntity toRemoveSchema : toRemoveSchemas) {
entityManager.remove(toRemoveSchema);
......@@ -334,7 +336,7 @@ public class TapSchemaHandler implements Serializable, Closeable {
} finally {
closeConnection();
}
loadEntityManager();
entityManager.getTransaction().begin();
......@@ -366,20 +368,38 @@ public class TapSchemaHandler implements Serializable, Closeable {
}
private void loadEntityManager() {
if(entityManager == null) {
if (entityManager == null) {
entityManager = DataProvider.getEntityManager(credentials, name);
}
}
@Override
public void close() {
EntityManagerFactory efFactory = entityManager.getEntityManagerFactory();
entityManager.close();
efFactory.close();
if (entityManager.isOpen()) {
EntityManagerFactory efFactory = entityManager.getEntityManagerFactory();
entityManager.close();
if (efFactory.isOpen()) {
efFactory.close();
}
}
try {
closeConnection();
} catch (SQLException e) {
e.printStackTrace(System.err);
}
}
/**
* Automatic closing on serialization
* @param stream
* @throws IOException
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
close();
stream.defaultWriteObject();
}
}
......@@ -7,6 +7,10 @@ import it.inaf.oats.ia2.tapschemamanager.datalayer.KeyEntity;
import it.inaf.oats.ia2.tapschemamanager.datalayer.SchemaEntity;
import it.inaf.oats.ia2.tapschemamanager.datalayer.TableEntity;
import it.inaf.oats.ia2.tapschemamanager.datalayer.TapSchemaHandler;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -109,6 +113,28 @@ public class TestQuery {
}
}
@Test
public void testSerialization() throws Exception {
TapSchemaHandler tapSchemaHandler = new TapSchemaHandler(credentials, "vlkb_voinfo_schema", true);
System.out.println("schemas size = " + tapSchemaHandler.getSchemas().size());
FileOutputStream fileOut = new FileOutputStream("/home/sonia/test.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(tapSchemaHandler);
out.close();
fileOut.close();
FileInputStream fileIn = new FileInputStream("/home/sonia/test.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
tapSchemaHandler = (TapSchemaHandler) in.readObject();
in.close();
fileIn.close();
tapSchemaHandler.save();
System.out.println("schemas size = " + tapSchemaHandler.getSchemas().size());
}
@Ignore
@Test
public void loadSchema() throws SQLException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment