public class ConfigurationFactory extends HibernateFactory
Modifier and Type | Method and Description |
---|---|
static byte[] |
bytesFromStream(java.io.InputStream stream,
java.lang.Long size)
Convert input stream to byte array
|
static void |
commit(ConfigChannel channel)
Save or update a config channel.
|
static ConfigFile |
commit(ConfigFile file)
Save or update a config file.
|
static ConfigRevision |
commit(ConfigRevision revision)
Save or update a config revision.
|
static void |
copyRevisionToChannel(User usr,
ConfigRevision revision,
ConfigChannel channel)
Copies the given config revision to the given channel.
|
static ConfigContent |
createNewContentFromStream(java.io.InputStream stream,
java.lang.Long size,
boolean isBinary,
java.lang.String delimStart,
java.lang.String delimEnd)
Creates a ConfigContent object whose BLOB is filled with the bytes from the
specified stream
|
static ConfigChannel |
createNewLocalChannel(Server server,
ConfigChannelType type)
Create a local config channel for the given server.
|
static ConfigRevision |
createNewRevisionFromStream(User usr,
java.io.InputStream stream,
java.lang.Long size,
ConfigFile file)
Creates a new revision object from the give input stream.
|
static java.lang.String |
getChannelNameDisplay(java.lang.String type,
java.lang.String channel)
Returns a localized string for the name of a config channel.
|
protected org.apache.log4j.Logger |
getLogger()
Get the Logger for the derived class so log messages show up on the
correct class
|
static java.lang.Long |
getNextRevisionForFile(ConfigFile file)
Returns new revision number for config file
|
static ConfigChannel |
lookupConfigChannelById(java.lang.Long id)
Lookup a ConfigChannel by its id
|
static ConfigChannel |
lookupConfigChannelByLabel(java.lang.String label,
Org org,
ConfigChannelType cct)
Lookup a ConfigChannel by its label.
|
static ConfigFile |
lookupConfigFileByChannelAndName(java.lang.Long channel,
java.lang.Long name)
Lookup a ConfigFile by its channel's id and config file name's id
|
static ConfigFile |
lookupConfigFileById(java.lang.Long id)
Lookup a ConfigFile by its id
|
static ConfigFileName |
lookupConfigFileNameById(java.lang.Long id)
Finds a ConfigFileName from the database with a given id.
|
static ConfigInfo |
lookupConfigInfoById(java.lang.Long id)
Finds a ConfigInfo from the database with a given id.
|
static ConfigRevision |
lookupConfigRevisionById(java.lang.Long id)
Finds a ConfigRevision from the database with a given id.
|
static ConfigRevision |
lookupConfigRevisionByRevId(ConfigFile cf,
java.lang.Long revId)
Finds a ConfigRevision for a given ConfigFile and given revision id
|
static java.util.List |
lookupConfigRevisions(ConfigFile cf)
Finds configuration revisions for a given configuration file
|
static ConfigFileName |
lookupOrInsertConfigFileName(java.lang.String path)
Return a
ConfigFileName for the path given. |
static ConfigInfo |
lookupOrInsertConfigInfo(java.lang.String username,
java.lang.String groupname,
java.lang.Long filemode,
java.lang.String selinuxCtx,
java.lang.String symlinkTargetPath)
Return a
ConfigInfo from the username, groupname, file mode, and
selinux context. |
static ConfigChannel |
newConfigChannel()
Create a new ConfigChannel object.
|
static ConfigContent |
newConfigContent()
Create a new ConfigContent object.
|
static ConfigFile |
newConfigFile()
Create a new ConfigFile object.
|
static ConfigRevision |
newConfigRevision()
Create a new ConfigRevision object.
|
static void |
removeConfigChannel(ConfigChannel channel)
Remove a ConfigChannel.
|
static void |
removeConfigFile(ConfigFile file)
Remove a ConfigFile.
|
static boolean |
removeConfigRevision(ConfigRevision revision,
java.lang.Long orgId)
Remove a ConfigRevision.
|
static void |
saveNewConfigChannel(ConfigChannel channel)
Save a new configuration channel.
|
static ConfigChannel |
saveNewConfigChannel(Org org,
ConfigChannelType type,
java.lang.String name,
java.lang.String label,
java.lang.String description)
Create and save a new configuration channel.
|
static java.lang.Long |
saveNewConfigFile(ConfigFile file)
Save a new configuration file.
|
static java.lang.Long |
saveNewConfigRevision(ConfigRevision revision)
Save a new ConfigRevision.
|
addConfigurator, blobToByteArray, byteArrayToBlob, closeSession, closeSessionFactory, commitTransaction, createSessionFactory, createSessionFactory, executeCallableMode, executeSelectMode, getBlobContents, getByteArrayContents, getObject, getSession, initialize, inTransaction, isClosed, isInitialized, listObjectsByNamedQuery, listObjectsByNamedQuery, listObjectsByNamedQuery, lockObject, lookupObjectByNamedQuery, lookupObjectByNamedQuery, reload, removeObject, rollbackTransaction, saveObject, saveObject, stringToByteArray
protected org.apache.log4j.Logger getLogger()
HibernateFactory
getLogger
in class HibernateFactory
public static ConfigFile newConfigFile()
public static ConfigRevision newConfigRevision()
public static ConfigChannel newConfigChannel()
public static ConfigContent newConfigContent()
public static ConfigChannel saveNewConfigChannel(Org org, ConfigChannelType type, java.lang.String name, java.lang.String label, java.lang.String description)
org
- The org for this configuration channel.type
- The type. Please use the constants located in this class.name
- The name of this configuration channel.label
- The label for this configuration channel.description
- The description of this configuration channel.public static void saveNewConfigChannel(ConfigChannel channel)
channel
- The channel object to persist.public static java.lang.Long saveNewConfigFile(ConfigFile file)
file
- The configuration file to persistpublic static java.lang.Long saveNewConfigRevision(ConfigRevision revision)
revision
- the new ConfigRevision we want to store.public static void commit(ConfigChannel channel)
channel
- The channel to save or updatepublic static ConfigFile commit(ConfigFile file)
file
- The file to save or updatepublic static ConfigRevision commit(ConfigRevision revision)
revision
- The revision to save or updatepublic static ConfigChannel lookupConfigChannelById(java.lang.Long id)
id
- The identifier for the ConfigChannelpublic static ConfigChannel lookupConfigChannelByLabel(java.lang.String label, Org org, ConfigChannelType cct)
label
- The label for the ConfigChannelorg
- the org to which the config channel belongs.cct
- the config channel type of the config channel.public static ConfigFile lookupConfigFileById(java.lang.Long id)
id
- The identifier for the ConfigFilepublic static ConfigFile lookupConfigFileByChannelAndName(java.lang.Long channel, java.lang.Long name)
channel
- The file's config channel idname
- The file's config file name idpublic static ConfigRevision lookupConfigRevisionById(java.lang.Long id)
id
- The identifier for the ConfigRevisionpublic static ConfigRevision lookupConfigRevisionByRevId(ConfigFile cf, java.lang.Long revId)
cf
- The ConfigFile to look for.revId
- The ConfigFile revision to look for.public static java.util.List lookupConfigRevisions(ConfigFile cf)
cf
- The ConfigFile to look for.public static ConfigInfo lookupConfigInfoById(java.lang.Long id)
id
- The identifier for the ConfigInfopublic static ConfigFileName lookupConfigFileNameById(java.lang.Long id)
id
- The identifier for the ConfigFileNamepublic static ConfigInfo lookupOrInsertConfigInfo(java.lang.String username, java.lang.String groupname, java.lang.Long filemode, java.lang.String selinuxCtx, java.lang.String symlinkTargetPath)
ConfigInfo
from the username, groupname, file mode, and
selinux context. If no corresponding entry exists yet in the database, one will be
created.
Uses the stored procedure lookup_config_info
to get the id of the
ConfigInfo and then uses hibernate to lookup using that id.
Note: we should use the stored procedure because it is autonomous and avoids race
conditions. However, we also need to make sure that hibernate knows that the object
already exists in the database. Therefore after storing it, instead of simply
creating the object in java, we ask hibernate to look it up (which will find the
correct created and modified dates as well).
ConfigInfo's have a unique constraint around username, groupname, and filemode
so we can't just create them willy nilly.username
- The linux username associated with a filegroupname
- The linux groupname associated with a filefilemode
- The three digit file mode (ex: 655)selinuxCtx
- The SELinux contextsymlinkTargetPath
- a target path for symlink or null for a non symlink pathpublic static ConfigFileName lookupOrInsertConfigFileName(java.lang.String path)
ConfigFileName
for the path given. If no corresponding
entry exists yet in the database, one will be created.
Uses the stored procedure lookup_config_filename
to get the id of the
ConfigFileName and then uses hibernate to lookup using that id.
Note: we should use the stored procedure because it is autonomous and avoids race
conditions. However, we also need to make sure that hibernate knows that the object
already exists in the database. Therefore after storing it, instead of simply
creating the object in java, we ask hibernate to look it up (which will find the
correct created and modified dates as well).
ConfigFileName's have a unique constraint around path so we can't just create
them willy nilly.path
- the path for the ConfigFileName
ConfigFileName
foundpublic static void removeConfigChannel(ConfigChannel channel)
channel
- Channel to removepublic static void removeConfigFile(ConfigFile file)
file
- Config File to removepublic static boolean removeConfigRevision(ConfigRevision revision, java.lang.Long orgId)
revision
- Revision to removeorgId
- The id for the org in which this revision is located.public static ConfigChannel createNewLocalChannel(Server server, ConfigChannelType type)
server
- The server used to help populate required fieldstype
- The type of the config channel. Either sandbox or local override.public static ConfigRevision createNewRevisionFromStream(User usr, java.io.InputStream stream, java.lang.Long size, ConfigFile file)
usr
- The user that is making the new revisionstream
- The input stream containing the content for this revision.size
- The size of the input stream to be read.file
- The parent object for this config revision.public static ConfigContent createNewContentFromStream(java.io.InputStream stream, java.lang.Long size, boolean isBinary, java.lang.String delimStart, java.lang.String delimEnd)
stream
- stream containing the contentsize
- number of bytes to readisBinary
- true if the content is to be treated as binary (which means we
won't expand macros, morph EOL, or let you edit it from the web UI)delimStart
- start delimeter or null for binarydelimEnd
- end delimeter or null for binarypublic static byte[] bytesFromStream(java.io.InputStream stream, java.lang.Long size)
stream
- input streamsize
- stream sizepublic static java.lang.Long getNextRevisionForFile(ConfigFile file)
file
- config filepublic static void copyRevisionToChannel(User usr, ConfigRevision revision, ConfigChannel channel)
usr
- The user asking for the new revisionrevision
- The revision to be copiedchannel
- The channel to be copied intopublic static java.lang.String getChannelNameDisplay(java.lang.String type, java.lang.String channel)
type
- The type of the channel (one of the labels for
CONFIG_CHANNEL_TYPE_* constants)channel
- The name of the channel, the system name for local channels.