-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#116) Implemented PgTriggers, created DbdTriggerMapping, DbdTriggerF…
…ields, PgTriggersQuery, TriggerOfResultSet
- Loading branch information
Showing
5 changed files
with
230 additions
and
3 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/org/fusionsoft/database/mapping/dbd/DbdTriggerMapping.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,37 @@ | ||
/* | ||
* Copyright (C) 2018-2021 FusionSoft | ||
* | ||
* 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 org.fusionsoft.database.mapping.dbd; | ||
|
||
import com.amihaiemil.eoyaml.YamlMapping; | ||
import org.fusionsoft.database.mapping.fields.DbdTriggerFields; | ||
import org.fusionsoft.lib.yaml.YamlMappingHasKeys; | ||
|
||
/** | ||
* The type of {@link YamlMappingHasKeys} of DBD/schemas/#schema/triggers/#trigger document node | ||
* that are validated by {@link DbdTriggerFields}. | ||
* @since 0.1 | ||
*/ | ||
public class DbdTriggerMapping extends YamlMappingHasKeys { | ||
|
||
/** | ||
* Instantiates a new Dbd trigger mapping. | ||
* @param mapping The YamlMapping to be encapsulated. | ||
*/ | ||
public DbdTriggerMapping(final YamlMapping mapping) { | ||
super(mapping, DbdTriggerFields.DDL); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/org/fusionsoft/database/mapping/fields/DbdTriggerFields.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,58 @@ | ||
/* | ||
* Copyright (C) 2018-2021 FusionSoft | ||
* | ||
* 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 org.fusionsoft.database.mapping.fields; | ||
|
||
import org.cactoos.Text; | ||
|
||
/** | ||
* The enum of {@link org.fusionsoft.database.mapping.dbd.DbdTriggerMapping} fields. | ||
*/ | ||
public enum DbdTriggerFields implements Text { | ||
/** | ||
*Schema dbd trigger fields. | ||
*/ | ||
SCHEMA("schema"), | ||
/** | ||
*Table dbd trigger fields. | ||
*/ | ||
TABLE("table"), | ||
/** | ||
*Trigger dbd trigger fields. | ||
*/ | ||
TRIGGER("trigger"), | ||
/** | ||
*Ddl dbd trigger fields. | ||
*/ | ||
DDL("ddl"); | ||
|
||
/** | ||
* The String encapsulated. | ||
*/ | ||
private final String text; | ||
|
||
/** | ||
* Instantiates a new Dbd trigger fields. | ||
* @param text The String to be encapsulated. | ||
*/ | ||
DbdTriggerFields(final String text) { | ||
this.text = text; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return this.text; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/org/fusionsoft/database/snapshot/objects/dbms/TriggerOfResultSet.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,78 @@ | ||
/* | ||
* Copyright (C) 2018-2021 FusionSoft | ||
* | ||
* 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 org.fusionsoft.database.snapshot.objects.dbms; | ||
|
||
import java.sql.ResultSet; | ||
import org.fusionsoft.database.mapping.dbd.DbdTriggerMapping; | ||
import org.fusionsoft.database.mapping.entries.MultilineScalarEntry; | ||
import org.fusionsoft.database.mapping.fields.DbdTriggerFields; | ||
import org.fusionsoft.database.snapshot.objects.ObjectType; | ||
import org.fusionsoft.database.snapshot.objects.SimpleDbObject; | ||
import org.fusionsoft.database.snapshot.objectsignature.FullObjectName; | ||
import org.fusionsoft.database.snapshot.objectsignature.SimpleObjectSignature; | ||
import org.fusionsoft.database.snapshot.query.Query; | ||
import org.fusionsoft.lib.text.TextOfResultSet; | ||
import org.fusionsoft.lib.yaml.MappingWithoutNullScalars; | ||
import org.fusionsoft.lib.yaml.YamlMappingOfEntries; | ||
|
||
/** | ||
* The type of {@link DbdTriggerMapping}, | ||
* can be constructed of {@link ResultSet} and {@link Query} of {@link DbdTriggerFields}. | ||
* @since 0.1 | ||
*/ | ||
public class TriggerOfResultSet extends SimpleDbObject<DbdTriggerMapping> { | ||
|
||
/** | ||
* Instantiates a new Trigger of result set. | ||
* @param rset The ResultSet to be encapsulated. | ||
* @param query The Query of {@link DbdTriggerFields} to be encapsulated. | ||
*/ | ||
public TriggerOfResultSet(final ResultSet rset, final Query<DbdTriggerFields> query) { | ||
super( | ||
new DbdTriggerMapping( | ||
new MappingWithoutNullScalars( | ||
new YamlMappingOfEntries( | ||
new MultilineScalarEntry( | ||
DbdTriggerFields.DDL, | ||
new TextOfResultSet( | ||
DbdTriggerFields.DDL, | ||
rset | ||
) | ||
) | ||
) | ||
) | ||
), | ||
new SimpleObjectSignature( | ||
new FullObjectName( | ||
new TextOfResultSet( | ||
query.outcomeFor(DbdTriggerFields.SCHEMA), | ||
rset | ||
), | ||
new TextOfResultSet( | ||
query.outcomeFor(DbdTriggerFields.TABLE), | ||
rset | ||
), | ||
new TextOfResultSet( | ||
query.outcomeFor(DbdTriggerFields.TRIGGER), | ||
rset | ||
) | ||
), | ||
ObjectType.TRIGGER | ||
) | ||
); | ||
} | ||
|
||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/org/fusionsoft/database/snapshot/query/PgTriggersQuery.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,47 @@ | ||
/* | ||
* Copyright (C) 2018-2021 FusionSoft | ||
* | ||
* 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 org.fusionsoft.database.snapshot.query; | ||
|
||
import org.fusionsoft.database.mapping.fields.DbdTriggerFields; | ||
|
||
/** | ||
* The only type of {@link PgMessageFormatQuery} of {@link DbdTriggerFields}. | ||
* @since 0.1 | ||
*/ | ||
public class PgTriggersQuery extends PgMessageFormatQuery<DbdTriggerFields> { | ||
|
||
/** | ||
* Instantiates a new Pg triggers query. | ||
*/ | ||
public PgTriggersQuery() { | ||
super( | ||
"SELECT \n" | ||
+ " ns.nspname AS {0},\n" | ||
+ " tbl.relname AS {1},\n" | ||
+ " trg.tgname AS {2},\n" | ||
+ " pg_get_triggerdef(trg.oid) AS {3} \n" | ||
+ "FROM pg_trigger trg\n" | ||
+ "JOIN pg_class tbl on trg.tgrelid = tbl.oid\n" | ||
+ "JOIN pg_namespace ns ON ns.oid = tbl.relnamespace\n" | ||
+ "and trg.tgconstraint=0", | ||
DbdTriggerFields.SCHEMA, | ||
DbdTriggerFields.TABLE, | ||
DbdTriggerFields.TRIGGER, | ||
DbdTriggerFields.DDL | ||
); | ||
} | ||
|
||
} |