diff --git a/src/main/java/act/db/DbPlugin.java b/src/main/java/act/db/DbPlugin.java index 6385763cb..5ac1a2b88 100644 --- a/src/main/java/act/db/DbPlugin.java +++ b/src/main/java/act/db/DbPlugin.java @@ -49,7 +49,7 @@ public void register() { * @return entity class annotations */ public Set> entityAnnotations() { - return C.set(); + return C.Set(); } @Override diff --git a/src/main/java/act/db/DbSession.java b/src/main/java/act/db/DbSession.java new file mode 100644 index 000000000..c28a054bc --- /dev/null +++ b/src/main/java/act/db/DbSession.java @@ -0,0 +1,45 @@ +package act.db; + +/*- + * #%L + * ACT Framework + * %% + * Copyright (C) 2014 - 2020 ActFramework + * %% + * 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. + * #L% + */ + +/** + * a `DbSession` encapsulates information that is required + * to interact with database, e.g. + * + * * DbService - provides db configuration/connection + * * (nested) TxScope and associated Tx spec + * * tenantId - for multi-tenancy support + * * target table(s)/collection(s) + * * entity (row/document) filter including pagination spec + * * field/property (column) projector + * * operation - CRUD + * * mapper - map result back to model entity + * + */ +public class DbSession { + + private DbService db; + + public DbService db() { + return db; + } + +} diff --git a/src/main/java/act/db/EntityFilter.java b/src/main/java/act/db/EntityFilter.java new file mode 100644 index 000000000..8da19e47c --- /dev/null +++ b/src/main/java/act/db/EntityFilter.java @@ -0,0 +1,29 @@ +package act.db; + +/*- + * #%L + * ACT Framework + * %% + * Copyright (C) 2014 - 2020 ActFramework + * %% + * 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. + * #L% + */ + +/** + * The `EntityFilter` encapsulates the information used to filter entities + */ +public class EntityFilter { + + +} diff --git a/src/main/java/act/db/Operator.java b/src/main/java/act/db/Operator.java new file mode 100644 index 000000000..fcb13cf1b --- /dev/null +++ b/src/main/java/act/db/Operator.java @@ -0,0 +1,27 @@ +package act.db; + +/*- + * #%L + * ACT Framework + * %% + * Copyright (C) 2014 - 2020 ActFramework + * %% + * 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. + * #L% + */ + +/** + * An `Operator` is used to specify a relationship in {@link EntityFilter filter}. + */ +public interface Operator { +} diff --git a/src/main/java/act/db/filter/FilterPart.java b/src/main/java/act/db/filter/FilterPart.java new file mode 100644 index 000000000..9c7a1fd73 --- /dev/null +++ b/src/main/java/act/db/filter/FilterPart.java @@ -0,0 +1,31 @@ +package act.db.filter; + +/*- + * #%L + * ACT Framework + * %% + * Copyright (C) 2014 - 2020 ActFramework + * %% + * 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. + * #L% + */ + +/** + * A `FilterPart` is a discrete part of a filter defines database records/rows that + * is impact by a certain DB operations. + * + * A `FilterPart` is composed of + * - + */ +public interface FilterPart { +} diff --git a/src/main/java/act/db2/Dao.java b/src/main/java/act/db2/Dao.java new file mode 100644 index 000000000..5578f51d4 --- /dev/null +++ b/src/main/java/act/db2/Dao.java @@ -0,0 +1,27 @@ +package act.db2; + +/*- + * #%L + * ACT Framework + * %% + * Copyright (C) 2014 - 2020 ActFramework + * %% + * 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. + * #L% + */ + +/** + * A `Dao` is the main entry to access a database table (or collection in mongodb). + */ +public class Dao { +} diff --git a/src/main/java/act/db2/DbService.java b/src/main/java/act/db2/DbService.java new file mode 100644 index 000000000..ad02a7138 --- /dev/null +++ b/src/main/java/act/db2/DbService.java @@ -0,0 +1,50 @@ +package act.db2; + +/*- + * #%L + * ACT Framework + * %% + * Copyright (C) 2014 - 2020 ActFramework + * %% + * 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. + * #L% + */ + +import org.osgl.util.E; + +import java.util.Map; + +/** + * A `DbService` provides methods to access a database source via underline service provider + * object, e.g. JDBC `Connection` for SQL database or `MongoClient` for mongodb. + * + * A `DbService` instance require a group of database configuration to be setup, including: + * - connection URL + * - username + * - password + * - other provider specific database configurations + */ +public class DbService { + + /** + * Run query statement with optional parameters and returns the result set. + * + * @param queryStatement the query statement + * @param parameters parameters + * @return + */ + public Map runQuery(String queryStatement, Object ... parameters) { + throw E.tbd(); + } + +} diff --git a/src/main/java/act/view/ActErrorResult.java b/src/main/java/act/view/ActErrorResult.java index a935cd1e9..6e50fe103 100644 --- a/src/main/java/act/view/ActErrorResult.java +++ b/src/main/java/act/view/ActErrorResult.java @@ -20,18 +20,19 @@ * #L% */ -import static act.util.ActError.Util.errorMessage; -import static act.util.ActError.Util.loadSourceInfo; -import static org.osgl.http.H.Status.INTERNAL_SERVER_ERROR; - import act.Act; -import act.app.*; +import act.app.ActionContext; +import act.app.App; +import act.app.SourceInfo; import act.asm.AsmContext; import act.asm.AsmException; import act.exception.BindException; import act.util.ActError; import org.osgl.$; -import org.osgl.exception.*; +import org.osgl.exception.AccessDeniedException; +import org.osgl.exception.ResourceNotFoundException; +import org.osgl.exception.ToBeImplemented; +import org.osgl.exception.UnsupportedException; import org.osgl.http.H; import org.osgl.mvc.annotation.ResponseStatus; import org.osgl.mvc.result.ErrorResult; @@ -39,9 +40,18 @@ import org.osgl.util.E; import org.osgl.util.S; -import java.util.*; import javax.persistence.PersistenceException; -import javax.validation.*; +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.validation.ValidationException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static act.util.ActError.Util.errorMessage; +import static act.util.ActError.Util.loadSourceInfo; +import static org.osgl.http.H.Status.INTERNAL_SERVER_ERROR; public class ActErrorResult extends ErrorResult implements ActError { @@ -157,7 +167,7 @@ protected void populateSourceInfo(AsmContext context) { this.sourceInfo = Util.loadSourceInfo(context); } - private static Map, $.Function> x = new HashMap<>(); + private static final Map, $.Function> x = new HashMap<>(); static { $.Function unsupported = new $.Transformer() {