-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- settled on Entity as the most apt term for schema interfaces and classes, rename refactor accordingly - interface/class extension support -- custom instance creation support via CustomEntityFactory dependency -- custom entity interface support via naming convention e.g., public interface CustomStore extends CustomEntity<Store> {...} -- custom base interface support via dbconfig -- custom base class support via dbconfig
- Loading branch information
1 parent
bbe9426
commit 14ecebe
Showing
31 changed files
with
575 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...fold-sql-inproc-test/src/test/java/manifold/sql/schema/customize/CustomInterfaceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2023 - Manifold Systems LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package manifold.sql.schema.customize; | ||
|
||
import manifold.ext.rt.api.auto; | ||
import manifold.sql.schema.simple.h2.H2Sakila.*; | ||
import manifold.sql.schema.h2.base.H2DdlServerTest; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class CustomInterfaceTest extends H2DdlServerTest | ||
{ | ||
@Test | ||
public void testCustomInterface() throws IOException | ||
{ | ||
loadData( "/samples/data/h2-sakila-data.sql" ); | ||
|
||
auto query = "[.sql:H2Sakila/] Select * From store where store_id = :store_id"; | ||
Store store = query.fetchOne( 1L ); | ||
assertEquals( 1L, store.myCustomMethod() ); // from neighboring CustomStore | ||
assertEquals( "myCustomBaseMethod", store.myCustomBaseMethod() ); // from dbconfig "customBaseClass" | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ent/manifold-sql-inproc-test/src/test/java/manifold/sql/schema/customize/CustomStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2023 - Manifold Systems LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package manifold.sql.schema.customize; | ||
|
||
import manifold.sql.rt.api.CustomEntity; | ||
import manifold.sql.schema.simple.h2.H2Sakila.Store; | ||
|
||
/** | ||
* Following the "Custom" + [entity interface name] naming convention, this interface becomes a super interface for Store. | ||
* As such, methods defined here are accessible directly from instances of Store. | ||
*/ | ||
public interface CustomStore extends CustomEntity<Store> | ||
{ | ||
default long myCustomMethod() | ||
{ | ||
return self().getStoreId(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ent/manifold-sql-inproc-test/src/test/java/manifold/sql/schema/customize/MyBaseClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2023 - Manifold Systems LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package manifold.sql.schema.customize; | ||
|
||
import manifold.sql.rt.api.BaseEntity; | ||
import manifold.sql.rt.api.TxBindings; | ||
|
||
public abstract class MyBaseClass extends BaseEntity implements MyBaseInterface | ||
{ | ||
public MyBaseClass( TxBindings txBindings ) | ||
{ | ||
super( txBindings ); | ||
} | ||
|
||
public String myCustomBaseMethod() | ||
{ | ||
return "myCustomBaseMethod"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
manifold-deps-parent/manifold-sql-rt/src/main/java/manifold/sql/rt/api/BaseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2023 - Manifold Systems LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package manifold.sql.rt.api; | ||
|
||
/** | ||
* Generated "Entity" classes from SchemaParentType extend this base class. Custom classes via {@link CustomEntityFactory} | ||
* must subclass this as well, or if a different super class is needed, the subclass must duplicate the behavior here. | ||
*/ | ||
public abstract class BaseEntity implements ResultRow | ||
{ | ||
private final TxBindings _txBindings; | ||
|
||
public BaseEntity( TxBindings txBindings ) | ||
{ | ||
_txBindings = txBindings; | ||
} | ||
|
||
@Override | ||
public TxBindings getBindings() | ||
{ | ||
return _txBindings; | ||
} | ||
|
||
public String toString() | ||
{ | ||
return "{" + getBindings().displayEntries() + "}"; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return getBindings().hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals( Object o ) | ||
{ | ||
if( this == o ) | ||
{ | ||
return true; | ||
} | ||
if( o == null || getClass() != o.getClass() ) | ||
{ | ||
return false; | ||
} | ||
BaseEntity that = (BaseEntity)o; | ||
return getBindings().equals( that.getBindings() ); | ||
} | ||
} |
Oops, something went wrong.