Package de.danet.an.util.persistentmaps

Examples of de.danet.an.util.persistentmaps.JDBCPersistentMap


    /**
     * Testing serialization
     * @exception Exception if an error occurs
     */
    public void serialize() throws Exception {
  JDBCPersistentMap map
      = new JDBCPersistentMap(null, "Danet","DefaultPersistenceMap");
  map.setConnection(con);
  map.put("HSc", "Holger Schl�ter");
  map.put("ML", "Dr. Michael Lipp");
  map.put("GB", "Gunnar von de Beck");
  ByteArrayOutputStream bo = new ByteArrayOutputStream();
  ObjectOutputStream o = new ObjectOutputStream(bo);
  o.writeObject(map);
  o.close();
  map.remove("HSc");
  map.store();
  map.load();
  assertTrue(map.size() == 2); // Two entries stored in DB 
  ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
  ObjectInputStream i = new ObjectInputStream(bi);
  map = (JDBCPersistentMap)i.readObject(); // Three object read
  assertTrue(map.size() == 3)
  i.close();
  map.setConnection(con);
  map.store(); // Three objects stored
  map.clear();
  assertTrue(map.size() == 0)
  map.load(); // All three objects read
  assertTrue(map.size() == 3)
    }
View Full Code Here


     * Test setting of connections.
     * This includes support of (two) parallel connections.
     * @exception Exception if an error occurs
     */
    public void setConnection() throws Exception {
  JDBCPersistentMap testMap = new JDBCPersistentMap(null, "Danet");
  testMap.setConnection(con);
  testMap.put("HSc", "Holger Schl�ter");
  testMap.put("MSc", "Matthias Schirm");
  testMap.setConnection(con);
  testMap.store();
  testMap.setConnection(con);
  testMap.store();
  if (secondCon != null) {
      testMap.clear();
      testMap.setConnection(secondCon);
      assertTrue(testMap.maxKeyLength() == 50);
      testMap.put("ALM", "Alex M�ller");
      testMap.store();
      testMap.clear();
      assertTrue(testMap.size() == 0);
      testMap.load();
      assertTrue(testMap.size() == 1);
  }
  testMap.setConnection(null);
  testMap.setConnection(con);
  assertTrue(testMap.maxKeyLength() == 50);
  testMap.load();
  assertTrue(testMap.size() == 2);
  if (secondCon != null) {
      testMap.setConnection(secondCon);
      testMap.store();
      testMap.load();
      assertTrue(testMap.size() == 2);
  }
  testMap.setConnection(con);
  if (secondCon != null) {
      // Change connection with unsaved modifications
      testMap.load();
      assertTrue(testMap.size() == 2);
      testMap.put("HSc", "Holger Schlueter"); //Update
      testMap.remove("MSc"); // Delete
      testMap.put("GB", "Gunnar von der Beck"); // Insert
      testMap.put("ALM", "Alex M�ller");
      assertTrue(testMap.size() == 3);
      testMap.setConnection(secondCon);
      testMap.store();
      testMap.load();
      assertTrue(testMap.size() == 3);
  }
  testMap.setConnection(con);
  testMap.clear();
  testMap.store();
  if (secondCon != null) {
      testMap.setConnection(secondCon);
      testMap.clear();
      testMap.store();
  }
    }
