Tim Holloway

Bartender
+ Follow
since Jun 25, 2001
Tim likes ...
Android Eclipse IDE Linux
Long-time moderator for the Tomcat and JavaServer Faces forums. Designer and manager for the mousetech.com enterprise server farm, which runs VMs, a private cloud and a whole raft of Docker containers.
These days, doing a lot of IoT stuff with Arduinos and Raspberry Pi's.
Jacksonville, Florida USA
Cows and Likes
Cows
Total received
95
In last 30 days
2
Total given
15
Likes
Total received
1450
Received in last 30 days
29
Total given
59
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tim Holloway

Some people love night shift jobs.

Yes, the night shift can be hard on your health, and rotating shifts can be absolutely brutal, but there are people who like the ability to do all those things that those of us on day shift cannot do like shop during the day. The main thing is that you're probably going to be trying to sleep when it's bright and noisy, so you need to make yourself a protected space so you can rest properly.

Night support can be like working for the fire department. Lots of dull time, punctuated by panic. If you don't mind that, you can spend the idle time in self-improvement, and be a hero when things fall apart. Or at least you could before everything had to be ultimately "efficient". Today's bean-count obsessed management is likely to resent that idle time because you're not putting in 110% and dump slop on you that is actually likely to keep you from being able to properly respond when things do go off the rails. Then again, they do that to day-shift workers too.

Back when batch-oriented mainframe computers were the norm, the night was when the heavy production batch processing was done and after that, when off-hours maintenance was attended to. Batch processing was one of those dump the job in and wait sort of things, so you didn't have to constantly hurry and scurry. Maintenance, however, was another thing. If someone had put in some changes for application overnight and a system didn't come back up again, the operations staff would call or page whoever was responsible for the broken system. And those folks in operations could be infuriatingly cheerful when they called me at 3 a.m.!
23 hours ago
Yes. Don't use strcpy like that. What you are actually telling the compiler is that you want to copy strings from memory locations 65, then 66, then 67, ...

Because strcpy works with pointers, not with character values. So the manifest constant 'a' gets translated into an integer equivalent to its ASCII code value (65), and strcpy attempts to copy characters starting at memory location 65. Which is generally hardware-protected low memory.

That's not a problem with shared memory or with client/server. You have failed at a basic C function. And C isn't very forgiving of failure.
23 hours ago
A statement like this:

can be optimized by the compiler (constant folding) and should be expected to have zero runtime cost compared to coding it as one long string. In this case, using a StringBuilder might possibly be less efficient.

However, I'd use a StringBuilder if I was building up a string out of components that were non-String and/or included variables.
23 hours ago
Is this one of those places where you're sitting in the sun and looking down the street, but you can't see the end of the street because it's a solid wall of water coming down?

We got another 3 inches of rain this weekend. I think the mildew is about to grow mildew.
1 day ago
I can't actually see the offending string. It's crammed into that little scrollable box. But the message certainly sounds like what you'd get when you attempted to do something like this:


That is, the single-quote in the literal string has annoyed the SQL parser.

To fix that, you'd have to do one of two things:

1) Escape the single-quote: "'O''Rourke'. Note that that's 2 single-quotes together, not 1 double-quote.

OR

2) Use a preparedstatement.

Another possibility is if you're trying to put 2 tons of fertilizer in a 1-ton truck (the database column definition isn't big enough), but I'm pretty sure it's a quotes problem.

SQL doesn't care about wild cards except when they appear in the LIKE clause of a SELECT statement. Otherwise they're simply seen as text.
This isn't just Spring, but the convention these days is that you can do your configuring and wiring via annotations, and then use XML as an override, if needed.

Before annotations, XML was the preferred way to do that kind of stuff (either that or property files), but it was a royal pain because you were constantly switching back and forth between the Java source and the XML config files in your editor session. Annotations got rid of that requirement by allowing meta-information to be stored directly with the Java source. So you only had to edit in one place and not 2, and thus, not only saved effort, but were a lot less likely to get out of sync.

However, XML was kept because sometimes you don't want the standard information. This is especially true if you're trying to re-use code in a different environment or if you want 2 instances of the same bean class, but need them to be cataloged under different bean names. Without some sort of override mechanism, you'd have to physically edit the Java files. With XML overrides, you can make a small XML file with just the override data in it and leave the bulk of the metadata to the stock annotations. And the original Java source code remains unchanged.

The @Inject annotation was developed for CDI and the last time I looked at trying to make Spring and CDI work together in a JSF webapp, I found CDI to be lacking so I kept to the original JSF and Spring annotations. Admittedly, that was some time ago and things may be better now, but at the time I had the impression that some basic characteristics between the 2 frameworks were in conflict.
2 days ago
You're still looking for a "program" to run the tests. As I said, Maven is the program that runs the tests (via its sureFire Junit mojo).

The surefire mojo automatically compiles and executes every test class it finds under src/test/resources when you run the Maven "test" goal, whether directly ("mvn test") or implicitly (as for example with "mvn assembly"). In fact, I don't have any includes elements in my POMs, only the bare minimum plugin information for surefire.

No application executable is ever created for surefire testing. Surefire invokes the test classes directly.
2 days ago
Yah. First time I went to Dallas, we landed in an arriving thunderstorm. Out on the freeway, people started pulling over right and left. I was concerned about what might be ahead. Answer: virtually nothing. Just heavy rain.

If we pulled over like that in Florida, we'd be permanently parked from June to November.

In fact, I had 2 inches of rain last Tuesday, and we're now in the "dry" season.

