Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work-in-Progress on PL/Java refactoring, API modernization #399

Open
wants to merge 120 commits into
base: REL1_7_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
580b25a
Easy warmup: less JNI in Invocation
jcflack Jan 23, 2022
17a3a26
These two lines considered redundant
jcflack Jan 23, 2022
9342f68
Tests for use of upper memory context
jcflack Jan 23, 2022
b2094ba
Add switchToUpperContext for non-composite SRFs
jcflack Jan 23, 2022
e441724
Use SPI in the purely nested fashion it expects
jcflack Jan 23, 2022
e380e6b
Add a nested/SPI test to SetOfRecordTest
jcflack Jan 23, 2022
2d54359
Also eliminate special SRF Invocation treatment
jcflack Jan 23, 2022
d2b920b
Merge Invocation/set-returning-function rework
jcflack Jan 23, 2022
41eb615
Two caching tools: CacheMap and SwitchPointCache
jcflack Jan 23, 2022
7655fde
Adapter and org.postgresql.pljava.adt.spi package
jcflack Jan 23, 2022
b35c65a
Package org.postgresql.pljava.adt: contracts
jcflack Jan 23, 2022
7786fbf
CharsetEncoding, CatalogObject, and a few more
jcflack Jan 23, 2022
42805b1
Add enough implementation for CharsetEncoding use
jcflack Jan 23, 2022
712f5d2
Expose MemoryContext and ResourceOwner in Java
jcflack Jan 23, 2022
5a9cdf9
Begin MemoryContext/ResourceOwner implementation
jcflack Jan 23, 2022
f387648
Fix an old PgSavepoint bug
jcflack Jan 23, 2022
169b5dc
Now an Invocation is also a Lifespan
jcflack Jan 23, 2022
f7561df
DualState clients that pass no Lifespan
jcflack Jan 23, 2022
6ba4e66
Clients using Invocation.current as Lifespan
jcflack Jan 23, 2022
901712a
Client using its own ResourceOwner as Lifespan
jcflack Jan 23, 2022
827f2d6
Client with both ResourceOwner and MemoryContext
jcflack Jan 23, 2022
349c3e8
Eliminate last use of DualState.Key
jcflack Jan 23, 2022
ea86c77
Merge MemoryContext/ResourceOwner API and uses
jcflack Jan 23, 2022
fc9bd9c
Adapt SQLXMLImpl to be creatable from Java
jcflack Jan 23, 2022
a0269b8
Build out the TupleDescriptor implementation
jcflack Jan 23, 2022
1f17675
Build out TupleTableSlot implementation
jcflack Jan 23, 2022
2e74a6b
Build out the CatalogObject implementation
jcflack Jan 23, 2022
a4656f5
RegClass and RegType have a special relationship
jcflack Jan 23, 2022
e742fae
Attribute, naturally, has complications
jcflack Jan 23, 2022
5adf2c8
Selectively invalidate RegClass and RegType
jcflack Jan 23, 2022
33530b5
Here's a simple complete one, a Database object
jcflack Jan 23, 2022
7ffea74
The rest is straight implementation
jcflack Jan 23, 2022
8ce2c87
A test jig that's been used during development
jcflack Jan 23, 2022
4a773cd
A couple straggling RegType methods
jcflack Jan 23, 2022
9a833d2
Spotted a copy-pasto in an assertion message
jcflack Jan 23, 2022
62d3694
Fix copyright years that were wrong as committed
jcflack Jan 31, 2022
4fa6a19
Pacify AppVeyor
jcflack Jan 31, 2022
f135135
Update straggling currentInvocation checks
jcflack Jan 31, 2022
0b0e4de
Missing initializer caught by MacOS clang
jcflack Jan 31, 2022
04431c4
Look for a way to confirm ARR_DIMS under clang
jcflack Jan 31, 2022
a9f24a9
Give up static check of OFFSET_ArrayType_DIMS
jcflack Jan 31, 2022
cf2f8c5
See if clang permits sizeof *ARR_DIMS(0)
jcflack Jan 31, 2022
13547a9
More work on array adapters
jcflack Feb 1, 2022
4bf4a8d
Some polishing of javadocs and code
jcflack Feb 1, 2022
8140b01
Merge REL1_7_STABLE into feature/REL1_7_STABLE/model
jcflack Jun 14, 2023
e55625e
New ACL rights appear in PG 15 and in 16
jcflack Jun 14, 2023
b0b198d
Whitespace only
jcflack Jun 14, 2023
52acfdf
Numeric typmods change in PG 15
jcflack Jun 14, 2023
acdbb2b
Fix example in AbstractType javadoc
jcflack Jul 31, 2023
101ae01
Additions to AbstractType
jcflack Jul 31, 2023
c7e9ae1
Add methods to Adapter to derive multiarrays
jcflack Jul 31, 2023
45830da
Add ArrayBuilder.build() and a suitable service
jcflack Jul 31, 2023
ff9768b
Implement the multi-array building
jcflack Jul 31, 2023
ecccd54
Consolidate the temporary test jig methods
jcflack Jul 31, 2023
1423366
Add an example for multi-array retrieval
jcflack Jul 31, 2023
87d9389
Add example of a composing Adapter
jcflack Jul 31, 2023
b1b7d13
Another composing adapter, of reference type
jcflack Jul 31, 2023
4147308
A subtlety with canFetchNull is worth mentioning
jcflack Jul 31, 2023
536e87f
Show autoboxing in Adapter composition
jcflack Aug 1, 2023
3db8e54
Tidy up that example SQL query
jcflack Aug 1, 2023
299b69f
No, canFetchNull is not that subtle after all
jcflack Aug 1, 2023
8cbc383
Example didn't demonstrate null long case
jcflack Aug 2, 2023
79a8569
Add PG_VERSION_NUM to ModelConstants
jcflack Aug 3, 2023
716eac5
Let formObjectId accept a version predicate
jcflack Aug 3, 2023
3887c05
Fix an unchecked warning in array service
jcflack Aug 12, 2023
786d546
Javadoc: typos in MultiArray, tweaks in Adapter
jcflack Aug 12, 2023
566edcb
Get rid of "throws SQLException" on tts.get
jcflack Aug 15, 2023
091d8bc
Enter TargetList and its subinterface, Projection
jcflack Aug 15, 2023
1c96e3a
Start on unwrapping ResultSet as Portal
jcflack Aug 15, 2023
4398724
Muck about with SPI class
jcflack Aug 15, 2023
6ec5627
Add more methods to Portal
jcflack Aug 15, 2023
d8bbd60
Lose temporary testmeSPI stuff
jcflack Aug 15, 2023
9d8e6b7
More notational convenience in DualState
jcflack Aug 15, 2023
d966f7b
Add TupleList to present different kinds of such
jcflack Aug 15, 2023
e299b4c
Update example
jcflack Aug 15, 2023
8a0d912
Decree: applyOver methods can throw SQLException
jcflack Aug 15, 2023
ef1f192
Deprecate old hasty TupleDescriptor methods
jcflack Aug 15, 2023
cb98c80
Add test for CatalogObject class initializations
jcflack Aug 15, 2023
10a18f8
Merge targetlist into feature/REL1_7_STABLE/model
jcflack Aug 15, 2023
630717d
Narrow visibility of CatalogObjectImpl additions
jcflack Aug 15, 2023
a0ce0ea
javadoc: a sterner note about the frankenstream
jcflack Aug 15, 2023
5cfdad8
Javadoc: clarify TupleDescriptor.rowType, intern
jcflack Aug 16, 2023
29bafab
Further tame the frankenstream
jcflack Aug 18, 2023
1fc0be2
Migrate SQLXMLImpl.Readable, VarlenaWrapper->Datum
jcflack Aug 20, 2023
c107f9a
Add a set-returning function example
jcflack Aug 24, 2023
59c0ba9
Upstream has reverted MAINTAIN privilege
jcflack Aug 24, 2023
8a88cbf
Beat down unchecked warnings from Datum migration
jcflack Aug 25, 2023
0391e18
Some more missing Adapters
jcflack Aug 26, 2023
45f965c
A reference NUMERIC -> BigDecimal implementation
jcflack Aug 26, 2023
c4b123f
Comment typos caught after pushing upstream
jcflack Aug 27, 2023
606caf0
Don't mistake SQL for Java
jcflack Aug 29, 2023
5e8fa13
Banish recent unchecked warning
jcflack Sep 8, 2023
e511a12
Allow IDX_... gaps in ModelConstants
jcflack Sep 8, 2023
dc62b4e
Regroup and renumber ModelConstants
jcflack Sep 8, 2023
d1e1db3
Pick up SIZEOF_INT via ModelConstants
jcflack Sep 8, 2023
cb71f38
Rename AttNames.andIf to alsoIf
jcflack Sep 9, 2023
3131af9
Merge branch 'REL1_7_STABLE' into feature/REL1_7_STABLE/model
jcflack Sep 19, 2023
f9acf5e
Quit using paired entry points to pass 'trusted'
jcflack Oct 9, 2023
e5dd9f8
Tidy some uses of currentInvocation->function
jcflack Oct 9, 2023
15997b5
check_function_bodies readable from Java
jcflack Oct 9, 2023
19b3c1a
Sundry fixes to CatalogObject implmementations
jcflack Oct 9, 2023
afec77d
Introduce AbstractNoSplitList
jcflack Oct 9, 2023
7faf6c9
Add Identifier.Simple.None
jcflack Oct 9, 2023
57ed135
Distinguish the polymorphic pseudotypes
jcflack Oct 9, 2023
0d65d2b
Add TupleDescImpl.synthesizeDescriptor
jcflack Oct 9, 2023
a061b4e
Interlude: BitSet <-> PostgreSQL bitmapset
jcflack Oct 9, 2023
95fcf8f
TupleTableSlotImpl.NullableDatum
jcflack Oct 9, 2023
08e2079
More invalidation: two more classes, and TupleDesc
jcflack Oct 9, 2023
1ea5bfa
Flesh out the RegProcedure.Memo idea
jcflack Oct 9, 2023
4567117
Give RegType a 'notional' TupleDescriptor
jcflack Oct 9, 2023
93b250c
Add API methods on RegProcedure and memo
jcflack Oct 9, 2023
7af5e94
Interfaces a PL/Java-based language implements
jcflack Oct 9, 2023
95d4133
Add DualState.SingleDeleteGlobalRefP
jcflack Oct 9, 2023
bcd6185
Now put the implementation under it
jcflack Oct 9, 2023
afaeb88
Add example
jcflack Oct 9, 2023
f6f9c61
Merge polyglot into feature/REL1_7_STABLE/model
jcflack Oct 9, 2023
cbfcd09
Restore pre-PG16 buildability (back to PG 13)
jcflack Oct 9, 2023
c327868
Fix added example for library-name diversity
jcflack Oct 9, 2023
75d93b2
Correct spelling of glot64
jcflack Apr 4, 2024
f072a64
Merge REL1_7_STABLE into feature/REL1_7_STABLE/model
jcflack Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Build out the TupleDescriptor implementation
As before, JNI methods for this 'model' framework continue to
be grouped together in ModelUtils.c; their total number and
complexity is expected to be low enough for that to be practical,
and then they can all be seen in one place.