View Full Code Here

    /**
     * Test setting of maximum svalue
     * @exception Exception if an error occurs
     */
    public void setSValueMax() throws Exception {
  JDBCPersistentMap testMap = new JDBCPersistentMap(null, "Danet");
  int maxSValue = 0;
  testMap.setSValueMax(130764);
  assertTrue(testMap.getSValueMax() == 130764);
  testMap.setConnection(con);
  maxSValue = testMap.getSValueMax()
  testMap.setSValueMax(maxSValue+1);
  assertTrue("Expected " + maxSValue + ", got " + testMap.getSValueMax(),
       testMap.getSValueMax() == maxSValue)
  testMap.setSValueMax(maxSValue-1);
  assertTrue(testMap.getSValueMax() == maxSValue-1)
  testMap.setSValueMax(maxSValue);
  assertTrue(testMap.getSValueMax() == maxSValue)
  testMap.setConnection(null);
  assertTrue(testMap.getSValueMax() == maxSValue)
  testMap.setSValueMax(maxSValue+1);
  assertTrue(testMap.getSValueMax() == maxSValue+1)

  JDBCPersistentMap testMap2 = new JDBCPersistentMap(null, "Danet2");
  Connection con2 = null;
  int maxSValue2 = 0;
  if (secondCon != null) {
      con2 = secondCon;
      testMap2.setConnection(con2);
      maxSValue2 = testMap2.getSValueMax()
      testMap2.setSValueMax(maxSValue2+1);
      assertTrue(testMap2.getSValueMax() == maxSValue2)
      testMap2.setSValueMax(maxSValue2-1);
      assertTrue(testMap2.getSValueMax() == maxSValue2-1);
      testMap2.setSValueMax(maxSValue2);
      assertTrue(testMap2.getSValueMax() == maxSValue2);
  } else {
      con2 = con;
      maxSValue2 = maxSValue;
      testMap2.setConnection(con2);
      testMap2.setSValueMax(maxSValue2);
      assertTrue(testMap2.getSValueMax() == maxSValue2);
  }
  if (maxSValue < maxSValue2) {
      testMap2.setConnection(con);
      assertTrue(testMap2.getSValueMax() == maxSValue);
  } else if (maxSValue2 < maxSValue) {
      testMap.setConnection(con2);
      assertTrue(testMap.getSValueMax() == maxSValue2);
  }
  testMap.setConnection(null);
  testMap.setSValueMax(maxSValue+maxSValue2);
  assertTrue(testMap.getSValueMax() == maxSValue+maxSValue2);
  assertTrue(testMap2.getSValueMax() != maxSValue+maxSValue2);
  testMap2.setConnection(null);
  testMap2.setSValueMax(maxSValue+maxSValue2);
  assertTrue(testMap2.getSValueMax() == maxSValue+maxSValue2)
  testMap.setConnection(con);
  assertTrue(testMap.getSValueMax() == maxSValue+maxSValue2);
  testMap.setConnection(null);
    }
View Full Code Here

     * @throws IOException in case of io problems
     */
    private void storeDataAuditEventProcessData
  (Connection con, long recKey, Map oldData, Map newData)
  throws SQLException, IOException {
  JDBCPersistentMap m = null;
  try {
      Long key = new Long(recKey);
      // old data
      if (oldData != null){
    m = new JDBCPersistentMap (ds, key, "DataAuditEventOldData");
    m.setConnection(con);
    m.setMapId (key);
    m.setNewMap ();
    m.putAll(oldData);
    try {
        m.store();
    } catch (PersistentMapSQLException e) {
        throw (SQLException)e.getCause();
    }
    m.setConnection(null);
      }
     
      // new data
      if (newData != null){
    m = new JDBCPersistentMap (ds, key, "DataAuditEventNewData");
    m.setConnection(con);
    m.setMapId (key);
    m.setNewMap ();
    m.putAll(newData);
    try {
        m.store();
    } catch (PersistentMapSQLException e) {
        throw (SQLException)e.getCause();
    }
    m.setConnection(null);
      }
  } finally {
      m.setConnection(null);
  }
    }
View Full Code Here

     * @throws IOException in case of data access problems
     */
    private ProcessData selectDataAuditEventData
  (Connection con, String recKey, String tableName)
  throws SQLException, IOException {
  JDBCPersistentMap m = new JDBCPersistentMap
      (ds, Long.valueOf (recKey), tableName);
  try {
      m.setConnection(con);
      m.load();
      ProcessData data = new DefaultProcessData();
      data.putAll(m);
      return data;
  } catch (PersistentMapSQLException e) {
      throw (SQLException)e.getCause();
  } finally {
      m.setConnection(null);
  }
    }
View Full Code Here

      readConfiguration();
  } catch (IOException ne) {
      throw new EJBException(ne);
  }
  try {
      confProps = new JDBCPersistentMap (ds, "Configuration");
  } catch (SQLException ne) {
      throw new EJBException(ne);
  }
    }
View Full Code Here

TOP

Related Classes of de.danet.an.util.persistentmaps.JDBCPersistentMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.