Here is shown the JPA approach of fine-grained object model in practice. It is implemented by JPA annotations @Embeddable and @Embedded. Nice real example is shown here:
http://www.concretepage.com/hibernate/example-embeddable-embedded-hibernate-annotation
Monday, October 27, 2014
Thursday, May 29, 2014
HTTP sessions - way of working
The basic premise of sessions is that only a session ID is stored on the client.
On the server, that ID is associated with other "real world" information such as a user name,
shopping cart etc. (This is a difference compared to using "raw" cookies to store information such as a user name on the client.)
HTTP sessions typically operate is as follows:
- when a client first requests a page where we need to start a session (e.g. the "login" page), our server allocates a random session ID;
- that session ID is then communicated back to the client;
- whenever the client subsequently requests a page from our server (or relevant path from our server), it sends back the same session ID;
- on the server, we can associate information with that session ID;
- on the server, we can eventually decide that the session has "expired", and/or provide the user with a means to manually
Thursday, May 15, 2014
Test Doubles - most clear definition
| Test Double Type | Description |
|---|---|
| Dummy | The simplest, most primitive type of test double. Dummies contain no implementation and are mostly used when required as parameter values, but not otherwise utilized. Nulls can be considered dummies, but real dummies are derivations of interfaces or base classes without any implementation at all. |
| Stub | A step up from dummies, stubs are minimal implementations of interfaces or base classes. Methods returning void will typically contain no implementation at all, while methods returning values will typically return hard-coded values. |
| Spy | A test spy is similar to a stub, but besides giving clients an instance on which to invoke members, a spy will also record which members were invoked so that unit tests can verify that members were invoked as expected. |
| Fake | A fake contains more complex implementations, typically handling interactions between different members of the type it's inheriting. While not a complete production implementation, a fake may resemble a production implementation, albeit with some shortcuts. |
| Mock | A mock is dynamically created by a mock library (the others are typically produced by a test developer using code). The test developer never sees the actual code implementing the interface or base class, but can configure the mock to provide return values, expect particular members to be invoked, and so on. Depending on its configuration, a mock can behave like a dummy, a stub, or a spy. |
Source: microsoft
Monday, July 22, 2013
replace all in file from console
The command is:
sed -i 's/oldString/newString/g' fileToBeReplaced.txt
For MAC the behaviour is more restrictive, and wants to specify an backup file this way:
sed -i.bak 's/oldString/newString/g' fileToBeReplaced.txt
In this case, a backup file ("fileToBeReplaced.txt.bak") will be created.
Thursday, July 18, 2013
SQL FOREIGN KEY Constraints
CREATE TABLE buildings (
building_no int(11) NOT NULL AUTO_INCREMENT,
building_name varchar(255) NOT NULL,
address varchar(355) NOT NULL,
PRIMARY KEY (building_no)
) ENGINE=InnoDB;
CREATE TABLE rooms (
room_no int(11) NOT NULL AUTO_INCREMENT,
room_name varchar(255) NOT NULL,
building_no int(11) NOT NULL,
PRIMARY KEY (room_no),
KEY building_no (building_no),
CONSTRAINT rooms_ibfk_1
FOREIGN KEY (building_no)
REFERENCES buildings (building_no)
ON DELETE CASCADE
) ENGINE=InnoDB;
Wednesday, July 17, 2013
SQL triggers
Syntax:
Dropping trigger:
Example 2:
CREATE TRIGGER trigger_name trigger_time trigger_event
ON table_name
FOR EACH ROW
BEGIN
...
END
Dropping trigger:
DROP TRIGGER table_name.trigger_name
Example 1:
CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));
CREATE TRIGGER ins_sum BEFORE INSERT ON account FOR EACH ROW SET @sum = @sum + NEW.amount;
SET @sum = 0;
mysql> INSERT INTO account VALUES(137,14.98),(141,1937.50),(97,-100.00);
mysql> SELECT @sum AS 'Total amount inserted';
Example 2:
CREATE TRIGGER `tutorial`.`before_delete_carts`
BEFORE DELETE ON `trigger_carts` FOR EACH ROW
BEGIN
DELETE FROM trigger_cart_items WHERE OLD.cart_id = cart_id;
END
Example 3:
CREATE TRIGGER `after_update_cost`
AFTER UPDATE ON `trigger_items_cost` FOR EACH ROW
BEGIN
UPDATE trigger_items
SET price = (NEW.cost * 1.3)
WHERE item_id = NEW.item_id;
END
Monday, March 25, 2013
Important notes on java synchronisation by stack overflow
I had issues with synchronisation with static variable. Volatile do not help me, but the thread below does (:
http://stackoverflow.com/questions/2120248/how-to-synchronize-a-static-variable-among-threads-running-different-instances-o
http://stackoverflow.com/questions/2120248/how-to-synchronize-a-static-variable-among-threads-running-different-instances-o
Subscribe to:
Posts (Atom)