Package pt.webdetails.cpf.persistence

Examples of pt.webdetails.cpf.persistence.ISimplePersistence


    }
    return instance;
  }

  public View getView( String viewName, String user ) {
    ISimplePersistence sp;
    try {
      sp = getSimplePersistence();
      Filter filter = new Filter();
      filter.where( "name" ).equalTo( viewName ).and().where( "user" ).equalTo( user );
      List<View> views = sp.load( View.class, filter );

      return ( views != null && views.size() > 0 ) ? views.get( 0 ) : null;
    } catch ( Exception e ) {
      logger.error( "Error while getting view.", e );
      return null;
View Full Code Here


    }
   
  }

  public JSONObject listViews( String user ) {
    ISimplePersistence sp;
    JSONObject obj = new JSONObject();
    JSONArray arr = new JSONArray();
    try {
      sp = getSimplePersistence();
      Filter filter = new Filter();
      filter.where( "user" ).equalTo( user );
      List<View> views = sp.load( View.class, filter );
      for ( View v : views ) {
        arr.put( v.toJSON() );
      }
    } catch ( Exception e ) {
      logger.warn( "Exception while writing result to json array", e );
View Full Code Here

    return obj;
  }

  public JSONObject listAllViews( String user ) {
    JSONObject response = new JSONObject();
    ISimplePersistence sp;
    try {
      sp = getSimplePersistence();
    } catch ( Exception e ) {
      logger.error( "Error while getting view.", e );
      return null;
    }
    Filter filter = new Filter();
    filter.where( "user" ).equalTo( user );
    List<View> views = sp.loadAll( View.class );
    JSONArray arr = new JSONArray();
    for ( View v : views ) {
      arr.put( v.toJSON() );
    }
    try {
View Full Code Here

  public String deleteView( String viewName, String user ) {
    try {
      Filter filter = new Filter();
      filter.where( "user" ).equalTo( user ).and().where( "name" ).equalTo( viewName );
      ISimplePersistence sp = getSimplePersistence();
      sp.delete( View.class, filter );
      return RESULT_OK;
    } catch ( Exception e ) {
      return RESULT_ERROR;
    }
View Full Code Here


  //Should return null when ISimplePersistence.load fails
  @Test
  public void testGetViewFailOnLoad() {
    ISimplePersistence isp = Mockito.mock( ISimplePersistence.class );
    Mockito.when( isp.load( Mockito.eq( View.class ), Mockito.any( Filter.class ) ) )
            .thenThrow( new OCommandExecutionException( "Exception" ) );
    ViewsEngineForTest vet = new ViewsEngineForTest( Mockito.mock( IPersistenceEngine.class ), isp );
    Assert.assertNull( vet.getView( "x" , vet.getSession().getName() ));
  }
View Full Code Here

  }

  //Should return error object when ISimplePersistence.load fails
  @Test
  public void testListViewsFailOnLoad() throws JSONException {
    ISimplePersistence isp = Mockito.mock( ISimplePersistence.class );
    Mockito.when( isp.load( Mockito.eq( View.class ), Mockito.any( Filter.class ) ) )
            .thenThrow( new OCommandExecutionException( "Exception" ) );
    ViewsEngineForTest vet = new ViewsEngineForTest( Mockito.mock( IPersistenceEngine.class ), isp );
    JSONObject result = vet.listViews( vet.getSession().getName() );
    Assert.assertNull( result );
  }
View Full Code Here

TOP

Related Classes of pt.webdetails.cpf.persistence.ISimplePersistence

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.