2014-01-25 23:21:17 -03:00
package com.wisemapping.dao ;
import com.wisemapping.model.Label ;
2014-01-26 18:21:01 -03:00
import com.wisemapping.model.User ;
2014-01-25 23:21:17 -03:00
import org.jetbrains.annotations.NotNull ;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport ;
2014-01-26 18:21:01 -03:00
import java.util.List ;
2014-01-25 23:21:17 -03:00
public class LabelManagerImpl extends HibernateDaoSupport
implements LabelManager {
@Override
2014-01-26 18:18:49 -03:00
public void addLabel ( @NotNull final Label label ) {
2014-01-25 23:21:17 -03:00
saveLabel ( label ) ;
}
@Override
2014-01-26 18:18:49 -03:00
public void saveLabel ( @NotNull final Label label ) {
2014-01-25 23:21:17 -03:00
getSession ( ) . save ( label ) ;
}
2014-01-26 18:21:01 -03:00
@NotNull
@Override
public List < Label > getAllLabels ( @NotNull final User user ) {
return getHibernateTemplate ( ) . find ( " from com.wisemapping.model.Label wisemapping where creator_id=? " , user . getId ( ) ) ;
}
2014-01-28 02:21:14 -03:00
@Nullable
@Override
public Label getLabelByTitle ( @NotNull String title , @NotNull final User user ) {
Label result = null ;
final List < Label > labels = getHibernateTemplate ( ) . find ( " from com.wisemapping.model.Label wisemapping where title=? and creator=? " , new Object [ ] { title , user } ) ;
if ( labels ! = null & & ! labels . isEmpty ( ) ) {
result = labels . get ( 0 ) ;
}
return result ;
}
2014-01-25 23:21:17 -03:00
}