Package org.atomojo.app.db

Examples of org.atomojo.app.db.DB$CollectionLocator


        
         boolean ok = true;
         List<String> failures = new ArrayList<String>();
         for (Map<String,DBInfo> map : lists) {
            for (DBInfo dbinfo : map.values()) {
               DB db = dbinfo.getDB();
               if (dbNames.size()>0 && !dbNames.contains(db.getName())) {
                  continue;
               }
               File dbDir = new File(dir,db.getName());
               boolean needsCleanup = false;
               try {
                  Storage storage = storageFactory.getStorage(db);
                  File zipFile = new File(dir,db.getName()+".zip");
                  if (!dbDir.exists() && zipFile.exists()) {
                     // This is what we want but it doesn't work
                     //introspectionURI = new URI("jar:"+zipFile.toURI()+"!/_introspection_.xml");
                     getLogger().info("Extracting backup for restore...");
                     needsCleanup = true;
                     extract(zipFile,zipFile.getParentFile());
                  }
                 
                  File introspect = new File(dbDir,"_introspection_.xml");
                  if (!introspect.exists()) {
                     getLogger().info("No database backup for database "+db.getName());
                     continue;
                  }
                  URI introspectionURI = introspect.toURI();

                  RemoteApp app = new RemoteApp(db,"backup");
                  app.setIntrospection(introspectionURI);
                  app.setRoot(dbDir.toURI());

                  SyncTarget target = new SyncTarget(db,"");
                  SyncProcess proc = new SyncProcess(db,"restore",true,target,app,null);

                  PullSynchronizer restore = new PullSynchronizer(getLogger(),getApplication().getMetadataService(),user,db,storage,proc);
                  restore.setAdditive(false);
                  try {
                     restore.sync();
                     if (restore.getErrorCount()>0) {
                        ok = false;
                        getLogger().severe("Restore failed on "+db.getName());
                        failures.add(db.getName());
                     }
                  } catch (SyncException ex) {
                     getLogger().log(Level.SEVERE,"Restore failed on "+db.getName()+" due to exception.",ex);
                     ok = false;
                     failures.add(db.getName());
                  }

               } catch (Exception ex) {
                  getLogger().log(Level.SEVERE,"Cannot restore database "+db.getName()+" due to exception.",ex);
                  ok = false;
                  failures.add(db.getName());
               }
               if (needsCleanup) {
                  delete(dbDir);
               }
            }
View Full Code Here


      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

      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 Storage storage = (Storage)getRequest().getAttributes().get(App.STORAGE_ATTR);
      XMLRepresentationParser parser = new XMLRepresentationParser();
      try {
         DocumentDestination dest = new DocumentDestination();
        
View Full Code Here

      setNegotiated(false);
   }
  
   public Representation get()
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      return new OutputRepresentation(MediaType.APPLICATION_XML) {
         public void write(OutputStream os)
            throws IOException
         {
            try {
               Writer out = new OutputStreamWriter(os,"UTF-8");
               out.write("<journal>\n");
               Iterator<Journal.Entry> entries = db.getJournal().getDeletes();
               while (entries.hasNext()) {
                  Journal.DeleteEntry delete = (Journal.DeleteEntry)entries.next();
                  out.write("<delete at='");
                  out.write(AtomResource.toXSDDate(delete.getOccurredOn()));
                  out.write("' feed='");
                  out.write(delete.getFeed().toString());
                  out.write("' path='");
                  out.write(delete.getPath());
                  UUID entryId = delete.getEntry();
                  if (entryId!=null) {
                     out.write("' entry='");
                     out.write(entryId.toString());
                  }
                  out.write("'/>\n");
               }
               entries = db.getJournal().getUpdates();
               while (entries.hasNext()) {
                  Journal.UpdatedEntry updated = (Journal.UpdatedEntry)entries.next();
                  String name = updated.getOperation()==Journal.CREATE_OPERATION ? "created" : "updated";
                  Feed feed = updated.getFeed();
                  Entry entry = updated.getEntry();
View Full Code Here

         }
      };
   }
  
   public Representation delete() {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      try {
         db.getJournal().truncate();
         getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
         return null;
      } catch (SQLException ex) {
         getContext().getLogger().log(Level.SEVERE,"Cannot get journal entries due to SQL exception.",ex);
         getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
View Full Code Here

      setNegotiated(false);
   }
  
   public Representation get()
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final Storage storage = (Storage)getRequest().getAttributes().get(App.STORAGE_ATTR);
      final Reference resourceBase = (Reference)getRequest().getAttributes().get(App.RESOURCE_BASE_ATTR);
      File tmpDir = (File)getContext().getAttributes().get(WebComponent.ATOMOJO_TMP_DIR);
      long tstamp = System.currentTimeMillis();
      String baseName = db.getName()+".backup."+tstamp;
      /*
      File dir = new File(tmpDir,baseName);
      if (!dir.mkdirs()) {
         getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,"Cannot create output directory.");
         return;
View Full Code Here

     
   }
  
   public Representation post(Representation entity)
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final Storage storage = (Storage)getRequest().getAttributes().get(App.STORAGE_ATTR);
      final Reference resourceBase = (Reference)getRequest().getAttributes().get(App.RESOURCE_BASE_ATTR);
      if (getRequest().getResourceRef().getRemainingPart().endsWith(".zip")) {
         getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
         return null;
View Full Code Here

   public RestartResource() {
      setNegotiated(false);
   }
  
   public Representation get() {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final Storage storage = (Storage)getRequest().getAttributes().get(App.STORAGE_ATTR);
      try {
         db.stop();
         db.connect();
         getResponse().setStatus(Status.SUCCESS_OK);
         Representation rep = new StringRepresentation("<success xmlns='"+AdminXML.NAMESPACE+"'/>",MediaType.APPLICATION_XML);
         rep.setCharacterSet(CharacterSet.UTF_8);
         return rep;
      } catch (Exception ex) {
View Full Code Here

      setNegotiated(false);
   }
  
   public Representation get()
   {
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final Storage storage = (Storage)getRequest().getAttributes().get(App.STORAGE_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();

      SyncProcess proc = db.getSyncProcess(name);
     
      if (proc!=null) {
         Synchronizer sync = null;
         if (proc.isPullSynchronization()) {
            User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
View Full Code Here

         }
         int h = path.indexOf('#');
         if (h>=0) {
            path = path.substring(0,h);
         }
         final DB atomDB = (DB)getContext().getAttributes().get(AtomApplication.DB_ATTR);
         Feed feed = null;
         if (path.length()>0) {
            String [] segments = path.split("/");
            feed = atomDB.findFeedByPath(segments);
            if (feed==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               return new StringRepresentation("No feed found at path: "+path);
            }
         }
         Form form = getRequest().getResourceRef().getQueryAsForm();
         String sinceS = form.getFirstValue("since");
         Date since = null;
         if (sinceS!=null && sinceS.length()>0) {
            try {
               since = AtomResource.fromXSDDate(sinceS);
            } catch (ParseException ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Bad since value '"+sinceS+"': "+ex.getMessage());
            }
         }
         String limitS = form.getFirstValue("limit");
         int limit = 100;
         if (limitS!=null && limitS.length()>0) {
            try {
               limit = Integer.parseInt(limitS);
            } catch (NumberFormatException  ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Bad limit value '"+limitS+"': "+ex.getMessage());
            }
         }
         String startS = form.getFirstValue("start");
         int start = 1;
         if (startS!=null && startS.length()>0) {
            try {
               start = Integer.parseInt(startS);
            } catch (NumberFormatException  ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Bad start value '"+startS+"': "+ex.getMessage());
            }
         }
         final int startRow = start;
         final int limitCount = limit;
         final Date sinceMarker = since==null ? new Date() : since;
         final Feed target = feed;
         return new OutputRepresentation(MediaType.APPLICATION_ATOM) {
            public void write(OutputStream os)
               throws IOException
            {
               setCharacterSet(CharacterSet.UTF_8);
               try {
                  String prevRef = null;
                  if (startRow>1) {
                     prevRef = getRequest().getResourceRef().toString();
                     int q = prevRef.indexOf('?');
                     prevRef = prevRef.substring(0,q);
                     prevRef += "?";
                     if (sinceMarker!=null) {
                        prevRef += "since=";
                        prevRef += AtomResource.toXSDDate(sinceMarker);
                        prevRef += "&";
                     }
                     prevRef += "start=";
                     int prevStart = startRow-limitCount;
                     int prevLimit = limitCount;
                     if (prevStart<1) {
                        prevStart = 1;
                        prevLimit = startRow-1;
                     }
                     prevRef += prevStart;
                     prevRef += "&limit=";
                     prevRef += prevLimit;
                  }
                  String nextRef = getRequest().getResourceRef().toString();
                  int q = nextRef.indexOf('?');
                  if (q>=0) {
                     nextRef = nextRef.substring(0,q);
                  }
                  nextRef += "?";
                  if (sinceMarker!=null) {
                     nextRef += "since=";
                     nextRef += AtomResource.toXSDDate(sinceMarker);
                     nextRef += "&";
                  }
                  nextRef += "start=";
                  nextRef += (startRow+limitCount);
                  nextRef += "&limit=";
                  nextRef += limitCount;
                  DBIterator<Entry> entries = atomDB.getEntriesModifiedBefore(target,sinceMarker,startRow,limitCount);
                  Form form = getRequest().getResourceRef().getQueryAsForm();
                  generate(new WriterItemDestination(new OutputStreamWriter(os,"UTF-8"),"UTF-8"),entries,prevRef,nextRef);
                  entries.finished();
               } catch (XMLException ex) {
                  getContext().getLogger().log(Level.SEVERE,"Cannot serialize metadata feed.",ex);
View Full Code Here

TOP

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

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.