At least we don't get Texas hail here. We get little chips. They get baseballs.

I count this month's weather as "unusual" in that it's actually "winter" weather for the first time in years. Except when it isn't. Melbourne, FL broke a record a week or so ago at 90 degrees.

We're getting the southern edge of those nasty systems like what dumped snow over North Carolina, but then another really warm spell hits. And repeat about once a week.
2 days ago

Bob Matthews wrote:Tim

Cursors:- embedded, named, scrollable, scrolling etc.
from Index to Book - The Complete Reference - SQL - 3rd edition

How can you say that there is no such thing as 'cursor' in SQL ?

Bob M



Because your "SQL" book covers more than just SQL.

An SQL RDBMS typically accepts not only SQL, but also DDL and not uncommonly some sort of proprietary procedural language such as Oracle's PL/SQL or Microsoft's Transact/SQL.

But SQL itself, as defined by Date and Codd is a mathematical language designed to operate on sets of data and has no procedural elements or constructs in it. No "if" statements, no loops, and no cursors.

There  are times when it is convenient to operate in a procedural manner on a set of data, which is why we have JDBC for client-side logic and PL/SQL for server-side logic and thus some sort of cursor mechanism to allow row-by-row operations. But that's not as efficient or as portable as SQL and therefore should be avoided where possible.
PreparedStatements are not procedures. And, to repeat, there is no such thing as a cursor - or anything named "cursor" - in SQL. Cursors are only possible in procedures, not in SQL.

However, while SQL will apply itself vertically to a column update, you can restrict which rows, get their columns updated. Which isn't the same thing as doing it with a cursor, but it gets the job done.

For example:


This takes the value of "occurances" for the row(s) being updated, add 1s to the value of "occurances" on that row, and updates the column value. You can code that as a PreparedStatement ("WHERE id = ?"), and generally should, but the action is the same either way.
Lazy fetching is extremely useful, since some entities are linked in so many ways that an eager fetch could pull in anything up to and including the entire database!

One thing to be aware of, however, is that Lazy fetches can only be resolved while the entities are attached to the persistence manager. When I code webapps, the database logic detaches the set of objects that it returns to the higher levels of the webapp (for example, the GUI layer). There are several reasons why I prefer doing this, but among the top ones is that it ensures that I don't accidentally zap database data in non-database code. Instead I work with detached data and then when AND IF I want that data to update in the database, I call one of the database logic services that will then convert it to attached data and post the changes to the database server (and, incidentally, ensure that no other process has altered the data behind my back).

To ensure you have exactly what you need in a detached data set, simply force fetches before you detach. For example, if I want to return a working set of an account and its associated funds, but not any other objects that the funds might link to, I'd simply iterate the funds collection that was mapped @ManyToMany and have the iteration look at one of the fields in the funds records (the funds ID field is often a good choice, but any field local to the funds record will do).
SQL is not a procedural language. When you say "update table_x set column_y = ?", it's doing a vertical operation on the column. There is no cursor in SQL, and in functional terms, the action can be considered to be happening simultaneously (that is, in parallel) on all rows of the table at once (actual internal implementation might not be exactly that, but the net effect muct be).

To process a table procedurally row by row, you'd have to use a stored procedure and the stored procedure would then establish a cursor row, advance the cursor row by row in a loop and assign to/from the cursor row.

The exact coding of such a stored procedure is totally dependent on the vendor of the database. Unlike SQL, there is no standard for stored procedures, and in fact, on many platforms stored procedures can be written in a variety of languages. For example, Oracle has their own language (PL/SQL), but you can also code stored procedures in Java. The PostgreSQL DBMS supports maybe half a dozen different languages that stored procedures can be written in.

Craig Walls wrote:Also, it's not used all that often, but Spring has long had an annotation called @Configurable that lets you do dependency injection into components that Spring doesn't manage the lifecycle for (such as JPA entities). It uses aspects to pull this off, so be aware of that.



Note that Craig means specifically JPA Entities - that is, the classes that map database rows as discrete objects. Spring JPA manages other aspects of JPA (such as repositories) as part of the JPA module's basic capabilities, so it doesn't need aspects for that part. I've never added special aspects to Entities myself - it's a very dangerous thing to do if you aren't careful.

Kalpesh Soni wrote:
Are there design patterns that go beyond a mickey mouse example that I can use where I can have objects with state?



I would consult some good texts on Design Patterns as to when it's best to use singleton objects as opposed to non-singletons and when to make objects stateful versus when to make them stateless. Factory objects are almost always singletons, and commonly (but not inevitably) are stateful. In fact, the Spring Bean Factory is a stateful Singleton. It maintains a cache of all the singleton Spring beans that it creates.
3 days ago

Isaac Ferguson wrote:

You might want to look at Spring REST: https://spring.io/guides/gs/rest-service



This is Spring but I want to use Spring Boot and the right starter.



Read it more carefully. There's Spring Boot sample code in there.

Also, I question that Spring REST requires persistence. Spring has a whole separate module realm for persistence and they don't tend to lump unrelated functions together.
3 days ago
It isn't in the Java program.

Maven works by reaching goals Often the goals themselves are defined as having sub-goals, which is how a command like "mvn assembly" might automatically run goals like "compile:compile",  "test", and "war:war".

Goals are defined via Maven "mojos", which are plugin javabean modules designed to be invoked by Maven. Fortunately, most of us can use the ready-made mojos.

This might be a good introduction: https://www.baeldung.com/maven-goals-phases

Also, here's Maven's own information on the goal chain: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings


3 days ago