jeudi 2 avril 2015

How to save changes in DB

I am having a shopping cart page which displays following information

Item No.,Description,Order Type,Quantity,available Qty,Dealer Information,Comments,Purchase Order Number

and some more fields(exactly 20). And at this point of time in cart I am having 20 sku.

I need to make this cart as persistent cart,

ie I have to save all changes made by user in following scenarios

1. If user changes anything I have to save it in db.

2. After adding item to cart, user logout.

3. User changes and goes to different page.

4. User changes qty and gone to take bath.

So How to do it, according to me possible solutions are

1.For all the events use AJAX to save the particular field. (But gives performance issue)

2. Save the value of changed element in session and save it in db when user navigates or logout


Thanks in Advacne!!


Which is the best way to use Guice 3.0 with MVC/MVP approach on Java Swing?

I am using the Guice 3.0 with Model-View-Presenter (MVP) to produce low coupling architecture (design) in Java Swing (quasi-MVP). I calling of the quasi-MVP because it is first stage to do this architecture (in this case, does not includes a refined view point yet). To do it, I created the packages below with DI – Decency Injection.



  • Presenter – consist a set of class to control access to lower layers such as Services.

  • View – consist in an set of class to represents the view (UI) elements

  • Model – a set of class to represents DTOs - Data Type Objects

  • Service – a model service layer which contains a set of methods to retrieve DTOs

  • Injectors – represents a set of useful stuffs for Guice inject dependency


My intention, it is to use Guice with Swing to have DI where I need. In addition, this architecture has some configurations files such as POMs and JNLPs, not showed. Also, this application is start from Java Webstart Application using JNLP.


So, my question is what is the best way to perform this architecture with Guice for small apps ? In addition, I have some doubt points, in particular if the AppPresenterFacade is a correct pattern and approach to avoid tight coupling as well as the package hierarchy defined. However, I would like to know some tips and suggestions. See the code below:


PS: I checked some questions related, such as How to use Guice in Swing application but I can't find issues involving design and architecture.





public class MainApp {
public static void main(String args[]) {
initPropertiesFromJnlp( args );
showApp();
}
// ... ...
private static void showApp() {
AppFrameView view = AppFrameView.getInstance(AppFrameView.class);
AppPanel panel = AppPanel.getInstance(AppPanel.class);
view
.addComponent( panel )
.showView();

}
}
}





public class AppPresenterImpl implements AppPresenter{


private final AppServices services;


@Inject
public AppPresenterImpl (AppServices services) {
this.services = services;
}

public void handleOkButton(final ActionEvent actionEvent){
new Thread(
new Runnable() {
@Override
public void run() {

// call service from DI
}
}
).start();
}

public void handleCancelButton(final ActionEvent actionEvent) {
System.exit(0);
}

}





public class AppIServicempl implements AppServices {
// some code from service
public void dispatchAppDoSomething() {}
}





public class AppView extends JFrame {
private JLabel lblSomeThing;

@Inject
public AppView(AppPresenter presenter) {
this();
this.presenter = presenter;
}
// more code
}





public class AppPresenterFacade {
private AppPresenterFacade(){}


public static <T> T getInstance(java.lang.Class<T> clazz){
Injector injector = Guice.createInjector( new AppModule() );
T instance = injector.getInstance(clazz);
return instance;
}
}





public class AppModule extends AbstractModule {


@Override
protected void configure() {
bind(AppServices.class).to(AppServicesImpl.class);
bind(AppPresenter.class).to(AppPresenterImpl.class);
}
}

C++ virtual function and design pattern

I have an abstract base class for Data type and two inherited class, Data1 and Data2. Data1 and Data2 have different members. I have an abstract class Proc which operates on these data. Proc has a virtual function update which takes a reference of Data as parameter. Proc1 and Proc2 both define its own implementation. However both of the implementation will use members defined in concrete class Data1 and Data2. How to make this work given the parameter is a reference of Data? For example.



class Data {};
class Data1: public Data{
int x;
};
class Data2: public Data{
string str;
};

class Proc{
virtual void update(const Data&) = 0;
};

class Proc1: public Proc{
update(const Data &d){
// this does not work
cout << x << endl;
}
};

class Proc2: public Proc{
update(const Data &d){
// this does not work
cout << str << endl;
}
};


Thank you for suggestions.


How does a sequence diagram look like wich contatins a State pattern (not switch statement)

Im wondering how a sequence diagram looks like wich contains a State pattern (not switch statement).


Thnx


How to build a nodeJS factory?

After reading examples online on creating module and design patterns like:


http://ift.tt/1se9jxu


http://ift.tt/1xEq87A


I am not able to decide which pattern is better. At the moment, I am using a singleton pattern. Is it the correct implementation?


Essentially I want to encapsulate different modules into a factory and return an object.


Each modules has its own config.


moduleA.js



var moduleA = function(config) {
this.wheels = config.wheels || 4;
this.display = function() {
console.log('wheels: '+this.wheels);
}
};
module.exports = moduleA;


moduleB.js



var moduleB = function(config) {
this.wheels = config.wheels || 8;
this.display = function() {
console.log('wheels: '+this.wheels);
}
};
module.exports = moduleB;


factory.js



var moduleA = require('./moduleA');
var moduleB = require('./moduleB');

var factory = function(config){
this.moduleClass = function(){};
switch(config.type){
case 'a' : this.moduleClass = moduleA; break;
case 'b' : this.moduleClass = moduleB; break;
}
return new this.moduleClass(config);
};
module.exports = factory;


Calling it should be something like :



var config = {type:'a', wheels: 4};
var myFactory = require('./factory')(config);
myFactory.getModuleA();
config = {type:'b', wheels: 8};
myFactory.setConfig(config);

Design pattern for chain of transformations to be applied to input

I am developing an application where I have a common problem of taking an input of some type and applying a chain of transformations to it to get an output.


For example, I take an image in the form of cv::Mat as input, apply a functor to it to get a bunch of local features in the form of std::vector<Eigen::VectorXf> which are then converted to a global descriptor in the form of a single Eigen::VectorXf. This is just an example, an actual chain of processing might be a lot longer.


I am trying to come up with a sensible way of representing this. I am currently thinking of a sort of linked list of operations, where each operation calls the next operation unless its next field is empty.


Is this the sensible way of going forward? Is there a design pattern that is meant for this situation?


Can you please explain in simple terms what is Consumer-Driven Contracts?

I was reading this article about Consumer-Driven Contracts but didn't understand properly. Can anybody please let me know in simple terms what is it and how can we implement in C# (any pseudo code will do)?


Thanks in advance.