Commit b5e4c83c authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Bugfix

parent 678ffebe
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -4,7 +4,7 @@
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets" >
                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">
    <ui:define name="content">
        <br/>
        <br/>
        <div class="container">
        <div class="container">
+31 −11
Original line number Original line Diff line number Diff line
package it.inaf.oats.ia2.tapschemamanager.datalayer;
package it.inaf.oats.ia2.tapschemamanager.datalayer;


import java.io.Closeable;
import java.io.Closeable;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLException;
@@ -67,9 +69,9 @@ class ColumnsInfo implements Serializable {
}
}


/**
/**
 * This class manage load of TAP_SCHEMA entities and other database schemas informations.
 * This class manage load of TAP_SCHEMA entities and other database schemas
 * IMPORTANT: If you use this class inside another object remember to call the 
 * informations. IMPORTANT: If you use this class inside another object remember
 * close method to release the occupied resources.
 * to call the close method to release the occupied resources.
 *
 *
 * @author Sonia Zorba <zorba at oats.inaf.it>
 * @author Sonia Zorba <zorba at oats.inaf.it>
 */
 */
@@ -373,13 +375,31 @@ public class TapSchemaHandler implements Serializable, Closeable {


    @Override
    @Override
    public void close() {
    public void close() {
        
        if (entityManager.isOpen()) {
            EntityManagerFactory efFactory = entityManager.getEntityManagerFactory();
            EntityManagerFactory efFactory = entityManager.getEntityManagerFactory();
            
            entityManager.close();
            entityManager.close();
            
            if (efFactory.isOpen()) {
                efFactory.close();
                efFactory.close();
            }
        }

        try {
        try {
            closeConnection();
            closeConnection();
        } catch (SQLException e) {
        } catch (SQLException e) {
            e.printStackTrace(System.err);
            e.printStackTrace(System.err);
        }
        }
    }
    }

    /**
     * Automatic closing on serialization
     * @param stream
     * @throws IOException 
     */
    private void writeObject(ObjectOutputStream stream) throws IOException {
        close();
        stream.defaultWriteObject();
    }
}
}
+26 −0
Original line number Original line Diff line number Diff line
@@ -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.SchemaEntity;
import it.inaf.oats.ia2.tapschemamanager.datalayer.TableEntity;
import it.inaf.oats.ia2.tapschemamanager.datalayer.TableEntity;
import it.inaf.oats.ia2.tapschemamanager.datalayer.TapSchemaHandler;
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.Connection;
import java.sql.SQLException;
import java.sql.SQLException;
import java.sql.Statement;
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
    @Ignore
    @Test
    @Test
    public void loadSchema() throws SQLException {
    public void loadSchema() throws SQLException {