module DataMetaDom
DataMeta DOM infrastructure root.
For command line details either check the new method's source or the README.rdoc file, the usage section.
Constants
- BITSET
Keyword, data type: bitset
- BOOL
Keyword, data type: boolean
- BOOL_CONV
Converter
for boolean.- CANNED_RX
keep in sync with generated classes such as the Java class `CannedRegexUtil` in DataMeta DOM Core/Java etc.
- CHAR
Keyword, data type: string with fixed length
- CONVS
All Converters hash keyed by the type, referencing an instance of the
Converter
class.- DATAMETA_LIB
Environment variable for DataMeta DOM library path.
- DATETIME
Keyword, data type: datetime
- DIMMED_TYPES
Data Types that must be dimensioned, with a length or with a length and a scale, as it includes all the
SCALE_TYPES
too..- DOC
Keyword
doc
, documentation.- DOC_TARGETS
All documentation targets
- DTTM_CONV
Converter
for datetime.- DTTM_TYPE
Reusable type -
DATETIME
, in Java projected intojava.time.ZonedDateTime
.- END_KW
Keyword, end
- ENUM
Keyword, data type, enum
- FLOAT
Keyword, data type: float (real numbers)
- FLOAT4
Reusable type - Float (Real number) of the length 4, aka Java's
float
.- FLOAT8
Reusable type - Float (Real number) of the length 8, aka Java's
double
.- FRACT_CONV
Numbers with fraction, such as real numbers, aka floating point.
- FULL_COMPARE
DataMetaSame
generation style: Full Compare, compare by all the fields defined in the class- IDENTITY
Keyword, identity
- ID_ONLY_COMPARE
DataMetaSame
generation style: Compare by the identity fields only as defined onDataMetaDom::Record
- ID_START
Valid first symbol of a DataMeta DOM idenifier such as entity or enum name, field name, enum item.
- INCLUDE
Keyword: include
- INDENT
One indent step for java classes, spaces.
- INDEX
Keyword, index
- INT
Keyword, data type: integer
- INT1
Reusable type - Integer of the length 1, aka Java's
byte
.- INT2
Reusable type - Integer of the length 2, aka Java's
short
.- INT4
Reusable type - Integer of the length 4, aka Java's
int
.- INT8
Reusable type - Integer of the length 8, aka Java's
long
.- INTEGRAL_CONV
Converter
for the integral types, meaning no fraction.- JAVA_DOC_TARGET
doc target for javadocs
- L
Logger set to WARN, daily rollover and max size 10M Feel free to change any of it.
- MAPPING
Keyword, data type: map
- MATCHES
Keyword, matches
- MODEL_LEVEL_TOKENS
DataMeta DOM source tokens on the
Model
level:- NAMESPACE
Keyword: namespace
- NO_NAMESPACE
Key to a no-namespace
- NUMERIC
Keyword, data type: numeric
- OPTIONAL_PFX
Prefix for an optional field
- OPT_DIMMABLE
Optionally dimmable types - may have a dim or may have not
- PACK_SEPARATOR
Package separator in a namespace.
- PLAIN_DOC_TARGET
doc target for plaintext
- RAW
Keyword, data type, the
RAW
type refers to raw data, like a byte array- RECORD
Keyword, record
- RECORD_LEVEL_TOKENS
An array of record level parse token classes, namely
RecIdentity
,RecIndex
,RecUnique
- REC_ATTR_KEYWORDS
Record
attribute keywords:-
identity
-
unique
-
index
-
- REQUIRED_PFX
Prefix for a required field
- SAME_FULL_SFX
Suffix for the java source files for the implementors of the DataMetaSame interface by all the fields on the class.
- SAME_ID_SFX
Suffix for the java source files for the implementors of the DataMetaSame interface by identity field(s) on the class.
- SCALE_TYPES
DataMeta DOM standard types that have a dimension with a scale
- SOURCE_INDENT
for source code generation, 2 spaces
- STANDARD_TYPES
standard types is a superset of dimmensionable types, adding
BOOL
andDATETIME
- STRING
Keyword, data type: string with variable length
- TEXT_CONV
Conterter for textual types, such as string or char.
- TYPE_START
Valid first symbol for a DataMeta DOM Type
- UNIQUE
Keyword, unique
- URL
Keyword, data type:
URL
- URL_TYPE
Reusable type -
URL
, in Java projected intojava.net.URL
.- VERSION
Current version
- VER_KW
Keyword
ver
, version info.- WIKI
Wiki for DataMeta DOM
- WIKI_REF_HTML
HTML tag referencing the
WIKI
Public Class Methods
Combines the namespace with the base name: if the namespace is empty or nil
, returns the base name as a symbol, otherwise returns namespace.base @param [String] namespace the namespace part @param [String] base the base name of the entity @return [String] base and namespace properly combined into full name specification
# File lib/dataMetaDom.rb, line 62 def combineNsBase(namespace, base) namespace && !namespace.empty? ? "#{namespace}.#{base}".to_sym : base.to_sym end
With the given full type including the namespace if any and the given namespace (java package, python package etc), figures out whether the full type has to be reference in full, if it belongs to a different namespace, or just by the base name if it belongs to the same package.
-
Parameters
-
fullType
- full data type including the namespace if any -
namespace
- reference namespace.
-
For example, passed:
"com.acme.proj.Klass", "com.acme.lib"
will return
"com.acme.proj.Klass"
but when passed:
"com.acme.proj.Klass", "com.acme.proj"
will return
"Klass"
This is to avoid excessive verbosity when referencing entities in the same package.
# File lib/dataMetaDom/util.rb, line 256 def condenseType(fullType, ref_namespace) ns, base = DataMetaDom.splitNameSpace(fullType) # noinspection RubyNestedTernaryOperatorsInspection DataMetaDom.validNs?(ns, base) ? ( ns == ref_namespace ? base : fullType) : fullType end
if name is a standard type, return it. if name is a fully qualified namespaced name, return it otherwise, combine the namespace provided with the base to return the full name
# File lib/dataMetaDom.rb, line 81 def fullTypeName(namespace, name) #noinspection RubyUnusedLocalVariable ns, _ = splitNameSpace(name.to_s) # if it is already a full namespaced name or a standard type, return original validNs?(ns, name) || STANDARD_TYPES.member?(name) ? name.to_sym : "#{combineNsBase(namespace, name)}".to_sym end
# Parses parenthesized dimension info such as (18, 2) or just (18)
Returns DimInfo::NIL if the dimSpec is nil
or the DimInfo
instance as specified
# File lib/dataMetaDom.rb, line 121 def getParenDimInfo(dimSpec) return DimInfo::NIL unless dimSpec result = dimSpec =~ /^\s*\(\s*(\d+)\s*(?:,\s*(\d+))?\s*\)\s*$/ raise "Invalid dimension specification: '#{dimSpec}'" unless result DimInfo.new($1.to_i, $2.to_i) end
Builds and returns the Java-style getter name for the given field. This style is used in other platforms such as Python, for consistency.
# File lib/dataMetaDom/util.rb, line 269 def getterName(f); "get#{DataMetaXtra::Str.capFirst(f.name.to_s)}" end
Helper method for runnables.
Prints help and exits placing the purpose of the runnable and the parameters description in proper spots.
Exits with code 0 if errorText is nil
, exits with code 1 otherwise. Prints errorText with proper dressing to the STDERR
.
# File lib/dataMetaDom/help.rb, line 13 def help(file, purpose, params, errorText = nil) puts <<HELP DataMeta DOM version #{DataMetaDom::VERSION} #{purpose}. Usage: #{File.basename(file)} #{params} HELP $stdout.flush # otherwise it may mix up with the $stderr output below $stderr.puts "\nERROR: #{errorText}" if errorText exit errorText ? 0 : 1 end
Adds options to help and version from the first argument And shortcuts to showing the help screen if the ARGV is empty. The options for help are either --help
or </tt>-h</tt>. The option for show version and exit is either --version
or -v
.
# File lib/dataMetaDom.rb, line 134 def helpAndVerFirstArg raise Trollop::HelpNeeded if ARGV.empty? || ARGV[0] == '--help' || ARGV[0] == '-h' # show help screen raise Trollop::VersionNeeded if ARGV[0] == '--version' || ARGV[0].downcase == '-v' # show version screen end
Shortcut to help for the MySQL DDL Generator.
# File lib/dataMetaDom/help.rb, line 37 def helpMySqlDdl(file, errorText=nil) help(file, 'MySQL DDL generator', '<DataMeta DOM source> <target directory>', errorText) end
Shortcut to help for the Pojo Generator.
# File lib/dataMetaDom/help.rb, line 27 def helpPojoGen(file, errorText=nil) help(file, 'POJO generator', '<DataMeta DOM source> <target directory>', errorText) end
Shortcut to help for the Pojo Generator.
# File lib/dataMetaDom/help.rb, line 32 def helpScalaGen(file, errorText=nil) help(file, 'Scala generator', '<DataMeta DOM source> <target directory>', errorText) end
adjust the namespace if required
# File lib/dataMetaDom.rb, line 51 def nsAdjustment(namespace, options, src) src && options[:autoVerNs] ? "#{namespace}.v#{src.ver.full.toVarName}" : namespace end
Builds and returns the Java-setter setter name for the given field. This style is used in other platforms such as Python, for consistency.
# File lib/dataMetaDom/util.rb, line 275 def setterName(f); "set#{DataMetaXtra::Str.capFirst(f.name.to_s)}" end
Returns an array of the namespace and the base, first element nil if no namespace both elements nil if not a proper namespace. @param [String] source source text to split @return [Array] array of String
, the namespace and the base
# File lib/dataMetaDom.rb, line 44 def splitNameSpace(source) #noinspection RubyNestedTernaryOperatorsInspection source =~ /(\w[\w\.]*)\.(#{TYPE_START}\w*)/ ? [($1.empty? ? nil : $1), $2] : (source =~ /(#{TYPE_START}\w*)/ ? [nil, source] : [nil, nil]) end
Quick and dirty turning a Windows path into a path of the platform on which this script is running. Assumes that backslash is never used as a part of a directory name, pretty safe assumption.
# File lib/dataMetaDom.rb, line 34 def uniPath(source) source.gsub(/\\/, File::SEPARATOR) end
Given the namespace and the base, returns true if the namespace is a valid one. @param [String] namespace the namespace part @param [String] base the base name of the entity @return [Boolean] true if the given namespace passes simple smell check with the given base
# File lib/dataMetaDom.rb, line 72 def validNs?(namespace, base) namespace && !namespace.empty? && namespace.to_sym != base end
Public Instance Methods
Shortcut to help for the Oracle DDL Generator.
# File lib/dataMetaDom/help.rb, line 42 def helpOracleDdl(file, errorText=nil) help(file, 'Oracle DDL generator', '<DataMeta DOM source> <target directory>', errorText) end
Migrator implementor name
# File lib/dataMetaDom/util.rb, line 263 def migrClass(base, ver1, ver2); "Migrate_#{base}_v#{ver1.toVarName}_to_v#{ver2.toVarName}" end
Returns qualified name for the given namespace: strips the namespace if the namespace is the same, or keep it
# File lib/dataMetaDom.rb, line 88 def qualName(namespace, name) ns, b = splitNameSpace(name.to_s) !STANDARD_TYPES.member?(name.to_sym) && (!validNs?(ns, b) || ns == namespace) ? b : name end
Private Instance Methods
Combines the namespace with the base name: if the namespace is empty or nil
, returns the base name as a symbol, otherwise returns namespace.base @param [String] namespace the namespace part @param [String] base the base name of the entity @return [String] base and namespace properly combined into full name specification
# File lib/dataMetaDom.rb, line 62 def combineNsBase(namespace, base) namespace && !namespace.empty? ? "#{namespace}.#{base}".to_sym : base.to_sym end
With the given full type including the namespace if any and the given namespace (java package, python package etc), figures out whether the full type has to be reference in full, if it belongs to a different namespace, or just by the base name if it belongs to the same package.
-
Parameters
-
fullType
- full data type including the namespace if any -
namespace
- reference namespace.
-
For example, passed:
"com.acme.proj.Klass", "com.acme.lib"
will return
"com.acme.proj.Klass"
but when passed:
"com.acme.proj.Klass", "com.acme.proj"
will return
"Klass"
This is to avoid excessive verbosity when referencing entities in the same package.
# File lib/dataMetaDom/util.rb, line 256 def condenseType(fullType, ref_namespace) ns, base = DataMetaDom.splitNameSpace(fullType) # noinspection RubyNestedTernaryOperatorsInspection DataMetaDom.validNs?(ns, base) ? ( ns == ref_namespace ? base : fullType) : fullType end
if name is a standard type, return it. if name is a fully qualified namespaced name, return it otherwise, combine the namespace provided with the base to return the full name
# File lib/dataMetaDom.rb, line 81 def fullTypeName(namespace, name) #noinspection RubyUnusedLocalVariable ns, _ = splitNameSpace(name.to_s) # if it is already a full namespaced name or a standard type, return original validNs?(ns, name) || STANDARD_TYPES.member?(name) ? name.to_sym : "#{combineNsBase(namespace, name)}".to_sym end
# Parses parenthesized dimension info such as (18, 2) or just (18)
Returns DimInfo::NIL if the dimSpec is nil
or the DimInfo
instance as specified
# File lib/dataMetaDom.rb, line 121 def getParenDimInfo(dimSpec) return DimInfo::NIL unless dimSpec result = dimSpec =~ /^\s*\(\s*(\d+)\s*(?:,\s*(\d+))?\s*\)\s*$/ raise "Invalid dimension specification: '#{dimSpec}'" unless result DimInfo.new($1.to_i, $2.to_i) end
Builds and returns the Java-style getter name for the given field. This style is used in other platforms such as Python, for consistency.
# File lib/dataMetaDom/util.rb, line 269 def getterName(f); "get#{DataMetaXtra::Str.capFirst(f.name.to_s)}" end
Helper method for runnables.
Prints help and exits placing the purpose of the runnable and the parameters description in proper spots.
Exits with code 0 if errorText is nil
, exits with code 1 otherwise. Prints errorText with proper dressing to the STDERR
.
# File lib/dataMetaDom/help.rb, line 13 def help(file, purpose, params, errorText = nil) puts <<HELP DataMeta DOM version #{DataMetaDom::VERSION} #{purpose}. Usage: #{File.basename(file)} #{params} HELP $stdout.flush # otherwise it may mix up with the $stderr output below $stderr.puts "\nERROR: #{errorText}" if errorText exit errorText ? 0 : 1 end
Adds options to help and version from the first argument And shortcuts to showing the help screen if the ARGV is empty. The options for help are either --help
or </tt>-h</tt>. The option for show version and exit is either --version
or -v
.
# File lib/dataMetaDom.rb, line 134 def helpAndVerFirstArg raise Trollop::HelpNeeded if ARGV.empty? || ARGV[0] == '--help' || ARGV[0] == '-h' # show help screen raise Trollop::VersionNeeded if ARGV[0] == '--version' || ARGV[0].downcase == '-v' # show version screen end
Shortcut to help for the MySQL DDL Generator.
# File lib/dataMetaDom/help.rb, line 37 def helpMySqlDdl(file, errorText=nil) help(file, 'MySQL DDL generator', '<DataMeta DOM source> <target directory>', errorText) end
Shortcut to help for the Pojo Generator.
# File lib/dataMetaDom/help.rb, line 27 def helpPojoGen(file, errorText=nil) help(file, 'POJO generator', '<DataMeta DOM source> <target directory>', errorText) end
Shortcut to help for the Pojo Generator.
# File lib/dataMetaDom/help.rb, line 32 def helpScalaGen(file, errorText=nil) help(file, 'Scala generator', '<DataMeta DOM source> <target directory>', errorText) end
adjust the namespace if required
# File lib/dataMetaDom.rb, line 51 def nsAdjustment(namespace, options, src) src && options[:autoVerNs] ? "#{namespace}.v#{src.ver.full.toVarName}" : namespace end
Builds and returns the Java-setter setter name for the given field. This style is used in other platforms such as Python, for consistency.
# File lib/dataMetaDom/util.rb, line 275 def setterName(f); "set#{DataMetaXtra::Str.capFirst(f.name.to_s)}" end
Returns an array of the namespace and the base, first element nil if no namespace both elements nil if not a proper namespace. @param [String] source source text to split @return [Array] array of String
, the namespace and the base
# File lib/dataMetaDom.rb, line 44 def splitNameSpace(source) #noinspection RubyNestedTernaryOperatorsInspection source =~ /(\w[\w\.]*)\.(#{TYPE_START}\w*)/ ? [($1.empty? ? nil : $1), $2] : (source =~ /(#{TYPE_START}\w*)/ ? [nil, source] : [nil, nil]) end
Quick and dirty turning a Windows path into a path of the platform on which this script is running. Assumes that backslash is never used as a part of a directory name, pretty safe assumption.
# File lib/dataMetaDom.rb, line 34 def uniPath(source) source.gsub(/\\/, File::SEPARATOR) end
Given the namespace and the base, returns true if the namespace is a valid one. @param [String] namespace the namespace part @param [String] base the base name of the entity @return [Boolean] true if the given namespace passes simple smell check with the given base
# File lib/dataMetaDom.rb, line 72 def validNs?(namespace, base) namespace && !namespace.empty? && namespace.to_sym != base end