RegClassImpl and RegTypeImpl acquire m_tupDescHolder arrays in
this commit, without much explanation; that will come a few commits
later.
  • Loading branch information
jcflack committed Jan 23, 2022
commit a0269b80f5ee150a34dd57a94e75799accb85077
14 changes: 14 additions & 0 deletions pljava-api/src/main/java/org/postgresql/pljava/model/RegType.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ public interface RegType
RegType REGROLE = formObjectId(CLASSID, REGROLEOID);
RegType REGCOLLATION = formObjectId(CLASSID, REGCOLLATIONOID);

RegClass relation();
RegType modifier(int typmod);

/**
* Returns the modifier if this instance has one, else -1.
*/
int modifier();

/**
* The corresponding {@link TupleDescriptor TupleDescriptor}, non-null only
* for composite types.
*/
TupleDescriptor.Interned tupleDescriptor();

/**
* The name of this type as a {@code String}, as the JDBC
* {@link SQLType SQLType} interface requires.
Expand Down
58 changes: 58 additions & 0 deletions pljava-so/src/main/c/ModelUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "org_postgresql_pljava_pg_DatumUtils.h"
#include "org_postgresql_pljava_pg_MemoryContextImpl_EarlyNatives.h"
#include "org_postgresql_pljava_pg_ResourceOwnerImpl_EarlyNatives.h"
#include "org_postgresql_pljava_pg_TupleDescImpl.h"

/*
* A compilation unit collecting various native methods used in the pg model
Expand All @@ -61,6 +62,24 @@ static jmethodID s_ResourceOwnerImpl_callback;
static void resourceReleaseCB(ResourceReleasePhase phase,
bool isCommit, bool isTopLevel, void *arg);

static jclass s_TupleDescImpl_class;
static jmethodID s_TupleDescImpl_fromByteBuffer;

jobject pljava_TupleDescriptor_create(TupleDesc tupdesc, Oid reloid)
{
jlong tupdesc_size = (jlong)TupleDescSize(tupdesc);
jobject td_b = JNI_newDirectByteBuffer(tupdesc, tupdesc_size);

jobject result = JNI_callStaticObjectMethodLocked(s_TupleDescImpl_class,
s_TupleDescImpl_fromByteBuffer,
td_b,
(jint)tupdesc->tdtypeid, (jint)tupdesc->tdtypmod,
(jint)reloid, (jint)tupdesc->tdrefcount);

JNI_deleteLocalRef(td_b);
return result;
}

static void memoryContextCallback(void *arg)
{
Ptr2Long p2l;
Expand Down Expand Up @@ -200,6 +219,16 @@ void pljava_ModelUtils_initialize(void)
{ 0, 0, 0 }
};

JNINativeMethod tdiMethods[] =
{
{
"_assign_record_type_typmod",
"(Ljava/nio/ByteBuffer;)I",
Java_org_postgresql_pljava_pg_TupleDescImpl__1assign_1record_1type_1typmod
},
{ 0, 0, 0 }
};

cls = PgObject_getJavaClass("org/postgresql/pljava/pg/CharsetEncodingImpl$EarlyNatives");
PgObject_registerNatives2(cls, charsetMethods);
JNI_deleteLocalRef(cls);
Expand Down Expand Up @@ -228,6 +257,17 @@ void pljava_ModelUtils_initialize(void)
s_ResourceOwnerImpl_callback = PgObject_getStaticJavaMethod(
s_ResourceOwnerImpl_class, "callback", "(J)V");

cls = PgObject_getJavaClass("org/postgresql/pljava/pg/TupleDescImpl");
s_TupleDescImpl_class = JNI_newGlobalRef(cls);
PgObject_registerNatives2(cls, tdiMethods);
JNI_deleteLocalRef(cls);

s_TupleDescImpl_fromByteBuffer = PgObject_getStaticJavaMethod(
s_TupleDescImpl_class,
"fromByteBuffer",
"(Ljava/nio/ByteBuffer;IIII)"
"Lorg/postgresql/pljava/model/TupleDescriptor;");

RegisterResourceReleaseCallback(resourceReleaseCB, NULL);
}

Expand Down Expand Up @@ -504,3 +544,21 @@ Java_org_postgresql_pljava_pg_ResourceOwnerImpl_00024EarlyNatives__1window(JNIEn

return r;
}

/*
* Class: org_postgresql_pljava_pg_TupleDescImpl
* Method: _assign_record_type_typmod
* Signature: (Ljava/nio/ByteBuffer)I
*/
JNIEXPORT jint JNICALL
Java_org_postgresql_pljava_pg_TupleDescImpl__1assign_1record_1type_1typmod(JNIEnv* env, jobject _cls, jobject td_b)
{
TupleDesc td = (*env)->GetDirectBufferAddress(env, td_b);
if ( NULL == td )
return -1;

BEGIN_NATIVE_AND_TRY
assign_record_type_typmod(td);
END_NATIVE_AND_CATCH("_assign_record_type_typmod")
return td->tdtypmod;
}
20 changes: 20 additions & 0 deletions pljava-so/src/main/include/pljava/ModelUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ extern void pljava_ModelUtils_initialize(void);

