EntityManagerFactory lifecycle and properties

EntityManagerFactory.close() could previously be called more than once, and methods of a closed factory either worked or failed deep inside the kernel. Now getProperties(), createEntityManager(), getCriteriaBuilder(), getMetamodel(), getPersistenceUnitUtil() and getSchemaManager() throw IllegalStateException after close(), and a second close() throws as well. createEntityManager(SynchronizationType.UNSYNCHRONIZED) throws IllegalStateException instead of UnsupportedOperationException (it is forbidden for RESOURCE_LOCAL units and still unimplemented for JTA units).

EntityManagerFactory.getProperties() no longer creates a temporary EntityManager to merge EntityManager-level defaults (lock timeout, cache modes, fetch plan settings) into its result, and null-valued entries are removed. This changes the behavior introduced by OPENJPA-849: applications that relied on those merged defaults should read them from EntityManager.getProperties() instead. addNamedQuery() now replaces an existing definition of the same name and records flush mode, max results and lock mode; a Criteria query keeps its compiled criteria form and is replayed by createNamedQuery() as a Criteria query instead of being re-labelled as JPQL, so renderings that are not parseable JPQL (unescaped string literals, unparenthesized subqueries) work as well. getQueryString() on the recreated query still returns the CQL rendering; as that rendering is not a query string the query can be parsed from, such a query is neither registered in the prepared query cache nor rebuilt from an entry that another query left there under the same text. The retained criteria form is transient, so a Criteria query registered at runtime is not recoverable from a serialized metadata repository.