Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

# Ismael Upright

Ranch Hand
since Feb 15, 2007
For More
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
1
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Ismael Upright

Thank you guys, that makes things much more clear
I've found the two's complement description on wiki but it wasn't as clear and simple explanation as yours.

At first I was thinking that the "negative zero" problem can be solved in a "shift by one" solution, so 0000 0000 0000 0000 would be zero, and 1000 0000 0000 0000 would be -1 ("adding 1" would be still easier to do and to read than "interchanging 0s and 1s and then adding 1"). One-number-waste problem would also be solved by that (although 1 number waste is only 0.0015% in this case).

But the unified and simplified adding convinced me in 100% I cannot find an example when two's complement is more time-consuming than "left bit is sign bit" encoding.
12 years ago
Hello,

Probably you know how the negative integers are stored in the memory. To remind it, if you want to get the binary representation (source):

- First get the binary representation of the number.
- Then interchange zeros and ones in the binary representation.
- Finally add one to the result.

So for example two's complement of -18 would be (assuming one byte representation):

- Converting 18 to binary -- 0001 0010
- Interchanging 0s and 1s -- 1110 1101
- Adding 1 -- 1110 1110

My question came from the curiosity: why they wanted to store negative integers in such a hard way?

I can't see any sense in it, but I believe there is a sense in it Maybe it's easier to read for the maschine or computations are faster but I'd like to see this sense so I can remember it easier

Anyone knows?
12 years ago
Hey there,

I'm using RCP to create the standalone desktop application. If you're not familiar, RCP uses SWT as graphic engine. But the question is rather about general programming pattern on how to organize the GUI code in readable way (doesn't have to be SWT code). Here we go:

I have a class which implements a composite. A composite is a rectangle that contains:

- Checkbox with text next to it
- Two radio buttons, one under another, each with text next to is; these radio buttons are active only if the checkbox above is checked
- Yet another checkbox with text next to it
- a table with some editable data
- two buttons: "create new" and "delete existing", used to create new row in table and to delete existing row from table.

The point is, the display of this composite depends on the previous user actions.

Sometimes I don't want to display radio buttone, only two checkboxes one under another, and table with buttons

Sometimes I don't want to display the table and buttons, only checkbox, 2 radios and checkbox again

Sometimes I want to display everything: checkbox, 2 radios, checkbox, table and 2 buttons

It's easy to do with lot's of "ifs" in the code but it makes the code much less readable. Maybe you know a pattern which would be useful in this case?

I need to:

- provide the information about display conditions from the outside of class (constructor? flags with setters and getters? others?)
- manage the internal code in the class in a readable way (inheritance? division of class to smaller parts? some "smart" methods for each graphic element? others?)
13 years ago
The solution was to revert the relation between Customer and CustomerBankAccount.

Why does it work with that change? No idea. I suspect that the entities are left in the cash and the database management works better with reversed relation.
13 years ago
In case if you wonder what the customerService does: it only calls GeneralDAO, which goes as follows:

The exception is raised in line 14.
13 years ago
...so I have the following two entities:

As you can see, every Customer can have one or zero bank accounts.

And the problematic code: I have created a customer and assigned abank account to it. Now I want to remove the bank account first, update the customer, and then I want to change the customer name.

The first update is done without problem, but during the second one I get the exception:

java.lang.IllegalArgumentException: Removing a detached instance Customer#262144
at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:65)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:108)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:957)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:940)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
... 44 more

What am I doing wrong?
And more important: what can I do to fix it?
13 years ago
Nobody knows?
13 years ago
Yes, it's SWT. Sorry, I forgot to point that out..
13 years ago
Hello,

My problem concerns SWT technology.

I'd like to customize the View Title Area. To explain I'll use the screen:

There is a text "MyView". It's placed on the blue background with "X" button. To the right of it there is a grey area, and on the end of this area there are two buttons: minimize and maximize.

What I'm trying to do is to:

1. remove "X" button
2. remove minimize and maximize buttons
3. extend the blue area to the end of the horizontal space so it ends where maximize button is placed now

Does anyone has knowledge on to how to do that?
13 years ago
Hello,

I'd like to add a new button before 3 windows buttons in the top right corner (minimize, maximize and close) and make it look similar to them. Is it possible? How to do that?

Now it looks like that:

[ _ ] [ O ] [ X ]

(I can't find a square on my keyboard so I put an 'O'...)

I want it to look like that:

[ ? ] [ _ ] [ O ] [ X ]
13 years ago
Hello,

Is it possible to have a table in SWT where first row has a height of 100 and second row has a height of 150?
13 years ago
Found the solution: <col width="0*">

13 years ago
Actually I know how to make a table with width to the screen size, the problem is how to make the second column to behave as I want.

I'll try to draw it:

Mr---------------------------------------------------------------------------------------Mrs-----
John Doe--------------------------------------------------------------------------------Jane Doe
Washington------------------------------------------------------------------------------Paris----
USA-------------------------------------------------------------------------------------UE------

Text in second column is to be aligned to the left (at least I tried...), but the column itself is supposed to be on the right side of the screen.
The width of the second column is to be equal to the widest text line contained in it (which is "Jane Doe").
The table is supposed to have the screen width.

Why "no CSS" well... long story short - it is supposed to be a HTML document builder, where you give the small pieces of document (like "John Doe personal data piece" and "Jane Doe personal data piece") and receive a complete document. One of the assumptions is "no CSS" directive
13 years ago
Hello,

I have a table with 2 columns. I want:
- make the table to fill all possible width
- text in second column not to be wrapped
- second column to have the width equal to width of the longest text line inside this column

Everything without scripts and CSS, just plain old HTML

Is it possible to do?
13 years ago

Paul Sturrock wrote:

Ismael Upright wrote:

Paul Sturrock wrote:If your entity does not have an ID it is not an update. Rather than creating a new instance of Book, load the existing one and update it.

My entities have IDs - hey are marked with @Id annotation.

Where in this code do you set the ID? The instance of Book associated with the instance of Shop has no identifier. You create a new instance of Book, and call merge. Merge will create a new instance in the database if it is not identified by anything. So if you had used the state of shop as is and updated the existing book you'd get the behaviour you want. Otherwise how else will Hibernate know to update an existing book, and which book to update?

Maybe we don't understand each other - if you mean the ID of the old book, you're right - it is not set in the new book object. But the new ID will be generated automatically thanks to annotation "@GeneratedValue".

And yes, now I see that Hibernate has no information that is the old book should be updated. "book1" is only the reference to the object.. thanks for pointing that out.

So... in the coding fewer it is quite easy to make this mistake and forget that the object is still in the database, even if you don't have the reference to it. Any good programming practices to solve that? Maybe disabling creation of new object using "new" operator or something?
13 years ago