extern void pljava_ResourceOwner_unregister(void);

/*
* Return a Java TupleDescriptor based on a PostgreSQL one.
*
* If the descriptor's tdtypeid is not RECORDOID (meaning the descriptor is
* for a named composite type), passing the relation oid here, if handy, will
* save a lookup in the Java code. In other cases, or if it simply is not
* handily available, InvalidOid can be passed, and the relation will be looked
* up if needed.
*
* If there is already a cached Java representation, the existing one
* is returned, and the supplied one's reference count (if it is counted) is
* untouched. If the supplied one is used to create a cached Java version, its
* reference count is incremented (without registering it for descriptor leak
* warnings), and it will be released upon removal from PL/Java's cache for
* invalidation or unreachability. If the descriptor is non-reference-counted,
* the returned Java object will not depend on it, and it is expendable
* after this function returns.
*/
extern jobject pljava_TupleDescriptor_create(TupleDesc tupdesc, Oid reloid);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ boolean foundIn(TupleDescriptor td)
*/
static class Cataloged extends AttributeImpl
{
private final RegClassImpl m_relation;

Cataloged(RegClassImpl relation)
{
m_relation = requireNonNull(relation);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static class Known<T extends CatalogObject.Addressed<T>>
{
}

TupleDescriptor.Interned[] m_tupDescHolder;

@Override
public TupleDescriptor.Interned tupleDescriptor()
{
Expand Down
74 changes: 74 additions & 0 deletions pljava/src/main/java/org/postgresql/pljava/pg/RegTypeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,68 @@ abstract class RegTypeImpl extends Addressed<RegType>
Nonshared<RegType>, Namespaced<Simple>, Owned,
AccessControlled<CatalogObject.USAGE>, RegType
{
@Override
public TupleDescriptor.Interned tupleDescriptor()
{
throw notyet();
}

@Override
public RegClass relation()
{
throw notyet();
}

/**
* Return the expected zero value for {@code subId}.
*<p>
* For keying the {@code CacheMap}, we sneak type modifiers in there
* (PG types do not otherwise use {@code subId}), but that's an
* implementation detail that could be done a different way if upstream
* ever decided to have subIds for types, and having it show in the address
* triple of a modified type could be surprising to an old PostgreSQL hand.
*/
@Override
public int subId()
{
return 0;
}

/**
* Return the type modifier.
*<p>
* In this implementation, where we snuck it in as the third component
* of the cache key, sneak it back out.
*/
@Override
public int modifier()
{
int m = super.subId();
if ( -1 == m )
return 0;
return m;
}

/**
* Represents a type that has been mentioned without an accompanying type
* modifier (or with the 'unspecified' value -1 for its type modifier).
*/
static class NoModifier extends RegTypeImpl
{
@Override
public int modifier()
{
return -1;
}

@Override
public RegType modifier(int typmod)
{
if ( -1 == typmod )
return this;
return (RegType)
CatalogObjectImpl.Factory.formMaybeModifiedType(oid(), typmod);
}
}

/**
Expand All @@ -56,8 +111,19 @@ static class NoModifier extends RegTypeImpl
*/
static class Modified extends RegTypeImpl
{
private final NoModifier m_base;

Modified(NoModifier base)
{
m_base = base;
}

@Override
public RegType modifier(int typmod)
{
if ( modifier() == typmod )
return this;
return m_base.modifier(typmod);
}
}

Expand All @@ -70,5 +136,13 @@ static class Modified extends RegTypeImpl
*/
static class Blessed extends RegTypeImpl
{
TupleDescriptor.Interned[] m_tupDescHolder;

@Override
public RegType modifier(int typmod)
{
throw new UnsupportedOperationException(
"may not alter the type modifier of an interned row type");
}
}
}
Loading