Пример #1
0
  /**
   * Creates an instance of JDO from a JNDI reference.
   *
   * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name,
   *     javax.naming.Context, java.util.Hashtable)
   */
  public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env)
      throws NamingException {
    Reference ref;

    // Can only reconstruct from a reference.
    if (refObj instanceof Reference) {
      ref = (Reference) refObj;
      // Make sure reference is of datasource class.
      if (!ref.getClassName().equals(getClass().getName())) {
        throw new NamingException("Reference not constructed from class " + getClass().getName());
      }

      JDO jdo;
      RefAddr addr;

      try {
        jdo = (JDO) Class.forName(ref.getClassName()).newInstance();
      } catch (Exception except) {
        throw new NamingException(except.toString());
      }
      addr = ref.get("description");
      if (addr != null) jdo._description = (String) addr.getContent();
      addr = ref.get("databaseName");
      if (addr != null) jdo._dbName = (String) addr.getContent();
      addr = ref.get("configuration");
      if (addr != null) jdo._jdoConfURI = (String) addr.getContent();
      addr = ref.get("lockTimeout");
      if (addr != null) jdo._lockTimeout = Integer.parseInt((String) addr.getContent());
      return jdo;

    } else if (refObj instanceof Remote) return refObj;
    else return null;
  }
Пример #2
0
  static {
    try {
      props = CfgReader.readCfg("server");
      jdo = new JDO();
      dbname = props.getProperty("db-name");
      if (dbname == null) throw new IllegalArgumentException("Can't get server-property 'db-name'");
      jdo.setDatabaseName(dbname);
      {
        Writer writer = new StringWriter();
        String m_props = props.getProperty("db-mgr-props");
        String m_jdocfg = props.getProperty("db-mgr-jdocfg");

        if (m_props == null)
          throw new IllegalArgumentException("Can't get server-property 'db-mgr-props'");
        if (m_jdocfg == null)
          throw new IllegalArgumentException("Can't get server-property 'db-mgr-jdocfg'");

        CfgReader.evaluateTemplate(m_props, writer, CfgReader.getXmlFileReader(m_jdocfg));
        writer.flush();
        Reader reader = new StringReader(writer.toString());
        EntityResolver resolver = new CfgEntityResolver();
        jdo.loadConfiguration(new org.xml.sax.InputSource(reader), resolver, null);
      }
      jdo.setClassLoader(jdo.getClass().getClassLoader());
      jdo.setDatabasePooling(props.getProperty("db-mgr-pooling") == "enabled");

      try {
        timeDiff = Long.parseLong(props.getProperty("db-time-diff"));
      } catch (NumberFormatException e) {
        timeDiff = 0;
        System.err.println("db-time-diff not specified. Set to 0.");
      }
      System.err.println("TIME-DIFF:" + timeDiff);
    } catch (Exception e) {
      e.printStackTrace(System.err);
      System.err.println(e.getLocalizedMessage());
      System.err.println("Can't initialize Castor JDO. I die.");
      System.exit(1);
    }
  }
Пример #3
0
  public void setUp() throws PersistenceException {
    _jdo = _category.getJDO();
    _jdo.setCallbackInterceptor(_i);
    _jdo.setInstanceFactory(_i);

    _db = _category.getDatabase();

    OQLQuery oql;
    QueryResults qres;

    LOG.debug("Delete everything");
    _db.begin();
    oql =
        _db.getOQLQuery("SELECT p FROM " + TimeStampableObject.class.getName() + " p WHERE id=$1");
    oql.bind(TimeStampableObject.DEFAULT_ID);
    qres = oql.execute();
    while (qres.hasMore()) {
      _db.remove(qres.next());
    }
    oql.close();
    _db.commit();
  }
Пример #4
0
  public void tearDown() throws PersistenceException {
    if (_db.isActive()) {
      _db.rollback();
    }

    OQLQuery oql;
    QueryResults qres;

    LOG.debug("Delete everything");
    _db.begin();
    oql =
        _db.getOQLQuery("SELECT p FROM " + TimeStampableObject.class.getName() + " p WHERE id=$1");
    oql.bind(TimeStampableObject.DEFAULT_ID);
    qres = oql.execute();
    while (qres.hasMore()) {
      _db.remove(qres.next());
    }
    oql.close();
    _db.commit();

    _db.close();

    _jdo.setCallbackInterceptor(null);
  }
Пример #5
0
 public static Database getConnection() throws DatabaseNotFoundException, PersistenceException {
   return jdo.getDatabase();
 }