Fix delete()function

Let’s have a look on the code in DataStore class (in the core).

 /**
         * Deletes the given object and returns the object if successful
         * @param The object to be deleted
         * @return The object being deleted
         */
        public <T> T delete(T aTNG){
                // Please see Wiki for more information on the ServerConfiguration.
                ClientConfiguration config = Db4oClientServer.newClientConfiguration();
                config.common().reflectWith(new JdkReflector(Thread.currentThread().getContextClassLoader()));

                logger.log(Level.FINE, "Database Delete Attempt...");
                //ObjectContainer client = server.openClient();
                ObjectSet<T> result = theDB.queryByExample(aTNG);
                T found = (T) result.next(); //<--- will send out exception:java.lang.IllegalStateException
                                                             //if "result" is empty.
                theDB.delete(found);
                theDB.commit();

                logger.log(Level.FINE, "Database Delete Success!");
                //return "Deleted "+aTNG;
                return found;

        }

Problem Analysis: 

In this term, many groups used Calendar object to store date information. However, it seems that calendar(or say GregorianCalendar) cannot be parsed and compared in db4o database.This makes queryByExample() method cannot locate the data we find. So if we pass a commitment, which we wanna delete from the database, to this method the  ObjectSet<T> result = theDB.queryByExample(aTNG);, it cannot find the one in the database and return an empty result collection. Then when we use .next() method on an empty collection, we will get errors. This is the reason why we pass the thing we wanna delete to the database, and the database can’t delete it and give us an error.

Solution: 

Since CalendarItem have a unique id. We just make a null CalendarItem(eg. CalendarItem(null,null,null)) and set it’s id to the one we wanna delete, and pass it to the delete method in the DataStore.

e.g:

public boolean deleteEntity(Session s, String id) throws WPISuiteException{

ensureRole(s, Role.ADMIN);

Commitment oldComm = new Commitment(null,null,null);

oldComm.setId(Integer.parseInt(id));

Commitment deletedComm = db.delete(oldComm);

if (deletedComm != null){

System.out.println("Here is deletEntity method. ---> delete Succesfull");

return true; // the deletion was successful

}   

System.out.println("Here is deletEntity method. ---> delete Fail");

return false; // The deletion was unsuccessful

}

 

Details:

1.queryByExample is the same as get() (deprecated) method  in the db4o.

Reference: http://www.db4o.com/about/productinformation/resources/db4o-6.3-tutorial-java.pdf

CSS基本笔记(CSS Memo)

1. Reasons to use CSS: DRY, Clean

Examles: 1.

<h1 style="color: #98c7d4;"> Hellow World! </h1>
2.
<head>
<style>
h1 { color: #98c7d4; }
</style>
</head>

This two way maybe will repeat numerous times, so the paragraph of code will be large. The best way is making a External sheet in the following way:

<head>
<title>CSS Cross Country</title>
<link rel="stylesheet" href="styles.css" />
</head>

This will make your codes DRY(Don’t Repeat Yourself)


2.Cascade Order(something about the code priority)

 

Using !important < Inline style arttribute  < In the <head>  < External <link>

 


3.Primary DOM selectors

Example:

<h1 class="intro" id="header">Hello World!</h1>

-Element selector
h1{
 color:#aba4ac;
 margin-bottom:10px;
}
-Class selector
.intro{
  color:#abc4ac;
  margin-bottom:10px;
}
-ID selector
#header{
  color:#abc4ac;
  margin-bottom:10px;
}

4.Float <float: left/right/none;>

when we put pictures and paragraphs in a container, we could us Float to deal with their relation.

*Floated elements stack up to the parent edge, then move down to the next available edge. 

*Take care with elements that have differing heights-the first available edge isn’t always below.

 

Clearfix

/*Originally developed by Tony Aslett and Refined by Nicholas Gallagher */
.group:before
.group:after{
  content:"";
  display:table;
}
.group:after{
  clear:both;
}
.group{
  zoom:1;/*IE6&7*/
}

 

5. Inheritance & Specificity

Override parent properties: nested selector

    0      ,0     ,0     ,0

inline style     #if ID       #of class   #of element

 

 6.BOX

Total box width = content width + padding width +border width

 

Box overflow:

overflow: visible /auto/hidden /scroll

↑when content beyond the container boundaries;

 

Positioning:<position: static/relative/absolute/fixed;>

 

Z-index:

z-index:1;

↑Overlaping

Example:

<article>

  <img class="Green" src="Green.jpg" alt="Ski!"/>

  <img class="sled" src="sled.jpg" alt="Sled!"/>

</article>
.Green, .Brown{

  z-index:1;

}
.Brown{

  z-index:1;

}

In these case the Brown class should be above the Green class

 

7. Display Types:<display: block/inline/inline block;>

block:<div><p><ul><ol><li>

inline:<span><a><em><img>

 

8.Horizontal Centering

In block level:

margin: 0 auto;

in inline block level:

text-align:center;

 

9. Image Cropping

Solutions:

Overflow:hidden;

Or we could

.cropping img {

  height: 300px;

  width:auto;

}

 

SSS:SCIENTIFIC AMERICAN 60-SECOND SCIENCE 科学美国人60秒『PDF+内嵌音频』

科学美国人60秒:

科学美国人60秒是Scientific American(《科学》的姊妹)下的一个60秒科学趣味播报专栏,语速快且清晰,精炼且经典。平时有时间每天听上一段,日积月累听力就会大大提升。本人在备考托福的路上很喜欢拿这个练听力,每次听完这个再听TPO就感觉TPO的语速慢了很多很多。 继续阅读“SSS:SCIENTIFIC AMERICAN 60-SECOND SCIENCE 科学美国人60秒『PDF+内嵌音频』”

成功不在于坚持了多久,而在于你能否继续坚持

遇到你之前,我以为爱是惊天动地,爱是轰轰烈烈抵死缠绵;我以为爱是荡气回肠,爱是热血沸腾幸福满满;我以为爱是窒息疯狂,爱是炙热的火炭。婚姻生活牵手走过酸甜苦辣温馨与艰难,我开始懂得——爱是经得起平淡的流年。 ——《全世爱》苏小懒 继续阅读“成功不在于坚持了多久,而在于你能否继续坚持”