Package org.atomojo.app.db

Examples of org.atomojo.app.db.DB


      testDir = getTestDir(dirName);
     
      dbList = DB.getDatabases(log,testDir);
      if (dbList.isEmpty()) {
         DB db = DB.createDB(log,testDir,"data");
         dbList.put(db.getName(),db);           
         try {
            DB.writeList(testDir,dbList);
         } catch (Exception ex) {
            ex.printStackTrace();
            return;
View Full Code Here


      setNegotiated(false);
   }
  
   public Representation get()
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      Representation rep = new OutputRepresentation(MediaType.APPLICATION_XML) {
         public void write(OutputStream os)
            throws IOException
         {
            try {
               Iterator<SyncProcess> procs = db.getSyncProcesses();
               Writer out = new OutputStreamWriter(os,"UTF-8");
               ItemDestination dest = new WriterItemDestination(out,"UTF-8");
               ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
               dest.send(constructor.createDocument());
               dest.send(constructor.createElement(AdminXML.NM_SYNC_PROCESSES));
View Full Code Here

      return rep;
   }
  
   public Representation post(Representation entity)
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      if (!XMLRepresentationParser.isXML(entity.getMediaType())) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
      }
      XMLRepresentationParser parser = new XMLRepresentationParser();
View Full Code Here

      setNegotiated(false);
   }
  
   public Representation get()
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();
      SyncProcess proc = new SyncProcess(db,name);
      if (proc.exists()) {
         return proc.getRepresentation();
      } else {
View Full Code Here

   {
      if (!XMLRepresentationParser.isXML(entity.getMediaType())) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
      }
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();
      XMLRepresentationParser parser = new XMLRepresentationParser();
      Document doc = null;
     
      try {
View Full Code Here

         return new StringRepresentation("XML parse error: "+ex.getMessage());
      }
   }
  
   public Representation delete() {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();
      SyncProcess proc = new SyncProcess(db,name);
      if (proc.exists()) {
         if (proc.delete()) {
            getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
View Full Code Here

               }
               DBInfo dbinfo = autodbList.get(dbName);
               Storage storage = null;
               if (dbinfo==null) {
                  getLogger().info("Creating DB "+dbName);
                  DB db = new DB(getLogger(),new File(dbDir,dbName));
                  dbinfo = new DBInfo(dbName,db,auth,groupT!=null ?  groupT.getFirstValue() : null, aliasT!=null ? aliasT.getFirstValue() : null);
                  storage = storageFactory.getStorage(db);
                  try {
                     getLogger().info("Connecting to DB "+dbName);
                     db.connect();
                     getLogger().info("Connected to DB "+dbName);
                     autodbList.put(dbName,dbinfo);
                     storage.start();
                  } catch (SQLException ex) {
                     getLogger().log(Level.SEVERE,"Cannot connect to database "+dbName,ex);
View Full Code Here

      setNegotiated(false);
   }

   public Representation get()
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();

      Representation rep = new OutputRepresentation(MediaType.APPLICATION_XML) {
         public void write(OutputStream os)
            throws IOException
         {
            Writer out = new OutputStreamWriter(os,"UTF-8");
            out.write("<table name='"+name+"'>\n");
            try {
               DBConnection dbConnection = db.getConnection();
               try {
                  Statement s = dbConnection.getConnection().createStatement();
                  ResultSet r = s.executeQuery("select * from "+name);
                  ResultSetMetaData meta = r.getMetaData();
                  int columnCount = meta.getColumnCount();
                  out.write("<head>");
                  for (int i=1; i<=columnCount; i++) {
                     out.write("<name>");
                     out.write(meta.getColumnName(i));
                     out.write("</name>");
                  }
                  out.write("</head>\n");
                  while (r.next()) {
                     out.write("<row>");
                     for (int i=1; i<=columnCount; i++) {
                        String data = r.getString(i);
                        if (data!=null) {
                           out.write("<col>");
                           out.write(data);
                           out.write("</col>");
                        } else {
                           out.write("<col/>");
                        }
                     }
                     out.write("</row>\n");
                  }
               } finally {
                  db.release(dbConnection);
               }
            } catch (SQLException ex) {
               throw new IOException(ex.getMessage());
            }
            out.write("</table>");
View Full Code Here

      try {
        
         if (create) {
            if (dbList.isEmpty()) {
               Logger log = Logger.getLogger(WebComponent.LOG_NAME);
               DB db = DB.createDB(log,dir,"data");
               dbList.put(db.getName(),db);           
               try {
                  DB.writeList(dir,dbList);
               } catch (Exception ex) {
                  ex.printStackTrace();
                  return;
               }
            }
            int argCount = args.length-argIndex;
            String hostname = argCount>1 ? args[argIndex+1] : "*";
            String ipAddress = argCount>1 ? args[argIndex+2] : "*";
            int port = argCount>1 ? Integer.parseInt(args[argIndex+3]) : 8080;

            File logDir = new File(dir,"logs");
            ServerConfiguration.Host host = new ServerConfiguration.Host(conf,"data",hostname,null,port,false,false,new File(logDir,hostname.equals("*") ? "any.log" : hostname+".log"));
            conf.getInterfaces().add(new ServerConfiguration.Interface(ipAddress,port,true));
            conf.getHosts().put(host.getName(),host);
            File keystoreFile = new File(dir,"keystore");
            conf.setKeystoreFile(keystoreFile);
            conf.setKeystorePassword("atomojo");
            conf.setKeyPassword("atomojo");
            conf.setLogDirectory(logDir);
            conf.setTempDirectory(dir);
            if (storageClassName!=null) {
               conf.setStorageClassName(storageClassName);
            }
            File serverConfFile = new File(dir,"server.conf");
            Writer out = new OutputStreamWriter(new FileOutputStream(serverConfFile),"UTF-8");
            WriterItemDestination dest = new WriterItemDestination(out,"UTF-8");
            conf.store(serverConfFile.toURI(),dest);
            out.flush();
            out.close();
            if (!keystoreFile.exists()) {
               copyResource("/org/atomojo/app/db/conf/keystore",keystoreFile);
            }
            initStorageClass();
            web = new WebComponent(dir,dbList,getStorageFactory(),conf);
         }
         System.out.println("Connecting to databases...");
         // Connect to all databases
         for (DB db : dbList.values()) {
            System.out.println("Connecting to DB "+db.getName());
            db.connect();
         }
        
        
         System.out.println("Starting server...");

View Full Code Here

         lists.add(autodbList);
        
         boolean ok = true;
         for (Map<String,DBInfo> map : lists) {
            for (DBInfo dbinfo : map.values()) {
               DB db = dbinfo.getDB();
               if (dbNames.size()>0 && !dbNames.contains(db.getName())) {
                  continue;
               }
               try {
                  Storage storage = storageFactory.getStorage(db);
                  Backup backup = new Backup(db,storage,AtomApplication.RESOURCE_BASE);
                  File zipFile = new File(dir,db.getName()+".zip");
                  backup.toZip(db.getName(), zipFile);
               } catch (Exception ex) {
                  getLogger().log(Level.SEVERE,"Cannot backup database "+db.getName()+" due to exception.",ex);
                  ok = false;
               }
            }
         }
        
View Full Code Here

TOP

Related Classes of org.atomojo.app.db.DB

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.