Package org.hivedb.meta

Examples of org.hivedb.meta.HiveSemaphore


    return getSemaphore();
  }

  private HiveSemaphore getSemaphore() {
    JdbcTemplate t = getJdbcTemplate();
    HiveSemaphore result;
    try {
      result = (HiveSemaphore) t.queryForObject("SELECT * FROM semaphore_metadata", new HiveSemaphoreRowMapper());
    } catch (BadSqlGrammarException ex) {
      throw new HiveSemaphoreNotFound(
        "Exception loading HiveSemaphore -- verify that semaphore_metadata has one and only one row: "
View Full Code Here


    }
    return result;
  }

  public HiveSemaphore create() {
    HiveSemaphore hs;
    if (doesHiveSemaphoreExist())
      hs = get();
    else {
      JdbcTemplate j = getJdbcTemplate();
      hs = new HiveSemaphoreImpl(Status.writable, 1);
      Object[] parameters = new Object[]{hs.getStatus().getValue(), hs.getRevision()};
      try {
        j.update("INSERT INTO semaphore_metadata (status,revision) VALUES (?,?)", parameters);
      } catch (BadSqlGrammarException e) {
        throw new HiveSemaphoreNotFound(e.getMessage());
      }
View Full Code Here

      return new HiveSemaphoreImpl(Status.getByValue(rs.getInt("status")), rs.getInt("revision"));
    }
  }

  public void incrementAndPersist() {
    HiveSemaphore hs = get();
    hs.incrementRevision();
    update(hs);
  }
View Full Code Here

public class TestHiveSemaphorePersistence extends HiveTest {
 
  @Test
  public void testUpdate() throws Exception {
    HiveSemaphoreDao hsd = new HiveSemaphoreDao(getDataSource(getConnectString(getHiveDatabaseName())));
    HiveSemaphore hs = hsd.create();
    hs.incrementRevision();
    hsd.update(hs);
   
    HiveSemaphore hs2 = hsd.get();
    Assert.assertEquals(hs.getRevision(),hs2.getRevision());
    Assert.assertEquals(hs.getStatus(),hs2.getStatus());
  }
View Full Code Here

TOP

Related Classes of org.hivedb.meta.HiveSemaphore

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.