Tool Class Public classMongodbdao {/*** Get MongoDB Client instance * *@return * @throwsException*/ Public StaticMongoclient getmongoclient ()throwsException {Try { //decryption with secret keyString SKey = Syspropertyjdbc.getproperty ("Jdbc.deskey"). substring (4, 28); String sIp=Desutil.decryptmode (SKey, Mongodbproperty.getproperty ("MIP")); intIport =integer.valueof (Desutil.decryptmode (SKey, Mongodbproperty.getproperty ("Mport"))); String Suser=Desutil.decryptmode (SKey, Mongodbproperty.getproperty ("Muser")); String Spasword=Desutil.decryptmode (SKey, Mongodbproperty.getproperty ("Mpassword")); String sdbnm=Desutil.decryptmode (SKey, Mongodbproperty.getproperty ("MDB")); // ===================================================//List<serveraddress> serverlist =NewArraylist<serveraddress>(); Serverlist.add (Newserveraddress (SIp, Iport)); // ===================================================//List<mongocredential> mclist =NewArraylist<mongocredential>(); Mclist.add (Mongocredential.createcredential (Suser, SDBNM, Spasword.tochararray ())); // ===================================================//Mongoclientoptions.builder Builder =Mongoclientoptions.builder (); //The maximum number of connection that can be established with the target database isBuilder.connectionsperhost (50); //If the current connection are in use, each of the connection can be queued for 50 threadsBuilder.threadsallowedtoblockforconnectionmultiplier (50); //when a thread accesses a database, the maximum wait time is 2 minutes before a successful access to an available database connection//This is dangerous, and if more than Maxwaittime has not acquired the connection, the thread will throw exception//Therefore, the maxwaittime set here should be large enough to avoid database access failures due to too many queued threadsBuilder.maxwaittime (1000 * 60 * 2); //the timeout setting to connect to the database is set to 1 minutesBuilder.connecttimeout (1000 * 60 * 1); // ===================================================//Mongoclientoptions MCO =Builder.build (); return Newmongoclient (serverlist, Mclist, MCO); } Catch(Exception e) {Throwe; }}} operation class Logger.debug ("START ..."); intpage = 0;//Scroll to load page numbers intPage10 = 0; if( This. Getpara ("Pagetimer")! =NULL) {page= Integer.parseint ( This. Getpara ("Pagetimer"));//Scroll to load page numbersPAGE10 = page * 10; } String Umac= This. Getpara ("Umac"); Calendar C=calendar.getinstance (); C.add (Calendar.month,-1); //System.out.println (C.gettime ()); Last month timeMongodbdao Mongodbdao =NewMongodbdao (); Mongoclient mongoclient=mongodbdao.getmongoclient (); Mongodatabase Database=mongoclient. Getdatabase (Desutil.decryptmode (Syspropertyjdbc.getproperty ("Jdbc.deskey"). Substring (4, page), Mongodbproperty.getproperty ("MDB"))); Mongocollection<Document> collection = Database.getcollection ("User_timeline"); //Query Criteriamongocursor<document> mongocursor = Collection.find (Filters.and (Filters.eq ("Umac", Umac), Filters.gt (" DateTime, C.gettime ())). Skip (PAGE10). Limit (10). iterator (); String Timershaft= "";//Return Display Items while(Mongocursor.hasnext ()) {Iterator<entry<string, object>> iter =Mongocursor.next (). EntrySet (). iterator (); Date datetime=NULL; String Host= ""; String resultdate= ""; while(Iter.hasnext ()) {Entry etmp=Iter.next (); String skeytmp=Etmp.getkey (). toString (); Switch(skeytmp) { Case"DateTime": DateTime=(Date) etmp.getvalue (); Break; Case"Host": Host=Etmp.getvalue (). toString (); Break; default: Break; } if(DateTime! =NULL) {resultdate=datedeal (datetime); }} Timershaft= Timershaft + "<li><div class=\" animationtime\ ">" + resultdate + "</div><div class=\" Animationtimen\ ">" +Host+ "</div></li>"; } This. SetAttr ("Pagetimer", page); This. SetAttr ("Timershaft", Timershaft); Tool class Public classSYSPROPERTYJDBC {/*** Initial*/ PrivateSYSPROPERTYJDBC ()throwsException { This. props =NewProperties (); Props.load ( This. GetClass (). getClassLoader (). getResourceAsStream (Props_name)); } Private Static FinalString props_name = "Jdbc.properties"; Private StaticSYSPROPERTYJDBC Sysprops; PrivateProperties props; Public StaticString GetProperty (String key)throwsException {returnsyspropertyjdbc.getinstance (). GetProperties (). GetProperty (key); } PrivateProperties getProperties () {return This. Props; } Private Static synchronizedSyspropertyjdbc getinstance ()throwsException {if(Sysprops = =NULL) {Sysprops=NewSyspropertyjdbc (); } returnSysprops; }} Public classMongodbproperty {PrivateMongodbproperty ()throwsException { This. props =NewProperties (); Props.load ( This. GetClass (). getClassLoader (). getResourceAsStream (Props_name)); } Private Static FinalString props_name = "Mongodb.properties"; Private StaticMongodbproperty Sysprops; PrivateProperties props; Public StaticString GetProperty (String key)throwsException {returnmongodbproperty.getinstance (). GetProperties (). GetProperty (key); } PrivateProperties getProperties () {return This. Props; } Private Static synchronizedMongodbproperty getinstance ()throwsException {if(Sysprops = =NULL) {Sysprops=NewMongodbproperty (); } returnSysprops; }}
#mongodb. Properties
mip=d9iw8gelyiwgjbrhrzgtrq==
mport=3ytpa2qmgvm=
muser=rit52btdodccvp34zzx6xg==
Mpassword=hjcidejqfmmo9w1ghpc+upie88wpzolh
mdb=sio7zyszzh3l2g2+ocvjmw==
Mongodbdao Tool Class